summaryrefslogtreecommitdiff
path: root/plugins/maven/src/main/java/org/jetbrains
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/maven/src/main/java/org/jetbrains')
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomProjectProcessorUtils.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenPropertyResolver.java12
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenConfigurationProducer.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunnerParameters.java8
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapter.java13
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenExecuteGoalAction.java3
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java9
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java51
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectSettings.java7
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java25
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManagerWatcher.java7
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java91
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettings.java6
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettingsComponent.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RunBuildAction.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ToggleProfileAction.java112
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java22
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java3
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenBeforeRunTasksProvider.java6
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenKeymapExtension.java5
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenTasksManager.java7
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenDataKeys.java4
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java4
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java55
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectOpenProcessor.java4
-rw-r--r--plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/SelectProfilesStep.java147
28 files changed, 455 insertions, 176 deletions
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomProjectProcessorUtils.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomProjectProcessorUtils.java
index ceebebb093e5..ba3d265b7d10 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomProjectProcessorUtils.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenDomProjectProcessorUtils.java
@@ -514,11 +514,12 @@ public class MavenDomProjectProcessorUtils {
MavenProject mavenProjectOrNull,
Processor<T> processor,
Function<? super MavenDomProfile, T> f) {
- Collection<String> activePropfiles = mavenProjectOrNull == null ? null : mavenProjectOrNull.getActivatedProfilesIds();
+ Collection<String> activeProfiles =
+ mavenProjectOrNull == null ? null : mavenProjectOrNull.getActivatedProfilesIds().getEnabledProfiles();
for (MavenDomProfile each : profilesDom.getProfiles()) {
XmlTag idTag = each.getId().getXmlTag();
if (idTag == null) continue;
- if (activePropfiles != null && !activePropfiles.contains(idTag.getValue().getTrimmedText())) continue;
+ if (activeProfiles != null && !activeProfiles.contains(idTag.getValue().getTrimmedText())) continue;
if (processProfile(each, processor, f)) return true;
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenPropertyResolver.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenPropertyResolver.java
index 66875895f278..0422898a2bbb 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenPropertyResolver.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenPropertyResolver.java
@@ -81,10 +81,10 @@ public class MavenPropertyResolver {
@Nullable Map<String, String> resolvedPropertiesParam,
Appendable out) throws IOException {
Map<String, String> resolvedProperties = resolvedPropertiesParam;
-
+
Matcher matcher = pattern.matcher(text);
int groupCount = matcher.groupCount();
-
+
int last = 0;
while (matcher.find()) {
if (escapeString != null) {
@@ -116,7 +116,7 @@ public class MavenPropertyResolver {
if (resolvedProperties == null) {
resolvedProperties = new HashMap<String, String>();
}
-
+
String propertyValue = resolvedProperties.get(propertyName);
if (propertyValue == null) {
if (resolvedProperties.containsKey(propertyName)) { // if cyclic property dependencies
@@ -146,7 +146,7 @@ public class MavenPropertyResolver {
out.append(propertyValue);
}
}
-
+
out.append(text, last, text.length());
}
@@ -177,10 +177,10 @@ public class MavenPropertyResolver {
collectPropertiesFromDOM(projectDom.getProperties(), result);
- Collection<String> activePropfiles = project.getActivatedProfilesIds();
+ Collection<String> activeProfiles = project.getActivatedProfilesIds().getEnabledProfiles();
for (MavenDomProfile each : projectDom.getProfiles().getProfiles()) {
XmlTag idTag = each.getId().getXmlTag();
- if (idTag == null || !activePropfiles.contains(idTag.getValue().getTrimmedText())) continue;
+ if (idTag == null || !activeProfiles.contains(idTag.getValue().getTrimmedText())) continue;
collectPropertiesFromDOM(each.getProperties(), result);
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenConfigurationProducer.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenConfigurationProducer.java
index 0bf342fcdcfa..13b58ca94b12 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenConfigurationProducer.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenConfigurationProducer.java
@@ -29,6 +29,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import java.util.Collection;
@@ -76,9 +77,9 @@ public class MavenConfigurationProducer extends RuntimeConfigurationProducer {
VirtualFile f = ((PsiFile)l.getPsiElement()).getVirtualFile();
List<String> goals = ((MavenGoalLocation)l).getGoals();
- Collection<String> profiles = MavenProjectsManager.getInstance(l.getProject()).getExplicitProfiles();
+ MavenExplicitProfiles profiles = MavenProjectsManager.getInstance(l.getProject()).getExplicitProfiles();
- return new MavenRunnerParameters(true, f.getParent().getPath(), goals, profiles);
+ return new MavenRunnerParameters(true, f.getParent().getPath(), goals, profiles.getEnabledProfiles(), profiles.getDisabledProfiles());
}
public int compareTo(Object o) {
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 c04f2d344e51..bca71b2c0d8f 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
@@ -23,6 +23,7 @@ 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.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.utils.Path;
import java.io.File;
@@ -53,6 +54,13 @@ public class MavenRunnerParameters implements Cloneable {
public MavenRunnerParameters(boolean isPomExecution,
@NotNull String workingDirPath,
@Nullable List<String> goals,
+ @NotNull MavenExplicitProfiles explicitProfiles) {
+ this(isPomExecution, workingDirPath, goals, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
+ }
+
+ public MavenRunnerParameters(boolean isPomExecution,
+ @NotNull String workingDirPath,
+ @Nullable List<String> goals,
@Nullable Collection<String> explicitEnabledProfiles,
@Nullable Collection<String> explicitDisabledProfiles) {
this.isPomExecution = isPomExecution;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapter.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapter.java
index 65e1b5ed2dce..e2a313ef30a9 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapter.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapter.java
@@ -19,12 +19,15 @@ import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.ModuleOrderEntryImpl;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.registry.Registry;
+import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFileManager;
@@ -45,6 +48,7 @@ import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
import java.io.File;
+import java.util.Arrays;
import java.util.Set;
public class MavenRootModelAdapter {
@@ -176,10 +180,7 @@ public class MavenRootModelAdapter {
public boolean isAlreadyExcluded(File f) {
String url = toUrl(f.getPath()).getUrl();
- for (String excludedUrl : myRootModel.getExcludeRootUrls()) {
- if (VfsUtilCore.isEqualOrAncestor(excludedUrl, url)) return true;
- }
- return false;
+ return VfsUtilCore.isUnder(url, Arrays.asList(myRootModel.getExcludeRootUrls()));
}
private boolean exists(String path) {
@@ -193,6 +194,10 @@ public class MavenRootModelAdapter {
if (e == null) return;
if (e.getUrl().equals(url.getUrl())) return;
e.addExcludeFolder(url.getUrl());
+ if (!Registry.is("ide.hide.excluded.files")) {
+ Project project = myRootModel.getProject();
+ ChangeListManager.getInstance(project).addDirectoryToIgnoreImplicitly(toPath(path).getPath());
+ }
}
public void unregisterAll(String path, boolean under, boolean unregisterSources) {
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java
index 86761532f6a0..04e93ac9e0e2 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/MavenProjectsNavigatorPanel.java
@@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.execution.MavenGoalLocation;
import org.jetbrains.idea.maven.model.MavenArtifact;
import org.jetbrains.idea.maven.model.MavenConstants;
+import org.jetbrains.idea.maven.model.MavenProfileKind;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.MavenDataKeys;
@@ -226,9 +227,9 @@ public class MavenProjectsNavigatorPanel extends SimpleToolWindowPanel implement
private Object extractProfiles() {
final List<MavenProjectsStructure.ProfileNode> nodes = getSelectedNodes(MavenProjectsStructure.ProfileNode.class);
- final List<String> profiles = new ArrayList<String>();
+ final Map<String, MavenProfileKind> profiles = new THashMap<String, MavenProfileKind>();
for (MavenProjectsStructure.ProfileNode node : nodes) {
- profiles.add(node.getProfileName());
+ profiles.put(node.getProfileName(), node.getState());
}
return profiles;
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenExecuteGoalAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenExecuteGoalAction.java
index e591bb61d11b..8c02946b5b72 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenExecuteGoalAction.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/navigator/actions/MavenExecuteGoalAction.java
@@ -37,6 +37,7 @@ import org.jetbrains.idea.maven.utils.MavenUtil;
import javax.swing.event.HyperlinkEvent;
import java.io.File;
import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -105,7 +106,7 @@ public class MavenExecuteGoalAction extends DumbAwareAction {
return;
}
- MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goals)), null);
+ MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goals)), Collections.<String>emptyList());
MavenGeneralSettings generalSettings = new MavenGeneralSettings();
generalSettings.setMavenHome(mavenHome.getPath());
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java
index 70a8aa8cfd81..01fc83800372 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProject.java
@@ -19,7 +19,6 @@ import com.intellij.execution.configurations.ParametersList;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ui.LightFilePointer;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Key;
@@ -29,13 +28,11 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.idea.maven.dom.MavenDomUtil;
import org.jetbrains.idea.maven.importing.MavenExtraArtifactType;
import org.jetbrains.idea.maven.importing.MavenImporter;
import org.jetbrains.idea.maven.model.*;
@@ -607,7 +604,7 @@ public class MavenProject {
@NotNull
public MavenProjectChanges read(@NotNull MavenGeneralSettings generalSettings,
- @NotNull Collection<String> profiles,
+ @NotNull MavenExplicitProfiles profiles,
@NotNull MavenProjectReader reader,
@NotNull MavenProjectReaderProjectLocator locator) {
return set(reader.readProject(generalSettings, myFile, profiles, locator), generalSettings, true, false, true);
@@ -805,7 +802,7 @@ public class MavenProject {
}
@NotNull
- public Collection<String> getActivatedProfilesIds() {
+ public MavenExplicitProfiles getActivatedProfilesIds() {
return myState.myActivatedProfilesIds;
}
@@ -1089,7 +1086,7 @@ public class MavenProject {
Map<String, String> myModelMap;
Collection<String> myProfilesIds;
- Collection<String> myActivatedProfilesIds;
+ MavenExplicitProfiles myActivatedProfilesIds;
Collection<MavenProjectProblem> myReadingProblems;
Set<MavenId> myUnresolvedArtifactIds;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java
index bb465f5e5fc1..31f245ccfdc6 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReader.java
@@ -47,9 +47,9 @@ public class MavenProjectReader {
public MavenProjectReaderResult readProject(MavenGeneralSettings generalSettings,
VirtualFile file,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
MavenProjectReaderProjectLocator locator) {
- Pair<RawModelReadResult, Collection<String>> readResult =
+ Pair<RawModelReadResult, MavenExplicitProfiles> readResult =
doReadProjectModel(generalSettings, file, explicitProfiles, new THashSet<VirtualFile>(), locator);
File basedir = getBaseDir(file);
@@ -76,11 +76,11 @@ public class MavenProjectReader {
return new File(file.getParent().getPath());
}
- private Pair<RawModelReadResult, Collection<String>> doReadProjectModel(MavenGeneralSettings generalSettings,
- VirtualFile file,
- Collection<String> explicitProfiles,
- Set<VirtualFile> recursionGuard,
- MavenProjectReaderProjectLocator locator) {
+ private Pair<RawModelReadResult, MavenExplicitProfiles> doReadProjectModel(MavenGeneralSettings generalSettings,
+ VirtualFile file,
+ MavenExplicitProfiles explicitProfiles,
+ Set<VirtualFile> recursionGuard,
+ MavenProjectReaderProjectLocator locator) {
RawModelReadResult cachedModel = myRawModelsCache.get(file);
if (cachedModel == null) {
cachedModel = doReadProjectModel(file, false);
@@ -364,7 +364,7 @@ public class MavenProjectReader {
private static ProfileApplicationResult applyProfiles(MavenModel model,
File basedir,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
Collection<String> alwaysOnProfiles) {
return MavenServerManager.getInstance().applyProfiles(model, basedir, explicitProfiles, alwaysOnProfiles);
}
@@ -372,7 +372,7 @@ public class MavenProjectReader {
private MavenModel resolveInheritance(final MavenGeneralSettings generalSettings,
MavenModel model,
final VirtualFile file,
- final Collection<String> explicitProfiles,
+ final MavenExplicitProfiles explicitProfiles,
final Set<VirtualFile> recursionGuard,
final MavenProjectReaderProjectLocator locator,
Collection<MavenProjectProblem> problems) {
@@ -456,21 +456,23 @@ public class MavenProjectReader {
public MavenProjectReaderResult resolveProject(MavenGeneralSettings generalSettings,
MavenEmbedderWrapper embedder,
VirtualFile file,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
MavenProjectReaderProjectLocator locator) throws MavenProcessCanceledException {
try {
- MavenServerExecutionResult result = embedder.resolveProject(file, explicitProfiles);
- if (result.projectData == null) {
+ MavenServerExecutionResult result =
+ embedder.resolveProject(file, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
+ MavenServerExecutionResult.ProjectData projectData = result.projectData;
+ if (projectData == null) {
MavenProjectReaderResult temp = readProject(generalSettings, file, explicitProfiles, locator);
temp.readingProblems.addAll(result.problems);
temp.unresolvedArtifactIds.addAll(result.unresolvedArtifacts);
return temp;
}
- return new MavenProjectReaderResult(result.projectData.mavenModel,
- result.projectData.mavenModelMap,
- result.projectData.activatedProfiles,
- result.projectData.nativeMavenProject,
+ return new MavenProjectReaderResult(projectData.mavenModel,
+ projectData.mavenModelMap,
+ new MavenExplicitProfiles(projectData.activatedProfiles, explicitProfiles.getDisabledProfiles()),
+ projectData.nativeMavenProject,
result.problems,
result.unresolvedArtifacts);
}
@@ -497,17 +499,18 @@ public class MavenProjectReader {
public static MavenProjectReaderResult generateSources(MavenEmbedderWrapper embedder,
MavenImportingSettings importingSettings,
VirtualFile file,
- Collection<String> profiles,
+ MavenExplicitProfiles profiles,
MavenConsole console) throws MavenProcessCanceledException {
try {
List<String> goals = Collections.singletonList(importingSettings.getUpdateFoldersOnImportPhase());
- MavenServerExecutionResult result = embedder.execute(file, profiles, goals);
- if (result.projectData == null) return null;
-
- return new MavenProjectReaderResult(result.projectData.mavenModel,
- result.projectData.mavenModelMap,
- result.projectData.activatedProfiles,
- result.projectData.nativeMavenProject,
+ MavenServerExecutionResult result = embedder.execute(file, profiles.getEnabledProfiles(), profiles.getDisabledProfiles(), goals);
+ MavenServerExecutionResult.ProjectData projectData = result.projectData;
+ if (projectData == null) return null;
+
+ return new MavenProjectReaderResult(projectData.mavenModel,
+ projectData.mavenModelMap,
+ new MavenExplicitProfiles(projectData.activatedProfiles, profiles.getDisabledProfiles()),
+ projectData.nativeMavenProject,
result.problems,
result.unresolvedArtifacts);
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java
index 29ac462b115a..cbec80162fd0 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectReaderResult.java
@@ -16,6 +16,7 @@
package org.jetbrains.idea.maven.project;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.model.MavenModel;
import org.jetbrains.idea.maven.model.MavenProjectProblem;
@@ -28,14 +29,14 @@ import java.util.Set;
public class MavenProjectReaderResult {
public final MavenModel mavenModel;
public final Map<String, String> nativeModelMap;
- public final Collection<String> activatedProfiles;
+ public final MavenExplicitProfiles activatedProfiles;
@Nullable public final NativeMavenProjectHolder nativeMavenProject;
public final Collection<MavenProjectProblem> readingProblems;
public final Set<MavenId> unresolvedArtifactIds;
public MavenProjectReaderResult(MavenModel mavenModel,
Map<String, String> nativeModelMap,
- Collection<String> activatedProfiles,
+ MavenExplicitProfiles activatedProfiles,
@Nullable NativeMavenProjectHolder nativeMavenProject,
Collection<MavenProjectProblem> readingProblems,
Set<MavenId> unresolvedArtifactIds) {
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectSettings.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectSettings.java
index 4671a261b590..6ff6c851c67b 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectSettings.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectSettings.java
@@ -25,8 +25,11 @@ import org.jetbrains.annotations.Nullable;
*/
@State(
name = "MavenProjectSettings",
- storages = {@Storage(
- file = StoragePathMacros.PROJECT_CONFIG_DIR + "/mavenProjectSettings.xml")})
+ storages = {
+ @Storage(file = StoragePathMacros.PROJECT_FILE),
+ @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/mavenProjectSettings.xml", scheme = StorageScheme.DIRECTORY_BASED)
+ }
+)
public class MavenProjectSettings implements PersistentStateComponent<MavenProjectSettings> {
private final Project myProject;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java
index 37a1a47cde6a..88b92ae679a6 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManager.java
@@ -183,9 +183,10 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
doInit(false);
}
- private void initNew(List<VirtualFile> files, List<String> explicitProfiles) {
+ private void initNew(List<VirtualFile> files, MavenExplicitProfiles explicitProfiles) {
myState.originalFiles = MavenUtil.collectPaths(files);
- getWorkspaceSettings().setEnabledProfiles(explicitProfiles);
+ getWorkspaceSettings().setEnabledProfiles(explicitProfiles.getEnabledProfiles());
+ getWorkspaceSettings().setDisabledProfiles(explicitProfiles.getDisabledProfiles());
doInit(true);
}
@@ -241,7 +242,9 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
}
private void applyStateToTree() {
- myProjectsTree.resetManagedFilesPathsAndProfiles(myState.originalFiles, getWorkspaceSettings().enabledProfiles);
+ MavenWorkspaceSettings settings = getWorkspaceSettings();
+ MavenExplicitProfiles explicitProfiles = new MavenExplicitProfiles(settings.enabledProfiles, settings.disabledProfiles);
+ myProjectsTree.resetManagedFilesPathsAndProfiles(myState.originalFiles, explicitProfiles);
myProjectsTree.setIgnoredFilesPaths(new ArrayList<String>(myState.ignoredFiles));
myProjectsTree.setIgnoredFilesPatterns(myState.ignoredPathMasks);
}
@@ -474,11 +477,11 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
}
@TestOnly
- public void resetManagedFilesAndProfilesInTests(List<VirtualFile> files, List<String> profiles) {
+ public void resetManagedFilesAndProfilesInTests(List<VirtualFile> files, MavenExplicitProfiles profiles) {
myWatcher.resetManagedFilesAndProfilesInTests(files, profiles);
}
- public void addManagedFilesWithProfiles(List<VirtualFile> files, List<String> profiles) {
+ public void addManagedFilesWithProfiles(List<VirtualFile> files, MavenExplicitProfiles profiles) {
if (!isInitialized()) {
initNew(files, profiles);
}
@@ -488,7 +491,7 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
}
public void addManagedFiles(@NotNull List<VirtualFile> files) {
- addManagedFilesWithProfiles(files, Collections.<String>emptyList());
+ addManagedFilesWithProfiles(files, MavenExplicitProfiles.NONE);
}
public void addManagedFilesOrUnignore(@NotNull List<VirtualFile> files) {
@@ -506,12 +509,12 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
}
@NotNull
- public Collection<String> getExplicitProfiles() {
- if (!isInitialized()) return Collections.emptyList();
+ public MavenExplicitProfiles getExplicitProfiles() {
+ if (!isInitialized()) return MavenExplicitProfiles.NONE;
return myProjectsTree.getExplicitProfiles();
}
- public void setExplicitProfiles(@NotNull Collection<String> profiles) {
+ public void setExplicitProfiles(@NotNull MavenExplicitProfiles profiles) {
myWatcher.setExplicitProfiles(profiles);
}
@@ -776,8 +779,10 @@ public class MavenProjectsManager extends MavenSimpleProjectComponent
@Override
public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
try {
+ MavenExplicitProfiles profiles = mavenProject.getActivatedProfilesIds();
String res =
- embedder.evaluateEffectivePom(mavenProject.getFile(), mavenProject.getActivatedProfilesIds());
+ embedder.evaluateEffectivePom(mavenProject.getFile(), profiles.getEnabledProfiles(),
+ profiles.getDisabledProfiles());
consumer.consume(res);
}
catch (UnsupportedOperationException e) {
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManagerWatcher.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManagerWatcher.java
index 81eb778b2466..b8644991eaff 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManagerWatcher.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsManagerWatcher.java
@@ -51,6 +51,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.idea.maven.model.MavenConstants;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.utils.MavenMergingUpdateQueue;
import org.jetbrains.idea.maven.utils.MavenUtil;
@@ -247,13 +248,13 @@ public class MavenProjectsManagerWatcher {
Disposer.dispose(myChangedDocumentsQueue);
}
- public synchronized void addManagedFilesWithProfiles(List<VirtualFile> files, List<String> explicitProfiles) {
+ public synchronized void addManagedFilesWithProfiles(List<VirtualFile> files, MavenExplicitProfiles explicitProfiles) {
myProjectsTree.addManagedFilesWithProfiles(files, explicitProfiles);
scheduleUpdateAll(false, true);
}
@TestOnly
- public synchronized void resetManagedFilesAndProfilesInTests(List<VirtualFile> files, List<String> explicitProfiles) {
+ public synchronized void resetManagedFilesAndProfilesInTests(List<VirtualFile> files, MavenExplicitProfiles explicitProfiles) {
myProjectsTree.resetManagedFilesAndProfiles(files, explicitProfiles);
scheduleUpdateAll(false, true);
}
@@ -263,7 +264,7 @@ public class MavenProjectsManagerWatcher {
scheduleUpdateAll(false, true);
}
- public synchronized void setExplicitProfiles(Collection<String> profiles) {
+ public synchronized void setExplicitProfiles(MavenExplicitProfiles profiles) {
myProjectsTree.setExplicitProfiles(profiles);
scheduleUpdateAll(false, false);
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java
index 89bf69711114..c7adefebf207 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenProjectsTree.java
@@ -68,8 +68,9 @@ public class MavenProjectsTree {
private volatile List<String> myIgnoredFilesPatterns = new ArrayList<String>();
private volatile Pattern myIgnoredFilesPatternsCache;
- private Set<String> myExplicitProfiles = new HashSet<String>();
- private final Set<String> myTemporarilyRemovedExplicitProfiles = new HashSet<String>();
+ private MavenExplicitProfiles myExplicitProfiles = MavenExplicitProfiles.NONE;
+ private final MavenExplicitProfiles myTemporarilyRemovedExplicitProfiles =
+ new MavenExplicitProfiles(new HashSet<String>(), new HashSet<String>());
private final List<MavenProject> myRootProjects = new ArrayList<MavenProject>();
@@ -100,7 +101,8 @@ public class MavenProjectsTree {
result.myManagedFilesPaths = readCollection(in, new LinkedHashSet<String>());
result.myIgnoredFilesPaths = readCollection(in, new ArrayList<String>());
result.myIgnoredFilesPatterns = readCollection(in, new ArrayList<String>());
- result.myExplicitProfiles = readCollection(in, new THashSet<String>());
+ result.myExplicitProfiles = new MavenExplicitProfiles(readCollection(in, new THashSet<String>()),
+ readCollection(in, new THashSet<String>()));
result.myRootProjects.addAll(readProjectsRecursively(in, result));
}
catch (IOException e) {
@@ -166,7 +168,8 @@ public class MavenProjectsTree {
writeCollection(out, myManagedFilesPaths);
writeCollection(out, myIgnoredFilesPaths);
writeCollection(out, myIgnoredFilesPatterns);
- writeCollection(out, myExplicitProfiles);
+ writeCollection(out, myExplicitProfiles.getEnabledProfiles());
+ writeCollection(out, myExplicitProfiles.getDisabledProfiles());
writeProjectsRecursively(out, myRootProjects);
}
finally {
@@ -194,7 +197,7 @@ public class MavenProjectsTree {
}
}
- public void resetManagedFilesPathsAndProfiles(List<String> paths, Collection<String> profiles) {
+ public void resetManagedFilesPathsAndProfiles(List<String> paths, MavenExplicitProfiles profiles) {
synchronized (myStateLock) {
myManagedFilesPaths = new LinkedHashSet<String>(paths);
}
@@ -202,19 +205,20 @@ public class MavenProjectsTree {
}
@TestOnly
- public void resetManagedFilesAndProfiles(List<VirtualFile> files, Collection<String> profiles) {
+ public void resetManagedFilesAndProfiles(List<VirtualFile> files, MavenExplicitProfiles profiles) {
resetManagedFilesPathsAndProfiles(MavenUtil.collectPaths(files), profiles);
}
- public void addManagedFilesWithProfiles(List<VirtualFile> files, Collection<String> profiles) {
+ public void addManagedFilesWithProfiles(List<VirtualFile> files, MavenExplicitProfiles profiles) {
List<String> newFiles;
- Set<String> newProfiles;
+ MavenExplicitProfiles newProfiles;
synchronized (myStateLock) {
newFiles = new ArrayList<String>(myManagedFilesPaths);
newFiles.addAll(MavenUtil.collectPaths(files));
- newProfiles = new THashSet<String>(myExplicitProfiles);
- newProfiles.addAll(profiles);
+ newProfiles = myExplicitProfiles.clone();
+ newProfiles.getEnabledProfiles().addAll(profiles.getEnabledProfiles());
+ newProfiles.getDisabledProfiles().addAll(profiles.getDisabledProfiles());
}
resetManagedFilesPathsAndProfiles(newFiles, newProfiles);
@@ -349,15 +353,15 @@ public class MavenProjectsTree {
}
}
- public Collection<String> getExplicitProfiles() {
+ public MavenExplicitProfiles getExplicitProfiles() {
synchronized (myStateLock) {
- return new THashSet<String>(myExplicitProfiles);
+ return myExplicitProfiles.clone();
}
}
- public void setExplicitProfiles(Collection<String> explicitProfiles) {
+ public void setExplicitProfiles(MavenExplicitProfiles explicitProfiles) {
synchronized (myStateLock) {
- myExplicitProfiles = new THashSet<String>(explicitProfiles);
+ myExplicitProfiles = explicitProfiles.clone();
}
fireProfilesChanged();
}
@@ -366,17 +370,25 @@ public class MavenProjectsTree {
Collection<String> available = getAvailableProfiles();
synchronized (myStateLock) {
- Collection<String> removedProfiles = new THashSet<String>(myExplicitProfiles);
- removedProfiles.removeAll(available);
- myTemporarilyRemovedExplicitProfiles.addAll(removedProfiles);
+ updateExplicitProfiles(myExplicitProfiles.getEnabledProfiles(), myTemporarilyRemovedExplicitProfiles.getEnabledProfiles(),
+ available);
+ updateExplicitProfiles(myExplicitProfiles.getDisabledProfiles(), myTemporarilyRemovedExplicitProfiles.getDisabledProfiles(),
+ available);
+ }
+ }
- Collection<String> restoredProfiles = new THashSet<String>(myTemporarilyRemovedExplicitProfiles);
- restoredProfiles.retainAll(available);
- myTemporarilyRemovedExplicitProfiles.removeAll(restoredProfiles);
+ private void updateExplicitProfiles(Collection<String> explicitProfiles, Collection<String> temporarilyRemovedExplicitProfiles,
+ Collection<String> available) {
+ Collection<String> removedProfiles = new THashSet<String>(explicitProfiles);
+ removedProfiles.removeAll(available);
+ temporarilyRemovedExplicitProfiles.addAll(removedProfiles);
- myExplicitProfiles.removeAll(removedProfiles);
- myExplicitProfiles.addAll(restoredProfiles);
- }
+ Collection<String> restoredProfiles = new THashSet<String>(temporarilyRemovedExplicitProfiles);
+ restoredProfiles.retainAll(available);
+ temporarilyRemovedExplicitProfiles.removeAll(restoredProfiles);
+
+ explicitProfiles.removeAll(removedProfiles);
+ explicitProfiles.addAll(restoredProfiles);
}
public Collection<String> getAvailableProfiles() {
@@ -396,17 +408,26 @@ public class MavenProjectsTree {
Collection<String> active = new THashSet<String>();
for (MavenProject each : getProjects()) {
available.addAll(each.getProfilesIds());
- active.addAll(each.getActivatedProfilesIds());
+ active.addAll(each.getActivatedProfilesIds().getEnabledProfiles());
}
- Collection<String> explicitProfiles = getExplicitProfiles();
+ Collection<String> enabledProfiles = getExplicitProfiles().getEnabledProfiles();
+ Collection<String> disabledProfiles = getExplicitProfiles().getDisabledProfiles();
for (String each : available) {
- MavenProfileKind state = MavenProfileKind.NONE;
- if (explicitProfiles.contains(each)) {
+ MavenProfileKind state;
+ if (disabledProfiles.contains(each)) {
+ state = MavenProfileKind.NONE;
+ }
+ else if (enabledProfiles.contains(each)) {
state = MavenProfileKind.EXPLICIT;
}
- else if (active.contains(each)) state = MavenProfileKind.IMPLICIT;
+ else if (active.contains(each)) {
+ state = MavenProfileKind.IMPLICIT;
+ }
+ else {
+ state = MavenProfileKind.NONE;
+ }
result.add(Pair.create(each, state));
}
return result;
@@ -414,7 +435,7 @@ public class MavenProjectsTree {
public void updateAll(boolean force, MavenGeneralSettings generalSettings, MavenProgressIndicator process) {
List<VirtualFile> managedFiles = getExistingManagedFiles();
- Collection<String> explicitProfiles = getExplicitProfiles();
+ MavenExplicitProfiles explicitProfiles = getExplicitProfiles();
MavenProjectReader projectReader = new MavenProjectReader();
update(managedFiles, true, force, explicitProfiles, projectReader, generalSettings, process);
@@ -434,7 +455,7 @@ public class MavenProjectsTree {
private void update(Collection<VirtualFile> files,
boolean recursive,
boolean force,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
MavenProjectReader projectReader,
MavenGeneralSettings generalSettings,
MavenProgressIndicator process) {
@@ -469,7 +490,7 @@ public class MavenProjectsTree {
private void doAdd(final VirtualFile f,
boolean recursuve,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
UpdateContext updateContext,
Stack<MavenProject> updateStack,
MavenProjectReader reader,
@@ -503,7 +524,7 @@ public class MavenProjectsTree {
boolean isNew,
boolean recursive,
boolean force,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
UpdateContext updateContext,
Stack<MavenProject> updateStack,
MavenProjectReader reader,
@@ -649,7 +670,7 @@ public class MavenProjectsTree {
}
private MavenProjectTimestamp calculateTimestamp(final MavenProject mavenProject,
- final Collection<String> explicitProfiles,
+ final MavenExplicitProfiles explicitProfiles,
final MavenGeneralSettings generalSettings) {
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
@@ -712,7 +733,7 @@ public class MavenProjectsTree {
private void delete(MavenProjectReader projectReader,
List<VirtualFile> files,
- Collection<String> explicitProfiles,
+ MavenExplicitProfiles explicitProfiles,
MavenGeneralSettings generalSettings,
MavenProgressIndicator process) {
if (files.isEmpty()) return;
@@ -892,7 +913,7 @@ public class MavenProjectsTree {
try {
final CRC32 crc = new CRC32();
- Set<String> profiles = myExplicitProfiles;
+ MavenExplicitProfiles profiles = myExplicitProfiles;
if (profiles != null) {
updateCrc(crc, profiles.hashCode());
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettings.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettings.java
index 3451f0c33f2e..4b0ef285a76d 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettings.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettings.java
@@ -24,10 +24,16 @@ public class MavenWorkspaceSettings {
public MavenImportingSettings importingSettings = new MavenImportingSettings();
public List<String> enabledProfiles = new ArrayList<String>();
+ public List<String> disabledProfiles = new ArrayList<String>();
public void setEnabledProfiles(Collection<String> profiles) {
enabledProfiles.clear();
enabledProfiles.addAll(profiles);
}
+ public void setDisabledProfiles(Collection<String> profiles) {
+ disabledProfiles.clear();
+ disabledProfiles.addAll(profiles);
+ }
+
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettingsComponent.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettingsComponent.java
index dc1bbdb79a8e..d5e9e2d92815 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettingsComponent.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenWorkspaceSettingsComponent.java
@@ -18,6 +18,7 @@ package org.jetbrains.idea.maven.project;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
@State(name = "MavenImportPreferences", storages = {@Storage( file = StoragePathMacros.WORKSPACE_FILE)})
public class MavenWorkspaceSettingsComponent implements PersistentStateComponent<MavenWorkspaceSettings> {
@@ -35,7 +36,9 @@ public class MavenWorkspaceSettingsComponent implements PersistentStateComponent
@NotNull
public MavenWorkspaceSettings getState() {
- mySettings.setEnabledProfiles(MavenProjectsManager.getInstance(myProject).getExplicitProfiles());
+ MavenExplicitProfiles profiles = MavenProjectsManager.getInstance(myProject).getExplicitProfiles();
+ mySettings.setEnabledProfiles(profiles.getEnabledProfiles());
+ mySettings.setDisabledProfiles(profiles.getDisabledProfiles());
return mySettings;
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RunBuildAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RunBuildAction.java
index e52453070a0e..497f29b6a7a8 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RunBuildAction.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/RunBuildAction.java
@@ -19,6 +19,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import org.jetbrains.idea.maven.execution.MavenRunConfigurationType;
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.utils.MavenDataKeys;
import org.jetbrains.idea.maven.utils.actions.MavenAction;
@@ -46,10 +47,12 @@ public class RunBuildAction extends MavenAction {
if (!perform) return true;
+ MavenExplicitProfiles explicitProfiles = MavenActionUtil.getProjectsManager(context).getExplicitProfiles();
final MavenRunnerParameters params = new MavenRunnerParameters(true,
project.getDirectory(),
goals,
- MavenActionUtil.getProjectsManager(context).getExplicitProfiles());
+ explicitProfiles.getEnabledProfiles(),
+ explicitProfiles.getDisabledProfiles());
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(context), params, null);
return true;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ToggleProfileAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ToggleProfileAction.java
index 3e9bf7f92ddd..af0fbd091aad 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ToggleProfileAction.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/project/actions/ToggleProfileAction.java
@@ -16,15 +16,15 @@
package org.jetbrains.idea.maven.project.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
+import org.jetbrains.idea.maven.model.MavenProfileKind;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.project.ProjectBundle;
import org.jetbrains.idea.maven.utils.MavenDataKeys;
import org.jetbrains.idea.maven.utils.actions.MavenAction;
import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
+import java.util.Map;
import java.util.Set;
public class ToggleProfileAction extends MavenAction {
@@ -32,47 +32,105 @@ public class ToggleProfileAction extends MavenAction {
super.update(e);
if (!isAvailable(e)) return;
- MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
- List<String> profiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
-
- e.getPresentation().setText(isActive(projectsManager, profiles)
- ? ProjectBundle.message("maven.profile.deactivate")
- : ProjectBundle.message("maven.profile.activate"));
+ MavenProfileKind targetState = getTargetState(e);
+ String text;
+ switch (targetState) {
+ case NONE:
+ text = ProjectBundle.message("maven.profile.deactivate");
+ break;
+ case EXPLICIT:
+ text = ProjectBundle.message("maven.profile.activate");
+ break;
+ case IMPLICIT:
+ default:
+ text = ProjectBundle.message("maven.profile.default");
+ break;
+ }
+ e.getPresentation().setText(text);
}
@Override
protected boolean isAvailable(AnActionEvent e) {
if (!super.isAvailable(e)) return false;
- List<String> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
- if (selectedProfiles == null || selectedProfiles.isEmpty()) return false;
+ return getTargetState(e) != null;
+ }
+
+ private static MavenProfileKind getTargetState(AnActionEvent e) {
+ Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
+ if (selectedProfiles == null || selectedProfiles.isEmpty()) return null;
- Collection<String> activeProfiles = MavenActionUtil.getProjectsManager(e.getDataContext()).getExplicitProfiles();
- int activeCount = 0;
- for (String profile : selectedProfiles) {
- if (activeProfiles.contains(profile)) {
- activeCount++;
+ MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
+ return getTargetState(projectsManager, selectedProfiles);
+ }
+
+ private static MavenProfileKind getTargetState(MavenProjectsManager projectsManager, Map<String, MavenProfileKind> profiles) {
+ MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
+ MavenProfileKind targetState = null;
+ // all profiles should target to the same state
+ for (Map.Entry<String, MavenProfileKind> profile : profiles.entrySet()) {
+ MavenProfileKind profileTargetState = getTargetState(profile, explicitProfiles);
+ if (targetState == null) {
+ targetState = profileTargetState;
+ }
+ else if (!targetState.equals(profileTargetState)) {
+ targetState = null;
+ break;
}
}
- return activeCount == 0 || activeCount == selectedProfiles.size();
+ return targetState;
}
- private static boolean isActive(MavenProjectsManager projectsManager, List<String> profiles) {
- return projectsManager.getExplicitProfiles().contains(profiles.get(0));
+ private static MavenProfileKind getTargetState(Map.Entry<String, MavenProfileKind> profile, MavenExplicitProfiles explicitProfiles) {
+ MavenProfileKind targetState;
+ if (explicitProfiles.getDisabledProfiles().contains(profile.getKey())) {
+ // explicitly disabled -> explicitly enabled
+ targetState = MavenProfileKind.EXPLICIT;
+ }
+ else if (explicitProfiles.getEnabledProfiles().contains(profile.getKey())) {
+ // explicitly enabled -> default
+ targetState = MavenProfileKind.IMPLICIT;
+ }
+ else {
+ // default
+ if (MavenProfileKind.NONE.equals(profile.getValue())) {
+ // default inactive -> explicitly enabled
+ targetState = MavenProfileKind.EXPLICIT;
+ }
+ else {
+ // default active -> explicitly disabled
+ targetState = MavenProfileKind.NONE;
+ }
+ }
+ return targetState;
}
@Override
public void actionPerformed(AnActionEvent e) {
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
- List<String> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
+ Map<String, MavenProfileKind> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
+ Set<String> selectedProfileIds = selectedProfiles.keySet();
- Set<String> activeProfiles = new HashSet<String>(manager.getExplicitProfiles());
- if (isActive(manager, selectedProfiles)) {
- activeProfiles.removeAll(selectedProfiles);
- }
- else {
- activeProfiles.addAll(selectedProfiles);
+ MavenProfileKind targetState = getTargetState(manager, selectedProfiles);
+ MavenExplicitProfiles newExplicitProfiles = manager.getExplicitProfiles().clone();
+ switch (targetState) {
+ case NONE:
+ // disable explicitly
+ newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
+ newExplicitProfiles.getDisabledProfiles().addAll(selectedProfileIds);
+ break;
+ case EXPLICIT:
+ // enable explicitly
+ newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
+ newExplicitProfiles.getEnabledProfiles().addAll(selectedProfileIds);
+ break;
+ case IMPLICIT:
+ default:
+ // reset to default state
+ newExplicitProfiles.getEnabledProfiles().removeAll(selectedProfileIds);
+ newExplicitProfiles.getDisabledProfiles().removeAll(selectedProfileIds);
+ break;
}
- manager.setExplicitProfiles(activeProfiles);
+ manager.setExplicitProfiles(newExplicitProfiles);
}
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java
index a0882e7c87fd..006f4caeac3a 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenEmbedderWrapper.java
@@ -93,22 +93,26 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper<MavenServ
@NotNull
public MavenServerExecutionResult resolveProject(@NotNull final VirtualFile file,
- @NotNull final Collection<String> activeProfiles) throws MavenProcessCanceledException {
+ @NotNull final Collection<String> activeProfiles,
+ @NotNull final Collection<String> inactiveProfiles)
+ throws MavenProcessCanceledException {
return perform(new RetriableCancelable<MavenServerExecutionResult>() {
@Override
public MavenServerExecutionResult execute() throws RemoteException, MavenServerProcessCanceledException {
- return getOrCreateWrappee().resolveProject(new File(file.getPath()), activeProfiles);
+ return getOrCreateWrappee().resolveProject(new File(file.getPath()), activeProfiles, inactiveProfiles);
}
});
}
@Nullable
- public String evaluateEffectivePom(@NotNull final VirtualFile file, @NotNull final Collection<String> activeProfiles)
- throws MavenProcessCanceledException {
+ public String evaluateEffectivePom(@NotNull final VirtualFile file,
+ @NotNull final Collection<String> activeProfiles,
+ @NotNull final Collection<String> inactiveProfiles) throws MavenProcessCanceledException {
return perform(new RetriableCancelable<String>() {
@Override
public String execute() throws RemoteException, MavenServerProcessCanceledException {
- return getOrCreateWrappee().evaluateEffectivePom(new File(file.getPath()), new ArrayList<String>(activeProfiles));
+ return getOrCreateWrappee()
+ .evaluateEffectivePom(new File(file.getPath()), new ArrayList<String>(activeProfiles), new ArrayList<String>(inactiveProfiles));
}
});
}
@@ -165,14 +169,14 @@ public abstract class MavenEmbedderWrapper extends RemoteObjectWrapper<MavenServ
@NotNull
public MavenServerExecutionResult execute(@NotNull final VirtualFile file,
- @NotNull final Collection<String> activeProfiles,
- @NotNull final List<String> goals) throws MavenProcessCanceledException {
+ @NotNull final Collection<String> activeProfiles,
+ @NotNull final Collection<String> inactiveProfiles,
+ @NotNull final List<String> goals) throws MavenProcessCanceledException {
return perform(new RetriableCancelable<MavenServerExecutionResult>() {
@Override
public MavenServerExecutionResult execute() throws RemoteException, MavenServerProcessCanceledException {
return getOrCreateWrappee()
- .execute(new File(file.getPath()), activeProfiles, Collections.<String>emptyList(), goals, Collections.<String>emptyList(), false,
- false);
+ .execute(new File(file.getPath()), activeProfiles, inactiveProfiles, goals, Collections.<String>emptyList(), false, false);
}
});
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java
index 5777e246f858..7ef16bdcfc4e 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java
@@ -45,6 +45,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.execution.MavenRunnerSettings;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.model.MavenModel;
import org.jetbrains.idea.maven.project.MavenConsole;
@@ -409,7 +410,7 @@ public class MavenServerManager extends RemoteObjectWrapper<MavenServer> impleme
public ProfileApplicationResult applyProfiles(final MavenModel model,
final File basedir,
- final Collection<String> explicitProfiles,
+ final MavenExplicitProfiles explicitProfiles,
final Collection<String> alwaysOnProfiles) {
return perform(new Retriable<ProfileApplicationResult>() {
@Override
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenBeforeRunTasksProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenBeforeRunTasksProvider.java
index b98fff5cd5d7..d128dac01b80 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenBeforeRunTasksProvider.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenBeforeRunTasksProvider.java
@@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.execution.MavenEditGoalDialog;
import org.jetbrains.idea.maven.execution.MavenRunner;
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.MavenLog;
@@ -162,7 +163,7 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider<MavenBefo
FileDocumentManager.getInstance().saveAllDocuments();
- final Collection<String> explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
+ final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
final MavenRunner mavenRunner = MavenRunner.getInstance(project);
targetDone.down();
@@ -173,7 +174,8 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider<MavenBefo
true,
mavenProject.getDirectory(),
ParametersListUtil.parse(task.getGoal()),
- explicitProfiles);
+ explicitProfiles.getEnabledProfiles(),
+ explicitProfiles.getDisabledProfiles());
result[0] = mavenRunner.runBatch(Collections.singletonList(params),
null,
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenKeymapExtension.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenKeymapExtension.java
index 7bde42d519e1..25db4aa482be 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenKeymapExtension.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenKeymapExtension.java
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.TestOnly;
import org.jetbrains.idea.maven.execution.MavenRunConfigurationType;
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
import org.jetbrains.idea.maven.model.MavenConstants;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.model.MavenPlugin;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.utils.MavenArtifactUtil;
@@ -176,10 +177,12 @@ public class MavenKeymapExtension implements KeymapExtension {
public void actionPerformed(AnActionEvent e) {
final DataContext context = e.getDataContext();
+ MavenExplicitProfiles explicitProfiles = MavenActionUtil.getProjectsManager(context).getExplicitProfiles();
MavenRunnerParameters params = new MavenRunnerParameters(true,
myMavenProject.getDirectory(),
Arrays.asList(myGoal),
- MavenActionUtil.getProjectsManager(context).getExplicitProfiles());
+ explicitProfiles.getEnabledProfiles(),
+ explicitProfiles.getDisabledProfiles());
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(context), params, null);
}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenTasksManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenTasksManager.java
index 3dabc5a32f25..c085e1867d10 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenTasksManager.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/MavenTasksManager.java
@@ -33,6 +33,7 @@ import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.execution.MavenRunner;
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProject;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.MavenSimpleProjectComponent;
@@ -133,10 +134,12 @@ public class MavenTasksManager extends MavenSimpleProjectComponent implements Pe
for (MavenCompilerTask each : tasks) {
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each.getProjectPath());
if (file == null) continue;
+ MavenExplicitProfiles explicitProfiles = myProjectsManager.getExplicitProfiles();
parametersList.add(new MavenRunnerParameters(true,
file.getParent().getPath(),
Arrays.asList(each.getGoal()),
- myProjectsManager.getExplicitProfiles()));
+ explicitProfiles.getEnabledProfiles(),
+ explicitProfiles.getDisabledProfiles()));
}
}
return myRunner.runBatch(parametersList, null, null, TasksBundle.message("maven.tasks.executing"), context.getProgressIndicator());
@@ -194,4 +197,4 @@ public class MavenTasksManager extends MavenSimpleProjectComponent implements Pe
public interface Listener {
void compileTasksChanged();
}
-} \ No newline at end of file
+}
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenDataKeys.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenDataKeys.java
index 397447c44393..aff34a18217a 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenDataKeys.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenDataKeys.java
@@ -18,16 +18,18 @@ package org.jetbrains.idea.maven.utils;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.openapi.actionSystem.DataKey;
import org.jetbrains.idea.maven.model.MavenArtifact;
+import org.jetbrains.idea.maven.model.MavenProfileKind;
import javax.swing.*;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
public class MavenDataKeys {
public static final DataKey<List<String>> MAVEN_GOALS = DataKey.create("MAVEN_GOALS");
public static final DataKey<RunnerAndConfigurationSettings> RUN_CONFIGURATION = DataKey.create("MAVEN_RUN_CONFIGURATION");
- public static final DataKey<List<String>> MAVEN_PROFILES = DataKey.create("MAVEN_PROFILES");
+ public static final DataKey<Map<String, MavenProfileKind>> MAVEN_PROFILES = DataKey.create("MAVEN_PROFILES");
public static final DataKey<Collection<MavenArtifact>> MAVEN_DEPENDENCIES = DataKey.create("MAVEN_DEPENDENCIES");
public static final DataKey<JTree> MAVEN_PROJECTS_TREE = DataKey.create("MAVEN_PROJECTS_TREE");
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java
index 30755ff733d8..1f0190aaff48 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenModuleBuilderHelper.java
@@ -194,7 +194,9 @@ public class MavenModuleBuilderHelper {
}
MavenRunnerParameters params = new MavenRunnerParameters(
- false, workingDir.getPath(), Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"), null);
+ false, workingDir.getPath(),
+ Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"),
+ Collections.<String>emptyList());
MavenRunner runner = MavenRunner.getInstance(project);
MavenRunnerSettings settings = runner.getState().clone();
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java
index 53a486fb47ba..730284863e32 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectBuilder.java
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.importing.MavenDefaultModifiableModelsProvider;
import org.jetbrains.idea.maven.importing.MavenUIModifiableModelsProvider;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.model.MavenId;
import org.jetbrains.idea.maven.project.*;
import org.jetbrains.idea.maven.utils.*;
@@ -53,7 +54,8 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
private VirtualFile myImportRoot;
private List<VirtualFile> myFiles;
private List<String> myProfiles = new ArrayList<String>();
- private List<String> mySelectedProfiles = new ArrayList<String>();
+ private List<String> myActivatedProfiles = new ArrayList<String>();
+ private MavenExplicitProfiles mySelectedProfiles = MavenExplicitProfiles.NONE;
private MavenProjectsTree myMavenProjectTree;
private List<MavenProject> mySelectedProjects;
@@ -109,20 +111,14 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
settings.generalSettings.setUserSettingsFile(settingsFile.trim());
}
- List<String> selectedProfiles = getSelectedProfiles();
+ MavenExplicitProfiles selectedProfiles = getSelectedProfiles();
- String profilesList = System.getProperty("idea.maven.import.enabled.profiles");
- if (profilesList != null) {
- Set<String> selectedProfilesSet = new LinkedHashSet<String>(selectedProfiles);
-
- for (String profile : StringUtil.split(profilesList, ",")) {
- String trimmedProfileName = profile.trim();
- if (!trimmedProfileName.isEmpty()) {
- selectedProfilesSet.add(trimmedProfileName);
- }
- }
-
- selectedProfiles = new ArrayList<String>(selectedProfilesSet);
+ String enabledProfilesList = System.getProperty("idea.maven.import.enabled.profiles");
+ String disabledProfilesList = System.getProperty("idea.maven.import.disabled.profiles");
+ if (enabledProfilesList != null || disabledProfilesList != null) {
+ selectedProfiles = selectedProfiles.clone();
+ appendProfilesFromString(selectedProfiles.getEnabledProfiles(), enabledProfilesList);
+ appendProfilesFromString(selectedProfiles.getDisabledProfiles(), disabledProfilesList);
}
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
@@ -138,9 +134,21 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
: new MavenDefaultModifiableModelsProvider(project));
}
+ private void appendProfilesFromString(Collection<String> selectedProfiles, String profilesList) {
+ if (profilesList == null) return;
+
+ for (String profile : StringUtil.split(profilesList, ",")) {
+ String trimmedProfileName = profile.trim();
+ if (!trimmedProfileName.isEmpty()) {
+ selectedProfiles.add(trimmedProfileName);
+ }
+ }
+ }
+
public boolean setRootDirectory(@Nullable Project projectToUpdate, final String root) throws ConfigurationException {
getParameters().myFiles = null;
getParameters().myProfiles.clear();
+ getParameters().myActivatedProfiles.clear();
getParameters().myMavenProjectTree = null;
getParameters().myProjectToUpdate = projectToUpdate; // We cannot determinate project in non-EDT thread.
@@ -174,7 +182,8 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
private void collectProfiles(MavenProgressIndicator process) {
process.setText(ProjectBundle.message("maven.searching.profiles"));
- Set<String> uniqueProfiles = new LinkedHashSet<String>();
+ Set<String> availableProfiles = new LinkedHashSet<String>();
+ Set<String> activatedProfiles = new LinkedHashSet<String>();
MavenProjectReader reader = new MavenProjectReader();
MavenGeneralSettings generalSettings = getGeneralSettings();
MavenProjectReaderProjectLocator locator = new MavenProjectReaderProjectLocator() {
@@ -185,21 +194,27 @@ public class MavenProjectBuilder extends ProjectImportBuilder<MavenProject> {
for (VirtualFile f : getParameters().myFiles) {
MavenProject project = new MavenProject(f);
process.setText2(ProjectBundle.message("maven.reading.pom", f.getPath()));
- project.read(generalSettings, Collections.<String>emptyList(), reader, locator);
- uniqueProfiles.addAll(project.getProfilesIds());
+ project.read(generalSettings, MavenExplicitProfiles.NONE, reader, locator);
+ availableProfiles.addAll(project.getProfilesIds());
+ activatedProfiles.addAll(project.getActivatedProfilesIds().getEnabledProfiles());
}
- getParameters().myProfiles = new ArrayList<String>(uniqueProfiles);
+ getParameters().myProfiles = new ArrayList<String>(availableProfiles);
+ getParameters().myActivatedProfiles = new ArrayList<String>(activatedProfiles);
}
public List<String> getProfiles() {
return getParameters().myProfiles;
}
- public List<String> getSelectedProfiles() {
+ public List<String> getActivatedProfiles() {
+ return getParameters().myActivatedProfiles;
+ }
+
+ public MavenExplicitProfiles getSelectedProfiles() {
return getParameters().mySelectedProfiles;
}
- public boolean setSelectedProfiles(List<String> profiles) {
+ public boolean setSelectedProfiles(MavenExplicitProfiles profiles) {
getParameters().myMavenProjectTree = null;
getParameters().mySelectedProfiles = profiles;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectOpenProcessor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectOpenProcessor.java
index 0ba88d7330a1..db9b5562e073 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectOpenProcessor.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectOpenProcessor.java
@@ -26,9 +26,9 @@ import com.intellij.projectImport.ProjectOpenProcessorBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.model.MavenConstants;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
import org.jetbrains.idea.maven.project.MavenProject;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -45,7 +45,7 @@ public class MavenProjectOpenProcessor extends ProjectOpenProcessorBase<MavenPro
public boolean doQuickImport(VirtualFile file, WizardContext wizardContext) {
getBuilder().setFiles(Arrays.asList(file));
- if (!getBuilder().setSelectedProfiles(new ArrayList<String>())) return false;
+ if (!getBuilder().setSelectedProfiles(MavenExplicitProfiles.NONE)) return false;
List<MavenProject> projects = getBuilder().getList();
if (projects.size() != 1) return false;
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/SelectProfilesStep.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/SelectProfilesStep.java
index 4f0238c2694b..3fc7fb47b202 100644
--- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/SelectProfilesStep.java
+++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/SelectProfilesStep.java
@@ -15,14 +15,21 @@
*/
package org.jetbrains.idea.maven.wizards;
-import com.intellij.ide.util.ElementsChooser;
+import com.intellij.ide.util.MultiStateElementsChooser;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.projectImport.ProjectImportWizardStep;
+import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.idea.maven.model.MavenExplicitProfiles;
+import org.jetbrains.idea.maven.model.MavenProfileKind;
import javax.swing.*;
-import java.util.ArrayList;
+import javax.swing.table.TableCellRenderer;
+import java.awt.*;
+import java.util.*;
import java.util.List;
/**
@@ -30,7 +37,8 @@ import java.util.List;
*/
public class SelectProfilesStep extends ProjectImportWizardStep {
private JPanel panel;
- private ElementsChooser<String> profileChooser;
+ private MultiStateElementsChooser<String, MavenProfileKind> profileChooser;
+ private MavenProfileKindMarkStateDescriptor myMarkStateDescriptor;
public SelectProfilesStep(final WizardContext context) {
super(context);
@@ -52,7 +60,8 @@ public class SelectProfilesStep extends ProjectImportWizardStep {
}
public void createUIComponents() {
- profileChooser = new ElementsChooser<String>(true);
+ myMarkStateDescriptor = new MavenProfileKindMarkStateDescriptor();
+ profileChooser = new MultiStateElementsChooser<String, MavenProfileKind>(true, myMarkStateDescriptor);
}
public JComponent getComponent() {
@@ -61,15 +70,39 @@ public class SelectProfilesStep extends ProjectImportWizardStep {
public void updateStep() {
List<String> allProfiles = getBuilder().getProfiles();
- List<String> markedProfiles = new ArrayList<String>(getBuilder().getSelectedProfiles());
- markedProfiles.retainAll(allProfiles); // mark only existing profiles
+ List<String> activatedProfiles = getBuilder().getActivatedProfiles();
+ MavenExplicitProfiles selectedProfiles = getBuilder().getSelectedProfiles();
+ List<String> enabledProfiles = new ArrayList<String>(selectedProfiles.getEnabledProfiles());
+ List<String> disabledProfiles = new ArrayList<String>(selectedProfiles.getDisabledProfiles());
+ enabledProfiles.retainAll(allProfiles); // mark only existing profiles
+ disabledProfiles.retainAll(allProfiles); // mark only existing profiles
- profileChooser.setElements(allProfiles, false);
- profileChooser.markElements(markedProfiles);
+ myMarkStateDescriptor.setActivatedProfiles(activatedProfiles);
+ profileChooser.setElements(allProfiles, null);
+ profileChooser.markElements(enabledProfiles, MavenProfileKind.EXPLICIT);
+ profileChooser.markElements(disabledProfiles, MavenProfileKind.NONE);
}
public boolean validate() throws ConfigurationException {
- return getBuilder().setSelectedProfiles(profileChooser.getMarkedElements());
+ Collection<String> activatedProfiles = myMarkStateDescriptor.getActivatedProfiles();
+ MavenExplicitProfiles newSelectedProfiles = MavenExplicitProfiles.NONE.clone();
+ for (Map.Entry<String, MavenProfileKind> entry : profileChooser.getElementMarkStates().entrySet()) {
+ String profile = entry.getKey();
+ MavenProfileKind profileKind = entry.getValue();
+ switch (profileKind) {
+ case NONE:
+ if (activatedProfiles.contains(profile)) {
+ newSelectedProfiles.getDisabledProfiles().add(profile);
+ }
+ break;
+ case EXPLICIT:
+ newSelectedProfiles.getEnabledProfiles().add(profile);
+ break;
+ case IMPLICIT:
+ break;
+ }
+ }
+ return getBuilder().setSelectedProfiles(newSelectedProfiles);
}
public void updateDataModel() {
@@ -79,4 +112,100 @@ public class SelectProfilesStep extends ProjectImportWizardStep {
public String getHelpId() {
return "reference.dialogs.new.project.import.maven.page2";
}
+
+ private static class MavenProfileKindMarkStateDescriptor
+ implements MultiStateElementsChooser.MarkStateDescriptor<String, MavenProfileKind> {
+ private Collection<String> myActivatedProfiles = Collections.emptySet();
+
+ public Collection<String> getActivatedProfiles() {
+ return myActivatedProfiles;
+ }
+
+ public void setActivatedProfiles(Collection<String> activatedProfiles) {
+ myActivatedProfiles = new THashSet<String>(activatedProfiles);
+ }
+
+ @NotNull
+ @Override
+ public MavenProfileKind getDefaultState(@NotNull String element) {
+ return myActivatedProfiles.contains(element) ? MavenProfileKind.IMPLICIT : MavenProfileKind.NONE;
+ }
+
+ @NotNull
+ @Override
+ public MavenProfileKind getNextState(@NotNull String element, @NotNull MavenProfileKind state) {
+ MavenProfileKind nextState;
+ switch (state) {
+ case NONE:
+ nextState = MavenProfileKind.EXPLICIT;
+ break;
+ case EXPLICIT:
+ nextState = getDefaultState(element);
+ break;
+ case IMPLICIT:
+ default:
+ nextState = MavenProfileKind.NONE;
+ break;
+ }
+ return nextState;
+ }
+
+ @Nullable
+ @Override
+ public MavenProfileKind getNextState(@NotNull Map<String, MavenProfileKind> elementsWithStates) {
+ MavenProfileKind nextState = null;
+ for (Map.Entry<String, MavenProfileKind> entry : elementsWithStates.entrySet()) {
+ MavenProfileKind nextElementState = getNextState(entry.getKey(), entry.getValue());
+ if (nextState == null) {
+ nextState = nextElementState;
+ }
+ else if (!nextState.equals(nextElementState)) {
+ nextState = null;
+ break;
+ }
+ }
+ return nextState;
+ }
+
+ @Override
+ public boolean isMarked(@NotNull MavenProfileKind state) {
+ return state != MavenProfileKind.NONE;
+ }
+
+ @Nullable
+ @Override
+ public MavenProfileKind getMarkState(@Nullable Object value) {
+ return value instanceof MavenProfileKind ? (MavenProfileKind)value : null;
+ }
+
+ @Nullable
+ @Override
+ public TableCellRenderer getMarkRenderer() {
+ return new CheckboxTableCellRenderer();
+ }
+ }
+
+ private static class CheckboxTableCellRenderer extends JCheckBox implements TableCellRenderer {
+ public CheckboxTableCellRenderer() {
+ setHorizontalAlignment(SwingConstants.CENTER);
+ setBorder(null);
+ }
+
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ if (isSelected) {
+ setForeground(table.getSelectionForeground());
+ super.setBackground(table.getSelectionBackground());
+ }
+ else {
+ setForeground(table.getForeground());
+ setBackground(table.getBackground());
+ }
+
+ MavenProfileKind state = (MavenProfileKind)value;
+ setSelected(state != MavenProfileKind.NONE);
+ setEnabled(state != MavenProfileKind.IMPLICIT);
+
+ return this;
+ }
+ }
}