# HG changeset patch # Parent dced82c6595e27a8ed9f54150ca8917da98fb0a5 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,21 +40,17 @@ TIP_Maven_Category=Set default Maven execution options. SettingsPanel.btnIndex.text=Index &Now -SettingsPanel.lblLocalRepository.text=&Local Repository \: +SettingsPanel.lblLocalRepository.text=&Local Repository: SettingsPanel.btnLocalRepository.text=&Browse... SettingsPanel.lblIndex.text=&Index Update Frequency\: SettingsPanel.cbSnapshots.text=Include &Snapshots In Local Index TIT_Select=Select Local Repository Location -SettingsPanel.lblCommandLine.text=External &Maven Home : +SettingsPanel.lblCommandLine.text=Active &Maven Runtime: TIT_Select2=Select Maven2 Installation Location - -SettingsPanel.txtCommandLine.text= -SettingsPanel.btnCommandLine.text=&Browse... SettingsPanel.btnGoals.text=Edit &Global Custom Goal Definitions... 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=Unable to determine version of embedded Maven @@ -68,14 +64,14 @@ FREQ_Always=On every startup FREQ_Never=Never ERR_Wrong_Settings_file=Cannot parse the ~/.m2/settings.xml file, any options related to that file will be disabled. -SettingsPanel.lblOptions.text=Global Execution &Options : +SettingsPanel.lblOptions.text=Global Execution &Options: SettingsPanel.btnOptions.text=&Add -GlobalOptionsPanel.lblOptions.text=&Global Execution Options : -SettingsPanel.lblBinaries.text=&Download Binaries : +GlobalOptionsPanel.lblOptions.text=&Global Execution Options: +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 +87,12 @@ FORCES_A_CHECK=Forces a check for updated releases and snapshots on remote repositories. DON'T_USE_PLUGIN-REGISTRY=Don't use ~/.m2/plugin-registry.xml for plugin versions TIT_Add_Globals=Add Global Option(s) -SettingsPanel.jLabel1.text=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 +MAVEN_RUNTIME_Embedded=Embedded +MAVEN_RUNTIME_External={0} +MAVEN_RUNTIME_Browse=Browse... +MAVEN_RUNTIME_ClearUserDefines=Clear User-Defined Maven Runtimes diff --git a/maven/src/org/netbeans/modules/maven/options/MyJTextField.java b/maven/src/org/netbeans/modules/maven/options/JHintedTextField.java rename from maven/src/org/netbeans/modules/maven/options/MyJTextField.java rename to maven/src/org/netbeans/modules/maven/options/JHintedTextField.java --- a/maven/src/org/netbeans/modules/maven/options/MyJTextField.java +++ b/maven/src/org/netbeans/modules/maven/options/JHintedTextField.java @@ -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 @@ -1,440 +1,528 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 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 2008 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.maven.options; - -import hidden.org.codehaus.plexus.util.StringUtils; -import hidden.org.codehaus.plexus.util.cli.Arg; -import hidden.org.codehaus.plexus.util.cli.CommandLineException; -import hidden.org.codehaus.plexus.util.cli.CommandLineUtils; -import hidden.org.codehaus.plexus.util.cli.Commandline; -import hidden.org.codehaus.plexus.util.cli.StreamConsumer; -import java.io.File; -import java.util.logging.Logger; -import java.util.prefs.BackingStoreException; -import java.util.prefs.Preferences; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.maven.execution.MavenExecutionRequest; -import org.netbeans.modules.maven.embedder.EmbedderFactory; -import org.openide.filesystems.FileUtil; -import org.openide.util.Exceptions; -import org.openide.util.NbPreferences; -import org.openide.util.Utilities; - -/** - * a netbeans settings for global options that cannot be put into the settings file. - * @author mkleint - */ -public class MavenSettings { - public static final String PROP_DEFAULT_OPTIONS = "defaultOptions"; // NOI18N - public static final String PROP_SYNCH_PROXY = "synchronizeProxySettings"; //NOI18N - public static final String PROP_USE_COMMANDLINE = "useCommandLineMaven"; //NOI18N - public static final String PROP_COMMANDLINE_PATH = "commandLineMavenPath"; //NOI18N - public static final String PROP_SHOW_RUN_DIALOG = "showRunDialog"; //NOI18N - public static final String PROP_SOURCE_DOWNLOAD = "sourceDownload"; //NOI18N - public static final String PROP_JAVADOC_DOWNLOAD = "javadocDownload"; //NOI18N - public static final String PROP_BINARY_DOWNLOAD = "binaryDownload"; //NOI18N - 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 - - //these are from former versions (6.5) and are here only for conversion - private static final String PROP_DEBUG = "showDebug"; // NOI18N - private static final String PROP_ERRORS = "showErrors"; //NOI18N - private static final String PROP_CHECKSUM_POLICY = "checksumPolicy"; //NOI18N - 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(); - - public static MavenSettings getDefault() { - return INSTANCE; - } - - public boolean isInteractive() { - return !hasOption("--batch", "-B"); //NOI18N - } - - public Boolean isOffline() { - if (hasOption("--offline", "-o")) { //NOI18N - return Boolean.TRUE; - } - return null; - } - - public boolean isShowDebug() { - return hasOption("--debug", "-X"); //NOI18N - } - - public boolean isShowErrors() { - return hasOption("--errors", "-e"); //NOI18N - } - - public boolean isUpdateSnapshots() { - return hasOption("--update-snapshots", "-U"); //NOI18N - } - - - public boolean hasOption(String longName, String shortName) { - String defOpts = getDefaultOptions(); - if (defOpts != null) { - try { - String[] strs = CommandLineUtils.translateCommandline(defOpts); - for (String s : strs) { - s = s.trim(); - if (s.startsWith(shortName) || s.startsWith(longName)) { - return true; - } - } - } catch (Exception ex) { - Logger.getLogger(MavenSettings.class.getName()).fine("Error parsing global options:" + defOpts); - //will check for contains of -X be enough? - return defOpts.contains(longName) || defOpts.contains(shortName); - } - } - return false; - } - - - protected final Preferences getPreferences() { - return NbPreferences.forModule(MavenSettings.class); - } - - protected final String putProperty(String key, String value) { - String retval = getProperty(key); - if (value != null) { - getPreferences().put(key, value); - } else { - getPreferences().remove(key); - } - return retval; - } - - protected final String getProperty(String key) { - return getPreferences().get(key, null); - } - - private MavenSettings() { - //import from older versions - String defOpts = getPreferences().get(PROP_DEFAULT_OPTIONS, null); - if (defOpts == null) { - defOpts = ""; - //only when not already set by user or by previous import - String debug = getPreferences().get(PROP_DEBUG, null); - if (debug != null) { - boolean val = Boolean.parseBoolean(debug); - if (val) { - defOpts = defOpts + " --debug";//NOI18N - } - getPreferences().remove(PROP_DEBUG); - } - String error = getPreferences().get(PROP_ERRORS, null); - if (error != null) { - boolean val = Boolean.parseBoolean(error); - if (val) { - defOpts = defOpts + " --errors"; //NOI18N - } - getPreferences().remove(PROP_ERRORS); - } - String checksum = getPreferences().get(PROP_CHECKSUM_POLICY, null); - if (checksum != null) { - if (MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals(checksum)) { - defOpts = defOpts + " --strict-checksums";//NOI18N - } else if (MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals(checksum)) { - defOpts = defOpts + " --lax-checksums";//NOI18N - } - getPreferences().remove(PROP_CHECKSUM_POLICY); - } - String fail = getPreferences().get(PROP_FAILURE_BEHAVIOUR, null); - if (fail != null) { - if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(fail)) { - defOpts = defOpts + " --fail-never";//NOI18N - } else if (MavenExecutionRequest.REACTOR_FAIL_FAST.equals(fail)) { - defOpts = defOpts + " --fail-fast";//NOI18N - } else if (MavenExecutionRequest.REACTOR_FAIL_AT_END.equals(fail)) { - defOpts = defOpts + " --fail-at-end";//NOI18N - } - getPreferences().remove(PROP_FAILURE_BEHAVIOUR); - } - String pluginUpdate = getPreferences().get(PROP_PLUGIN_POLICY, null); - if (pluginUpdate != null) { - if (Boolean.parseBoolean(pluginUpdate)) { - defOpts = defOpts + " --check-plugin-updates";//NOI18N - } else { - defOpts = defOpts + " --no-plugin-updates";//NOI18N - } - getPreferences().remove(PROP_PLUGIN_POLICY); - } - String registry = getPreferences().get(PROP_USE_REGISTRY, null); - if (registry != null) { - if (!Boolean.parseBoolean(registry)) { - defOpts = defOpts + " --no-plugin-registry";//NOI18N - } - getPreferences().remove(PROP_USE_REGISTRY); - } - setDefaultOptions(defOpts); - try { - getPreferences().flush(); - } catch (BackingStoreException ex) { -// Exceptions.printStackTrace(ex); - } - } - } - - public String getDefaultOptions() { - return getPreferences().get(PROP_DEFAULT_OPTIONS, ""); //NOI18N - } - - public void setDefaultOptions(String options) { - putProperty(PROP_DEFAULT_OPTIONS, options); - } - - - public String getLastArchetypeGroupId() { - return getPreferences().get(PROP_LAST_ARCHETYPE_GROUPID, "com.mycompany"); //NOI18N - } - - public void setLastArchetypeGroupId(String groupId) { - putProperty(PROP_LAST_ARCHETYPE_GROUPID, groupId); - } - - - public void setSynchronizeProxy(boolean sync) { - getPreferences().putBoolean(PROP_SYNCH_PROXY, sync); - } - - public boolean isSynchronizeProxy() { - return getPreferences().getBoolean(PROP_SYNCH_PROXY, true); - } - - public void setCustomLocalRepository(String text) { - if (text != null && text.trim().length() == 0) { - text = null; - } - String oldText = getCustomLocalRepository(); - putProperty(PROP_CUSTOM_LOCAL_REPOSITORY, text); - //reset the project embedder to use the new local repo value. - if (!StringUtils.equals(oldText, text)) { - EmbedderFactory.resetProjectEmbedder(); - } - } - - public String getCustomLocalRepository() { - return getPreferences().get(PROP_CUSTOM_LOCAL_REPOSITORY, null); - } - - public File getCommandLinePath() { - String str = getPreferences().get(PROP_COMMANDLINE_PATH, null); - if (str != null) { - return FileUtil.normalizeFile(new File(str)); - } - return null; - } - - public void setCommandLinePath(File path) { - if (path == null) { - getPreferences().remove(PROP_COMMANDLINE_PATH); - } else { - putProperty(PROP_COMMANDLINE_PATH, FileUtil.normalizeFile(path).getAbsolutePath()); - } - } - - public boolean isShowRunDialog(){ - return getPreferences().getBoolean(PROP_SHOW_RUN_DIALOG, false); - } - public void setShowRunDialog(boolean b){ - getPreferences().putBoolean(PROP_SHOW_RUN_DIALOG, b); - } - - public boolean isSkipTests() { - return getPreferences().getBoolean(PROP_SKIP_TESTS, false); - } - - public void setSkipTests(boolean skipped) { - getPreferences().putBoolean(PROP_SKIP_TESTS, skipped); - } - - public static enum DownloadStrategy { - NEVER, - FIRST_OPEN, - EVERY_OPEN - } - - public DownloadStrategy getSourceDownloadStrategy() { - String val = getPreferences().get(PROP_SOURCE_DOWNLOAD, DownloadStrategy.NEVER.name()); - try { - return DownloadStrategy.valueOf(val); - } catch (IllegalArgumentException ex) { - return DownloadStrategy.NEVER; - } - } - - public void setSourceDownloadStrategy(DownloadStrategy ds) { - if (ds != null) { - getPreferences().put(PROP_SOURCE_DOWNLOAD, ds.name()); - } else { - getPreferences().remove(PROP_SOURCE_DOWNLOAD); - } - } - - public DownloadStrategy getJavadocDownloadStrategy() { - String val = getPreferences().get(PROP_JAVADOC_DOWNLOAD, DownloadStrategy.NEVER.name()); - try { - return DownloadStrategy.valueOf(val); - } catch (IllegalArgumentException ex) { - return DownloadStrategy.NEVER; - } - } - - public void setJavadocDownloadStrategy(DownloadStrategy ds) { - if (ds != null) { - getPreferences().put(PROP_JAVADOC_DOWNLOAD, ds.name()); - } else { - getPreferences().remove(PROP_JAVADOC_DOWNLOAD); - } - } - - public DownloadStrategy getBinaryDownloadStrategy() { - String val = getPreferences().get(PROP_BINARY_DOWNLOAD, DownloadStrategy.NEVER.name()); - try { - return DownloadStrategy.valueOf(val); - } catch (IllegalArgumentException ex) { - return DownloadStrategy.NEVER; - } - } - - public void setBinaryDownloadStrategy(DownloadStrategy ds) { - if (ds != null) { - getPreferences().put(PROP_BINARY_DOWNLOAD, ds.name()); - } else { - getPreferences().remove(PROP_BINARY_DOWNLOAD); - } - } - - 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); - } - - private static String getMavenVersion(String ex) { - 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); - return cons.version != null ? cons.version.trim() : null; - } catch (CommandLineException ex1) { - Exceptions.printStackTrace(ex1); - return null; - } - - } - - public static String getCommandLineMavenVersion() { - File path = getDefault().getCommandLinePath(); - if (path == null) { - return getDefaultMavenInstanceVersion(); - } - String pathString = path.getAbsolutePath() + File.separator + "bin" + File.separator + (Utilities.isWindows() ? "mvn.bat" : "mvn"); //NOI18N - String ver = getMavenVersion(pathString); - if (ver != null) { - return ver; - } - //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:(.*)"); - private static final Pattern PATTERN_210 = Pattern.compile("^Apache Maven ([0-9\\.]*) .*"); - boolean hasMavenAround = false; - String version = null; - - public void consumeLine(String line) { - Matcher match = PATTERN.matcher(line); - if (!match.matches()) { - match = PATTERN_210.matcher(line); - } - if (match.matches()) { - hasMavenAround = true; - version = match.group(1); - } - } - }; - - -} +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 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 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.options; + +import hidden.org.codehaus.plexus.util.StringUtils; +import hidden.org.codehaus.plexus.util.cli.Arg; +import hidden.org.codehaus.plexus.util.cli.CommandLineException; +import hidden.org.codehaus.plexus.util.cli.CommandLineUtils; +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.Collections; +import java.util.List; +import java.util.logging.Logger; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.maven.execution.MavenExecutionRequest; +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; + +/** + * a netbeans settings for global options that cannot be put into the settings file. + * @author mkleint + */ +public class MavenSettings { + public static final String PROP_DEFAULT_OPTIONS = "defaultOptions"; // NOI18N + public static final String PROP_SYNCH_PROXY = "synchronizeProxySettings"; //NOI18N + public static final String PROP_USE_COMMANDLINE = "useCommandLineMaven"; //NOI18N + public static final String PROP_COMMANDLINE_PATH = "commandLineMavenPath"; //NOI18N + public static final String PROP_SHOW_RUN_DIALOG = "showRunDialog"; //NOI18N + public static final String PROP_SOURCE_DOWNLOAD = "sourceDownload"; //NOI18N + public static final String PROP_JAVADOC_DOWNLOAD = "javadocDownload"; //NOI18N + public static final String PROP_BINARY_DOWNLOAD = "binaryDownload"; //NOI18N + 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 + private static final String PROP_ERRORS = "showErrors"; //NOI18N + private static final String PROP_CHECKSUM_POLICY = "checksumPolicy"; //NOI18N + 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(); + + public static MavenSettings getDefault() { + return INSTANCE; + } + + public boolean isInteractive() { + return !hasOption("--batch", "-B"); //NOI18N + } + + public Boolean isOffline() { + if (hasOption("--offline", "-o")) { //NOI18N + return Boolean.TRUE; + } + return null; + } + + public boolean isShowDebug() { + return hasOption("--debug", "-X"); //NOI18N + } + + public boolean isShowErrors() { + return hasOption("--errors", "-e"); //NOI18N + } + + public boolean isUpdateSnapshots() { + return hasOption("--update-snapshots", "-U"); //NOI18N + } + + + public boolean hasOption(String longName, String shortName) { + String defOpts = getDefaultOptions(); + if (defOpts != null) { + try { + String[] strs = CommandLineUtils.translateCommandline(defOpts); + for (String s : strs) { + s = s.trim(); + if (s.startsWith(shortName) || s.startsWith(longName)) { + return true; + } + } + } catch (Exception ex) { + Logger.getLogger(MavenSettings.class.getName()).fine("Error parsing global options:" + defOpts); + //will check for contains of -X be enough? + return defOpts.contains(longName) || defOpts.contains(shortName); + } + } + return false; + } + + + protected final Preferences getPreferences() { + return NbPreferences.forModule(MavenSettings.class); + } + + protected final String putProperty(String key, String value) { + String retval = getProperty(key); + if (value != null) { + getPreferences().put(key, value); + } else { + getPreferences().remove(key); + } + return retval; + } + + protected final String getProperty(String key) { + return getPreferences().get(key, null); + } + + private MavenSettings() { + //import from older versions + String defOpts = getPreferences().get(PROP_DEFAULT_OPTIONS, null); + if (defOpts == null) { + defOpts = ""; + //only when not already set by user or by previous import + String debug = getPreferences().get(PROP_DEBUG, null); + if (debug != null) { + boolean val = Boolean.parseBoolean(debug); + if (val) { + defOpts = defOpts + " --debug";//NOI18N + } + getPreferences().remove(PROP_DEBUG); + } + String error = getPreferences().get(PROP_ERRORS, null); + if (error != null) { + boolean val = Boolean.parseBoolean(error); + if (val) { + defOpts = defOpts + " --errors"; //NOI18N + } + getPreferences().remove(PROP_ERRORS); + } + String checksum = getPreferences().get(PROP_CHECKSUM_POLICY, null); + if (checksum != null) { + if (MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals(checksum)) { + defOpts = defOpts + " --strict-checksums";//NOI18N + } else if (MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals(checksum)) { + defOpts = defOpts + " --lax-checksums";//NOI18N + } + getPreferences().remove(PROP_CHECKSUM_POLICY); + } + String fail = getPreferences().get(PROP_FAILURE_BEHAVIOUR, null); + if (fail != null) { + if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(fail)) { + defOpts = defOpts + " --fail-never";//NOI18N + } else if (MavenExecutionRequest.REACTOR_FAIL_FAST.equals(fail)) { + defOpts = defOpts + " --fail-fast";//NOI18N + } else if (MavenExecutionRequest.REACTOR_FAIL_AT_END.equals(fail)) { + defOpts = defOpts + " --fail-at-end";//NOI18N + } + getPreferences().remove(PROP_FAILURE_BEHAVIOUR); + } + String pluginUpdate = getPreferences().get(PROP_PLUGIN_POLICY, null); + if (pluginUpdate != null) { + if (Boolean.parseBoolean(pluginUpdate)) { + defOpts = defOpts + " --check-plugin-updates";//NOI18N + } else { + defOpts = defOpts + " --no-plugin-updates";//NOI18N + } + getPreferences().remove(PROP_PLUGIN_POLICY); + } + String registry = getPreferences().get(PROP_USE_REGISTRY, null); + if (registry != null) { + if (!Boolean.parseBoolean(registry)) { + defOpts = defOpts + " --no-plugin-registry";//NOI18N + } + getPreferences().remove(PROP_USE_REGISTRY); + } + setDefaultOptions(defOpts); + try { + getPreferences().flush(); + } catch (BackingStoreException ex) { +// Exceptions.printStackTrace(ex); + } + } + } + + public String getDefaultOptions() { + return getPreferences().get(PROP_DEFAULT_OPTIONS, ""); //NOI18N + } + + public void setDefaultOptions(String options) { + putProperty(PROP_DEFAULT_OPTIONS, options); + } + + + public String getLastArchetypeGroupId() { + return getPreferences().get(PROP_LAST_ARCHETYPE_GROUPID, "com.mycompany"); //NOI18N + } + + public void setLastArchetypeGroupId(String groupId) { + putProperty(PROP_LAST_ARCHETYPE_GROUPID, groupId); + } + + + public void setSynchronizeProxy(boolean sync) { + getPreferences().putBoolean(PROP_SYNCH_PROXY, sync); + } + + public boolean isSynchronizeProxy() { + return getPreferences().getBoolean(PROP_SYNCH_PROXY, true); + } + + public void setCustomLocalRepository(String text) { + if (text != null && text.trim().length() == 0) { + text = null; + } + String oldText = getCustomLocalRepository(); + putProperty(PROP_CUSTOM_LOCAL_REPOSITORY, text); + //reset the project embedder to use the new local repo value. + if (!StringUtils.equals(oldText, text)) { + EmbedderFactory.resetProjectEmbedder(); + } + } + + public String getCustomLocalRepository() { + return getPreferences().get(PROP_CUSTOM_LOCAL_REPOSITORY, null); + } + + public File getCommandLinePath() { + String str = getPreferences().get(PROP_COMMANDLINE_PATH, null); + if (str != null) { + return FileUtil.normalizeFile(new File(str)); + } + return null; + } + + public void setCommandLinePath(File path) { + if (path == null) { + getPreferences().remove(PROP_COMMANDLINE_PATH); + } else { + putProperty(PROP_COMMANDLINE_PATH, FileUtil.normalizeFile(path).getAbsolutePath()); + } + } + + public boolean isShowRunDialog(){ + return getPreferences().getBoolean(PROP_SHOW_RUN_DIALOG, false); + } + public void setShowRunDialog(boolean b){ + getPreferences().putBoolean(PROP_SHOW_RUN_DIALOG, b); + } + + public boolean isSkipTests() { + return getPreferences().getBoolean(PROP_SKIP_TESTS, false); + } + + public void setSkipTests(boolean skipped) { + getPreferences().putBoolean(PROP_SKIP_TESTS, skipped); + } + + public static enum DownloadStrategy { + NEVER, + FIRST_OPEN, + EVERY_OPEN + } + + public DownloadStrategy getSourceDownloadStrategy() { + String val = getPreferences().get(PROP_SOURCE_DOWNLOAD, DownloadStrategy.NEVER.name()); + try { + return DownloadStrategy.valueOf(val); + } catch (IllegalArgumentException ex) { + return DownloadStrategy.NEVER; + } + } + + public void setSourceDownloadStrategy(DownloadStrategy ds) { + if (ds != null) { + getPreferences().put(PROP_SOURCE_DOWNLOAD, ds.name()); + } else { + getPreferences().remove(PROP_SOURCE_DOWNLOAD); + } + } + + public DownloadStrategy getJavadocDownloadStrategy() { + String val = getPreferences().get(PROP_JAVADOC_DOWNLOAD, DownloadStrategy.NEVER.name()); + try { + return DownloadStrategy.valueOf(val); + } catch (IllegalArgumentException ex) { + return DownloadStrategy.NEVER; + } + } + + public void setJavadocDownloadStrategy(DownloadStrategy ds) { + if (ds != null) { + getPreferences().put(PROP_JAVADOC_DOWNLOAD, ds.name()); + } else { + getPreferences().remove(PROP_JAVADOC_DOWNLOAD); + } + } + + public DownloadStrategy getBinaryDownloadStrategy() { + String val = getPreferences().get(PROP_BINARY_DOWNLOAD, DownloadStrategy.NEVER.name()); + try { + return DownloadStrategy.valueOf(val); + } catch (IllegalArgumentException ex) { + return DownloadStrategy.NEVER; + } + } + + public void setBinaryDownloadStrategy(DownloadStrategy ds) { + if (ds != null) { + getPreferences().put(PROP_BINARY_DOWNLOAD, ds.name()); + } else { + getPreferences().remove(PROP_BINARY_DOWNLOAD); + } + } + + static String getDefaultMavenInstanceVersion() { + String ex = Utilities.isWindows() ? "mvn.bat" : "mvn"; //NOI18N + return getMavenVersion(ex); + } + + private static String getMavenVersion(String ex) { + 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); + return cons.version != null ? cons.version.trim() : null; + } catch (CommandLineException ex1) { + Exceptions.printStackTrace(ex1); + return null; + } + + } + + public static String getCommandLineMavenVersion() { + File path = getDefault().getCommandLinePath(); + if (path == null) { + return getDefaultMavenInstanceVersion(); + } + String pathString = path.getAbsolutePath() + File.separator + "bin" + File.separator + (Utilities.isWindows() ? "mvn.bat" : "mvn"); //NOI18N + String ver = getMavenVersion(pathString); + if (ver != null) { + return ver; + } + //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:(.*)"); + private static final Pattern PATTERN_210 = Pattern.compile("^Apache Maven ([0-9\\.]*) .*"); + boolean hasMavenAround = false; + String version = null; + + public void consumeLine(String line) { + Matcher match = PATTERN.matcher(line); + if (!match.matches()) { + match = PATTERN_210.matcher(line); + } + if (match.matches()) { + hasMavenAround = true; + version = match.group(1); + } + } + }; + + private List initMavenRuntimes(String[] paths, boolean stopOnFirstValid) { + List runtimes = new ArrayList(); + for (String path : paths) { + File file = new File(path); + path = FileUtil.normalizeFile(file).getAbsolutePath(); + String version = MavenUtil.getExternalVersion(path); + if (version != null) { + runtimes.add(new MavenRuntime(path, version)); + if (stopOnFirstValid) { + break; + } + } + } + + return runtimes; + } + + /** + * 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.

