Commits

Anonymous committed d613d50

Re-enable MANUAL/AUTO modes for deployment. Stored in project properties. It doesn't work for preferred device yet.

Comments (0)

Files changed (10)

project/src/org/netbeans/modules/android/project/AndroidActionProvider.java

 import com.google.common.collect.Maps;
 import com.google.common.collect.ObjectArrays;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import org.netbeans.modules.android.project.launch.Launches;
 import org.netbeans.modules.android.project.launch.LaunchInfo;
 import org.netbeans.modules.android.project.queries.ClassPathProviderImpl;
-import org.netbeans.modules.android.project.ui.UiUtils;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.netbeans.spi.project.ActionProvider;
 import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
 
             private void doLaunchAfterBuild(FileObject buildFo, ExecutorTask task) {
               // TODO(radim): where to get config
-              LaunchConfiguration launchConfig = Launches.forProject(project);
+              final LaunchConfiguration launchConfig = Launches.forProject(project);
 
               final DalvikPlatform platform = AndroidProjects.projectPlatform(project);
               final AndroidLauncher launcher = Preconditions.checkNotNull(
                     launcher.launch(platform,
                         Lookups.fixed(fixLaunchedAppName(launchInfo, appName, alternativeAppName), 
                             Launches.actionForProject(project), 
+                            launchConfig.getTargetMode(),
                             project),
                         command);
                   }
                       final Future<Client> future = launcher.launch(platform,
                           Lookups.fixed(fixLaunchedAppName(launchInfo, appName, alternativeAppName), 
                               Launches.actionForProject(project), 
+                              launchConfig.getTargetMode(),
                               project),
                           command);
                       if (future != null) {

project/src/org/netbeans/modules/android/project/AvdSelector.java

 import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
 import java.util.HashMap;
 import java.util.Map;
+import org.netbeans.modules.android.project.launch.LaunchConfiguration;
 import org.openide.util.Exceptions;
 
 /**
  */
 public class AvdSelector {
 
-  public static enum Mode {
-    MANUAL,
-    AUTO
-  }
-
   /**
    * A wrapper for data need to run the application.
    * {@link AvdInfo} is needed to start the emulator if it is not running yet.
     AvdInfo[] getValidAvds();
   }
 
-  private final Mode mode;
+  private final LaunchConfiguration.TargetMode mode;
   private final String prefferedAvdName;
   private final AvdManagerMock avdManager;
   private final IAndroidTarget target;
   /**
    *
    * @param mode auto or manual
-   * @param prefferedAvdName if it is auto there can a name of favoured device, null otherwise
+   * @param prefferedAvdName if it is auto there can a name of favored device, null otherwise
    * @param avdManager
    * @param target target platform to check compatibility
-   * @param adbDevices list of curently running devices from ADB
+   * @param adbDevices list of currently running devices from ADB
    */
-  public AvdSelector(Mode mode, String prefferedAvdName,
+  public AvdSelector(LaunchConfiguration.TargetMode mode, String prefferedAvdName,
       AvdManagerMock avdManager, IAndroidTarget target, IDevice[] adbDevices) {
     this.mode = mode;
     this.prefferedAvdName = prefferedAvdName;
    */
   public LaunchData selectDevice(DeviceChooser chooser) {
     LaunchData launch = null;
-    if (Mode.AUTO.equals(mode)) {
+    if (LaunchConfiguration.TargetMode.AUTO.equals(mode)) {
       launch = selectAvdName();
     }
     if (launch == null && chooser != null) {

project/src/org/netbeans/modules/android/project/launch/AndroidLauncherImpl.java

         return launch;
       }
 
-      // TODO(radim): get these from run configuration
-      AvdSelector.Mode mode = AvdSelector.Mode.MANUAL;
+      LaunchConfiguration.TargetMode mode = context.lookup(LaunchConfiguration.TargetMode.class);
+      if (mode == null) {
+        mode = LaunchConfiguration.TargetMode.AUTO;
+      }
       String targetAvd = null;
       // targetAvd = this.project.evaluator().getProperty(AndroidProjectProperties.PROP_TARGET_PREFFERED_AVD);
 

project/src/org/netbeans/modules/android/project/launch/LaunchConfiguration.java

     ACTIVITY,
     DO_NOTHING
   }
+  
+  public enum TargetMode {
+    AUTO,
+    MANUAL;
+  }
 
   private Action launchAction = Action.MAIN;
   /** Name of launched activity (only important when {@link Action#ACTIVITY} is used. */
   
   /** Build mode: debug or release. */
   private String mode = MODE_DEBUG;
+  
+  private TargetMode targetMode = TargetMode.AUTO;
 
   public Action getLaunchAction() {
     return launchAction;
     this.mode = mode;
   }
 
+  public TargetMode getTargetMode() {
+    return targetMode;
+  }
+
+  public void setTargetMode(TargetMode targetMode) {
+    this.targetMode = targetMode;
+  }
+
   @Override
   public String toString() {
     return "LaunchConfiguration{" + "launchAction=" + launchAction + 

project/src/org/netbeans/modules/android/project/launch/Launches.java

     }
     String launchAction = props.get(AndroidProjectProperties.PROP_LAUNCH_ACTION, false);
     if (launchAction == null) {
-      return configWithMode(props, new LaunchConfiguration());
+      return configWithModes(props, new LaunchConfiguration());
     }
     if (AndroidProjectProperties.LAUNCH_ACTION_DO_NOTHING.equals(launchAction)) {
-      return configWithMode(props, createLaunchConfig(LaunchConfiguration.Action.DO_NOTHING));
+      return configWithModes(props, createLaunchConfig(LaunchConfiguration.Action.DO_NOTHING));
     } else if (AndroidProjectProperties.LAUNCH_ACTION_MAIN.equals(launchAction)) {
-      return configWithMode(props, new LaunchConfiguration());
+      return configWithModes(props, new LaunchConfiguration());
     }
     LaunchConfiguration l = createLaunchConfig(LaunchConfiguration.Action.ACTIVITY);
     l.setActivityName(launchAction);
-    return configWithMode(props, l);
+    return configWithModes(props, l);
   }
   
-  private static LaunchConfiguration configWithMode(
+  private static LaunchConfiguration configWithModes(
       AuxiliaryProperties props, LaunchConfiguration c) {
     String mode = props.get(AndroidProjectProperties.PROP_LAUNCH_MODE, false);
     if (mode != null) {
       c.setMode(mode);
     }
+    String target = props.get(AndroidProjectProperties.PROP_LAUNCH_TARGET_MODE, false);
+    if (target != null) {
+      c.setTargetMode(LaunchConfiguration.TargetMode.valueOf(target));
+    }
     return c;
   }
   
     if (!LaunchConfiguration.MODE_DEBUG.equals(l.getMode())) {
       props.put(AndroidProjectProperties.PROP_LAUNCH_MODE, l.getMode(), false);
     }
+    props.put(AndroidProjectProperties.PROP_LAUNCH_TARGET_MODE, l.getTargetMode().toString(), false);
   }
 
   public static LaunchConfiguration createLaunchConfig(

project/src/org/netbeans/modules/android/project/ui/customizer/AndroidProjectProperties.java

     public static final String LAUNCH_ACTION_TEST = "test";
     /** Name of property for build mode of a launch configuration (debug/release). */
     public static final String PROP_LAUNCH_MODE = "launch.mode";
+    
+    /** Name of property to control selection of target device. */
+    public static final String PROP_LAUNCH_TARGET_MODE = "launch.target";
 
     /** Test instrumentation runner class name. */
     public static final String PROP_INSTR_RUNNER = "test.instrumentation.runner";

project/src/org/netbeans/modules/android/project/ui/customizer/CustomizerRun.form

         <Component class="javax.swing.JLabel" name="jLabelAdditionalOps">
           <Properties>
             <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
-              <ComponentRef name="additionaOps"/>
+              <ComponentRef name="additionalOps"/>
             </Property>
             <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
               <ResourceString bundle="org/netbeans/modules/android/project/ui/customizer/Bundle.properties" key="LBL_RunAdditionalOptions" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
             </Constraint>
           </Constraints>
         </Component>
-        <Component class="javax.swing.JTextField" name="additionaOps">
+        <Component class="javax.swing.JTextField" name="additionalOps">
           <Constraints>
             <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
               <GridBagConstraints gridX="1" gridY="2" gridWidth="0" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="12" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
             <Property name="text" type="java.lang.String" value="Manual"/>
             <Property name="actionCommand" type="java.lang.String" value="manual"/>
           </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="targetManualRadioActionPerformed"/>
+          </Events>
           <Constraints>
             <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
               <GridBagConstraints gridX="0" gridY="4" gridWidth="0" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
             <Property name="text" type="java.lang.String" value="Automatic"/>
             <Property name="actionCommand" type="java.lang.String" value="auto"/>
           </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="targetAutoRadioActionPerformed"/>
+          </Events>
           <Constraints>
             <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
               <GridBagConstraints gridX="0" gridY="5" gridWidth="0" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="6" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>

project/src/org/netbeans/modules/android/project/ui/customizer/CustomizerRun.java

     launchButtonGroup = new javax.swing.ButtonGroup();
     mainPanel = new javax.swing.JPanel();
     jLabelAdditionalOps = new javax.swing.JLabel();
-    additionaOps = new javax.swing.JTextField();
+    additionalOps = new javax.swing.JTextField();
     targetGroupLabel = new javax.swing.JLabel();
     targetManualRadio = new javax.swing.JRadioButton();
     targetAutoRadio = new javax.swing.JRadioButton();
 
     mainPanel.setLayout(new java.awt.GridBagLayout());
 
-    jLabelAdditionalOps.setLabelFor(additionaOps);
+    jLabelAdditionalOps.setLabelFor(additionalOps);
     org.openide.awt.Mnemonics.setLocalizedText(jLabelAdditionalOps, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_RunAdditionalOptions")); // NOI18N
     gridBagConstraints = new java.awt.GridBagConstraints();
     gridBagConstraints.gridx = 0;
     gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
     gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
     gridBagConstraints.insets = new java.awt.Insets(0, 12, 5, 0);
-    mainPanel.add(additionaOps, gridBagConstraints);
+    mainPanel.add(additionalOps, gridBagConstraints);
 
     org.openide.awt.Mnemonics.setLocalizedText(targetGroupLabel, "Target Device");
     gridBagConstraints = new java.awt.GridBagConstraints();
     targetButtonGroup.add(targetManualRadio);
     org.openide.awt.Mnemonics.setLocalizedText(targetManualRadio, "Manual");
     targetManualRadio.setActionCommand("manual");
+    targetManualRadio.addActionListener(new java.awt.event.ActionListener() {
+      public void actionPerformed(java.awt.event.ActionEvent evt) {
+        targetManualRadioActionPerformed(evt);
+      }
+    });
     gridBagConstraints = new java.awt.GridBagConstraints();
     gridBagConstraints.gridx = 0;
     gridBagConstraints.gridy = 4;
     targetButtonGroup.add(targetAutoRadio);
     org.openide.awt.Mnemonics.setLocalizedText(targetAutoRadio, "Automatic");
     targetAutoRadio.setActionCommand("auto");
+    targetAutoRadio.addActionListener(new java.awt.event.ActionListener() {
+      public void actionPerformed(java.awt.event.ActionEvent evt) {
+        targetAutoRadioActionPerformed(evt);
+      }
+    });
     gridBagConstraints = new java.awt.GridBagConstraints();
     gridBagConstraints.gridx = 0;
     gridBagConstraints.gridy = 5;
     updateLaunchConfig();
   }//GEN-LAST:event_radioLaunchMainActionPerformed
 
+  private void targetManualRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_targetManualRadioActionPerformed
+    updateLaunchConfig();
+  }//GEN-LAST:event_targetManualRadioActionPerformed
+
+  private void targetAutoRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_targetAutoRadioActionPerformed
+    updateLaunchConfig();
+  }//GEN-LAST:event_targetAutoRadioActionPerformed
+
   // Variables declaration - do not modify//GEN-BEGIN:variables
-  private javax.swing.JTextField additionaOps;
+  private javax.swing.JTextField additionalOps;
   private javax.swing.JLabel avdLabel;
   private org.netbeans.modules.android.core.ui.AvdUISelector avdUISelector;
   private javax.swing.JComboBox comboLaunchActivity;
         }
       }
     }
+    switch (launchConfig.getTargetMode()) {
+      case AUTO:
+        targetAutoRadio.setSelected(true);
+        break;
+      case MANUAL:
+        targetManualRadio.setSelected(true);
+        break;
+      default:
+        throw new AssertionError();
+    }
   }
 
   private void updateLaunchConfig() {
       launchConfig.setActivityName(
           (String) comboLaunchActivity.getModel().getSelectedItem());
     }
