# HG changeset patch # Parent 55d28f1831dcec71059748a991e86bccf76c4048 (#183455) Multiple Maven Runtimes support diff --git a/maven/src/org/netbeans/modules/maven/api/customizer/support/CheckBoxUpdater.java b/maven/src/org/netbeans/modules/maven/api/customizer/support/CheckBoxUpdater.java --- a/maven/src/org/netbeans/modules/maven/api/customizer/support/CheckBoxUpdater.java +++ b/maven/src/org/netbeans/modules/maven/api/customizer/support/CheckBoxUpdater.java @@ -74,7 +74,7 @@ inherited = false; component.setFont(component.getFont().deriveFont(Font.BOLD)); - component.setToolTipText(""); //NOI18N + component.setToolTipText(null); } else { component.setToolTipText(NbBundle.getMessage(CheckBoxUpdater.class, "MSG_Value_Inherited")); //NOI18N inherited = true; @@ -103,7 +103,7 @@ private void setCheckBoxValue(Boolean value, boolean defValue, JCheckBox component) { if (value != null) { component.setSelected(value.booleanValue()); - component.setToolTipText(""); //NOI18N + component.setToolTipText(null); inherited = false; component.setFont(component.getFont().deriveFont(Font.BOLD)); } else { diff --git a/maven/src/org/netbeans/modules/maven/api/customizer/support/ComboBoxUpdater.java b/maven/src/org/netbeans/modules/maven/api/customizer/support/ComboBoxUpdater.java --- a/maven/src/org/netbeans/modules/maven/api/customizer/support/ComboBoxUpdater.java +++ b/maven/src/org/netbeans/modules/maven/api/customizer/support/ComboBoxUpdater.java @@ -79,7 +79,7 @@ // component.setBackground(DEFAULT); label.setFont(label.getFont().deriveFont(Font.BOLD)); - component.setToolTipText(""); //NOI18N + component.setToolTipText(null); } @SuppressWarnings("unchecked") T val = (T)component.getSelectedItem(); @@ -114,7 +114,7 @@ private void setComboValue(T value, T projectValue, JComboBox field) { if (value != null) { field.setSelectedItem(value); - component.setToolTipText(""); //NOI18N + component.setToolTipText(null); inherited = false; label.setFont(label.getFont().deriveFont(Font.BOLD)); } else if (projectValue != null) { @@ -125,7 +125,7 @@ inherited = true; } else { field.setSelectedItem(field.getModel().getElementAt(0)); - component.setToolTipText(""); //NOI18N + component.setToolTipText(null); inherited = false; label.setFont(label.getFont().deriveFont(Font.BOLD)); } diff --git a/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java b/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java --- a/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java +++ b/maven/src/org/netbeans/modules/maven/execute/MavenCommandLineExecutor.java @@ -56,7 +56,9 @@ import java.net.URL; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; @@ -419,6 +421,14 @@ builder.environment().put(env, val); display.append(Utilities.escapeParameters(new String[] {env + "=" + val})).append(' '); // NOI18N } + for (Iterator> it = builder.environment().entrySet().iterator(); it.hasNext(); ) { + Entry entry = it.next(); + if ("M2_HOME".equals(entry.getKey())) { + // M2_HOME must be filtered when 2.x being used and 3.x on the PATH + it.remove(); + continue; + } + } List command = builder.command(); display.append(Utilities.escapeParameters(command.toArray(new String[command.size()]))); printGray(ioput, display.toString()); diff --git a/maven/src/org/netbeans/modules/maven/options/Bundle.properties b/maven/src/org/netbeans/modules/maven/options/Bundle.properties --- a/maven/src/org/netbeans/modules/maven/options/Bundle.properties +++ b/maven/src/org/netbeans/modules/maven/options/Bundle.properties @@ -43,15 +43,14 @@ TIP_Maven_Category=Set default Maven execution options. SettingsPanel.btnIndex.text=Index &Now -SettingsPanel.lblLocalRepository.text=&Local Repository \: +SettingsPanel.lblLocalRepository.text=&Local Repository: SettingsPanel.btnLocalRepository.text=&Browse... SettingsPanel.lblIndex.text=&Index Update Frequency\: SettingsPanel.cbSnapshots.text=Include &Snapshots In Local Index TIT_Select=Select Local Repository Location -SettingsPanel.lblCommandLine.text=&Maven Home : +SettingsPanel.lblCommandLine.text=&Maven Home: TIT_Select2=Select Maven Installation Location -SettingsPanel.btnCommandLine.text=&Browse... SettingsPanel.btnGoals.text=Edit &Global Custom Goal Definitions... TIT_Global=Global Maven Goal definitions ACSD_Global=Global Maven Goal definitions @@ -62,14 +61,14 @@ FREQ_Always=On every startup FREQ_Never=Never ERR_Wrong_Settings_file=Cannot parse the ~/.m2/settings.xml file, any options related to that file will be disabled. -SettingsPanel.lblOptions.text=Global Execution &Options : +SettingsPanel.lblOptions.text=Global Execution &Options: SettingsPanel.btnOptions.text=&Add GlobalOptionsPanel.lblOptions.text=&Global Execution Options : -SettingsPanel.lblBinaries.text=&Download Binaries : +SettingsPanel.lblBinaries.text=&Download Binaries: SettingsPanel.jLabel3.text=Please note that setting any of these to values other than "Never" can make opening projects significantly slower. On_Project_Open=Dependency Download Strategy -SettingsPanel.lblSource.text=Check &Sources : -SettingsPanel.lblJavadoc.text=Check &Javadoc : +SettingsPanel.lblSource.text=Check &Sources: +SettingsPanel.lblJavadoc.text=Check &Javadoc: txt_default_repository= WORK_OFFLINE=Work offline. PRODUCE_EXECUTION_DEBUG_OUTPUT=Produce execution debug output. @@ -85,9 +84,12 @@ FORCES_A_CHECK=Forces a check for updated releases and snapshots on remote repositories. DON'T_USE_PLUGIN-REGISTRY=Don't use ~/.m2/plugin-registry.xml for plugin versions TIT_Add_Globals=Add Global Option(s) -SettingsPanel.jLabel1.text=Dependency Download Strategy : +SettingsPanel.jLabel1.text=Dependency Download Strategy: TIT_NEVER=Never TIT_EVERY=Every Project Open TIT_FIRST=First Project Open Only SettingsPanel.cbSkipTests.text=Skip &Tests for any build executions not directly related to testing -SettingsPanel.btnDefault.text=Default +MAVEN_RUNTIME_Embedded=Embedded +MAVEN_RUNTIME_External={0} +MAVEN_RUNTIME_Browse=Browse... +MAVEN_RUNTIME_ClearUserDefines=Clear User-Defined Maven Runtimes diff --git a/maven/src/org/netbeans/modules/maven/options/MyJTextField.java b/maven/src/org/netbeans/modules/maven/options/JHintedTextField.java rename from maven/src/org/netbeans/modules/maven/options/MyJTextField.java rename to maven/src/org/netbeans/modules/maven/options/JHintedTextField.java --- a/maven/src/org/netbeans/modules/maven/options/MyJTextField.java +++ b/maven/src/org/netbeans/modules/maven/options/JHintedTextField.java @@ -50,7 +50,7 @@ * * @author mkleint */ -public class MyJTextField extends JTextField { +public class JHintedTextField extends JTextField { Color origForeground; String origText = ""; @@ -75,7 +75,7 @@ } }; - public MyJTextField() { + public JHintedTextField() { addFocusListener(listener); } diff --git a/maven/src/org/netbeans/modules/maven/options/MavenSettings.java b/maven/src/org/netbeans/modules/maven/options/MavenSettings.java --- a/maven/src/org/netbeans/modules/maven/options/MavenSettings.java +++ b/maven/src/org/netbeans/modules/maven/options/MavenSettings.java @@ -42,6 +42,7 @@ package org.netbeans.modules.maven.options; +import com.sun.tools.javac.resources.version; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils; import java.io.File; @@ -49,6 +50,9 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Properties; import java.util.logging.Logger; import java.util.prefs.BackingStoreException; @@ -59,6 +63,7 @@ import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; import org.openide.modules.InstalledFileLocator; +import org.openide.util.NbBundle; import org.openide.util.NbPreferences; /** @@ -76,6 +81,7 @@ public static final String PROP_LAST_ARCHETYPE_GROUPID = "lastArchetypeGroupId"; //NOI18N public static final String PROP_CUSTOM_LOCAL_REPOSITORY = "localRepository"; //NOI18N public static final String PROP_SKIP_TESTS = "skipTests"; //NOI18N + public static final String PROP_MAVEN_RUNTIMES = "mavenRuntimes"; //NOI18N //these are from former versions (6.5) and are here only for conversion private static final String PROP_DEBUG = "showDebug"; // NOI18N @@ -84,7 +90,6 @@ private static final String PROP_PLUGIN_POLICY = "pluginUpdatePolicy"; //NOI18N private static final String PROP_FAILURE_BEHAVIOUR = "failureBehaviour"; //NOI18N private static final String PROP_USE_REGISTRY = "usePluginRegistry"; //NOI18N - private static final MavenSettings INSTANCE = new MavenSettings(); @@ -288,6 +293,7 @@ public boolean isShowRunDialog(){ return getPreferences().getBoolean(PROP_SHOW_RUN_DIALOG, false); } + public void setShowRunDialog(boolean b){ getPreferences().putBoolean(PROP_SHOW_RUN_DIALOG, b); } @@ -390,5 +396,93 @@ } return null; } + + private static List searchMavenRuntimes(String[] paths, boolean stopOnFirstValid) { + List runtimes = new ArrayList(); + for (String path : paths) { + File file = new File(path); + path = FileUtil.normalizeFile(file).getAbsolutePath(); + String version = getCommandLineMavenVersion(new File(path)); + if (version != null) { + runtimes.add(path); + if (stopOnFirstValid) { + break; + } + } + } + + return runtimes; + } + + /** + * Searches for Maven Runtimes by the environment settings and returns the first valid one. + * + *

