new framework detection: conversion of old excludes settings

This commit is contained in:
nik
2011-08-08 13:18:53 +04:00
parent fccc84983e
commit 58e0fd9fe8
15 changed files with 331 additions and 95 deletions
@@ -1,171 +0,0 @@
/*
* Copyright 2000-2009 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.facet.impl.autodetecting;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.SortedList;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* @author nik
*/
@Tag("facet-type")
public class DisabledAutodetectionByTypeElement {
public static final Comparator<DisabledAutodetectionByTypeElement> COMPARATOR = new Comparator<DisabledAutodetectionByTypeElement>() {
@Override
public int compare(DisabledAutodetectionByTypeElement o1, DisabledAutodetectionByTypeElement o2) {
return StringUtil.compare(o1.getFacetTypeId(), o2.getFacetTypeId(), true);
}
};
private String myFacetTypeId;
private List<DisabledAutodetectionInModuleElement> myModuleElements = new SortedList<DisabledAutodetectionInModuleElement>(DisabledAutodetectionInModuleElement.COMPARATOR);
public DisabledAutodetectionByTypeElement() {
}
public DisabledAutodetectionByTypeElement(final String facetTypeId) {
myFacetTypeId = facetTypeId;
}
public DisabledAutodetectionByTypeElement(String facetTypeId, String moduleName) {
this(facetTypeId);
myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName));
}
public DisabledAutodetectionByTypeElement(String facetTypeId, String moduleName, String url, final boolean recursively) {
this(facetTypeId);
myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName, url, recursively));
}
@Attribute("id")
public String getFacetTypeId() {
return myFacetTypeId;
}
@Tag("modules")
@AbstractCollection(surroundWithTag = false)
public List<DisabledAutodetectionInModuleElement> getModuleElements() {
return myModuleElements;
}
public void setFacetTypeId(final String facetTypeId) {
myFacetTypeId = facetTypeId;
}
public void setModuleElements(final List<DisabledAutodetectionInModuleElement> moduleElements) {
myModuleElements = moduleElements;
}
public void addDisabled(@NotNull String moduleName) {
if (myModuleElements.isEmpty()) return;
DisabledAutodetectionInModuleElement element = findElement(moduleName);
if (element != null) {
element.getFiles().clear();
element.getDirectories().clear();
return;
}
myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName));
}
public void disableInProject() {
myModuleElements.clear();
}
public void addDisabled(@NotNull String moduleName, @NotNull String fileUrl, final boolean recursively) {
if (myModuleElements.isEmpty()) return;
DisabledAutodetectionInModuleElement element = findElement(moduleName);
if (element != null) {
if (!element.isDisableInWholeModule()) {
if (recursively) {
element.getDirectories().add(fileUrl);
}
else {
element.getFiles().add(fileUrl);
}
}
return;
}
myModuleElements.add(new DisabledAutodetectionInModuleElement(moduleName, fileUrl, recursively));
}
@Nullable
public DisabledAutodetectionInModuleElement findElement(final @NotNull String moduleName) {
for (DisabledAutodetectionInModuleElement element : myModuleElements) {
if (moduleName.equals(element.getModuleName())) {
return element;
}
}
return null;
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final DisabledAutodetectionByTypeElement that = (DisabledAutodetectionByTypeElement)o;
return myFacetTypeId.equals(that.myFacetTypeId) && myModuleElements.equals(that.myModuleElements);
}
public int hashCode() {
return myFacetTypeId.hashCode()+ 31 * myModuleElements.hashCode();
}
public boolean isDisabled(final String moduleName, final String url) {
if (myModuleElements.isEmpty()) return true;
DisabledAutodetectionInModuleElement element = findElement(moduleName);
if (element == null) return false;
if (element.isDisableInWholeModule() || element.getFiles().contains(url)) {
return true;
}
for (String directoryUrl : element.getDirectories()) {
if (!directoryUrl.endsWith("/")) {
directoryUrl += "/";
}
if (url.startsWith(directoryUrl) || !SystemInfo.isFileSystemCaseSensitive && StringUtil.startsWithIgnoreCase(url, directoryUrl)) {
return true;
}
}
return false;
}
public boolean removeDisabled(final String moduleName) {
Iterator<DisabledAutodetectionInModuleElement> iterator = myModuleElements.iterator();
while (iterator.hasNext()) {
DisabledAutodetectionInModuleElement element = iterator.next();
if (element.getModuleName().equals(moduleName)) {
iterator.remove();
break;
}
}
return myModuleElements.size() > 0;
}
}
@@ -1,108 +0,0 @@
/*
* Copyright 2000-2009 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.facet.impl.autodetecting;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author nik
*/
@Tag("module")
public class DisabledAutodetectionInModuleElement {
public static final Comparator<DisabledAutodetectionInModuleElement> COMPARATOR = new Comparator<DisabledAutodetectionInModuleElement>() {
@Override
public int compare(DisabledAutodetectionInModuleElement o1, DisabledAutodetectionInModuleElement o2) {
return StringUtil.compare(o1.getModuleName(), o2.getModuleName(), true);
}
};
private String myModuleName;
private Set<String> myFiles = new LinkedHashSet<String>();
private Set<String> myDirectories = new LinkedHashSet<String>();
public DisabledAutodetectionInModuleElement() {
}
public DisabledAutodetectionInModuleElement(final String moduleName) {
myModuleName = moduleName;
}
public DisabledAutodetectionInModuleElement(final String moduleName, final String url, final boolean recursively) {
myModuleName = moduleName;
if (recursively) {
myDirectories.add(url);
}
else {
myFiles.add(url);
}
}
@Attribute("name")
public String getModuleName() {
return myModuleName;
}
@Tag("files")
@AbstractCollection(surroundWithTag = false, elementTag = "file", elementValueAttribute = "url")
public Set<String> getFiles() {
return myFiles;
}
@Tag("directories")
@AbstractCollection(surroundWithTag = false, elementTag = "directory", elementValueAttribute = "url")
public Set<String> getDirectories() {
return myDirectories;
}
public void setModuleName(final String moduleName) {
myModuleName = moduleName;
}
public void setFiles(final Set<String> files) {
myFiles = files;
}
public void setDirectories(final Set<String> directories) {
myDirectories = directories;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final DisabledAutodetectionInModuleElement that = (DisabledAutodetectionInModuleElement)o;
return myDirectories.equals(that.myDirectories) && myFiles.equals(that.myFiles) && myModuleName.equals(that.myModuleName);
}
@Override
public int hashCode() {
return 31 * (31 * myModuleName.hashCode() + myFiles.hashCode()) + myDirectories.hashCode();
}
public boolean isDisableInWholeModule() {
return myFiles.isEmpty() && myDirectories.isEmpty();
}
}
@@ -1,103 +0,0 @@
/*
* Copyright 2000-2009 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.facet.impl.autodetecting;
import com.intellij.util.containers.SortedList;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author nik
*/
public class DisabledAutodetectionInfo {
private List<DisabledAutodetectionByTypeElement> myElements = new SortedList<DisabledAutodetectionByTypeElement>(DisabledAutodetectionByTypeElement.COMPARATOR);
@Tag("autodetection-disabled")
@AbstractCollection(surroundWithTag = false)
public List<DisabledAutodetectionByTypeElement> getElements() {
return myElements;
}
public void setElements(final List<DisabledAutodetectionByTypeElement> elements) {
myElements = elements;
}
public boolean isDisabled(final @NotNull String facetType, final @NotNull String moduleName, String url) {
DisabledAutodetectionByTypeElement element = findElement(facetType);
return element != null && element.isDisabled(moduleName, url);
}
public void replaceElement(@NotNull String facetTypeId, @Nullable DisabledAutodetectionByTypeElement element) {
final DisabledAutodetectionByTypeElement old = findElement(facetTypeId);
if (old != null) {
myElements.remove(old);
}
if (element != null) {
myElements.add(element);
}
}
@Nullable
public DisabledAutodetectionByTypeElement findElement(@NotNull String facetTypeId) {
for (DisabledAutodetectionByTypeElement element : myElements) {
if (facetTypeId.equals(element.getFacetTypeId())) {
return element;
}
}
return null;
}
public void addDisabled(final @NotNull String facetTypeId) {
DisabledAutodetectionByTypeElement element = findElement(facetTypeId);
if (element != null) {
element.disableInProject();
}
else {
myElements.add(new DisabledAutodetectionByTypeElement(facetTypeId));
}
}
public void addDisabled(final @NotNull String facetTypeId, final @NotNull String moduleName) {
DisabledAutodetectionByTypeElement element = findElement(facetTypeId);
if (element != null) {
element.addDisabled(moduleName);
}
else {
myElements.add(new DisabledAutodetectionByTypeElement(facetTypeId, moduleName));
}
}
public void addDisabled(final @NotNull String facetTypeId, final @NotNull String moduleName, String url, final boolean recursively) {
DisabledAutodetectionByTypeElement element = findElement(facetTypeId);
if (element != null) {
element.addDisabled(moduleName, url, recursively);
}
else {
myElements.add(new DisabledAutodetectionByTypeElement(facetTypeId, moduleName, url, recursively));
}
}
public void addDisabled(final @NotNull String facetTypeId, final @NotNull String moduleName, final @NotNull String... urls) {
for (String url : urls) {
addDisabled(facetTypeId, moduleName, url, false);
}
}
}
@@ -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);
}
@@ -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) {
@@ -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);