diff options
Diffstat (limited to 'plugins/maven/src/main/java/org/jetbrains/idea/maven/project')
11 files changed, 212 insertions, 111 deletions
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); } } |