+    if (targetAutoRadio.isSelected()) {
+      launchConfig.setTargetMode(LaunchConfiguration.TargetMode.AUTO);
+    } else if (targetManualRadio.isSelected()) {
+      launchConfig.setTargetMode(LaunchConfiguration.TargetMode.MANUAL);
+    }
   }
 }

project/test/unit/src/org/netbeans/modules/android/project/AvdSelectorTest.java

 
 package org.netbeans.modules.android.project;
 
+import org.netbeans.modules.android.project.launch.LaunchConfiguration;
 import com.android.ddmlib.IDevice;
 import com.android.prefs.AndroidLocation.AndroidLocationException;
 import com.android.sdklib.IAndroidTarget;
     AvdSelector.AvdManagerMock avdManager = new TestAvdManager(
         target, new AvdInfo(MY_AVD, "path", "targetHash", target, null));
     when(target.canRunOn(target)).thenReturn(Boolean.TRUE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, MY_AVD, avdManager, target, null);
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, MY_AVD, avdManager, target, null);
     LaunchData launch = s.selectAvdName();
     assertEquals(MY_AVD, launch.getAvdInfo().getName());
   }
     AvdSelector.AvdManagerMock avdManager = new TestAvdManager(
         target, new AvdInfo(MY_AVD, "path", "targetHash", target, null));
     when(target.canRunOn(target)).thenReturn(Boolean.TRUE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, null, avdManager, target, null);
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, null, avdManager, target, null);
     LaunchData launch = s.selectAvdName();
     assertEquals(MY_AVD, launch.getAvdInfo().getName());
   }
         new AvdInfo(MY_AVD, "path", "targetHash", target, null));
     when(target.canRunOn(target)).thenReturn(Boolean.TRUE);
     when(target.canRunOn(incompatibleTarget)).thenReturn(Boolean.FALSE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, null, avdManager, target, null);
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, null, avdManager, target, null);
     LaunchData launch = s.selectAvdName();
     assertEquals(MY_AVD, launch.getAvdInfo().getName());
   }
         new AvdInfo(BAD_AVD, "path", "targetHash", incompatibleTarget, null));
     when(target.canRunOn(compatibleTarget)).thenReturn(Boolean.TRUE);
     when(target.canRunOn(incompatibleTarget)).thenReturn(Boolean.FALSE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, null, avdManager, target, null);
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, null, avdManager, target, null);
     LaunchData launch = s.selectAvdName();
     assertEquals(MY_AVD, launch.getAvdInfo().getName());
   }
     final IAndroidTarget target = mock(IAndroidTarget.class);
     AvdSelector.AvdManagerMock avdManager = new TestAvdManager(
         target);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, null, avdManager, target, null);
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, null, avdManager, target, null);
 
     LaunchData launch = s.selectAvdName();
     assertNull(launch);
     AvdSelector.AvdManagerMock avdManager = new TestAvdManager(
         target, new AvdInfo(MY_AVD, "path", "targetHash", target, null));
     when(target.canRunOn(target)).thenReturn(Boolean.TRUE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, MY_AVD, avdManager, target,
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, MY_AVD, avdManager, target,
         new IDevice[] { phone, emulator });
 
     LaunchData launch = s.selectAvdName();
     AvdSelector.AvdManagerMock avdManager = new TestAvdManager(
         target, new AvdInfo(MY_AVD, "path", "targetHash", target, null));
     when(target.canRunOn(target)).thenReturn(Boolean.TRUE);