It searches in this order: + *

    + *
  • MAVEN_HOME
  • + *
  • M2_HOME
  • + *
  • PATH
+ *

+ *

Only the first appereance will be appended.

+ * + * @returns the default external Maven runtime on the path. + */ + public static String getDefaultExternalMavenRuntime() { + String paths = System.getenv("PATH"); // NOI18N + String mavenHome = System.getenv("MAVEN_HOME"); // NOI18N + String m2Home = System.getenv("M2_HOME"); // NOI18N + + List mavenEnvDirs = new ArrayList(); + if (mavenHome != null) { + mavenEnvDirs.add(mavenHome); + } + if (m2Home != null) { + mavenEnvDirs.add(m2Home); + } + if (paths != null) { + for (String path : paths.split(File.pathSeparator)) { + if (!path.endsWith("bin")) { // NOI18N + continue; + } + + mavenEnvDirs.add(path.substring(0, + path.length() - "bin".length() - File.pathSeparator.length())); + } + } + + List runtimes = searchMavenRuntimes(mavenEnvDirs.toArray(new String[0]), true); + return !runtimes.isEmpty() ? runtimes.get(0) : null; + } + + public List getUserDefinedMavenRuntimes() { + List runtimes = new ArrayList(); + + String defaultRuntimePath = getDefaultExternalMavenRuntime(); + String runtimesPref = getPreferences().get(PROP_MAVEN_RUNTIMES, null); + if (runtimesPref != null) { + for (String runtimePath : runtimesPref.split(File.pathSeparator)) { + if (!"".equals(runtimePath) && !runtimePath.equals(defaultRuntimePath)) { + runtimes.add(runtimePath); + } + } + } + + return Collections.unmodifiableList(runtimes); + } + + public void setMavenRuntimes(List runtimes) { + if (runtimes == null) { + getPreferences().remove(PROP_MAVEN_RUNTIMES); + } else { + String runtimesPref = ""; + for (String path : runtimes) { + runtimesPref += path + File.pathSeparator; + } + if (runtimesPref.endsWith(File.pathSeparator)) { + runtimesPref = runtimesPref.substring(0, runtimesPref.length() - 1); + } + putProperty(PROP_MAVEN_RUNTIMES, runtimesPref); + } + } } diff --git a/maven/src/org/netbeans/modules/maven/options/SettingsPanel.form b/maven/src/org/netbeans/modules/maven/options/SettingsPanel.form --- a/maven/src/org/netbeans/modules/maven/options/SettingsPanel.form +++ b/maven/src/org/netbeans/modules/maven/options/SettingsPanel.form @@ -25,7 +25,7 @@ - + @@ -33,23 +33,16 @@ - + - - - - - - - - + - - - - - + + + + + @@ -58,6 +51,10 @@ + + + + @@ -77,13 +74,13 @@ - + - + @@ -93,9 +90,7 @@ - - - + @@ -142,7 +137,7 @@ - + @@ -155,28 +150,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -214,7 +187,7 @@ - + @@ -319,5 +292,12 @@ + + + + + + + diff --git a/maven/src/org/netbeans/modules/maven/options/SettingsPanel.java b/maven/src/org/netbeans/modules/maven/options/SettingsPanel.java --- a/maven/src/org/netbeans/modules/maven/options/SettingsPanel.java +++ b/maven/src/org/netbeans/modules/maven/options/SettingsPanel.java @@ -47,6 +47,7 @@ import java.awt.event.ActionListener; import java.io.File; import java.io.StringReader; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.swing.BorderFactory; @@ -54,10 +55,12 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; import javax.swing.JFileChooser; +import javax.swing.JLabel; import javax.swing.JList; +import javax.swing.JSeparator; import javax.swing.ListCellRenderer; import javax.swing.SwingUtilities; -import javax.swing.event.DocumentEvent; +import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentListener; import org.netbeans.modules.maven.TextValueCompleter; import org.netbeans.modules.maven.indexer.api.RepositoryIndexer; @@ -86,12 +89,52 @@ */ public class SettingsPanel extends javax.swing.JPanel { private static final String CP_SELECTED = "wasSelected"; //NOI18N + private static final String SEPARATOR = "SEPARATOR"; + private static final String EMBEDDED_RUNTIME_VERSION = + MavenSettings.getCommandLineMavenVersion(MavenSettings.getDefaultMavenHome()); + private static final int RUNTIME_COUNT_LIMIT = 5; private boolean changed; private boolean valid; private ActionListener listener; private DocumentListener docList; private MavenOptionController controller; private TextValueCompleter completer; + private ActionListener listItemChangedListener; + private List userDefinedMavenRuntimes = new ArrayList(); + private List predefinedRuntimes = new ArrayList(); + private DefaultComboBoxModel mavenHomeDataModel = new DefaultComboBoxModel(); + private String mavenRuntimeHome = null; + private int lastSelected = -1; + + private class ComboBoxRenderer extends JLabel implements ListCellRenderer { + + private JSeparator separator; + + public ComboBoxRenderer() { + setOpaque(true); + setBorder(new EmptyBorder(1, 1, 1, 1)); + separator = new JSeparator(JSeparator.HORIZONTAL); + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + if (SEPARATOR.equals(value)) { + return separator; + } + if (isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + + setFont(list.getFont()); + setText(value.toString()); + return this; + } + }; /** Creates new form SettingsPanel */ SettingsPanel(MavenOptionController controller) { @@ -101,6 +144,7 @@ comBinaries.setModel(new DefaultComboBoxModel(downloads)); comJavadoc.setModel(new DefaultComboBoxModel(downloads)); comSource.setModel(new DefaultComboBoxModel(downloads)); + comMavenHome.setModel(mavenHomeDataModel); ListCellRenderer rend = new DefaultListCellRenderer() { @Override @@ -119,21 +163,57 @@ comBinaries.setRenderer(rend); comSource.setRenderer(rend); comJavadoc.setRenderer(rend); + comMavenHome.setRenderer(new ComboBoxRenderer()); this.controller = controller; - docList = new DocumentListener() { - public void insertUpdate(DocumentEvent e) { - documentChanged(e); - } - public void removeUpdate(DocumentEvent e) { - documentChanged(e); - } - public void changedUpdate(DocumentEvent e) { - documentChanged(e); + listItemChangedListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (SEPARATOR.equals(comMavenHome.getSelectedItem())) { + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + int selected = comMavenHome.getSelectedIndex(); + if (selected == mavenHomeDataModel.getSize() - 1) { + // clear all user defined runtimes + if (userDefinedMavenRuntimes.isEmpty()) { + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + int count = userDefinedMavenRuntimes.size() + 1; + userDefinedMavenRuntimes.clear(); + for (int i = 0; i < count; ++i) { + mavenHomeDataModel.removeElementAt(predefinedRuntimes.size()); + } + + lastSelected = 0; + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + if (selected == mavenHomeDataModel.getSize() - 2) { + // browse + comMavenHome.setSelectedIndex(lastSelected); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + browseAddNewRuntime(); + } + + }); + return; + } + + listDataChanged(); + lastSelected = selected; } }; initValues(); - ((MyJTextField)txtLocalRepository).setHintText(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "txt_default_repository")); + ((JHintedTextField)txtLocalRepository).setHintText(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "txt_default_repository")); listener = new ActionListenerImpl(); cbSnapshots.addActionListener(listener); comIndex.addActionListener(listener); @@ -179,43 +259,64 @@ return Arrays.asList(AVAILABLE_OPTIONS); } - private void initExternalVersion() - { - String path = txtCommandLine.getText().trim(); - File root = new File(path); - String version = MavenSettings.getCommandLineMavenVersion(root); - if (version != null) { - lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion2", version)); - } else { - //add red color.. - lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "ERR_NoValidInstallation")); - } - } - private void initValues() { comIndex.setSelectedIndex(0); cbSnapshots.setSelected(true); } - private void documentChanged(DocumentEvent e) { + private String getSelectedRuntime(int selected) { + if (selected < 0) { + return null; + } + + if (selected < predefinedRuntimes.size()) { + return predefinedRuntimes.get(selected); + + } else if (!userDefinedMavenRuntimes.isEmpty() && + selected - predefinedRuntimes.size() <= userDefinedMavenRuntimes.size()) { + return userDefinedMavenRuntimes.get(selected - 1 - predefinedRuntimes.size()); + } + + return null; + } + + private void listDataChanged() { changed = true; boolean oldvalid = valid; - if (txtCommandLine.getText().trim().length() > 0) { - File fil = new File(txtCommandLine.getText()); + int selected = comMavenHome.getSelectedIndex(); + String path = getSelectedRuntime(selected); + if (path != null) { + path = path.trim(); + if ("".equals(path)) { + path = null; + valid = true; + lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion2", EMBEDDED_RUNTIME_VERSION)); + } + } + + if (path != null) { + path = path.trim(); + File fil = new File(path); + String ver = null; if (fil.exists() && new File(fil, "bin" + File.separator + "mvn").exists()) { //NOI18N + ver = MavenSettings.getCommandLineMavenVersion(new File(path)); + } + + if (ver != null) { + lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion2", ver)); valid = true; + } else { - valid = false; + lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "ERR_NoValidInstallation")); } - } else { - valid = true; } + + mavenRuntimeHome = path; if (oldvalid != valid) { controller.firePropChange(MavenOptionController.PROP_VALID, Boolean.valueOf(oldvalid), Boolean.valueOf(valid)); } - initExternalVersion(); } - + private ComboBoxModel createComboModel() { return new DefaultComboBoxModel( new String[] { @@ -238,16 +339,13 @@ bgPlugins = new javax.swing.ButtonGroup(); bgFailure = new javax.swing.ButtonGroup(); lblCommandLine = new javax.swing.JLabel(); - txtCommandLine = new javax.swing.JTextField(); - btnCommandLine = new javax.swing.JButton(); - btnDefault = new javax.swing.JButton(); lblExternalVersion = new javax.swing.JLabel(); lblOptions = new javax.swing.JLabel(); txtOptions = new javax.swing.JTextField(); btnOptions = new javax.swing.JButton(); cbSkipTests = new javax.swing.JCheckBox(); lblLocalRepository = new javax.swing.JLabel(); - txtLocalRepository = new MyJTextField(); + txtLocalRepository = new org.netbeans.modules.maven.options.JHintedTextField(); btnLocalRepository = new javax.swing.JButton(); lblBinaries = new javax.swing.JLabel(); comBinaries = new javax.swing.JComboBox(); @@ -262,23 +360,10 @@ comIndex = new javax.swing.JComboBox(); btnIndex = new javax.swing.JButton(); cbSnapshots = new javax.swing.JCheckBox(); + comMavenHome = new javax.swing.JComboBox(); org.openide.awt.Mnemonics.setLocalizedText(lblCommandLine, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblCommandLine.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(btnCommandLine, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnCommandLine.text")); // NOI18N - btnCommandLine.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnCommandLineActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(btnDefault, NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnDefault.text")); // NOI18N - btnDefault.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnDefaultActionPerformed(evt); - } - }); - org.openide.awt.Mnemonics.setLocalizedText(lblOptions, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblOptions.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(btnOptions, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnOptions.text")); // NOI18N @@ -347,25 +432,22 @@ .add(lblLocalRepository)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(txtCommandLine, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(btnCommandLine) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(btnDefault)) - .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE) + .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(comSource, 0, 387, Short.MAX_VALUE) - .add(comJavadoc, 0, 387, Short.MAX_VALUE) - .add(comBinaries, 0, 387, Short.MAX_VALUE) - .add(txtLocalRepository, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE) - .add(txtOptions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)) + .add(comSource, 0, 404, Short.MAX_VALUE) + .add(comJavadoc, 0, 404, Short.MAX_VALUE) + .add(comBinaries, 0, 404, Short.MAX_VALUE) + .add(txtLocalRepository, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE) + .add(txtOptions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(btnLocalRepository) .add(btnOptions))) - .add(cbSkipTests))) + .add(cbSkipTests) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(comMavenHome, 0, 402, Short.MAX_VALUE) + .add(122, 122, 122)))) .add(jLabel1) .add(layout.createSequentialGroup() .add(12, 12, 12) @@ -381,13 +463,13 @@ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(cbSnapshots) - .add(comIndex, 0, 396, Short.MAX_VALUE)) + .add(comIndex, 0, 421, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnIndex))) .addContainerGap()) ); - layout.linkSize(new java.awt.Component[] {btnCommandLine, btnIndex, btnLocalRepository, btnOptions}, org.jdesktop.layout.GroupLayout.HORIZONTAL); + layout.linkSize(new java.awt.Component[] {btnIndex, btnLocalRepository, btnOptions}, org.jdesktop.layout.GroupLayout.HORIZONTAL); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -395,9 +477,7 @@ .add(6, 6, 6) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblCommandLine) - .add(txtCommandLine, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(btnDefault) - .add(btnCommandLine)) + .add(comMavenHome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(18, 18, 18) @@ -437,7 +517,7 @@ .add(comIndex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbSnapshots) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(23, Short.MAX_VALUE)) ); }// //GEN-END:initComponents @@ -465,7 +545,7 @@ chooser.setDialogTitle(NbBundle.getMessage(SettingsPanel.class, "TIT_Select")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setFileHidingEnabled(false); - String path = ((MyJTextField)txtLocalRepository).getRealText(); + String path = ((JHintedTextField)txtLocalRepository).getRealText(); if (path.trim().length() == 0) { path = new File(System.getProperty("user.home"), ".m2").getAbsolutePath(); //NOI18N } @@ -477,33 +557,10 @@ } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); - ((MyJTextField)txtLocalRepository).setRealText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); + ((JHintedTextField)txtLocalRepository).setRealText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } }//GEN-LAST:event_btnLocalRepositoryActionPerformed - private void btnCommandLineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCommandLineActionPerformed - JFileChooser chooser = new JFileChooser(); - FileUtil.preventFileChooserSymlinkTraversal(chooser, null); - chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "TIT_Select2")); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setFileHidingEnabled(false); - String path = txtCommandLine.getText(); - if (path.trim().length() == 0) { - path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N - } - if (path.length() > 0) { - File f = new File(path); - if (f.exists()) { - chooser.setSelectedFile(f); - } - } - if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { - File projectDir = chooser.getSelectedFile(); - txtCommandLine.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); - } - - }//GEN-LAST:event_btnCommandLineActionPerformed - private void btnGoalsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoalsActionPerformed NbGlobalActionGoalProvider provider = null; for (MavenActionsProvider prov : Lookup.getDefault().lookupAll(MavenActionsProvider.class)) { @@ -538,18 +595,12 @@ } }//GEN-LAST:event_btnOptionsActionPerformed - - private void btnDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDefaultActionPerformed - txtCommandLine.setText(MavenSettings.getDefaultMavenHome().getAbsolutePath()); - }//GEN-LAST:event_btnDefaultActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup bgChecksums; private javax.swing.ButtonGroup bgFailure; private javax.swing.ButtonGroup bgPlugins; - private javax.swing.JButton btnCommandLine; - private javax.swing.JButton btnDefault; private javax.swing.JButton btnGoals; private javax.swing.JButton btnIndex; private javax.swing.JButton btnLocalRepository; @@ -559,6 +610,7 @@ private javax.swing.JComboBox comBinaries; private javax.swing.JComboBox comIndex; private javax.swing.JComboBox comJavadoc; + private javax.swing.JComboBox comMavenHome; private javax.swing.JComboBox comSource; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; @@ -570,23 +622,96 @@ private javax.swing.JLabel lblLocalRepository; private javax.swing.JLabel lblOptions; private javax.swing.JLabel lblSource; - private javax.swing.JTextField txtCommandLine; private javax.swing.JTextField txtLocalRepository; private javax.swing.JTextField txtOptions; // End of variables declaration//GEN-END:variables + private void browseAddNewRuntime() { + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "TIT_Select2")); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setFileHidingEnabled(false); + int selected = comMavenHome.getSelectedIndex(); + String path = getSelectedRuntime(selected); + if (path == null || path.trim().length() == 0) { + path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N + } + if (path.length() > 0) { + File f = new File(path); + if (f.exists()) { + chooser.setSelectedFile(f); + } + } + if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { + File projectDir = chooser.getSelectedFile(); + String newRuntimePath = FileUtil.normalizeFile(projectDir).getAbsolutePath(); + boolean existed = false; + List runtimes = new ArrayList(); + runtimes.addAll(predefinedRuntimes); + runtimes.addAll(userDefinedMavenRuntimes); + for (String runtime : runtimes) { + if (runtime.equals(newRuntimePath)) { + existed = true; + } + } + if (!existed) { + // do not add duplicated directory + if (userDefinedMavenRuntimes.isEmpty()) { + mavenHomeDataModel.insertElementAt(SEPARATOR, predefinedRuntimes.size()); + } + userDefinedMavenRuntimes.add(newRuntimePath); + mavenHomeDataModel.insertElementAt(newRuntimePath, runtimes.size() + 1); + } + comMavenHome.setSelectedItem(newRuntimePath); + } + } + public void setValues() { txtOptions.setText(MavenSettings.getDefault().getDefaultOptions()); - txtCommandLine.getDocument().removeDocumentListener(docList); + + predefinedRuntimes.clear(); + predefinedRuntimes.add(""); + predefinedRuntimes.add(MavenSettings.getDefaultExternalMavenRuntime()); + userDefinedMavenRuntimes.clear(); + userDefinedMavenRuntimes.addAll(MavenSettings.getDefault().getUserDefinedMavenRuntimes()); + comMavenHome.removeActionListener(listItemChangedListener); + mavenHomeDataModel.removeAllElements(); File command = MavenSettings.getDefault().getMavenHome(); - txtCommandLine.setText(command != null ? command.getAbsolutePath() : ""); //NOI18N - initExternalVersion(); - txtCommandLine.getDocument().addDocumentListener(docList); + String embedded = null; + for (String runtime : predefinedRuntimes) { + boolean embeddedRuntime = "".equals(runtime); + String desc = org.openide.util.NbBundle.getMessage(SettingsPanel.class, + embeddedRuntime ? "MAVEN_RUNTIME_Embedded" : "MAVEN_RUNTIME_External", + new Object[]{runtime, + embeddedRuntime ? EMBEDDED_RUNTIME_VERSION : MavenSettings.getCommandLineMavenVersion(new File(runtime))}); // NOI18N + mavenHomeDataModel.addElement(desc); + } + + if (!userDefinedMavenRuntimes.isEmpty()) { + mavenHomeDataModel.addElement(SEPARATOR); + for (String runtime : userDefinedMavenRuntimes) { + String desc = org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_External", + new Object[]{runtime, MavenSettings.getCommandLineMavenVersion(new File(runtime))}); // NOI18N + mavenHomeDataModel.addElement(desc); + } + } + + mavenHomeDataModel.addElement(SEPARATOR); + mavenHomeDataModel.addElement(org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_Browse")); + mavenHomeDataModel.addElement(org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_ClearUserDefines")); + comMavenHome.setSelectedItem(command != null ? command.getAbsolutePath() : embedded); //NOI18N + listDataChanged(); + lastSelected = comMavenHome.getSelectedIndex(); + comMavenHome.addActionListener(listItemChangedListener); cbSnapshots.setSelected(RepositoryPreferences.getInstance().isIncludeSnapshots()); comIndex.setSelectedIndex(RepositoryPreferences.getInstance().getIndexUpdateFrequency()); String repo = MavenSettings.getDefault().getCustomLocalRepository(); - ((MyJTextField)txtLocalRepository).setRealText(repo != null ? repo : ""); + ((JHintedTextField)txtLocalRepository).setRealText(repo != null ? repo : ""); comBinaries.setSelectedItem(MavenSettings.getDefault().getBinaryDownloadStrategy()); comJavadoc.setSelectedItem(MavenSettings.getDefault().getJavadocDownloadStrategy()); comSource.setSelectedItem(MavenSettings.getDefault().getSourceDownloadStrategy()); @@ -596,11 +721,26 @@ } public void applyValues() { - MavenSettings.getDefault().setDefaultOptions(txtOptions.getText().trim()); - MavenSettings.getDefault().setCustomLocalRepository(((MyJTextField)txtLocalRepository).getRealText()); - String cl = txtCommandLine.getText().trim(); + MavenSettings.getDefault().setCustomLocalRepository(((JHintedTextField)txtLocalRepository).getRealText()); + // remember only user-defined runtimes of RUNTIME_COUNT_LIMIT count at the most + List runtimes = new ArrayList(); + for (int i = 0; i < userDefinedMavenRuntimes.size() && i < RUNTIME_COUNT_LIMIT; ++i) { + runtimes.add(0, userDefinedMavenRuntimes.get(userDefinedMavenRuntimes.size() - 1 - i)); + } + int selected = comMavenHome.getSelectedIndex() - predefinedRuntimes.size() - 1; + if (runtimes.size() == RUNTIME_COUNT_LIMIT && userDefinedMavenRuntimes.size() - RUNTIME_COUNT_LIMIT > selected) { + runtimes.set(0, userDefinedMavenRuntimes.get(selected)); + } + if (predefinedRuntimes.size() > 1) { + runtimes.add(0, predefinedRuntimes.get(1)); + } + MavenSettings.getDefault().setMavenRuntimes(runtimes); + String cl = mavenRuntimeHome; + if (cl != null && cl.length() == 0) { + cl = null; + } //MEVENIDE-553 - File command = cl.isEmpty() ? null : new File(cl); + File command = (cl == null || cl.isEmpty()) ? null : new File(cl); if (command != null && command.isDirectory()) { MavenSettings.getDefault().setMavenHome(command); } else {