# HG changeset patch # Parent c190a715f91e847a7e19a18b237f1652ace0f18c 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 @@ -71,7 +71,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; @@ -100,7 +100,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/execute/Bundle.properties b/maven/src/org/netbeans/modules/maven/api/execute/Bundle.properties --- a/maven/src/org/netbeans/modules/maven/api/execute/Bundle.properties +++ b/maven/src/org/netbeans/modules/maven/api/execute/Bundle.properties @@ -34,6 +34,6 @@ # Contributor(s): # # Portions Copyrighted 2009 Sun Microsystems, Inc. -HINT_EmbeddedBuild=No Apache Maven installation was found on your computer.

As a fallback, an embedded instance will be used for building. \ -However, the embedded version is not a stable release and errors and incompatibilities in the build execution are to be expected.

Please specify a Maven location in the Options window. - +HINT_EmbeddedBuild=You're using an embedded Maven runtime for building.\ +

However, the embedded version is not a stable release and errors and incompatibilities in the build execution are to be expected.

\ +Please specify an external Maven runtime in the Options window. diff --git a/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java b/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java --- a/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java +++ b/maven/src/org/netbeans/modules/maven/api/execute/RunUtils.java @@ -84,7 +84,7 @@ } } - if (!useEmbedded && MavenSettings.canFindExternalMaven()) { + if (!useEmbedded && MavenSettings.getDefault().isUsingExternalRuntime()) { exec = new MavenCommandLineExecutor(config); } else { if (!warningShown && DontShowAgainSettings.getDefault().showWarningAboutEmbeddedBuild()) { diff --git a/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.form b/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.form --- a/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.form +++ b/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.form @@ -1,4 +1,4 @@ - +

@@ -20,8 +20,8 @@ - - + + @@ -36,10 +36,10 @@ - - + + - + @@ -51,13 +51,13 @@ - + - + - + diff --git a/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java b/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java --- a/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java +++ b/maven/src/org/netbeans/modules/maven/customizer/ActionMappings.java @@ -232,26 +232,29 @@ org.netbeans.modules.maven.model.profile.Profile prof = handle.getNetbeansPrivateProfile(false); if (prof != null) { org.netbeans.modules.maven.model.profile.Properties profprops = prof.getProperties(); - if (profprops != null && profprops.getProperty(Constants.HINT_USE_EXTERNAL) != null) { - return Boolean.valueOf(prof.getProperties().getProperty(Constants.HINT_USE_EXTERNAL)); + if (profprops != null && profprops.getProperty(Constants.HINT_USE_EXTERNAL) != null && !Boolean.valueOf(prof.getProperties().getProperty(Constants.HINT_USE_EXTERNAL))) { + return !Boolean.valueOf(prof.getProperties().getProperty(Constants.HINT_USE_EXTERNAL)); } } org.netbeans.modules.maven.model.pom.Properties mdlprops = handle.getPOMModel().getProject().getProperties(); String val; if (mdlprops != null) { val = mdlprops.getProperty(Constants.HINT_USE_EXTERNAL); - if (val != null) { - return Boolean.valueOf(val); + if (val != null && !Boolean.valueOf(val)) { + return !Boolean.valueOf(val); } } val = handle.getRawAuxiliaryProperty(Constants.HINT_USE_EXTERNAL, true); - if (val != null) { - return Boolean.valueOf(val); + if (val != null && !Boolean.valueOf(val)) { + return !Boolean.valueOf(val); } return null; } public void setValue(Boolean value) { + // The meaning of this option is opposite to the configuration + // Constants.HINT_USE_EXTERNAL + value = (value == null) ? null : !value.booleanValue(); boolean hasConfig = handle.getRawAuxiliaryProperty(Constants.HINT_USE_EXTERNAL, true) != null; //TODO also try to take the value in pom vs inherited pom value into account. @@ -287,7 +290,8 @@ } public boolean getDefaultValue() { - return true; + // false means DON'T Force to use an embedded Maven runtime. + return false; } }; clearFields(); @@ -475,8 +479,8 @@ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(cbCommandLine) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE) - .addComponent(btnSetup, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 172, Short.MAX_VALUE) + .addComponent(btnSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -489,10 +493,10 @@ .addComponent(lblDirectory)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(txtProfiles, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE) - .addComponent(txtGoals, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE) + .addComponent(txtProfiles, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE) + .addComponent(txtGoals, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnRemove) @@ -501,12 +505,12 @@ .addComponent(cbRecursively) .addGap(18, 18, 18) .addComponent(cbBuildWithDeps)) - .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE) + .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(comConfiguration, 0, 297, Short.MAX_VALUE) + .addComponent(comConfiguration, 0, 299, Short.MAX_VALUE) .addGap(143, 143, 143)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(txtDirectory, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE) + .addComponent(txtDirectory, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnDirectory))))) .addContainerGap()) diff --git a/maven/src/org/netbeans/modules/maven/customizer/Bundle.properties b/maven/src/org/netbeans/modules/maven/customizer/Bundle.properties --- a/maven/src/org/netbeans/modules/maven/customizer/Bundle.properties +++ b/maven/src/org/netbeans/modules/maven/customizer/Bundle.properties @@ -108,9 +108,9 @@ TIT_Add_action=Action Name\: LBL_AddAction=Enter action name LBL_Actions=Ac&tions: -LBL_UseExternal=&Use external Maven for build execution +LBL_UseExternal=Force to &use embedded Maven runtime TLT_UseExternal=If selected, will build with external version of Maven. Otherwise builds with embedded Maven. -LBL_SetupExternal=Setup external Maven &home +LBL_SetupExternal=Setup Maven &Runtimes ActionMappings.lblConfiguration.text=Confi&guration: TIT_Project_Properties=Project Properties - {0} ActionMappings.btnAddProps.text=A&dd > @@ -132,9 +132,9 @@ CompilePanel.cbDeprecate.text=Report Uses of &Deprecated APIs CompilePanel.lblJavaPlatform.text=Java &Platform: CompilePanel.btnMngPlatform.text=&Manage Java Platforms... -CompilePanel.lblWarnPlatform.text=Warning: Setting Java Platform is not possible with the embedded Maven which is currently in use. To set the Java Platform you must use an external Maven installation. +CompilePanel.lblWarnPlatform.text=Warning: Setting Java Platform is not possible with the embedded Maven which is currently in use. To set the Java Platform you must use an external Maven runtime. AddPropertyDialog.lblPropertyExpressions.text=Property Expressions : -CompilePanel.btnSetupHome.text=Set up &external Maven home +CompilePanel.btnSetupHome.text=Setup Mav&en Runtimes AN_SourceLevel=Source level combo box SourcesPanel.lblSrc.text=&Source Folder: SourcesPanel.lblTestSrc.text=&Test Source Folder: diff --git a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.form b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.form --- a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.form +++ b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.form @@ -1,4 +1,4 @@ - + @@ -34,14 +34,14 @@ - - + + - + @@ -71,7 +71,7 @@ - + diff --git a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java --- a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java +++ b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java @@ -380,7 +380,7 @@ String val = props.get(Constants.HINT_USE_EXTERNAL, true); boolean useEmbedded = "false".equalsIgnoreCase(val); - return !useEmbedded && MavenSettings.canFindExternalMaven(); + return !useEmbedded && MavenSettings.getDefault().isUsingExternalRuntime(); } private void checkExternalMaven () { @@ -464,12 +464,12 @@ .add(lblJavaPlatform)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(comJavaPlatform, 0, 302, Short.MAX_VALUE) - .add(comCompileOnSave, 0, 302, Short.MAX_VALUE)) + .add(comJavaPlatform, 0, 273, Short.MAX_VALUE) + .add(comCompileOnSave, 0, 273, Short.MAX_VALUE)) .add(16, 16, 16) .add(btnMngPlatform)) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(lblWarnPlatform, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE) + .add(lblWarnPlatform, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnSetupHome))) .addContainerGap()) @@ -493,10 +493,10 @@ .add(cbDebug) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbDeprecate) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 109, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 114, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(btnSetupHome) - .add(lblWarnPlatform)) + .add(lblWarnPlatform, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); 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 @@ -40,25 +40,19 @@ TIP_Maven_Category=Setting up of 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=External &Maven Home : TIT_Select2=Select Maven2 Installation Location - -SettingsPanel.txtCommandLine.text= -SettingsPanel.btnCommandLine.text=&Browse... -SettingsPanel.btnGoals.text=Edit &Global Custom Goal Definitions... +SettingsPanel.btnGoals.text=Edit TIT_Global=Global Maven Goal definitions ACSD_Global=Global Maven Goal definitions -SettingsPanel.lblEmbeddedVersion.text= LBL_MavenVersion1=(Embedded Maven version: {0} built on {1}) LBL_MavenVersion2=(Embedded Maven version: {0}) LBL_MavenVersion3=Cannot figure version of embedded Maven -SettingsPanel.lblExternalVersion.text= LBL_ExMavenVersion1=(Version: {0} built on {1}) LBL_ExMavenVersion2=(Version: {0}) LBL_ExMavenVersion3=Using Default Maven Version: {0} (as found on PATH) @@ -68,14 +62,13 @@ 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.btnOptions.text=&Add +SettingsPanel.lblOptions.text=Global Execution &Options: 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=On Project Open -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. @@ -91,8 +84,20 @@ 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=On Project Open : +SettingsPanel.jLabel1.text=On Project Open: TIT_NEVER=Never TIT_EVERY=Every Project Open TIT_FIRST=First Open Only SettingsPanel.cbSkipTests.text=Skip &Tests for any build executions not directly related to testing +SettingsPanel.btnAddRuntime.text=&Add +SettingsPanel.btnEditRuntime.text=&Edit +SettingsPanel.btnRemoveRuntime.text=&Remove +SettingsPanel.lblMavenRuntimes.text=&Maven Runtimes: +SettingsPanel.jLabel2.text=Global Goal Definitions: +SettingsPanel.btnAddOption.text=Add +SettingsPanel.btnRemoveOption.text=Remove +MAVEN_RUNTIME_Embedded=Embedded {1} +MAVEN_RUNTIME_External=External {0} {1} +MAVEN_RUNTIME_ErrorCaption=Error +MAVEN_RUNTIME_Error_DuplicatedRuntime_Message=The selected directory {0} is not a valid Maven directory. +MAVEN_RUNTIME_Error_AlreadyRegistered_Message=The selected Maven directory is already registered. diff --git a/maven/src/org/netbeans/modules/maven/options/GlobalOptionsPanel.java b/maven/src/org/netbeans/modules/maven/options/GlobalOptionsPanel.java --- a/maven/src/org/netbeans/modules/maven/options/GlobalOptionsPanel.java +++ b/maven/src/org/netbeans/modules/maven/options/GlobalOptionsPanel.java @@ -40,6 +40,7 @@ package org.netbeans.modules.maven.options; import java.util.HashMap; +import java.util.LinkedList; import javax.swing.DefaultListModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -76,15 +77,15 @@ }); } - String getSelectedOnes() { - String toRet = ""; + String[] getSelectedOnes() { Object[] objs = jList1.getSelectedValues(); + String[] result = new String[objs == null ? 0 : objs.length]; if (objs != null) { - for (Object obj : objs) { - toRet = toRet + " " + obj; + for (int i = 0; i < objs.length; ++i) { + result[i] = (String) objs[i]; } } - return toRet; + return result; } /** This method is called from within the constructor to 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 @@ -47,7 +47,7 @@ * * @author mkleint */ -public class MyJTextField extends JTextField { +public class JHintedTextField extends JTextField { Color origForeground; String origText = ""; @@ -72,7 +72,7 @@ } }; - public MyJTextField() { + public JHintedTextField() { addFocusListener(listener); } diff --git a/maven/src/org/netbeans/modules/maven/options/MavenRuntime.java b/maven/src/org/netbeans/modules/maven/options/MavenRuntime.java new file mode 100644 --- /dev/null +++ b/maven/src/org/netbeans/modules/maven/options/MavenRuntime.java @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.options; + +import java.io.Serializable; + +/** + * + * @author johnsonlau@netbeans.org + */ +public class MavenRuntime implements Serializable { + + private String path; + private String version; + + public MavenRuntime(String path, String version) { + this.path = path; + this.version = version; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public boolean isExternal() { + return !"".equals(path); + } + +} 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 @@ -46,6 +46,8 @@ import hidden.org.codehaus.plexus.util.cli.Commandline; import hidden.org.codehaus.plexus.util.cli.StreamConsumer; import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Logger; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; @@ -55,6 +57,7 @@ import org.netbeans.modules.maven.embedder.EmbedderFactory; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.NbBundle; import org.openide.util.NbPreferences; import org.openide.util.Utilities; @@ -74,6 +77,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 @@ -263,7 +267,7 @@ } public File getCommandLinePath() { - String str = getPreferences().get(PROP_COMMANDLINE_PATH, null); + String str = getPreferences().get(PROP_COMMANDLINE_PATH, null); if (str != null) { return FileUtil.normalizeFile(new File(str)); } @@ -350,37 +354,6 @@ } } - private static Boolean cachedMaven = null; - - public static boolean canFindExternalMaven() { - File home = MavenSettings.getDefault().getCommandLinePath(); - String ex = Utilities.isWindows() ? "mvn.bat" : "mvn"; //NOI18N - if (home != null && home.exists()) { - File bin = new File(home, "bin" + File.separator + ex);//NOI18N - if (bin.exists()) { - return true; - } - } - if (cachedMaven != null) { - return cachedMaven.booleanValue(); - } - Commandline cmdline = new Commandline(); - cmdline.setExecutable(ex); - Arg arg = cmdline.createArg(); - arg.setValue("--version"); //NOI18N - cmdline.addArg(arg); - RegExpConsumer cons = new RegExpConsumer(); - try { - int ret = CommandLineUtils.executeCommandLine(cmdline, cons, cons); - cachedMaven = cons.hasMavenAround; - return cons.hasMavenAround; - } catch (CommandLineException ex1) { - Exceptions.printStackTrace(ex1); - cachedMaven = false; - return false; - } - } - static String getDefaultMavenInstanceVersion() { String ex = Utilities.isWindows() ? "mvn.bat" : "mvn"; //NOI18N return getMavenVersion(ex); @@ -416,7 +389,7 @@ //TODO examine the version's lib folder and the prop file in there.. see SettingsPanel.java return null; } - + private static class RegExpConsumer implements StreamConsumer { private static final Pattern PATTERN = Pattern.compile("^Maven version:(.*)"); @@ -436,5 +409,103 @@ } }; + private void initExternalVersion(List mavenRuntimes, String[] paths, boolean stopOnFirstValid) { + for (String path : paths) { + File file = new File(path); + path = FileUtil.normalizeFile(file).getAbsolutePath(); + String version = MavenUtil.getExternalVersion(path); + if (version != null) { + mavenRuntimes.add(new MavenRuntime(path, version)); + if (stopOnFirstValid) { + return; + } + } + } + } + + /** + * Searches Maven runtimes according to the environment settings. + * + *

It searches in this order: + *

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

+ *

Only the first appereance will be appended.

+ * + * @param mavenRuntimes a list to store all Maven Runtime configurations. + */ + private void initDefaultExternalVersion(List mavenRuntimes) { + 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())); + } + } + + initExternalVersion(mavenRuntimes, mavenEnvDirs.toArray(new String[0]), true); + } + + public MavenRuntime[] getMavenRuntimes() { + List runtimes = new ArrayList(); + + // Embedded + runtimes.add(new MavenRuntime("", + NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion2", "3.0-SNAPSHOT"))); + + String runtimesPref = getPreferences().get(PROP_MAVEN_RUNTIMES, null); + if (runtimesPref != null) { + for (String runtimePath : runtimesPref.split(File.pathSeparator)) { + if (!"".equals(runtimePath)) { + String version = MavenUtil.getExternalVersion(runtimePath); + if (version != null) { + runtimes.add(new MavenRuntime(runtimePath, version)); + } + } + } + + } else { + // Try to find + initDefaultExternalVersion(runtimes); + } + + return runtimes.toArray(new MavenRuntime[0]); + } + + public void setMavenRuntimes(MavenRuntime[] runtimes) { + if (runtimes == null) { + getPreferences().remove(PROP_MAVEN_RUNTIMES); + } else { + String runtimesPref = ""; + for (MavenRuntime runtime : runtimes) { + runtimesPref += runtime.getPath() + File.pathSeparator; + } + putProperty(PROP_MAVEN_RUNTIMES, runtimesPref); + } + } + + /** + * Checks whether an external runtime is being used. + * @return true if using an external runtime. Otherwise false. + */ + public boolean isUsingExternalRuntime() { + return getCommandLinePath() != null; + } } diff --git a/maven/src/org/netbeans/modules/maven/options/MavenUtil.java b/maven/src/org/netbeans/modules/maven/options/MavenUtil.java new file mode 100644 --- /dev/null +++ b/maven/src/org/netbeans/modules/maven/options/MavenUtil.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.options; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import org.openide.util.NbBundle; + +/** + * Maven relevant utility methods. + * + * @author johnsonlau@netbeans.org + */ +public class MavenUtil { + + /** + * Gets an external Maven installation's version. + * + * @param path external maven installation path. + * @return version description of the installation. null when failed. + */ + public static String getExternalVersion(String path) { + File root = new File(path); + File lib = new File(root, "lib"); //NOI18N + if (lib.exists()) { + File[] jars = lib.listFiles(new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".jar"); //NOI18N + } + }); + for (File jar : jars) { + JarFile jf = null; + try + { + jf = new JarFile(jar); + ZipEntry entry = jf.getEntry("META-INF/maven/org.apache.maven/maven-core/pom.properties");//NOI18N + if (entry != null) { + InputStream resourceAsStream = jf.getInputStream(entry); + Properties properties = new Properties(); + properties.load( resourceAsStream ); + if ( properties.getProperty( "builtOn" ) != null ) { //NOI18N + return NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion1", + properties.getProperty( "version", "unknown" ), properties.getProperty( "builtOn" ));//NOI18N + } else { + return NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion2", properties.getProperty( "version", "unknown" ));//NOI18N + } + } + } catch ( IOException ex ) + { + //ignore.. + } finally { + if (jf != null) { + try { + jf.close(); + } catch (IOException x) {} + } + } + } + } + + return null; + } + + public static boolean isDefaultMavenRuntime(MavenRuntime runtime, + File commandLinePath) { + return (!runtime.isExternal() && commandLinePath == null) || + (commandLinePath != null && commandLinePath.getAbsolutePath().equals(runtime.getPath())); + } + +} diff --git a/maven/src/org/netbeans/modules/maven/options/RadioButtonTable.java b/maven/src/org/netbeans/modules/maven/options/RadioButtonTable.java new file mode 100644 --- /dev/null +++ b/maven/src/org/netbeans/modules/maven/options/RadioButtonTable.java @@ -0,0 +1,155 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.options; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.EventObject; +import javax.swing.AbstractCellEditor; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; + +/** + * A simple JTable implementation with Radio Buttons for boolean value. + * + * @author johnsonlau + */ +public class RadioButtonTable extends JTable { + + private class RadioButtonCellRenderer extends JPanel implements TableCellRenderer { + + private boolean fixedWidth = false; + + private JRadioButton radioBtn; + + public RadioButtonCellRenderer(boolean fixedWidth) { + this.fixedWidth = fixedWidth; + radioBtn = new JRadioButton(); + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + add(radioBtn, c); + } + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + radioBtn.setSelected(value != null ? (Boolean) value : false); + if (isSelected) { + radioBtn.setBackground(table.getSelectionBackground()); + setBackground(table.getSelectionBackground()); + } else { + radioBtn.setBackground(table.getBackground()); + setBackground(table.getBackground()); + } + Dimension preferredSize = getPreferredSize(); + int width = preferredSize.width; + int rowHeight = table.getRowHeight(); + TableColumn tableColumn = table.getColumnModel().getColumn(column); + tableColumn.setMinWidth(width); + tableColumn.setPreferredWidth(width); + if (fixedWidth) { + tableColumn.setMaxWidth(width); + } + table.setRowHeight(row, rowHeight > preferredSize.height ? rowHeight : preferredSize.height); + return this; + } + + } + + private class RadioButtonCellEditor extends AbstractCellEditor implements TableCellEditor { + + private JPanel panel = new JPanel(); + private JRadioButton radioBtn = new JRadioButton(); + + public RadioButtonCellEditor() { + panel.setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + panel.add(radioBtn, c); + } + + @Override + public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) { + radioBtn.setSelected(value != null ? (Boolean) value : false); + panel.setBackground(table.getSelectionBackground()); + radioBtn.setBackground(table.getSelectionBackground()); + radioBtn.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + RadioButtonCellEditor.this.fireEditingStopped(); + } + + }); + return panel; + } + + @Override + public boolean shouldSelectCell(EventObject anEvent) { + return true; + } + + @Override + public Object getCellEditorValue() { + return radioBtn.isSelected(); + } + + } + + public RadioButtonTable() { + this(null, null, null); + } + + public RadioButtonTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) { + super(dm, cm, sm); + setDefaultRenderer(Boolean.class, new RadioButtonCellRenderer(false)); + setDefaultEditor(Boolean.class, new RadioButtonCellEditor()); + } + +} 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 @@ -1,4 +1,4 @@ - + @@ -24,160 +24,181 @@ - - + + - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + - - + + - - - - - + - + - + - + - + - + - - - - - - - + - + - - - - - - - @@ -185,18 +206,6 @@ - - - - - - - - - - - - @@ -213,7 +222,7 @@ - + @@ -226,13 +235,6 @@ - - - - - - - @@ -325,5 +327,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ -43,26 +43,24 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStream; import java.io.StringReader; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Enumeration; import java.util.List; -import java.util.Properties; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; import javax.swing.BorderFactory; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; import javax.swing.JFileChooser; import javax.swing.JList; +import javax.swing.JOptionPane; 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 javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.AbstractTableModel; import org.netbeans.modules.maven.indexer.api.RepositoryIndexer; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; import org.netbeans.modules.maven.indexer.api.RepositoryPreferences; @@ -92,10 +90,79 @@ private boolean changed; private boolean valid; private ActionListener listener; - private DocumentListener docList; - private MavenOptionController controller; - private TextValueCompleter completer; + private File commandLinePath; + private List mavenRuntimes; + private AbstractTableModel tableModel = new AbstractTableModel() { + @Override + public int getRowCount() { + return mavenRuntimes.size(); + } + + @Override + public int getColumnCount() { + return 2; + } + + @Override + public Class getColumnClass(int columnIndex) { + if (columnIndex == 0) { + return Boolean.class; + } else { + return String.class; + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 0) { + MavenRuntime runtime = mavenRuntimes.get(rowIndex); + return !MavenUtil.isDefaultMavenRuntime(runtime, commandLinePath); + } + + return false; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + if (columnIndex == 0) { + MavenRuntime runtime = mavenRuntimes.get(rowIndex); + if (MavenUtil.isDefaultMavenRuntime(runtime, commandLinePath)) { + return; + } + + commandLinePath = runtime.isExternal() ? new File(runtime.getPath()) : null; + for (int i = 0; i < mavenRuntimes.size(); ++i) { + fireTableCellUpdated(i, columnIndex); + } + + } else { + super.setValueAt(aValue, rowIndex, columnIndex); + } + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + switch (columnIndex) { + case 0: { + MavenRuntime runtime = mavenRuntimes.get(rowIndex); + return MavenUtil.isDefaultMavenRuntime(runtime, commandLinePath); + } + + case 1: { + MavenRuntime runtime = mavenRuntimes.get(rowIndex); + String key = runtime.isExternal() ? "MAVEN_RUNTIME_External" : "MAVEN_RUNTIME_Embedded"; + return NbBundle.getMessage(SettingsPanel.class, key, + new Object[]{runtime.getPath(), runtime.getVersion()}); + } + } + + return null; + } + }; + + private DefaultListModel optionsModel = new DefaultListModel(); + /** Creates new form SettingsPanel */ SettingsPanel(MavenOptionController controller) { initComponents(); @@ -105,6 +172,44 @@ comJavadoc.setModel(new DefaultComboBoxModel(downloads)); comSource.setModel(new DefaultComboBoxModel(downloads)); + mavenRuntimes = new ArrayList(); + tblMavenRuntimes.setModel(tableModel); + tblMavenRuntimes.setTableHeader(null); + tblMavenRuntimes.getColumnModel().getColumn(0).setMaxWidth(20); + tblMavenRuntimes.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + int selected = tblMavenRuntimes.getSelectedRow(); + if (selected != -1 && mavenRuntimes.get(selected).isExternal()) { + btnEditRuntime.setEnabled(true); + btnRemoveRuntime.setEnabled(true); + } else { + btnEditRuntime.setEnabled(false); + btnRemoveRuntime.setEnabled(false); + } + } + } + + }); + + lstOptions.setModel(optionsModel); + lstOptions.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + if (optionsModel.getSize() > 0) { + btnRemoveOption.setEnabled(true); + } else { + btnRemoveOption.setEnabled(false); + } + } + } + + }); + ListCellRenderer rend = new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { @@ -123,25 +228,11 @@ comSource.setRenderer(rend); comJavadoc.setRenderer(rend); - 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); - } - }; 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); - completer = new TextValueCompleter(getGlobalOptions(), txtOptions, " "); //NOI18N - initEmbeddedVersion(); } static String[] AVAILABLE_OPTIONS = new String[] { @@ -183,12 +274,10 @@ return Arrays.asList(AVAILABLE_OPTIONS); } - private void initEmbeddedVersion() - { +// private void initEmbeddedVersion() { //there was a renumbering scheme for maven. current trunk is not 2.1 but 3.0 //http://blogs.sonatype.com/brian/2008/09/05/1220649145080.html //XXX: just hardwire here to not confuse people with old style versions. - lblEmbeddedVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion2", "3.0-SNAPSHOT")); //NOI18N // InputStream resourceAsStream; // try { @@ -206,86 +295,13 @@ // catch ( IOException e ) { // lblEmbeddedVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion3")); // } - } +// } - private void initExternalVersion() - { - String path = txtCommandLine.getText().trim(); - if (path.length() == 0) { - String ver = MavenSettings.getDefaultMavenInstanceVersion(); - if (ver != null) { - lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion3", ver));//NOI18N - } else { - lblExternalVersion.setText(ver != null ? ver : ""); //NOI18N - } - return; - } - File root = new File(path); - File lib = new File(root, "lib"); //NOI18N - if (lib.exists()) { - File[] jars = lib.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".jar"); //NOI18N - } - }); - for (File jar : jars) { - JarFile jf = null; - try - { - jf = new JarFile(jar); - ZipEntry entry = jf.getEntry("META-INF/maven/org.apache.maven/maven-core/pom.properties");//NOI18N - if (entry != null) { - InputStream resourceAsStream = jf.getInputStream(entry); - Properties properties = new Properties(); - properties.load( resourceAsStream ); - if ( properties.getProperty( "builtOn" ) != null ) { //NOI18N - lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion1", - properties.getProperty( "version", "unknown" ), properties.getProperty( "builtOn" )));//NOI18N - } else { - lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_ExMavenVersion2", properties.getProperty( "version", "unknown" )));//NOI18N - } - return; - } - } catch ( IOException ex ) - { - //ignore.. - } finally { - if (jf != null) { - try { - jf.close(); - } catch (IOException x) {} - } - } - } - } - //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) { - changed = true; - boolean oldvalid = valid; - if (txtCommandLine.getText().trim().length() > 0) { - File fil = new File(txtCommandLine.getText()); - if (fil.exists() && new File(fil, "bin" + File.separator + "mvn").exists()) { //NOI18N - valid = true; - } else { - valid = false; - } - } else { - valid = true; - } - if (oldvalid != valid) { - controller.firePropChange(MavenOptionController.PROP_VALID, Boolean.valueOf(oldvalid), Boolean.valueOf(valid)); - } - initExternalVersion(); - } - private ComboBoxModel createComboModel() { return new DefaultComboBoxModel( new String[] { @@ -307,18 +323,13 @@ bgChecksums = new javax.swing.ButtonGroup(); 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(); - lblExternalVersion = new javax.swing.JLabel(); + lblMavenRuntimes = new javax.swing.JLabel(); + btnRemoveRuntime = new javax.swing.JButton(); 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 JHintedTextField(); btnLocalRepository = new javax.swing.JButton(); - lblEmbeddedVersion = new javax.swing.JLabel(); lblBinaries = new javax.swing.JLabel(); comBinaries = new javax.swing.JComboBox(); lblJavadoc = new javax.swing.JLabel(); @@ -332,29 +343,28 @@ comIndex = new javax.swing.JComboBox(); btnIndex = new javax.swing.JButton(); cbSnapshots = new javax.swing.JCheckBox(); + btnAddRuntime = new javax.swing.JButton(); + btnEditRuntime = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + tblMavenRuntimes = new RadioButtonTable(); + jScrollPane2 = new javax.swing.JScrollPane(); + lstOptions = new javax.swing.JList(); + jLabel2 = new javax.swing.JLabel(); + btnAddOption = new javax.swing.JButton(); + btnRemoveOption = new javax.swing.JButton(); - org.openide.awt.Mnemonics.setLocalizedText(lblCommandLine, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblCommandLine.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lblMavenRuntimes, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblMavenRuntimes.text")); // NOI18N - txtCommandLine.setText(org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.txtCommandLine.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() { + org.openide.awt.Mnemonics.setLocalizedText(btnRemoveRuntime, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnRemoveRuntime.text")); // NOI18N + btnRemoveRuntime.setEnabled(false); + btnRemoveRuntime.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - btnCommandLineActionPerformed(evt); + btnRemoveRuntimeActionPerformed(evt); } }); - org.openide.awt.Mnemonics.setLocalizedText(lblExternalVersion, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblExternalVersion.text", new Object[] {})); // NOI18N - 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 - btnOptions.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnOptionsActionPerformed(evt); - } - }); - org.openide.awt.Mnemonics.setLocalizedText(cbSkipTests, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.cbSkipTests.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(lblLocalRepository, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblLocalRepository.text")); // NOI18N @@ -366,8 +376,6 @@ } }); - org.openide.awt.Mnemonics.setLocalizedText(lblEmbeddedVersion, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblEmbeddedVersion.text")); // NOI18N - lblBinaries.setLabelFor(comBinaries); org.openide.awt.Mnemonics.setLocalizedText(lblBinaries, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.lblBinaries.text")); // NOI18N @@ -402,110 +410,177 @@ org.openide.awt.Mnemonics.setLocalizedText(cbSnapshots, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.cbSnapshots.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(btnAddRuntime, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnAddRuntime.text")); // NOI18N + btnAddRuntime.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnAddRuntimeActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(btnEditRuntime, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnEditRuntime.text")); // NOI18N + btnEditRuntime.setEnabled(false); + btnEditRuntime.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnEditRuntimeActionPerformed(evt); + } + }); + + tblMavenRuntimes.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {}, + {}, + {}, + {} + }, + new String [] { + + } + )); + tblMavenRuntimes.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN); + tblMavenRuntimes.setShowVerticalLines(false); + jScrollPane1.setViewportView(tblMavenRuntimes); + + jScrollPane2.setViewportView(lstOptions); + + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.jLabel2.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(btnAddOption, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnAddOption.text")); // NOI18N + btnAddOption.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnAddOptionActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(btnRemoveOption, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "SettingsPanel.btnRemoveOption.text")); // NOI18N + btnRemoveOption.setEnabled(false); + btnRemoveOption.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnRemoveOptionActionPerformed(evt); + } + }); + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jLabel1) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblCommandLine) - .add(lblOptions) - .add(lblLocalRepository)) + .add(jLabel2) + .add(lblIndex)) + .add(10, 10, 10) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(2, 2, 2) + .add(comIndex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 425, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(btnIndex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 87, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(cbSnapshots) + .add(btnGoals, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() + .add(9, 9, 9) + .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)) + .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() + .add(10, 10, 10) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(lblBinaries) + .add(lblJavadoc) + .add(lblSource)) + .add(36, 36, 36) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) + .add(org.jdesktop.layout.GroupLayout.TRAILING, comSource, 0, 427, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, comJavadoc, 0, 427, Short.MAX_VALUE) + .add(comBinaries, 0, 427, Short.MAX_VALUE))) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(lblMavenRuntimes) + .add(lblOptions) + .add(lblLocalRepository)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, cbSkipTests, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE) + .add(txtLocalRepository, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)))) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblEmbeddedVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(txtCommandLine, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(btnCommandLine)) - .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 470, 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)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(btnLocalRepository) - .add(btnOptions))) - .add(cbSkipTests))) - .add(jLabel1) - .add(layout.createSequentialGroup() - .add(12, 12, 12) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblJavadoc) - .add(lblBinaries) - .add(lblSource) - .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 531, Short.MAX_VALUE)) - .add(106, 106, 106)) - .add(btnGoals) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(lblIndex) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(cbSnapshots) - .add(comIndex, 0, 391, Short.MAX_VALUE)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(btnIndex))) + .add(btnLocalRepository) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(org.jdesktop.layout.GroupLayout.LEADING, btnRemoveOption, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, btnAddOption, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, btnRemoveRuntime, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, btnEditRuntime, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, btnAddRuntime, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))))) .addContainerGap()) ); - - layout.linkSize(new java.awt.Component[] {btnCommandLine, btnIndex, btnLocalRepository, btnOptions}, org.jdesktop.layout.GroupLayout.HORIZONTAL); - layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() - .add(lblEmbeddedVersion) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(lblMavenRuntimes)) + .add(layout.createSequentialGroup() + .add(6, 6, 6) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(btnAddRuntime) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(btnEditRuntime) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(btnRemoveRuntime)) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .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(btnCommandLine)) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(lblOptions) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(cbSkipTests)) + .add(layout.createSequentialGroup() + .add(btnAddOption) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(btnRemoveOption))) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(txtLocalRepository, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(lblLocalRepository) + .add(btnLocalRepository)))) .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) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(lblOptions) - .add(txtOptions, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(btnOptions)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(cbSkipTests) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(txtLocalRepository, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(btnLocalRepository) - .add(lblLocalRepository)) - .add(16, 16, 16) .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblBinaries) .add(comBinaries, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblJavadoc) .add(comJavadoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(comSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(lblSource)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 46, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(lblSource) - .add(comSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(btnGoals) + .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 44, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(btnGoals) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(btnIndex) .add(lblIndex) - .add(comIndex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .add(comIndex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(btnIndex)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbSnapshots) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) ); }// //GEN-END:initComponents @@ -533,7 +608,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 } @@ -545,32 +620,17 @@ } 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 btnRemoveRuntimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveRuntimeActionPerformed + int selected = tblMavenRuntimes.getSelectedRow(); + if (selected != -1 && selected < mavenRuntimes.size()) { + mavenRuntimes.remove(selected); + tableModel.fireTableDataChanged(); + } + }//GEN-LAST:event_btnRemoveRuntimeActionPerformed private void btnGoalsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoalsActionPerformed NbGlobalActionGoalProvider provider = null; @@ -597,26 +657,121 @@ } }//GEN-LAST:event_btnGoalsActionPerformed - private void btnOptionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOptionsActionPerformed + private boolean tryEditMavenRuntime(String path, MavenRuntime mavenRuntime) { + if (path == null || path.length() == 0) { + path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N + } + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setDialogTitle(NbBundle.getMessage(SettingsPanel.class, "TIT_Select2")); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setFileHidingEnabled(false); + 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(); + path = FileUtil.normalizeFile(projectDir).getAbsolutePath(); + String version = MavenUtil.getExternalVersion(path); + if (version == null) { + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(SettingsPanel.class, "MAVEN_RUNTIME_Error_DuplicatedRuntime_Message", new Object[]{path}), + NbBundle.getMessage(SettingsPanel.class, "MAVEN_RUNTIME_ErrorCaption"), + JOptionPane.ERROR_MESSAGE); + return false; + } + + for (MavenRuntime runtime : mavenRuntimes) { + if (runtime.isExternal() && runtime.getPath().equals(path)) { + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(SettingsPanel.class, "MAVEN_RUNTIME_Error_AlreadyRegistered_Message", new Object[]{path}), + NbBundle.getMessage(SettingsPanel.class, "MAVEN_RUNTIME_ErrorCaption"), + JOptionPane.ERROR_MESSAGE); + return false; + } + } + + mavenRuntime.setPath(path); + mavenRuntime.setVersion(version); + return true; + } + + return false; + } + + private void btnAddRuntimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddRuntimeActionPerformed + int selected = tblMavenRuntimes.getSelectedRow(); + String path = null; + if (selected != -1) { + path = mavenRuntimes.get(selected).getPath(); + } + + MavenRuntime newRuntime = new MavenRuntime("", ""); + if (tryEditMavenRuntime(path, newRuntime)) { + mavenRuntimes.add(newRuntime); + tableModel.fireTableDataChanged(); + } + }//GEN-LAST:event_btnAddRuntimeActionPerformed + + private void btnEditRuntimeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditRuntimeActionPerformed + int selected = tblMavenRuntimes.getSelectedRow(); + if (selected == -1) { + return; + } + + MavenRuntime runtime = mavenRuntimes.get(selected); + if (tryEditMavenRuntime(runtime.getPath(), runtime)) { + tableModel.fireTableDataChanged(); + } + + }//GEN-LAST:event_btnEditRuntimeActionPerformed + + private void btnAddOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddOptionActionPerformed GlobalOptionsPanel pnl = new GlobalOptionsPanel(); DialogDescriptor dd = new DialogDescriptor(pnl, org.openide.util.NbBundle.getMessage(SettingsPanel.class, "TIT_Add_Globals")); Object ret = DialogDisplayer.getDefault().notify(dd); if (ret == DialogDescriptor.OK_OPTION) { - txtOptions.setText(txtOptions.getText() + pnl.getSelectedOnes()); + String[] newOptions = pnl.getSelectedOnes(); + int size = optionsModel.getSize(); + for (String option : newOptions) { + if (optionsModel.contains(option)) { + continue; + } + + optionsModel.addElement(option); + } + if (lstOptions.getSelectedIndex() == -1 && size != optionsModel.getSize()) { + lstOptions.setSelectedIndex(optionsModel.getSize() - 1); + } } + }//GEN-LAST:event_btnAddOptionActionPerformed - }//GEN-LAST:event_btnOptionsActionPerformed + private void btnRemoveOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveOptionActionPerformed + int[] selectedIndices = lstOptions.getSelectedIndices(); + for (int i = selectedIndices.length - 1; i >= 0; --i) { + optionsModel.remove(selectedIndices[i]); + } + int newSelected = selectedIndices.length > 0 && selectedIndices[0] < optionsModel.getSize() ? + selectedIndices[0] : optionsModel.getSize() - 1; + lstOptions.setSelectedIndex(newSelected); + }//GEN-LAST:event_btnRemoveOptionActionPerformed // 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 btnAddOption; + private javax.swing.JButton btnAddRuntime; + private javax.swing.JButton btnEditRuntime; private javax.swing.JButton btnGoals; private javax.swing.JButton btnIndex; private javax.swing.JButton btnLocalRepository; - private javax.swing.JButton btnOptions; + private javax.swing.JButton btnRemoveOption; + private javax.swing.JButton btnRemoveRuntime; private javax.swing.JCheckBox cbSkipTests; private javax.swing.JCheckBox cbSnapshots; private javax.swing.JComboBox comBinaries; @@ -624,33 +779,43 @@ private javax.swing.JComboBox comJavadoc; private javax.swing.JComboBox comSource; private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; private javax.swing.JLabel lblBinaries; - private javax.swing.JLabel lblCommandLine; - private javax.swing.JLabel lblEmbeddedVersion; - private javax.swing.JLabel lblExternalVersion; private javax.swing.JLabel lblIndex; private javax.swing.JLabel lblJavadoc; private javax.swing.JLabel lblLocalRepository; + private javax.swing.JLabel lblMavenRuntimes; private javax.swing.JLabel lblOptions; private javax.swing.JLabel lblSource; - private javax.swing.JTextField txtCommandLine; + private javax.swing.JList lstOptions; + private javax.swing.JTable tblMavenRuntimes; private javax.swing.JTextField txtLocalRepository; - private javax.swing.JTextField txtOptions; // End of variables declaration//GEN-END:variables public void setValues() { - txtOptions.setText(MavenSettings.getDefault().getDefaultOptions()); - txtCommandLine.getDocument().removeDocumentListener(docList); - File command = MavenSettings.getDefault().getCommandLinePath(); - txtCommandLine.setText(command != null ? command.getAbsolutePath() : ""); //NOI18N - initExternalVersion(); - txtCommandLine.getDocument().addDocumentListener(docList); - + String defaultOptions = MavenSettings.getDefault().getDefaultOptions(); + optionsModel.clear(); + if (!"".equals(defaultOptions.trim())) { // NOI18N + String[] optionArr = MavenSettings.getDefault().getDefaultOptions().split(" "); // NOI18N + for (String option : optionArr) { + optionsModel.addElement(option); + } + } + lstOptions.setSelectedIndex(-1); + + mavenRuntimes.clear(); + MavenRuntime[] runtimes = MavenSettings.getDefault().getMavenRuntimes(); + mavenRuntimes.addAll(Arrays.asList(runtimes)); + tableModel.fireTableDataChanged(); + + commandLinePath = MavenSettings.getDefault().getCommandLinePath(); 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()); @@ -660,16 +825,18 @@ } public void applyValues() { - MavenSettings.getDefault().setDefaultOptions(txtOptions.getText().trim()); - MavenSettings.getDefault().setCustomLocalRepository(((MyJTextField)txtLocalRepository).getRealText()); - String cl = txtCommandLine.getText().trim(); - if (cl.length() == 0) { - cl = null; - } + String options = ""; + Enumeration optEnum = optionsModel.elements(); + while(optEnum.hasMoreElements()) { + options += optEnum.nextElement() + " "; + } + + MavenSettings.getDefault().setDefaultOptions(options.trim()); + MavenSettings.getDefault().setCustomLocalRepository(((JHintedTextField)txtLocalRepository).getRealText()); + MavenSettings.getDefault().setMavenRuntimes(mavenRuntimes.toArray(new MavenRuntime[0])); //MEVENIDE-553 - File command = cl != null ? new File(cl) : null; - if (command != null && command.exists()) { - MavenSettings.getDefault().setCommandLinePath(command); + if (commandLinePath != null && commandLinePath.exists()) { + MavenSettings.getDefault().setCommandLinePath(commandLinePath); } else { MavenSettings.getDefault().setCommandLinePath(null); } @@ -689,7 +856,7 @@ boolean hasChangedValues() { return changed; } - + private class ActionListenerImpl implements ActionListener { public void actionPerformed(ActionEvent e) {