diff --git a/plugins/maven/maven.iml b/plugins/maven/maven.iml
index 64fe10b280ce..208fc49323e2 100644
--- a/plugins/maven/maven.iml
+++ b/plugins/maven/maven.iml
@@ -54,6 +54,7 @@
+
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalParameters.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalParameters.java
index da8e45472898..ada6643b2e0d 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalParameters.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalParameters.java
@@ -37,7 +37,6 @@ import org.jetbrains.idea.maven.utils.MavenUtil;
import java.io.File;
import java.io.IOException;
-import java.text.MessageFormat;
import java.util.*;
/**
@@ -144,7 +143,7 @@ public class MavenExternalParameters {
parametersList.add(goal);
}
- addOption(parametersList, "P", encodeProfiles(parameters.getProfiles()));
+ addOption(parametersList, "P", encodeProfiles(parameters.getProfilesMap()));
}
private static void addOption(ParametersList cmdList, @NonNls String key, @NonNls String value) {
@@ -233,13 +232,16 @@ public class MavenExternalParameters {
}
}
- private static String encodeProfiles(final Collection profiles) {
- final StringBuilder stringBuilder = new StringBuilder();
- for (String profile : profiles) {
+ private static String encodeProfiles(Map profiles) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (Map.Entry entry : profiles.entrySet()) {
if (stringBuilder.length() != 0) {
stringBuilder.append(",");
}
- stringBuilder.append(profile);
+ if (!entry.getValue()) {
+ stringBuilder.append("-");
+ }
+ stringBuilder.append(entry.getKey());
}
return stringBuilder.toString();
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunConfiguration.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunConfiguration.java
index 84770fa6c2b9..17fe46f4cada 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunConfiguration.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunConfiguration.java
@@ -143,10 +143,7 @@ public class MavenRunConfiguration extends RunConfigurationBase implements Locat
if (mySettings.myRunnerParameters == null) mySettings.myRunnerParameters = new MavenRunnerParameters();
// fix old settings format
- File workingDir = mySettings.myRunnerParameters.getWorkingDirFile();
- if (MavenConstants.POM_XML.equals(workingDir.getName())) {
- mySettings.myRunnerParameters.setWorkingDirPath(workingDir.getParent());
- }
+ mySettings.myRunnerParameters.fixAfterLoadingFromOldFormat();
}
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParameters.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParameters.java
index fa41ce4798fb..a75aa5e42dbf 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParameters.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParameters.java
@@ -15,6 +15,13 @@
*/
package org.jetbrains.idea.maven.execution;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Maps;
+import com.intellij.util.xmlb.annotations.OptionTag;
+import com.intellij.util.xmlb.annotations.Transient;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.maven.model.MavenConstants;
import org.jetbrains.idea.maven.utils.Path;
import java.io.File;
@@ -24,21 +31,53 @@ public class MavenRunnerParameters implements Cloneable {
private boolean isPomExecution;
private Path myWorkingDirPath;
private List myGoals;
- private SortedSet myProfiles;
+
+ private final Map myProfilesMap = new LinkedHashMap();
+
+ private final Collection myEnabledProfilesForXmlSerializer = new TreeSet();
public MavenRunnerParameters() {
- this(true, "", null, null);
+ this(true, "", null, null, null);
}
- public MavenRunnerParameters(boolean isPomExecution, String workingDirPath, List goals, Collection profiles) {
+ public MavenRunnerParameters(boolean isPomExecution, String workingDirPath,
+ @Nullable List goals,
+ @Nullable Collection explicitEnabledProfiles) {
+ this(isPomExecution, workingDirPath, goals, explicitEnabledProfiles, null);
+ }
+
+ public MavenRunnerParameters(boolean isPomExecution, String workingDirPath,
+ @Nullable List goals,
+ @Nullable Collection explicitEnabledProfiles,
+ @Nullable Collection explicitDisabledProfiles) {
this.isPomExecution = isPomExecution;
setWorkingDirPath(workingDirPath);
setGoals(goals);
- setProfiles(profiles);
+
+ if (explicitEnabledProfiles != null) {
+ for (String profile : explicitEnabledProfiles) {
+ myProfilesMap.put(profile, Boolean.TRUE);
+ }
+ }
+
+ if (explicitDisabledProfiles != null) {
+ for (String profile : explicitDisabledProfiles) {
+ myProfilesMap.put(profile, Boolean.FALSE);
+ }
+ }
+ }
+
+ public MavenRunnerParameters(String workingDirPath, boolean isPomExecution,
+ @Nullable List goals,
+ @NotNull Map profilesMap) {
+ this.isPomExecution = isPomExecution;
+ setWorkingDirPath(workingDirPath);
+ setGoals(goals);
+ setProfilesMap(profilesMap);
}
public MavenRunnerParameters(MavenRunnerParameters that) {
- this(that.isPomExecution, that.getWorkingDirPath(), that.myGoals, that.myProfiles);
+ this(that.getWorkingDirPath(), that.isPomExecution, that.myGoals, that.myProfilesMap);
}
public boolean isPomExecution() {
@@ -57,6 +96,7 @@ public class MavenRunnerParameters implements Cloneable {
return new File(myWorkingDirPath.getPath());
}
+ @Nullable
public String getPomFilePath() {
if (!isPomExecution) return null;
return new File(myWorkingDirPath.getPath(), "pom.xml").getPath();
@@ -73,14 +113,68 @@ public class MavenRunnerParameters implements Cloneable {
}
}
- public Collection getProfiles() {
- return myProfiles;
+ @Deprecated // Must be used by XML Serializer only!!!
+ @OptionTag("profiles")
+ public Collection getEnabledProfilesForXmlSerializer() {
+ return myEnabledProfilesForXmlSerializer;
}
- public void setProfiles(Collection profiles) {
- myProfiles = new TreeSet();
+ @Deprecated // Must be used by XML Serializer only!!!
+ public void setEnabledProfilesForXmlSerializer(@Nullable Collection enabledProfilesForXmlSerializer) {
+ if (enabledProfilesForXmlSerializer != null) {
+ if (myEnabledProfilesForXmlSerializer == enabledProfilesForXmlSerializer) return; // Called from XML Serializer
+ myEnabledProfilesForXmlSerializer.retainAll(enabledProfilesForXmlSerializer);
+ myEnabledProfilesForXmlSerializer.addAll(enabledProfilesForXmlSerializer);
+ }
+ }
+
+ public void fixAfterLoadingFromOldFormat() {
+ for (String profile : myEnabledProfilesForXmlSerializer) {
+ myProfilesMap.put(profile, true);
+ }
+ myEnabledProfilesForXmlSerializer.clear();
+
+ File workingDir = getWorkingDirFile();
+ if (MavenConstants.POM_XML.equals(workingDir.getName())) {
+ setWorkingDirPath(workingDir.getParent());
+ }
+ }
+
+ @OptionTag("profilesMap")
+ public Map getProfilesMap() {
+ return myProfilesMap;
+ }
+
+ public void setProfilesMap(@NotNull Map profilesMap) {
+ if (myProfilesMap == profilesMap) return; // Called from XML Serializer
+ myProfilesMap.clear();
+ for (Map.Entry entry : profilesMap.entrySet()) {
+ if (entry.getValue() != null) {
+ myProfilesMap.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Was left for compatibility with old plugins.
+ * @deprecated use getProfileMap()
+ * @return
+ */
+ @Transient
+ public Collection getProfiles() {
+ return Maps.filterValues(myProfilesMap, Predicates.equalTo(true)).keySet();
+ }
+
+ /**
+ * Was left for compatibility with old plugins.
+ * @deprecated use getProfileMap()
+ * @param profiles
+ */
+ public void setProfiles(@Nullable Collection profiles) {
if (profiles != null) {
- myProfiles.addAll(profiles);
+ for (String profile : profiles) {
+ myProfilesMap.put(profile, true);
+ }
}
}
@@ -97,7 +191,7 @@ public class MavenRunnerParameters implements Cloneable {
if (isPomExecution != that.isPomExecution) return false;
if (myGoals != null ? !myGoals.equals(that.myGoals) : that.myGoals != null) return false;
if (myWorkingDirPath != null ? !myWorkingDirPath.equals(that.myWorkingDirPath) : that.myWorkingDirPath != null) return false;
- if (myProfiles != null ? !myProfiles.equals(that.myProfiles) : that.myProfiles != null) return false;
+ if (!myProfilesMap.equals(that.myProfilesMap)) return false;
return true;
}
@@ -107,7 +201,7 @@ public class MavenRunnerParameters implements Cloneable {
result = isPomExecution ? 1 : 0;
result = 31 * result + (myWorkingDirPath != null ? myWorkingDirPath.hashCode() : 0);
result = 31 * result + (myGoals != null ? myGoals.hashCode() : 0);
- result = 31 * result + (myProfiles != null ? myProfiles.hashCode() : 0);
+ result = 31 * result + myProfilesMap.hashCode();
return result;
}
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.form b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.form
index f809c0a477b2..4ea26c5ab04e 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.form
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.form
@@ -1,6 +1,6 @@
-
+
@@ -44,6 +44,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.java
index 60c0e8227f25..3e5b419b02d2 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParametersConfigurable.java
@@ -38,10 +38,7 @@ import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.*;
import javax.swing.*;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
/**
* @author Vladislav.Kaznacheev
@@ -66,6 +63,16 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
if (!project.isDefault()) {
MyCompletionProvider profilesCompletionProvider = new MyCompletionProvider(project) {
+ @NotNull
+ @Override
+ protected String getPrefix(@NotNull String currentTextPrefix) {
+ String prefix = super.getPrefix(currentTextPrefix);
+ if (prefix.startsWith("-") || prefix.startsWith("!")) {
+ prefix = prefix.substring(1);
+ }
+ return prefix;
+ }
+
@Override
protected void addVariants(@NotNull CompletionResultSet result, MavenProjectsManager manager) {
for (String profile : manager.getAvailableProfiles()) {
@@ -155,13 +162,40 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
private void setData(final MavenRunnerParameters data) {
data.setWorkingDirPath(workingDirComponent.getComponent().getText());
data.setGoals(Strings.tokenize(goalsComponent.getComponent().getText(), " "));
- data.setProfiles(Strings.tokenize(profilesComponent.getComponent().getText(), " "));
+
+ Map profilesMap = new LinkedHashMap();
+
+ for (String profile : Strings.tokenize(profilesComponent.getComponent().getText(), " ,;")) {
+ Boolean isEnabled = true;
+ if (profile.startsWith("-") || profile.startsWith("!")) {
+ profile = profile.substring(1);
+ if (profile.isEmpty()) continue;
+
+ isEnabled = false;
+ }
+
+ profilesMap.put(profile, isEnabled);
+ }
+ data.setProfilesMap(profilesMap);
}
private void getData(final MavenRunnerParameters data) {
workingDirComponent.getComponent().setText(data.getWorkingDirPath());
goalsComponent.getComponent().setText(Strings.detokenize(data.getGoals(), ' '));
- profilesComponent.getComponent().setText(Strings.detokenize(data.getProfiles(), ' '));
+
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry entry : data.getProfilesMap().entrySet()) {
+ if (sb.length() != 0) {
+ sb.append(" ");
+ }
+ if (!entry.getValue()) {
+ sb.append("-");
+ }
+
+ sb.append(entry.getKey());
+ }
+
+ profilesComponent.getComponent().setText(sb.toString());
}
protected abstract MavenRunnerParameters getParameters();
@@ -179,7 +213,7 @@ public abstract class MavenRunnerParametersConfigurable implements Configurable,
profilesComponent.setAnchor(anchor);
}
- private static abstract class MyCompletionProvider extends TextFieldCompletionProvider {
+ private abstract class MyCompletionProvider extends TextFieldCompletionProvider {
private final Project myProject;
protected MyCompletionProvider(Project project) {
diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationTest.java
index fef5429a229c..f4ad8fc7f869 100644
--- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationTest.java
+++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/execution/MavenRunConfigurationTest.java
@@ -15,6 +15,7 @@
*/
package org.jetbrains.idea.maven.execution;
+import com.google.common.collect.ImmutableMap;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
@@ -26,7 +27,7 @@ public class MavenRunConfigurationTest extends IdeaTestCase {
MavenRunConfiguration.MavenSettings s = new MavenRunConfiguration.MavenSettings(myProject);
s.myRunnerParameters.setWorkingDirPath("some path");
s.myRunnerParameters.setGoals(Arrays.asList("clean validate"));
- s.myRunnerParameters.setProfiles(Arrays.asList("prof1 prof2"));
+ s.myRunnerParameters.setProfilesMap(ImmutableMap.of("prof1", true, "prof2", true, "prof3", false));
Element xml = XmlSerializer.serialize(s);
MavenRunConfiguration.MavenSettings loaded
@@ -34,6 +35,6 @@ public class MavenRunConfigurationTest extends IdeaTestCase {
assertEquals(s.myRunnerParameters.getWorkingDirPath(), loaded.myRunnerParameters.getWorkingDirPath());
assertEquals(s.myRunnerParameters.getGoals(), loaded.myRunnerParameters.getGoals());
- assertEquals(s.myRunnerParameters.getProfiles(), loaded.myRunnerParameters.getProfiles());
+ assertEquals(s.myRunnerParameters.getProfilesMap(), loaded.myRunnerParameters.getProfilesMap());
}
}