mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new framework detection: conversion of old excludes settings
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+7
-39
@@ -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<DisabledAutodetectionInfo> {
|
||||
@NonNls public static final String COMPONENT_NAME = "FacetAutodetectingManager";
|
||||
public class FacetAutodetectingManagerImpl extends FacetAutodetectingManager implements AutodetectionFilter, ProjectComponent {
|
||||
private final MultiValuesMap<FileType, FacetDetectorWrapper> myDetectors = new MultiValuesMap<FileType, FacetDetectorWrapper>();
|
||||
private final Map<String, FacetDetector<?,?>> myId2Detector = new HashMap<String, FacetDetector<?,?>>();
|
||||
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) {
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-1
@@ -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<VirtualFile> files, @NotNull FrameworkDetector detector);
|
||||
public abstract void removeExcluded(@NotNull Collection<VirtualFile> files,
|
||||
final FrameworkType frameworkType);
|
||||
}
|
||||
|
||||
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
+21
-14
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+71
-25
@@ -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<ExcludesConfigurationState>, Disposable {
|
||||
private Map<String, VirtualFilePointerContainer> myExcludedFiles;
|
||||
private Set<String> 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<String>();
|
||||
myExcludedFiles = new FactoryMap<String, VirtualFilePointerContainer>() {
|
||||
@@ -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<VirtualFile> files, @NotNull FrameworkDetector detector) {
|
||||
if (myExcludedFrameworks.contains(detector.getFrameworkType().getId())) {
|
||||
public void removeExcluded(@NotNull Collection<VirtualFile> files, final FrameworkType frameworkType) {
|
||||
ensureOldSettingsLoaded();
|
||||
if (myExcludedFrameworks.contains(frameworkType.getId())) {
|
||||
files.clear();
|
||||
return;
|
||||
}
|
||||
@@ -122,14 +149,18 @@ public class DetectionExcludesConfigurationImpl extends DetectionExcludesConfigu
|
||||
final Iterator<VirtualFile> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
+1
-1
@@ -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;
|
||||
+101
@@ -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<DisabledAutodetectionInfo> {
|
||||
@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<DisabledAutodetectionInModuleElement> moduleElements = element.getModuleElements();
|
||||
if (moduleElements.isEmpty()) {
|
||||
state.getFrameworkTypes().add(frameworkId);
|
||||
continue;
|
||||
}
|
||||
Set<String> excludedUrls = new LinkedHashSet<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
+120
@@ -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<VirtualFile> files = new ArrayList<VirtualFile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -205,6 +205,7 @@
|
||||
<fileBasedIndex implementation="com.intellij.framework.detection.impl.FrameworkDetectionIndex"/>
|
||||
<projectService serviceInterface="com.intellij.framework.detection.DetectionExcludesConfiguration"
|
||||
serviceImplementation="com.intellij.framework.detection.impl.exclude.DetectionExcludesConfigurationImpl"/>
|
||||
<projectService serviceImplementation="com.intellij.framework.detection.impl.exclude.old.OldFacetDetectionExcludesConfiguration"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.codeInsight.AutoPopupController"
|
||||
serviceImplementation="com.intellij.codeInsight.AutoPopupController"/>
|
||||
|
||||
Reference in New Issue
Block a user