-    AvdSelector s = new AvdSelector(AvdSelector.Mode.AUTO, null, avdManager, target,
+    AvdSelector s = new AvdSelector(LaunchConfiguration.TargetMode.AUTO, null, avdManager, target,
         new IDevice[] { phone, emulator });
 
     LaunchData launch = s.selectAvdName();

project/test/unit/src/org/netbeans/modules/android/project/launch/LaunchesTest.java

   }
   
   @Test
+  public void targetModes() {
+    AndroidProject p = mock(AndroidProject.class);
+    Map<String, String> props = Maps.newHashMap();
+    AuxiliaryProperties aprops = new APImpl(props);
+    when(p.getLookup()).thenReturn(Lookups.fixed(aprops));
+    
+    LaunchConfiguration result = Launches.forProject(p);
+    assertNotNull(result);
+    assertEquals(LaunchConfiguration.MODE_DEBUG, result.getMode());
+    
+    props.put(AndroidProjectProperties.PROP_LAUNCH_TARGET_MODE, LaunchConfiguration.TargetMode.AUTO.toString());
+    result = Launches.forProject(p);
+    assertNotNull(result);
+    assertEquals(LaunchConfiguration.TargetMode.AUTO, result.getTargetMode());
+    
+    props.put(AndroidProjectProperties.PROP_LAUNCH_TARGET_MODE, LaunchConfiguration.TargetMode.MANUAL.toString());
+    result = Launches.forProject(p);
+    assertNotNull(result);
+    assertEquals(LaunchConfiguration.TargetMode.MANUAL, result.getTargetMode());
+  }
+  
+  @Test
   public void saveLaunchConfig() {
     LaunchConfiguration c = new LaunchConfiguration();
     c.setMode(LaunchConfiguration.MODE_RELEASE);
     assertEquals(LaunchConfiguration.MODE_RELEASE, result.getMode());
   }
   
+  @Test
+  public void saveLaunchConfig_targetMode() {
+    LaunchConfiguration c = new LaunchConfiguration();
+    c.setTargetMode(LaunchConfiguration.TargetMode.MANUAL);
+    
+    AndroidProject p = mock(AndroidProject.class);
+    Map<String, String> props = Maps.newHashMap();
+    AuxiliaryProperties aprops = new APImpl(props);
+    when(p.getLookup()).thenReturn(Lookups.fixed(aprops));
+    
+    Launches.saveProject(p, c);
+    LaunchConfiguration result = Launches.forProject(p);
+    assertNotNull(result);
+    assertEquals(LaunchConfiguration.TargetMode.MANUAL, result.getTargetMode());
+  }
+  
   private static class APImpl implements AuxiliaryProperties {
 
     private Map<String, String> props;