+ * + * @returns the default external Maven runtime on the path. + */ + public MavenRuntime 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 = initMavenRuntimes(mavenEnvDirs.toArray(new String[0]), true); + return !runtimes.isEmpty() ? runtimes.get(0) : null; + } + + public MavenRuntime getEmbeddedMavenRuntime() { + return new MavenRuntime("", + NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion2", "3.0-SNAPSHOT")); + } + + public List getPredefinedMavenRuntimes() { + List runtimes = new ArrayList(); + + // Embedded + runtimes.add(getEmbeddedMavenRuntime()); + + // Try to find default external Maven runtime on path + MavenRuntime defaultRuntime = getDefaultExternalMavenRuntime(); + if (defaultRuntime != null) { + runtimes.add(defaultRuntime); + } + + return Collections.unmodifiableList(runtimes); + } + + public List getUserDefinedMavenRuntimes() { + List runtimes = new ArrayList(); + + MavenRuntime defaultRuntime = getDefaultExternalMavenRuntime(); + String runtimesPref = getPreferences().get(PROP_MAVEN_RUNTIMES, null); + if (runtimesPref != null) { + for (String runtimePath : runtimesPref.split(File.pathSeparator)) { + if (!"".equals(runtimePath) && + defaultRuntime != null && !defaultRuntime.getPath().equals(runtimePath)) { + String version = MavenUtil.getExternalVersion(runtimePath); + runtimes.add(new MavenRuntime(runtimePath, version)); + } + } + } + + return Collections.unmodifiableList(runtimes); + } + + public void setMavenRuntimes(List 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/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 @@ - + @@ -27,78 +27,81 @@ + + + + + + + + + - - - - - - - + + + + + + + + + + + - + + + + + + - + - - + - - - - - + + + - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + - + @@ -112,7 +115,7 @@ - + @@ -141,7 +144,7 @@ - + @@ -154,23 +157,6 @@
- - - - - - - - - - - - - - - - - @@ -213,7 +199,7 @@ - + @@ -226,13 +212,6 @@ - - - - - - - @@ -325,5 +304,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 @@ -43,25 +43,22 @@ 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.Collections; 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.JFileChooser; +import javax.swing.JLabel; import javax.swing.JList; +import javax.swing.JSeparator; import javax.swing.ListCellRenderer; import javax.swing.SwingUtilities; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; +import javax.swing.border.EmptyBorder; import org.netbeans.modules.maven.TextValueCompleter; import org.netbeans.modules.maven.indexer.api.RepositoryIndexer; import org.netbeans.modules.maven.indexer.api.RepositoryInfo; @@ -89,12 +86,49 @@ */ public class SettingsPanel extends javax.swing.JPanel { private static final String CP_SELECTED = "wasSelected"; //NOI18N + private static final String SEPARATOR = "SEPARATOR"; + private static final int RUNTIME_COUNT_LIMIT = 5; private boolean changed; private boolean valid; private ActionListener listener; - private DocumentListener docList; + private ActionListener listItemChangedListener; private MavenOptionController controller; private TextValueCompleter completer; + private List userDefinedMavenRuntimes = new ArrayList(); + private List predefinedRuntimes = new ArrayList(); + private DefaultComboBoxModel mavenHomeDataModel = new DefaultComboBoxModel(); + private MavenRuntime activeMavenRuntime = null; + private int lastSelected = -1; + + private class ComboBoxRenderer extends JLabel implements ListCellRenderer { + + private JSeparator separator; + + public ComboBoxRenderer() { + setOpaque(true); + setBorder(new EmptyBorder(1, 1, 1, 1)); + separator = new JSeparator(JSeparator.HORIZONTAL); + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + if (SEPARATOR.equals(value)) { + return separator; + } + if (isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + + setFont(list.getFont()); + setText(value.toString()); + return this; + } + }; /** Creates new form SettingsPanel */ SettingsPanel(MavenOptionController controller) { @@ -104,6 +138,7 @@ comBinaries.setModel(new DefaultComboBoxModel(downloads)); comJavadoc.setModel(new DefaultComboBoxModel(downloads)); comSource.setModel(new DefaultComboBoxModel(downloads)); + comMavenHome.setModel(mavenHomeDataModel); ListCellRenderer rend = new DefaultListCellRenderer() { @Override @@ -122,26 +157,62 @@ 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); + listItemChangedListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (SEPARATOR.equals(comMavenHome.getSelectedItem())) { + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + int selected = comMavenHome.getSelectedIndex(); + if (selected == mavenHomeDataModel.getSize() - 1) { + // clear all user defined runtimes + if (userDefinedMavenRuntimes.isEmpty()) { + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + int count = userDefinedMavenRuntimes.size() + 1; + userDefinedMavenRuntimes.clear(); + for (int i = 0; i < count; ++i) { + mavenHomeDataModel.removeElementAt(predefinedRuntimes.size()); + } + + lastSelected = 0; + comMavenHome.setSelectedIndex(lastSelected); + return; + } + + if (selected == mavenHomeDataModel.getSize() - 2) { + // browse + comMavenHome.setSelectedIndex(lastSelected); + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + browseAddNewRuntime(); + } + + }); + return; + } + + listDataChanged(); + lastSelected = selected; } - 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,107 +254,73 @@ return Arrays.asList(AVAILABLE_OPTIONS); } - 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 { -// Properties properties = new Properties(); -// resourceAsStream = EmbedderFactory.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/pom.properties" ); //NOI18N -// properties.load( resourceAsStream ); -// -// if ( properties.getProperty( "builtOn" ) != null ) { //NOI18N -// lblEmbeddedVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion1", -// properties.getProperty( "version", "unknown" ), properties.getProperty( "builtOn" ))); -// } else { -// lblEmbeddedVersion.setText(NbBundle.getMessage(SettingsPanel.class, "LBL_MavenVersion2", properties.getProperty( "version", "unknown" ))); -// } -// } -// 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) { + private MavenRuntime 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 = null; + if (selected >= 0) { + MavenRuntime runtime = getSelectedRuntime(selected); + if (runtime != null) { + activeMavenRuntime = runtime; + if (!runtime.isExternal()) { + path = null; + valid = true; + lblExternalVersion.setText(runtime.getVersion()); + + } else { + path = runtime.getPath(); + } + + } else { + path = (String) mavenHomeDataModel.getElementAt(selected); + activeMavenRuntime = new MavenRuntime(path, ""); + userDefinedMavenRuntimes.add(activeMavenRuntime); + } + } + + 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 = MavenUtil.getExternalVersion(path); + } + + if (ver != null) { + lblExternalVersion.setText(ver); valid = true; + activeMavenRuntime.setVersion(ver); + } else { - valid = false; + lblExternalVersion.setText(NbBundle.getMessage(SettingsPanel.class, "ERR_NoValidInstallation")); } - } else { - valid = true; } + if (oldvalid != valid) { controller.firePropChange(MavenOptionController.PROP_VALID, Boolean.valueOf(oldvalid), Boolean.valueOf(valid)); } - initExternalVersion(); } private ComboBoxModel createComboModel() { @@ -308,17 +345,14 @@ 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(); lblOptions = new javax.swing.JLabel(); txtOptions = new javax.swing.JTextField(); btnOptions = new javax.swing.JButton(); cbSkipTests = new javax.swing.JCheckBox(); lblLocalRepository = new javax.swing.JLabel(); - txtLocalRepository = new MyJTextField(); + txtLocalRepository = new org.netbeans.modules.maven.options.JHintedTextField(); btnLocalRepository = new javax.swing.JButton(); - lblEmbeddedVersion = new javax.swing.JLabel(); lblBinaries = new javax.swing.JLabel(); comBinaries = new javax.swing.JComboBox(); lblJavadoc = new javax.swing.JLabel(); @@ -332,18 +366,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 - 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() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnCommandLineActionPerformed(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 @@ -366,8 +392,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 @@ -410,65 +434,65 @@ .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() + .add(lblCommandLine) + .add(31, 31, 31) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblCommandLine) - .add(lblOptions) - .add(lblLocalRepository)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(comMavenHome, 0, 394, Short.MAX_VALUE) + .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)) + .add(137, 137, 137)) + .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblEmbeddedVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE) + .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, 570, Short.MAX_VALUE)) + .add(106, 106, 106)) + .add(btnGoals) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(txtCommandLine, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE) + .add(lblIndex) + .add(18, 18, 18) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, cbSnapshots) + .add(comIndex, 0, 398, 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(btnIndex)) + .add(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(lblOptions) + .add(lblLocalRepository) + .add(jLabel1)) .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))) - .addContainerGap()) + .add(cbSkipTests) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, comSource, 0, 394, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, comJavadoc, 0, 394, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, comBinaries, 0, 394, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, txtLocalRepository, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.LEADING, txtOptions, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(btnLocalRepository) + .add(btnOptions)))))) + .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) .add(layout.createSequentialGroup() - .add(lblEmbeddedVersion) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .addContainerGap() .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)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(comMavenHome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(lblCommandLine)) + .add(8, 8, 8) .add(lblExternalVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(18, 18, 18) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .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) @@ -480,7 +504,7 @@ .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(18, 18, 18) .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) @@ -505,7 +529,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(37, Short.MAX_VALUE)) ); }// //GEN-END:initComponents @@ -533,7 +557,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,18 +569,21 @@ } 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 + 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); - String path = txtCommandLine.getText(); - if (path.trim().length() == 0) { + int selected = comMavenHome.getSelectedIndex(); + MavenRuntime selectedRuntime = getSelectedRuntime(selected); + String path = selectedRuntime != null && selectedRuntime.isExternal() ? + selectedRuntime.getPath() : null; + if (path == null || path.trim().length() == 0) { path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N } if (path.length() > 0) { @@ -567,11 +594,27 @@ } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); - txtCommandLine.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); + String newRuntimePath = FileUtil.normalizeFile(projectDir).getAbsolutePath(); + boolean existed = false; + List runtimes = new ArrayList(); + runtimes.addAll(predefinedRuntimes); + runtimes.addAll(userDefinedMavenRuntimes); + for (MavenRuntime runtime : runtimes) { + if (runtime.getPath().equals(newRuntimePath)) { + existed = true; + } + } + if (!existed) { + // do not add duplicated directory + if (userDefinedMavenRuntimes.isEmpty()) { + mavenHomeDataModel.insertElementAt(SEPARATOR, predefinedRuntimes.size()); + } + mavenHomeDataModel.insertElementAt(newRuntimePath, runtimes.size() + 1); + } + comMavenHome.setSelectedItem(newRuntimePath); } - - }//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)) { @@ -612,7 +655,6 @@ private javax.swing.ButtonGroup bgChecksums; private javax.swing.ButtonGroup bgFailure; private javax.swing.ButtonGroup bgPlugins; - private javax.swing.JButton btnCommandLine; private javax.swing.JButton btnGoals; private javax.swing.JButton btnIndex; private javax.swing.JButton btnLocalRepository; @@ -622,35 +664,67 @@ 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; 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 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 public void setValues() { txtOptions.setText(MavenSettings.getDefault().getDefaultOptions()); - txtCommandLine.getDocument().removeDocumentListener(docList); + + predefinedRuntimes.clear(); + predefinedRuntimes.addAll(MavenSettings.getDefault().getPredefinedMavenRuntimes()); + userDefinedMavenRuntimes.clear(); + userDefinedMavenRuntimes.addAll(MavenSettings.getDefault().getUserDefinedMavenRuntimes()); + comMavenHome.removeActionListener(listItemChangedListener); + mavenHomeDataModel.removeAllElements(); File command = MavenSettings.getDefault().getCommandLinePath(); - txtCommandLine.setText(command != null ? command.getAbsolutePath() : ""); //NOI18N - initExternalVersion(); - txtCommandLine.getDocument().addDocumentListener(docList); + String embedded = null; + for (MavenRuntime runtime : predefinedRuntimes) { + String desc = org.openide.util.NbBundle.getMessage(SettingsPanel.class, + (runtime.isExternal() ? "MAVEN_RUNTIME_External" : "MAVEN_RUNTIME_Embedded"), + new Object[]{runtime.getPath(), runtime.getVersion()}); // NOI18N + mavenHomeDataModel.addElement(desc); + if (embedded == null && !runtime.isExternal()) { + embedded = desc; + } + } + + if (!userDefinedMavenRuntimes.isEmpty()) { + mavenHomeDataModel.addElement(SEPARATOR); + for (MavenRuntime runtime : userDefinedMavenRuntimes) { + String desc = org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_External", + new Object[]{runtime.getPath(), runtime.getVersion()}); // NOI18N + mavenHomeDataModel.addElement(desc); + } + } + + mavenHomeDataModel.addElement(SEPARATOR); + mavenHomeDataModel.addElement(org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_Browse")); + mavenHomeDataModel.addElement(org.openide.util.NbBundle.getMessage(SettingsPanel.class, + "MAVEN_RUNTIME_ClearUserDefines")); + comMavenHome.setSelectedItem(command != null ? command.getAbsolutePath() : embedded); //NOI18N + listDataChanged(); + lastSelected = comMavenHome.getSelectedIndex(); + comMavenHome.addActionListener(listItemChangedListener); cbSnapshots.setSelected(RepositoryPreferences.getInstance().isIncludeSnapshots()); comIndex.setSelectedIndex(RepositoryPreferences.getInstance().getIndexUpdateFrequency()); String repo = MavenSettings.getDefault().getCustomLocalRepository(); - ((MyJTextField)txtLocalRepository).setRealText(repo != null ? repo : ""); + ((JHintedTextField)txtLocalRepository).setRealText(repo != null ? repo : ""); comBinaries.setSelectedItem(MavenSettings.getDefault().getBinaryDownloadStrategy()); comJavadoc.setSelectedItem(MavenSettings.getDefault().getJavadocDownloadStrategy()); comSource.setSelectedItem(MavenSettings.getDefault().getSourceDownloadStrategy()); @@ -661,9 +735,27 @@ public void applyValues() { MavenSettings.getDefault().setDefaultOptions(txtOptions.getText().trim()); - MavenSettings.getDefault().setCustomLocalRepository(((MyJTextField)txtLocalRepository).getRealText()); - String cl = txtCommandLine.getText().trim(); - if (cl.length() == 0) { + MavenSettings.getDefault().setCustomLocalRepository(((JHintedTextField)txtLocalRepository).getRealText()); + // remember only user-defined runtimes of RUNTIME_COUNT_LIMIT count at the most + List runtimes = new ArrayList(); + runtimes.addAll(predefinedRuntimes); + int startIndex = 0, endIndex = userDefinedMavenRuntimes.size(); + if (!userDefinedMavenRuntimes.isEmpty() && endIndex - startIndex > RUNTIME_COUNT_LIMIT) { + int selected = comMavenHome.getSelectedIndex() - predefinedRuntimes.size() - 1; + if (selected < 0) { + selected = 0; + } + if (selected + RUNTIME_COUNT_LIMIT < endIndex) { + endIndex = selected + RUNTIME_COUNT_LIMIT; + } + if (endIndex - RUNTIME_COUNT_LIMIT > startIndex) { + startIndex = endIndex - RUNTIME_COUNT_LIMIT; + } + } + runtimes.addAll(userDefinedMavenRuntimes.subList(startIndex, endIndex)); + MavenSettings.getDefault().setMavenRuntimes(runtimes); + String cl = activeMavenRuntime != null ? activeMavenRuntime.getPath() : null; + if (cl != null && cl.length() == 0) { cl = null; } //MEVENIDE-553