# HG changeset patch
# Parent 55f2e678a3f477dc8af484f9d2aaf4028b088d49
(#183455) Multiple Maven Runtimes support
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
@@ -90,4 +90,6 @@
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_Bundled=Bundled
+MAVEN_RUNTIME_External={0}
+MAVEN_RUNTIME_Browse=Browse...
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
@@ -49,6 +49,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 +62,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 +80,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 +89,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 +292,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 +395,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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -187,6 +160,9 @@
+
+
+
@@ -319,5 +295,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;
@@ -55,9 +56,9 @@
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFileChooser;
import javax.swing.JList;
+import javax.swing.JSeparator;
import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities;
-import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.netbeans.modules.maven.TextValueCompleter;
import org.netbeans.modules.maven.indexer.api.RepositoryIndexer;
@@ -86,12 +87,41 @@
*/
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 BUNDLED_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 static class ComboBoxRenderer extends DefaultListCellRenderer {
+
+ private JSeparator separator;
+
+ public ComboBoxRenderer() {
+ super();
+ 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;
+ }
+ return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ }
+ };
/** Creates new form SettingsPanel */
SettingsPanel(MavenOptionController controller) {
@@ -101,6 +131,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,17 +150,35 @@
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) {
+ // browse
+ comMavenHome.setSelectedIndex(lastSelected);
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ browseAddNewRuntime();
+ }
+
+ });
+ return;
+ }
+
+ listDataChanged();
+ lastSelected = selected;
}
};
initValues();
@@ -179,43 +228,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", BUNDLED_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,9 +308,6 @@
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();
@@ -262,23 +329,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 +401,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 +432,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 +446,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 +486,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
@@ -481,29 +530,6 @@
}
}//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 +564,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 +579,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,18 +591,89 @@
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 bundled = null;
+ for (String runtime : predefinedRuntimes) {
+ boolean bundledRuntime = "".equals(runtime);
+ String desc = org.openide.util.NbBundle.getMessage(SettingsPanel.class,
+ bundledRuntime ? "MAVEN_RUNTIME_Bundled" : "MAVEN_RUNTIME_External",
+ new Object[]{runtime,
+ bundledRuntime ? BUNDLED_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"));
+ comMavenHome.setSelectedItem(command != null ? command.getAbsolutePath() : bundled); //NOI18N
+ listDataChanged();
+ lastSelected = comMavenHome.getSelectedIndex();
+ comMavenHome.addActionListener(listItemChangedListener);
cbSnapshots.setSelected(RepositoryPreferences.getInstance().isIncludeSnapshots());
comIndex.setSelectedIndex(RepositoryPreferences.getInstance().getIndexUpdateFrequency());
@@ -598,9 +690,24 @@
public void applyValues() {
MavenSettings.getDefault().setDefaultOptions(txtOptions.getText().trim());
MavenSettings.getDefault().setCustomLocalRepository(((MyJTextField)txtLocalRepository).getRealText());
- String cl = txtCommandLine.getText().trim();
+
+ // 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 (selected >= 0 && 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;
//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 {