From 58e0fd9fe8fc0bf78e55abc10e487e4c639ab283 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 4 Aug 2011 14:11:10 +0400 Subject: [PATCH] new framework detection: conversion of old excludes settings --- .../EnableAutodetectionWorker.java | 2 + .../FacetAutodetectingManager.java | 6 - .../FacetAutodetectingManagerImpl.java | 46 +------ .../FacetAutodetectionConfigurable.java | 4 +- .../impl/ui/facetType/FacetTypeEditor.java | 4 - .../DetectionExcludesConfiguration.java | 3 +- .../impl/FrameworkDetectionManager.java | 2 +- .../DetectionExcludesConfigurable.java | 35 +++-- .../DetectionExcludesConfigurationImpl.java | 96 ++++++++++---- .../DisabledAutodetectionByTypeElement.java | 2 +- .../DisabledAutodetectionInModuleElement.java | 2 +- .../old}/DisabledAutodetectionInfo.java | 2 +- ...ldFacetDetectionExcludesConfiguration.java | 101 +++++++++++++++ .../ConvertingOldDetectionExcludesTest.java | 120 ++++++++++++++++++ .../src/META-INF/LangExtensions.xml | 1 + 15 files changed, 331 insertions(+), 95 deletions(-) rename {java/idea-ui/src/com/intellij/facet/impl/autodetecting => platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old}/DisabledAutodetectionByTypeElement.java (98%) rename {java/idea-ui/src/com/intellij/facet/impl/autodetecting => platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old}/DisabledAutodetectionInModuleElement.java (98%) rename {java/idea-ui/src/com/intellij/facet/impl/autodetecting => platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old}/DisabledAutodetectionInfo.java (98%) create mode 100644 platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/OldFacetDetectionExcludesConfiguration.java create mode 100644 platform/lang-impl/testSrc/com/intellij/framework/detection/ConvertingOldDetectionExcludesTest.java diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java index ba8b339ffa77..57bcf1f1ca55 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java +++ b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/EnableAutodetectionWorker.java @@ -16,6 +16,8 @@ package com.intellij.facet.impl.autodetecting; import com.intellij.facet.FacetType; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInModuleElement; import com.intellij.ide.caches.FileContent; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java index 9e1a5f70322d..9c7770c122d0 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java +++ b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManager.java @@ -34,10 +34,4 @@ public abstract class FacetAutodetectingManager { public abstract void disableAutodetectionInFiles(@NotNull FacetType type, @NotNull Module module, @NotNull String... fileUrls); public abstract void disableAutodetectionInModule(FacetType type, Module module); - - public abstract void disableAutodetectionInProject(); - - public abstract void disableAutodetectionInProject(FacetType type); - - public abstract boolean hasDetectors(@NotNull FacetType facetType); } diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java index 9bf00c07c103..70e6b806f072 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java +++ b/java/idea-ui/src/com/intellij/facet/impl/autodetecting/FacetAutodetectingManagerImpl.java @@ -25,12 +25,11 @@ import com.intellij.facet.autodetecting.UnderlyingFacetSelector; import com.intellij.facet.impl.autodetecting.model.FacetInfo2; import com.intellij.facet.impl.autodetecting.model.ProjectFacetInfoSet; import com.intellij.facet.pointers.FacetPointersManager; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInfo; import com.intellij.ide.caches.FileContent; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; @@ -52,16 +51,7 @@ import java.util.*; /** * @author nik */ -@State( - name = FacetAutodetectingManagerImpl.COMPONENT_NAME, - storages = { - @Storage( - file = "$PROJECT_FILE$" - ) - } -) -public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager implements AutodetectionFilter, ProjectComponent, PersistentStateComponent { - @NonNls public static final String COMPONENT_NAME = "FacetAutodetectingManager"; +public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager implements AutodetectionFilter, ProjectComponent { private final MultiValuesMap myDetectors = new MultiValuesMap(); private final Map> myId2Detector = new HashMap>(); private final Project myProject; @@ -108,7 +98,7 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp @NonNls @NotNull public String getComponentName() { - return COMPONENT_NAME; + return "OldFacetAutodetectingManagerImpl"; } public void initComponent() { @@ -145,14 +135,6 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp return myDisabledAutodetectionInfo.findElement(type.getStringId()); } - public DisabledAutodetectionInfo getState() { - return myDisabledAutodetectionInfo; - } - - public void loadState(final DisabledAutodetectionInfo state) { - myDisabledAutodetectionInfo = state; - } - public void processFile(FileContent fileContent) { final VirtualFile file = fileContent.getVirtualFile(); if (!file.isValid() || file.isDirectory() || myProject.isDisposed() @@ -231,10 +213,6 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp } } - public boolean hasDetectors(@NotNull FacetType facetType) { - return myFacetTypesWithDetectors.contains(facetType); - } - public void redetectFacets() { myEnableAutodetectionWorker.redetectFacets(); } @@ -298,29 +276,19 @@ public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager imp } public void disableAutodetectionInModule(final FacetType type, final Module module) { - getState().addDisabled(type.getStringId(), module.getName()); - } - - public void disableAutodetectionInProject() { - for (FacetType facetType : FacetTypeRegistry.getInstance().getFacetTypes()) { - disableAutodetectionInProject(facetType); - } - } - - public void disableAutodetectionInProject(final FacetType type) { - getState().addDisabled(type.getStringId()); + myDisabledAutodetectionInfo.addDisabled(type.getStringId(), module.getName()); } public void disableAutodetectionInDirs(@NotNull Module module, @NotNull String... dirUrls) { for (FacetType facetType : myFacetTypesWithDetectors) { for (String dirUrl : dirUrls) { - getState().addDisabled(facetType.getStringId(), module.getName(), dirUrl, true); + myDisabledAutodetectionInfo.addDisabled(facetType.getStringId(), module.getName(), dirUrl, true); } } } public void disableAutodetectionInFiles(@NotNull final FacetType type, @NotNull final Module module, @NotNull final String... fileUrls) { - getState().addDisabled(type.getStringId(), module.getName(), fileUrls); + myDisabledAutodetectionInfo.addDisabled(type.getStringId(), module.getName(), fileUrls); } public void setDisabledAutodetectionState(final @NotNull FacetType facetType, final @Nullable DisabledAutodetectionByTypeElement element) { diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java index 7e0341a38fd9..8a1380aff2fd 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java @@ -16,8 +16,8 @@ package com.intellij.facet.impl.ui.facetType; import com.intellij.facet.FacetType; -import com.intellij.facet.impl.autodetecting.DisabledAutodetectionByTypeElement; -import com.intellij.facet.impl.autodetecting.DisabledAutodetectionInModuleElement; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInModuleElement; import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; import com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl; import com.intellij.openapi.actionSystem.CommonShortcuts; diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetTypeEditor.java b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetTypeEditor.java index 545cfb8f8015..84271d85d798 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetTypeEditor.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetTypeEditor.java @@ -20,7 +20,6 @@ import com.intellij.facet.FacetConfiguration; import com.intellij.facet.FacetType; import com.intellij.facet.ProjectFacetManager; import com.intellij.facet.impl.ProjectFacetsConfigurator; -import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; import com.intellij.facet.impl.invalid.InvalidFacetType; import com.intellij.facet.ui.DefaultFacetSettingsEditor; import com.intellij.facet.ui.FacetEditor; @@ -59,9 +58,6 @@ public class FacetTypeEditor extends UnnamedConfigurableGroup { myProject = project; myContext = context; myFacetType = facetType; - if (FacetAutodetectingManager.getInstance(project).hasDetectors(facetType)) { - myInitialConfigurables.add(new FacetAutodetectionConfigurable(project, context, facetType)); - } if (!(facetType instanceof InvalidFacetType)) { C configuration = ProjectFacetManager.getInstance(project).createDefaultConfiguration(facetType); diff --git a/platform/lang-impl/src/com/intellij/framework/detection/DetectionExcludesConfiguration.java b/platform/lang-impl/src/com/intellij/framework/detection/DetectionExcludesConfiguration.java index 25171d1c7fe2..201cf1d27f20 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/DetectionExcludesConfiguration.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/DetectionExcludesConfiguration.java @@ -35,5 +35,6 @@ public abstract class DetectionExcludesConfiguration { public abstract void addExcludedFramework(@NotNull FrameworkType type); public abstract void addExcludedFile(@NotNull VirtualFile file, @Nullable FrameworkType type); - public abstract void removeExcluded(@NotNull Collection files, @NotNull FrameworkDetector detector); + public abstract void removeExcluded(@NotNull Collection files, + final FrameworkType frameworkType); } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java index 53b3320087e6..b098f8e633c0 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionManager.java @@ -202,7 +202,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen return Collections.emptyList(); } - excludesConfiguration.removeExcluded(filesToProcess, detector); + excludesConfiguration.removeExcluded(filesToProcess, detector.getFrameworkType()); if (LOG.isDebugEnabled()) { LOG.debug("Detector '" + detector.getDetectorId() + "': " + acceptedFiles.size() + " accepted files, " + filesToProcess.size() + " files to process"); } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java index f59318e8c71f..370d40131de6 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurable.java @@ -26,6 +26,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; @@ -205,7 +206,7 @@ public class DetectionExcludesConfigurable implements Configurable { @Override public boolean isModified() { - return !computeState().equals(myConfiguration.getState()); + return !Comparing.equal(computeState(), myConfiguration.getActualState()); } @Override @@ -213,7 +214,11 @@ public class DetectionExcludesConfigurable implements Configurable { myConfiguration.loadState(computeState()); } + @Nullable private ExcludesConfigurationState computeState() { + if (myModel.getItems().isEmpty()) { + return null; + } final ExcludesConfigurationState state = new ExcludesConfigurationState(); for (ExcludeListItem item : myModel.getItems()) { final String url = item.getFileUrl(); @@ -231,20 +236,22 @@ public class DetectionExcludesConfigurable implements Configurable { @Override public void reset() { myModel.clear(); - final ExcludesConfigurationState state = myConfiguration.getState(); - for (String typeId : state.getFrameworkTypes()) { - final FrameworkType frameworkType = FrameworkDetectorRegistry.getInstance().findFrameworkType(typeId); - myModel.add(frameworkType != null ? new ValidExcludeListItem(frameworkType, null) : new InvalidExcludeListItem(typeId, null)); - } - for (ExcludedFileState fileState : state.getFiles()) { - VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(fileState.getUrl()); - final String typeId = fileState.getFrameworkType(); - if (typeId == null) { - myModel.add(file != null ? new ValidExcludeListItem(null, file) : new InvalidExcludeListItem(null, fileState.getUrl())); - } - else { + final ExcludesConfigurationState state = myConfiguration.getActualState(); + if (state != null) { + for (String typeId : state.getFrameworkTypes()) { final FrameworkType frameworkType = FrameworkDetectorRegistry.getInstance().findFrameworkType(typeId); - myModel.add(frameworkType != null && file != null? new ValidExcludeListItem(frameworkType, file) : new InvalidExcludeListItem(typeId, fileState.getUrl())); + myModel.add(frameworkType != null ? new ValidExcludeListItem(frameworkType, null) : new InvalidExcludeListItem(typeId, null)); + } + for (ExcludedFileState fileState : state.getFiles()) { + VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(fileState.getUrl()); + final String typeId = fileState.getFrameworkType(); + if (typeId == null) { + myModel.add(file != null ? new ValidExcludeListItem(null, file) : new InvalidExcludeListItem(null, fileState.getUrl())); + } + else { + final FrameworkType frameworkType = FrameworkDetectorRegistry.getInstance().findFrameworkType(typeId); + myModel.add(frameworkType != null && file != null? new ValidExcludeListItem(frameworkType, file) : new InvalidExcludeListItem(typeId, fileState.getUrl())); + } } } } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java index 9766e7f37b54..4fb3c2c71095 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/DetectionExcludesConfigurationImpl.java @@ -17,11 +17,12 @@ package com.intellij.framework.detection.impl.exclude; import com.intellij.framework.FrameworkType; import com.intellij.framework.detection.DetectionExcludesConfiguration; -import com.intellij.framework.detection.FrameworkDetector; +import com.intellij.framework.detection.impl.exclude.old.OldFacetDetectionExcludesConfiguration; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -49,9 +50,12 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu implements PersistentStateComponent, Disposable { private Map myExcludedFiles; private Set myExcludedFrameworks; + private final Project myProject; private VirtualFilePointerManager myPointerManager; + private boolean myConverted; - public DetectionExcludesConfigurationImpl(VirtualFilePointerManager pointerManager) { + public DetectionExcludesConfigurationImpl(Project project, VirtualFilePointerManager pointerManager) { + myProject = project; myPointerManager = pointerManager; myExcludedFrameworks = new HashSet(); myExcludedFiles = new FactoryMap() { @@ -64,6 +68,7 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu @Override public void addExcludedFramework(@NotNull FrameworkType type) { + convert(); myExcludedFrameworks.add(type.getId()); final VirtualFilePointerContainer container = myExcludedFiles.remove(type.getId()); if (container != null) { @@ -71,22 +76,9 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu } } - private boolean isFileExcluded(@NotNull VirtualFile file, @Nullable String typeId) { - if (myExcludedFiles.containsKey(typeId) && isUnder(file, myExcludedFiles.get(typeId))) return true; - return typeId != null && myExcludedFiles.containsKey(null) && isUnder(file, myExcludedFiles.get(null)); - } - - private static boolean isUnder(VirtualFile file, final VirtualFilePointerContainer container) { - for (VirtualFile excludedFile : container.getFiles()) { - if (VfsUtil.isAncestor(excludedFile, file, false)) { - return true; - } - } - return false; - } - @Override public void addExcludedFile(@NotNull VirtualFile file, @Nullable FrameworkType type) { + convert(); final String typeId = type != null ? type.getId() : null; if (typeId != null && myExcludedFrameworks.contains(typeId) || isFileExcluded(file, typeId)) { return; @@ -104,6 +96,40 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu container.add(file); } + private void convert() { + ensureOldSettingsLoaded(); + markAsConverted(); + } + + private void markAsConverted() { + myConverted = true; + OldFacetDetectionExcludesConfiguration.getInstance(myProject).loadState(null); + } + + private void ensureOldSettingsLoaded() { + if (!myConverted) { + final OldFacetDetectionExcludesConfiguration oldConfiguration = OldFacetDetectionExcludesConfiguration.getInstance(myProject); + final ExcludesConfigurationState oldState = oldConfiguration.convert(); + if (oldState != null) { + doLoadState(oldState); + } + } + } + + private boolean isFileExcluded(@NotNull VirtualFile file, @Nullable String typeId) { + if (myExcludedFiles.containsKey(typeId) && isUnder(file, myExcludedFiles.get(typeId))) return true; + return typeId != null && myExcludedFiles.containsKey(null) && isUnder(file, myExcludedFiles.get(null)); + } + + private static boolean isUnder(VirtualFile file, final VirtualFilePointerContainer container) { + for (VirtualFile excludedFile : container.getFiles()) { + if (VfsUtil.isAncestor(excludedFile, file, false)) { + return true; + } + } + return false; + } + private void removeDescendants(VirtualFile file, VirtualFilePointerContainer container) { for (VirtualFile virtualFile : container.getFiles()) { if (VfsUtil.isAncestor(file, virtualFile, false)) { @@ -113,8 +139,9 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu } @Override - public void removeExcluded(@NotNull Collection files, @NotNull FrameworkDetector detector) { - if (myExcludedFrameworks.contains(detector.getFrameworkType().getId())) { + public void removeExcluded(@NotNull Collection files, final FrameworkType frameworkType) { + ensureOldSettingsLoaded(); + if (myExcludedFrameworks.contains(frameworkType.getId())) { files.clear(); return; } @@ -122,14 +149,18 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu final Iterator iterator = files.iterator(); while (iterator.hasNext()) { VirtualFile file = iterator.next(); - if (isFileExcluded(file, detector.getFrameworkType().getId())) { + if (isFileExcluded(file, frameworkType.getId())) { iterator.remove(); } } } - @Override - public ExcludesConfigurationState getState() { + @Nullable + public ExcludesConfigurationState getActualState() { + if (myExcludedFiles.isEmpty() && myExcludedFrameworks.isEmpty()) { + return null; + } + final ExcludesConfigurationState state = new ExcludesConfigurationState(); state.getFrameworkTypes().addAll(myExcludedFrameworks); Collections.sort(state.getFrameworkTypes()); @@ -149,15 +180,30 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu return state; } + @Override @Nullable + public ExcludesConfigurationState getState() { + if (!myConverted) return null; + return getActualState(); + } + @Override - public void loadState(ExcludesConfigurationState state) { + public void loadState(@Nullable ExcludesConfigurationState state) { + doLoadState(state); + if (!myExcludedFiles.isEmpty() || !myExcludedFrameworks.isEmpty()) { + markAsConverted(); + } + } + + private void doLoadState(@Nullable ExcludesConfigurationState state) { myExcludedFrameworks.clear(); - myExcludedFrameworks.addAll(state.getFrameworkTypes()); for (VirtualFilePointerContainer container : myExcludedFiles.values()) { container.clear(); } - for (ExcludedFileState fileState : state.getFiles()) { - myExcludedFiles.get(fileState.getFrameworkType()).add(fileState.getUrl()); + if (state != null) { + myExcludedFrameworks.addAll(state.getFrameworkTypes()); + for (ExcludedFileState fileState : state.getFiles()) { + myExcludedFiles.get(fileState.getFrameworkType()).add(fileState.getUrl()); + } } } diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionByTypeElement.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionByTypeElement.java similarity index 98% rename from java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionByTypeElement.java rename to platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionByTypeElement.java index e69ee791ebef..13488f059ddb 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionByTypeElement.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionByTypeElement.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.intellij.facet.impl.autodetecting; +package com.intellij.framework.detection.impl.exclude.old; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInModuleElement.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInModuleElement.java similarity index 98% rename from java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInModuleElement.java rename to platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInModuleElement.java index 84b6e6a4c56e..45ad0e8cef92 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInModuleElement.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInModuleElement.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.intellij.facet.impl.autodetecting; +package com.intellij.framework.detection.impl.exclude.old; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.xmlb.annotations.AbstractCollection; diff --git a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInfo.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInfo.java similarity index 98% rename from java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInfo.java rename to platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInfo.java index e05e3ab07e38..1f4863319408 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/autodetecting/DisabledAutodetectionInfo.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/DisabledAutodetectionInfo.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.intellij.facet.impl.autodetecting; +package com.intellij.framework.detection.impl.exclude.old; import com.intellij.util.containers.SortedList; import com.intellij.util.xmlb.annotations.AbstractCollection; diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/OldFacetDetectionExcludesConfiguration.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/OldFacetDetectionExcludesConfiguration.java new file mode 100644 index 000000000000..5892dd63c412 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/exclude/old/OldFacetDetectionExcludesConfiguration.java @@ -0,0 +1,101 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.framework.detection.impl.exclude.old; + +import com.intellij.framework.detection.impl.exclude.ExcludedFileState; +import com.intellij.framework.detection.impl.exclude.ExcludesConfigurationState; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ModuleRootManager; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * @author nik + */ +@State( + name = "FacetAutodetectingManager", + storages = { + @Storage( + file = "$PROJECT_FILE$" + ) + } +) +public class OldFacetDetectionExcludesConfiguration implements PersistentStateComponent { + @NonNls public static final String COMPONENT_NAME = "FacetAutodetectingManager"; + private DisabledAutodetectionInfo myDisabledAutodetectionInfo; + private final Project myProject; + + public static OldFacetDetectionExcludesConfiguration getInstance(Project project) { + return ServiceManager.getService(project, OldFacetDetectionExcludesConfiguration.class); + } + + public OldFacetDetectionExcludesConfiguration(Project project) { + myProject = project; + } + + public DisabledAutodetectionInfo getState() { + return myDisabledAutodetectionInfo; + } + + public void loadState(final DisabledAutodetectionInfo state) { + myDisabledAutodetectionInfo = state; + } + + @Nullable + public ExcludesConfigurationState convert() { + if (myDisabledAutodetectionInfo == null || myDisabledAutodetectionInfo.getElements().isEmpty()) { + return null; + } + + final ExcludesConfigurationState state = new ExcludesConfigurationState(); + for (DisabledAutodetectionByTypeElement element : myDisabledAutodetectionInfo.getElements()) { + final String frameworkId = element.getFacetTypeId(); + final List moduleElements = element.getModuleElements(); + if (moduleElements.isEmpty()) { + state.getFrameworkTypes().add(frameworkId); + continue; + } + Set excludedUrls = new LinkedHashSet(); + for (DisabledAutodetectionInModuleElement moduleElement : moduleElements) { + if (moduleElement.isDisableInWholeModule()) { + final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleElement.getModuleName()); + if (module != null) { + Collections.addAll(excludedUrls, ModuleRootManager.getInstance(module).getContentRootUrls()); + } + } + else { + excludedUrls.addAll(moduleElement.getFiles()); + excludedUrls.addAll(moduleElement.getDirectories()); + } + } + for (String url : excludedUrls) { + state.getFiles().add(new ExcludedFileState(url, frameworkId)); + } + } + return state; + } +} diff --git a/platform/lang-impl/testSrc/com/intellij/framework/detection/ConvertingOldDetectionExcludesTest.java b/platform/lang-impl/testSrc/com/intellij/framework/detection/ConvertingOldDetectionExcludesTest.java new file mode 100644 index 000000000000..9b180ac8fb6c --- /dev/null +++ b/platform/lang-impl/testSrc/com/intellij/framework/detection/ConvertingOldDetectionExcludesTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.framework.detection; + +import com.intellij.framework.FrameworkType; +import com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurationImpl; +import com.intellij.framework.detection.impl.exclude.ExcludedFileState; +import com.intellij.framework.detection.impl.exclude.ExcludesConfigurationState; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionByTypeElement; +import com.intellij.framework.detection.impl.exclude.old.DisabledAutodetectionInfo; +import com.intellij.framework.detection.impl.exclude.old.OldFacetDetectionExcludesConfiguration; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.PsiTestUtil; +import com.intellij.testFramework.TempFiles; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class ConvertingOldDetectionExcludesTest extends PlatformTestCase { + public static final String FRAMEWORK_ID = "my-framework"; + private TempFiles myTempFiles; + + @Override + protected void setUp() throws Exception { + super.setUp(); + myTempFiles = new TempFiles(myFilesToDelete); + } + + public void testUseOldConfiguration() { + final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo(); + final VirtualFile file = myTempFiles.createVFile("my-file", ".xml"); + state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName(), file.getUrl(), false)); + getOldConfiguration().loadState(state); + + assertTrue(isFileExcluded(file)); + assertNull(getNewConfiguration().getState()); + assertOneElement(getOldConfiguration().getState().getElements()); + } + + public void testExcludeModuleConfiguration() { + final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo(); + final VirtualFile dir = myTempFiles.createTempVDir(); + PsiTestUtil.addContentRoot(myModule, dir); + final VirtualFile file = myTempFiles.createVFile(dir, "my-file", ".xml"); + state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName())); + getOldConfiguration().loadState(state); + + assertTrue(isFileExcluded(file)); + assertNull(getNewConfiguration().getState()); + assertOneElement(getOldConfiguration().getState().getElements()); + } + + public void testExcludeFrameworkConfiguration() { + final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo(); + final VirtualFile file = myTempFiles.createVFile("my-file", ".xml"); + state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID)); + getOldConfiguration().loadState(state); + + assertTrue(isFileExcluded(file)); + assertNull(getNewConfiguration().getState()); + assertOneElement(getOldConfiguration().getState().getElements()); + } + + public void testUseNewConfiguration() { + final ExcludesConfigurationState state = new ExcludesConfigurationState(); + final VirtualFile file = myTempFiles.createVFile("xxx", ".xml"); + state.getFiles().add(new ExcludedFileState(file.getUrl(), FRAMEWORK_ID)); + getNewConfiguration().loadState(state); + + assertTrue(isFileExcluded(file)); + assertNull(getOldConfiguration().getState()); + assertOneElement(getNewConfiguration().getState().getFiles()); + } + + private boolean isFileExcluded(VirtualFile file) { + final List files = new ArrayList(); + files.add(file); + getNewConfiguration().removeExcluded(files, new FrameworkType(FRAMEWORK_ID, "", null)); + return files.isEmpty(); + } + + public void testConvert() { + final DisabledAutodetectionInfo state = new DisabledAutodetectionInfo(); + final VirtualFile file = myTempFiles.createVFile("my-file", ".xml"); + state.getElements().add(new DisabledAutodetectionByTypeElement(FRAMEWORK_ID, myModule.getName(), file.getUrl(), false)); + getOldConfiguration().loadState(state); + + getNewConfiguration().addExcludedFramework(new FrameworkType("my-framework-2", "", null)); + assertNull(getOldConfiguration().getState()); + final ExcludesConfigurationState newState = getNewConfiguration().getState(); + assertNotNull(newState); + assertEquals(FRAMEWORK_ID, assertOneElement(newState.getFiles()).getFrameworkType()); + assertEquals("my-framework-2", assertOneElement(newState.getFrameworkTypes())); + } + + private DetectionExcludesConfigurationImpl getNewConfiguration() { + return ((DetectionExcludesConfigurationImpl)DetectionExcludesConfiguration.getInstance(myProject)); + } + + private OldFacetDetectionExcludesConfiguration getOldConfiguration() { + return OldFacetDetectionExcludesConfiguration.getInstance(myProject); + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 49936ba0cae1..555e693e3e2e 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -205,6 +205,7 @@ +