diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FacetBasedDetectedFrameworkDescriptionInWizard.java b/java/idea-ui/src/com/intellij/ide/util/importProject/FacetBasedDetectedFrameworkDescriptionInWizard.java new file mode 100644 index 000000000000..be7887da7420 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FacetBasedDetectedFrameworkDescriptionInWizard.java @@ -0,0 +1,57 @@ +/* + * 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.ide.util.importProject; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetConfiguration; +import com.intellij.framework.detection.FacetBasedFrameworkDetector; +import com.intellij.framework.detection.impl.FacetBasedDetectedFrameworkDescription; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ModifiableModelsProvider; +import com.intellij.openapi.roots.ui.configuration.ModulesProvider; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +/** + * @author nik + */ +public class FacetBasedDetectedFrameworkDescriptionInWizard extends FacetBasedDetectedFrameworkDescription { + private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.importProject.FacetBasedDetectedFrameworkDescriptionInWizard"); + private final ModuleDescriptor myModuleDescriptor; + + public FacetBasedDetectedFrameworkDescriptionInWizard(@NotNull ModuleDescriptor moduleDescriptor, + FacetBasedFrameworkDetector detector, + @NotNull C configuration, + Set files) { + super(detector, configuration, files); + myModuleDescriptor = moduleDescriptor; + } + + @Override + protected String getModuleName() { + return myModuleDescriptor.getName(); + } + + @Override + public void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider) { + Module module = modulesProvider.getModule(getModuleName()); + LOG.assertTrue(module != null, getModuleName()); + doConfigure(modifiableModelsProvider, module); + } +} diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java index 159745ede075..1f988e520b0f 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java @@ -17,38 +17,72 @@ package com.intellij.ide.util.importProject; import com.intellij.facet.Facet; import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.framework.detection.impl.FrameworkDetectionContextBase; -import com.intellij.ide.util.projectWizard.SourcePathsBuilder; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.io.File; +import java.util.*; /** * @author nik */ -public class FrameworkDetectionInWizardContext extends FrameworkDetectionContextBase { - private final SourcePathsBuilder myBuilder; - - public FrameworkDetectionInWizardContext(SourcePathsBuilder builder) { - myBuilder = builder; +public abstract class FrameworkDetectionInWizardContext extends FrameworkDetectionContextBase { + protected FrameworkDetectionInWizardContext() { } @NotNull @Override - public List createDetectedFacetDescriptions(@NotNull FacetType facetType, - @NotNull Collection files, - @NotNull FacetConfigurationCreator creator) { - return Collections.emptyList(); + public List createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector detector, + @NotNull Collection files) { + final List descriptors = getModuleDescriptors(); + MultiMap filesByModule = new MultiMap(); + for (VirtualFile file : files) { + final File ioFile = VfsUtil.virtualToIoFile(file); + ModuleDescriptor descriptor = findDescriptorByFile(descriptors, ioFile); + if (descriptor != null) { + filesByModule.putValue(descriptor, file); + } + } + + final List result = new ArrayList(); + for (ModuleDescriptor module : filesByModule.keySet()) { + final List>> pairs = detector.createConfigurations(filesByModule.get(module), Collections.emptyList()); + for (Pair> pair : pairs) { + result.add(new FacetBasedDetectedFrameworkDescriptionInWizard(module, detector, pair.getFirst(), + new HashSet(pair.getSecond()))); + } + } + return result; + } + + protected abstract List getModuleDescriptors(); + + @Nullable + private static ModuleDescriptor findDescriptorByFile(List descriptors, File file) { + for (ModuleDescriptor descriptor : descriptors) { + for (File root : descriptor.getContentRoots()) { + if (FileUtil.isAncestor(root, file, false)) { + return descriptor; + } + } + } + return null; } public VirtualFile getBaseDir() { - final String path = myBuilder.getContentEntryPath(); + final String path = getContentPath(); return path != null ? LocalFileSystem.getInstance().refreshAndFindFileByPath(path) : null; } + + @Nullable + protected abstract String getContentPath(); } diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java index e8cdc80b8824..1daa39ae23b0 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java @@ -16,31 +16,23 @@ package com.intellij.ide.util.importProject; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeRegistry; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.UnderlyingFacetSelector; -import com.intellij.facet.impl.autodetecting.FacetDetectorForWizardRegistry; -import com.intellij.facet.impl.autodetecting.FacetDetectorRegistryEx; -import com.intellij.facet.impl.autodetecting.FileContentPattern; import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.DetectionExcludesConfiguration; import com.intellij.framework.detection.FrameworkDetectionContext; +import com.intellij.framework.detection.FrameworkDetector; import com.intellij.framework.detection.impl.FrameworkDetectionProcessor; import com.intellij.framework.detection.impl.ui.DetectedFrameworksComponent; import com.intellij.ide.util.newProjectWizard.ProjectFromSourcesBuilder; import com.intellij.ide.util.projectWizard.AbstractStepWithProgress; import com.intellij.ide.util.projectWizard.SourcePathsBuilder; import com.intellij.openapi.application.ApplicationNamesInfo; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.PlatformModifiableModelsProvider; +import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -63,10 +55,20 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress
  • getModuleDescriptors() { + return FrameworkDetectionStep.this.getModuleDescriptors(); + } + + @Override + protected String getContentPath() { + return builder.getContentEntryPath(); + } + }; myDetectedFrameworksComponent = new DetectedFrameworksComponent(myContext); } @@ -97,13 +99,11 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress
  • result = new ArrayList(); FrameworkDetectionProcessor processor = new FrameworkDetectionProcessor(progressIndicator, myContext); - processor.processRoots(roots); - return result; + return processor.processRoots(roots); } - protected abstract List getModuleDescriptors(); + public abstract List getModuleDescriptors(); private List getRoots() { List roots = new ArrayList(); @@ -127,26 +127,8 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress
  • facetType : FacetTypeRegistry.getInstance().getFacetTypes()) { - if (facetType.isSuitableModuleType(moduleType)) { - final Ref hasDetector = Ref.create(false); - //noinspection unchecked - facetType.registerDetectors(new FacetDetectorRegistryEx(new FacetDetectorForWizardRegistry() { - - public void register(FileType fileType, - @NotNull FileContentPattern fileContentPattern, - FacetDetector facetDetector, - UnderlyingFacetSelector underlyingFacetSelector) { - hasDetector.set(true); - } - }, null)); - if (hasDetector.get()) { - return true; - } - } - } - return false; + public static boolean isEnabled() { + return FrameworkDetector.EP_NAME.getExtensions().length > 0; } @NonNls @@ -157,7 +139,7 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress
  • getModuleDescriptors() { + public List getModuleDescriptors() { return projectBuilder.getModules(); } }; diff --git a/platform/lang-impl/src/com/intellij/framework/FrameworkType.java b/platform/lang-impl/src/com/intellij/framework/FrameworkType.java index ae256c6ba46f..2261c52b6b38 100644 --- a/platform/lang-impl/src/com/intellij/framework/FrameworkType.java +++ b/platform/lang-impl/src/com/intellij/framework/FrameworkType.java @@ -15,7 +15,9 @@ */ package com.intellij.framework; +import com.intellij.util.ui.EmptyIcon; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -27,10 +29,10 @@ public class FrameworkType { private final String myPresentableName; private final Icon myIcon; - public FrameworkType(@NotNull String id, @NotNull String presentableName, @NotNull Icon icon) { + public FrameworkType(@NotNull String id, @NotNull String presentableName, @Nullable Icon icon) { myId = id; myPresentableName = presentableName; - myIcon = icon; + myIcon = icon != null ? icon : EmptyIcon.ICON_16; } @NotNull diff --git a/platform/lang-impl/src/com/intellij/framework/detection/DetectedFrameworkDescription.java b/platform/lang-impl/src/com/intellij/framework/detection/DetectedFrameworkDescription.java index a9d9a7c24e6b..53b426cd3102 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/DetectedFrameworkDescription.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/DetectedFrameworkDescription.java @@ -17,6 +17,7 @@ package com.intellij.framework.detection; import com.intellij.framework.FrameworkType; import com.intellij.openapi.roots.ModifiableModelsProvider; +import com.intellij.openapi.roots.ui.configuration.ModulesProvider; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -35,7 +36,7 @@ public abstract class DetectedFrameworkDescription { @NotNull public abstract String getSetupDescription(); - public abstract void configureFramework(ModifiableModelsProvider modifiableModelsProvider); + public abstract void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider); public abstract boolean equals(Object obj); diff --git a/platform/lang-impl/src/com/intellij/framework/detection/FacetBasedFrameworkDetector.java b/platform/lang-impl/src/com/intellij/framework/detection/FacetBasedFrameworkDetector.java new file mode 100644 index 000000000000..0685c304ed2f --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/FacetBasedFrameworkDetector.java @@ -0,0 +1,56 @@ +/* + * 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.facet.Facet; +import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.FacetType; +import com.intellij.framework.FrameworkType; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.List; + +/** + * @author nik + */ +public abstract class FacetBasedFrameworkDetector extends FrameworkDetector { + public FacetBasedFrameworkDetector(String detectorId) { + super(detectorId); + } + + public abstract FacetType getFacetType(); + + @NotNull + public abstract List>> createConfigurations(@NotNull Collection files, + @NotNull Collection existentFacetConfigurations); + + public void setupFacet(@NotNull F facet) { + } + + @Override + public List detect(@NotNull Collection newFiles, + @NotNull FrameworkDetectionContext context) { + return context.createDetectedFacetDescriptions(this, newFiles); + } + + @Override + public FrameworkType getFrameworkType() { + return new FrameworkType(getFacetType().getStringId(), getFacetType().getPresentableName(), getFacetType().getIcon()); + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java b/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java index 1427cf440477..a39faa354e74 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java @@ -17,9 +17,6 @@ package com.intellij.framework.detection; import com.intellij.facet.Facet; import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.openapi.roots.ModuleRootModel; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,17 +34,9 @@ public interface FrameworkDetectionContext { @NotNull - List createDetectedFacetDescriptions(@NotNull FacetType facetType, @NotNull Collection files); + List createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector detector, + @NotNull Collection files); - @NotNull - - List createDetectedFacetDescriptions(@NotNull FacetType facetType, @NotNull Collection files, - @NotNull FacetConfigurationCreator creator); - - abstract class FacetConfigurationCreator { - @NotNull - public abstract List>> createConfigurations(@NotNull Collection files, - @NotNull ModuleRootModel rootModel, - @NotNull Collection existentFacetConfigurations); + abstract class FacetConfigurationCreator { } } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FacetBasedDetectedFrameworkDescription.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FacetBasedDetectedFrameworkDescription.java index 4ac3ed939aa2..24b6967dffe6 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FacetBasedDetectedFrameworkDescription.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FacetBasedDetectedFrameworkDescription.java @@ -15,16 +15,13 @@ */ package com.intellij.framework.detection.impl; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetManager; -import com.intellij.facet.FacetType; -import com.intellij.facet.ModifiableFacetModel; +import com.intellij.facet.*; import com.intellij.framework.FrameworkType; import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.openapi.module.Module; import com.intellij.openapi.roots.ModifiableModelsProvider; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ui.EmptyIcon; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -34,20 +31,22 @@ import java.util.Set; /** * @author nik */ -public class FacetBasedDetectedFrameworkDescription extends DetectedFrameworkDescription { - private final Module myModule; +public abstract class FacetBasedDetectedFrameworkDescription extends DetectedFrameworkDescription { + private final FacetBasedFrameworkDetector myDetector; private final C myConfiguration; private final Set myRelatedFiles; - private final FacetType myFacetType; - private FrameworkType myFrameworkType; + private final FacetType myFacetType; + private final FrameworkType myFrameworkType; - public FacetBasedDetectedFrameworkDescription(@NotNull Module module, @NotNull C configuration, Set files, FacetType type) { - myModule = module; + public FacetBasedDetectedFrameworkDescription(FacetBasedFrameworkDetector detector, + @NotNull C configuration, + Set files) { + myDetector = detector; myConfiguration = configuration; myRelatedFiles = files; - myFacetType = type; + myFacetType = detector.getFacetType(); final Icon icon = myFacetType.getIcon(); - myFrameworkType = new FrameworkType(myFacetType.getStringId(), myFacetType.getPresentableName(), icon != null ? icon : EmptyIcon.ICON_16); + myFrameworkType = new FrameworkType(myFacetType.getStringId(), myFacetType.getPresentableName(), icon); } @NotNull @@ -65,14 +64,17 @@ public class FacetBasedDetectedFrameworkDescription extends FacetBasedDetectedFrameworkDescription { + private final Module myModule; + + public FacetBasedDetectedFrameworkDescriptionImpl(@NotNull Module module, + FacetBasedFrameworkDetector detector, @NotNull C configuration, + Set files) { + super(detector, configuration, files); + myModule = module; + } + + protected String getModuleName() { + return myModule.getName(); + } + + @Override + public void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider) { + doConfigure(modifiableModelsProvider, myModule); + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextBase.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextBase.java index 9362b12f6388..90cda2ad4d24 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextBase.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextBase.java @@ -15,35 +15,10 @@ */ package com.intellij.framework.detection.impl; -import com.intellij.facet.Facet; -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.FacetType; -import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.FrameworkDetectionContext; -import com.intellij.openapi.roots.ModuleRootModel; -import com.intellij.openapi.util.Pair; -import com.intellij.openapi.vfs.VirtualFile; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; /** * @author nik */ public abstract class FrameworkDetectionContextBase implements FrameworkDetectionContext { - @NotNull - @Override - public List createDetectedFacetDescriptions(@NotNull final FacetType facetType, - @NotNull Collection files) { - return createDetectedFacetDescriptions(facetType, files, new FacetConfigurationCreator() { - @NotNull - @Override - public List>> createConfigurations(@NotNull Collection files, - @NotNull ModuleRootModel rootModel, @NotNull Collection existentFacetConfigurations) { - return Collections.singletonList(Pair.create(facetType.createDefaultConfiguration(), files)); - } - }); - } } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextImpl.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextImpl.java index 176e021ea0c6..da3ace0cc82b 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextImpl.java @@ -20,10 +20,10 @@ import com.intellij.facet.FacetConfiguration; import com.intellij.facet.FacetType; import com.intellij.facet.impl.DefaultFacetsProvider; import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ui.configuration.FacetsProvider; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; @@ -47,9 +47,8 @@ public class FrameworkDetectionContextImpl extends FrameworkDetectionContextBase @NotNull @Override - public List createDetectedFacetDescriptions(@NotNull FacetType facetType, - @NotNull Collection files, - @NotNull FacetConfigurationCreator creator) { + public List createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector detector, + @NotNull Collection files) { MultiMapBasedOnSet filesByModule = new MultiMapBasedOnSet(); for (VirtualFile file : files) { final Module module = ModuleUtil.findModuleForFile(file, myProject); @@ -58,6 +57,7 @@ public class FrameworkDetectionContextImpl extends FrameworkDetectionContextBase } } final List result = new ArrayList(); + final FacetType facetType = detector.getFacetType(); final FacetsProvider provider = DefaultFacetsProvider.INSTANCE; for (Module module : filesByModule.keySet()) { final Collection facets = provider.getFacetsByType(module, facetType.getId()); @@ -69,9 +69,10 @@ public class FrameworkDetectionContextImpl extends FrameworkDetectionContextBase //noinspection unchecked existentConfigurations.add((C)facet.getConfiguration()); } - final List>> pairs = creator.createConfigurations(files, ModuleRootManager.getInstance(module), existentConfigurations); + final Collection moduleFiles = filesByModule.get(module); + final List>> pairs = detector.createConfigurations(moduleFiles, existentConfigurations); for (Pair> pair : pairs) { - result.add(new FacetBasedDetectedFrameworkDescription(module, pair.getFirst(), new HashSet(pair.getSecond()), facetType)); + result.add(new FacetBasedDetectedFrameworkDescriptionImpl(module, detector, pair.getFirst(), new HashSet(pair.getSecond()))); } } return result; 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 8614e2b16d52..d8df6f799d24 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 @@ -36,6 +36,7 @@ import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.PlatformModifiableModelsProvider; +import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; @@ -219,7 +220,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen try { final PlatformModifiableModelsProvider provider = new PlatformModifiableModelsProvider(); for (DetectedFrameworkDescription description : selected) { - description.configureFramework(provider); + description.configureFramework(provider, new DefaultModulesProvider(myProject)); myDetectedFrameworksData.putExistentFrameworkFiles(frameworksToId.get(description), description.getRelatedFiles()); } } diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java index ba9fb4426226..8dd037bb5984 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java @@ -18,6 +18,7 @@ package com.intellij.framework.detection.impl; import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.FrameworkDetectionContext; import com.intellij.framework.detection.FrameworkDetector; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.vfs.LocalFileSystem; @@ -28,15 +29,21 @@ import com.intellij.util.indexing.FileContent; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author nik */ public class FrameworkDetectionProcessor { + private static final Logger LOG = Logger.getInstance("#com.intellij.framework.detection.impl.FrameworkDetectionProcessor"); private final ProgressIndicator myProgressIndicator; private final MultiMap myDetectorsByFileType; + private Set myProcessedFiles; + private final FrameworkDetectionContext myContext; public FrameworkDetectionProcessor(ProgressIndicator progressIndicator, final FrameworkDetectionContext context) { @@ -50,6 +57,7 @@ public class FrameworkDetectionProcessor { } public List processRoots(List roots) { + myProcessedFiles = new HashSet(); for (File root : roots) { VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); if (virtualFile == null) continue; @@ -63,7 +71,7 @@ public class FrameworkDetectionProcessor { } private void collectSuitableFiles(@NotNull VirtualFile file) { - if (myProgressIndicator.isCanceled()) return; + if (myProgressIndicator.isCanceled() || !myProcessedFiles.add(file)) return; if (file.isDirectory()) { file.getChildren();//initialize myChildren field to ensure that refresh will be really performed @@ -76,17 +84,22 @@ public class FrameworkDetectionProcessor { } final FileType fileType = file.getFileType(); - if (myDetectorsByFileType.containsKey(fileType)) { + if (!myDetectorsByFileType.containsKey(fileType)) { return; } myProgressIndicator.setText2(file.getPresentableUrl()); - FileContent fileContent = new FileContent(file); - for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) { - if (detector.myFilePattern.accepts(fileContent)) { - detector.mySuitableFiles.add(file); + try { + FileContent fileContent = new FileContent(file, file.contentsToByteArray(false)); + for (FrameworkDetectorData detector : myDetectorsByFileType.get(fileType)) { + if (detector.myFilePattern.accepts(fileContent)) { + detector.mySuitableFiles.add(file); + } } } + catch (IOException e) { + LOG.info(e); + } } private static class FrameworkDetectorData { diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksTree.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksTree.java index 56fc901ff5dd..6b2936e65ade 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksTree.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksTree.java @@ -67,11 +67,15 @@ public class DetectedFrameworksTree extends CheckboxTree { externalNodes.add(frameworkNode); } } + List rootDirs = new ArrayList(); for (FrameworkDirectoryNode directoryNode : nodes.values()) { if (directoryNode.getParent() == null) { - root.add(collapseDirectoryNode(directoryNode)); + rootDirs.add(directoryNode); } } + for (FrameworkDirectoryNode dir : rootDirs) { + root.add(collapseDirectoryNode(dir)); + } for (DetectedFrameworkNode node : externalNodes) { root.add(node); } diff --git a/platform/lang-impl/testSrc/com/intellij/framework/detection/DetectionExcludesConfigurationTest.java b/platform/lang-impl/testSrc/com/intellij/framework/detection/DetectionExcludesConfigurationTest.java index 02a6638464a8..c02f0dd460d2 100644 --- a/platform/lang-impl/testSrc/com/intellij/framework/detection/DetectionExcludesConfigurationTest.java +++ b/platform/lang-impl/testSrc/com/intellij/framework/detection/DetectionExcludesConfigurationTest.java @@ -22,7 +22,6 @@ import com.intellij.framework.detection.impl.exclude.ExcludesConfigurationState; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestCase; -import com.intellij.util.ui.EmptyIcon; import java.io.File; import java.io.IOException; @@ -128,11 +127,11 @@ public class DetectionExcludesConfigurationTest extends PlatformTestCase { } private static FrameworkType getType() { - return new FrameworkType("type", "Type", EmptyIcon.ICON_16); + return new FrameworkType("type", "Type", null); } private static FrameworkType getType2() { - return new FrameworkType("type2", "Type2", EmptyIcon.ICON_16); + return new FrameworkType("type2", "Type2", null); } private DetectionExcludesConfigurationImpl getConfiguration() {