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 new file mode 100644 index 000000000000..159745ede075 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java @@ -0,0 +1,54 @@ +/* + * 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.facet.FacetType; +import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.impl.FrameworkDetectionContextBase; +import com.intellij.ide.util.projectWizard.SourcePathsBuilder; +import com.intellij.openapi.vfs.LocalFileSystem; +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 class FrameworkDetectionInWizardContext extends FrameworkDetectionContextBase { + private final SourcePathsBuilder myBuilder; + + public FrameworkDetectionInWizardContext(SourcePathsBuilder builder) { + myBuilder = builder; + } + + @NotNull + @Override + public List createDetectedFacetDescriptions(@NotNull FacetType facetType, + @NotNull Collection files, + @NotNull FacetConfigurationCreator creator) { + return Collections.emptyList(); + } + + public VirtualFile getBaseDir() { + final String path = myBuilder.getContentEntryPath(); + return path != null ? LocalFileSystem.getInstance().refreshAndFindFileByPath(path) : null; + } +} diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.form b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.form similarity index 84% rename from java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.form rename to java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.form index 2caf01a4fa2a..79003de1bb3b 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.form +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.form @@ -1,5 +1,5 @@ -
+ @@ -8,15 +8,15 @@ - + - + - + diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.java b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java similarity index 57% rename from java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.java rename to java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java index 1f88c3cd416c..e8cdc80b8824 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/FacetDetectionStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionStep.java @@ -23,21 +23,24 @@ 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.facet.impl.autodetecting.facetsTree.DetectedFacetsTreeComponent; -import com.intellij.facet.impl.ui.FacetDetectionProcessor; +import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.DetectionExcludesConfiguration; +import com.intellij.framework.detection.FrameworkDetectionContext; +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.Module; 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.ModifiableRootModel; +import com.intellij.openapi.roots.PlatformModifiableModelsProvider; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Ref; -import com.intellij.ui.ScrollPaneFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -45,28 +48,26 @@ import javax.swing.*; import java.awt.*; import java.io.File; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * @author nik */ -public abstract class FacetDetectionStep extends AbstractStepWithProgress>>> +public abstract class FrameworkDetectionStep extends AbstractStepWithProgress> implements ProjectFromSourcesBuilder.ProjectConfigurationUpdater { private final Icon myIcon; - private final ModuleType myModuleType; private List myLastRoots = null; - private final DetectedFacetsTreeComponent myDetectedFacetsComponent; + private final DetectedFrameworksComponent myDetectedFrameworksComponent; private JPanel myMainPanel; - private JPanel myFacetsTreePanel; - private JLabel myFacetsDetectedLabel; + private JPanel myFrameworksPanel; + private JLabel myFrameworksDetectedLabel; + private final FrameworkDetectionContext myContext; - public FacetDetectionStep(final Icon icon, ModuleType moduleType) { - super(ProjectBundle.message("message.text.stop.searching.for.facets", ApplicationNamesInfo.getInstance().getProductName())); + public FrameworkDetectionStep(final Icon icon, SourcePathsBuilder builder) { + super(ProjectBundle.message("message.text.stop.searching.for.frameworks", ApplicationNamesInfo.getInstance().getProductName())); myIcon = icon; - myModuleType = moduleType; - myDetectedFacetsComponent = new DetectedFacetsTreeComponent(); + myContext = new FrameworkDetectionInWizardContext(builder); + myDetectedFrameworksComponent = new DetectedFrameworksComponent(myContext); } public void updateDataModel() { @@ -77,38 +78,28 @@ public abstract class FacetDetectionStep extends AbstractStepWithProgress>> calculate() { + protected List calculate() { myLastRoots = getRoots(); ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); - Map>> result = new HashMap>>(); + List roots = new ArrayList(); for (ModuleDescriptor moduleDescriptor : getModuleDescriptors()) { - - Map> root2Facets = new HashMap>(); - for (File root : moduleDescriptor.getContentRoots()) { - FacetDetectionProcessor processor = new FacetDetectionProcessor(progressIndicator, myModuleType); - processor.process(root); - List facets = processor.getDetectedFacetsInfos(); - if (!facets.isEmpty()) { - root2Facets.put(root, facets); - } - } - - if (!root2Facets.isEmpty()) { - result.put(moduleDescriptor, root2Facets); - } + roots.addAll(moduleDescriptor.getContentRoots()); } + List result = new ArrayList(); + FrameworkDetectionProcessor processor = new FrameworkDetectionProcessor(progressIndicator, myContext); + processor.processRoots(roots); return result; } @@ -122,17 +113,13 @@ public abstract class FacetDetectionStep extends AbstractStepWithProgress>> result, final boolean canceled) { - myDetectedFacetsComponent.clear(); - for (ModuleDescriptor moduleDescriptor : result.keySet()) { - myDetectedFacetsComponent.addFacets(moduleDescriptor, result.get(moduleDescriptor)); - } - myDetectedFacetsComponent.createTree(); + protected void onFinished(final List result, final boolean canceled) { + myDetectedFrameworksComponent.getTree().rebuildTree(result); if (result.isEmpty()) { - myFacetsDetectedLabel.setText(ProjectBundle.message("label.text.no.facets.detected")); + myFrameworksDetectedLabel.setText(ProjectBundle.message("label.text.no.frameworks.detected")); } else { - myFacetsDetectedLabel.setText(ProjectBundle.message("label.text.the.following.facets.are.detected")); + myFrameworksDetectedLabel.setText(ProjectBundle.message("label.text.the.following.frameworks.are.detected")); } } @@ -167,7 +154,11 @@ public abstract class FacetDetectionStep extends AbstractStepWithProgress projectLibs = new HashMap(); final List result = new ArrayList(); - // create project-level libraries - Exception e = ApplicationManager.getApplication().runWriteAction(new Computable() { - public Exception compute() { - try { - for (LibraryDescriptor lib : myChosenLibraries) { - if (lib.getLevel() == LibraryDescriptor.Level.PROJECT) { - final Collection files = lib.getJars(); - final Library projectLib = projectLibraryTable.createLibrary(lib.getName()); - final Library.ModifiableModel model = projectLib.getModifiableModel(); - for (File file : files) { - model.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES); - } - model.commit(); - projectLibs.put(lib, projectLib); + try { + AccessToken token = WriteAction.start(); + try { + // create project-level libraries + for (LibraryDescriptor lib : myChosenLibraries) { + if (lib.getLevel() == LibraryDescriptor.Level.PROJECT) { + final Collection files = lib.getJars(); + final Library projectLib = projectLibraryTable.createLibrary(lib.getName()); + final Library.ModifiableModel libraryModel = projectLib.getModifiableModel(); + for (File file : files) { + libraryModel.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES); } + libraryModel.commit(); + projectLibs.put(lib, projectLib); } - return null; - } - catch (Exception e) { - return e; } } - }); - if (e != null) { + finally { + token.finish(); + } + } + catch (Exception e) { Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module")); } - - + // create modules and set up dependencies final Map sourceRootToPrefixMap = new HashMap(); for (Pair pair : getSourcePaths()) { sourceRootToPrefixMap.put(FileUtil.toSystemIndependentName(pair.getFirst()), pair.getSecond()); } final Map descriptorToModuleMap = new HashMap(); - Exception ex = ApplicationManager.getApplication().runWriteAction(new Computable() { - public Exception compute() { - try { - final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel(); - for (final ModuleDescriptor moduleDescriptor : myChosenModules) { - final Module module; - if (moduleDescriptor.isReuseExistingElement()) { - final ExistingModuleLoader moduleLoader = ImportImlMode.setUpLoader(FileUtil.toSystemIndependentName(moduleDescriptor.computeModuleFilePath())); - module = moduleLoader.createModule(moduleModel); - } - else { - module = createModule(project, moduleDescriptor, sourceRootToPrefixMap, projectLibs, moduleModel); - } - result.add(module); - descriptorToModuleMap.put(moduleDescriptor, module); + + try { + AccessToken token = WriteAction.start(); + try { + final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel(); + for (final ModuleDescriptor moduleDescriptor : myChosenModules) { + final Module module; + if (moduleDescriptor.isReuseExistingElement()) { + final ExistingModuleLoader moduleLoader = + ImportImlMode.setUpLoader(FileUtil.toSystemIndependentName(moduleDescriptor.computeModuleFilePath())); + module = moduleLoader.createModule(moduleModel); } - moduleModel.commit(); + else { + module = createModule(moduleDescriptor, sourceRootToPrefixMap, projectLibs, moduleModel); + } + result.add(module); + descriptorToModuleMap.put(moduleDescriptor, module); } - catch (Exception e) { - return e; - } - return null; + moduleModel.commit(); + } + finally { + token.finish(); } - }); - if (ex != null) { - Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", ex.getMessage()), IdeBundle.message("title.add.module")); } - + catch (Exception e) { + Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module")); + } + // setup dependencies between modules - ex = ApplicationManager.getApplication().runWriteAction(new Computable() { - public Exception compute() { - try { - for (final ModuleDescriptor descriptor : myChosenModules) { - final Module module = descriptorToModuleMap.get(descriptor); - if (module == null) { - continue; - } - final Set deps = descriptor.getDependencies(); - if (deps.size() == 0) { - continue; - } - final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); - for (ModuleDescriptor dependentDescriptor : deps) { - final Module dependentModule = descriptorToModuleMap.get(dependentDescriptor); - if (dependentModule != null) { - rootModel.addModuleOrderEntry(dependentModule); - } - } - rootModel.commit(); + try { + AccessToken token = WriteAction.start(); + try { + for (final ModuleDescriptor descriptor : myChosenModules) { + final Module module = descriptorToModuleMap.get(descriptor); + if (module == null) { + continue; } + final Set deps = descriptor.getDependencies(); + if (deps.size() == 0) { + continue; + } + final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); + for (ModuleDescriptor dependentDescriptor : deps) { + final Module dependentModule = descriptorToModuleMap.get(dependentDescriptor); + if (dependentModule != null) { + rootModel.addModuleOrderEntry(dependentModule); + } + } + rootModel.commit(); } - catch (Exception e) { - return e; - } - return null; } - }); - - if (ex != null) { - Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", ex.getMessage()), IdeBundle.message("title.add.module")); + finally { + token.finish(); + } } + catch (Exception e) { + Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", e.getMessage()), IdeBundle.message("title.add.module")); + } + + AccessToken token = WriteAction.start(); + try { + for (ProjectConfigurationUpdater updater : myUpdaters) { + updater.updateProject(project); + } + } + finally { + token.finish(); + } + return result; } @@ -200,7 +205,7 @@ public class ProjectFromSourcesBuilder extends ProjectBuilder implements SourceP } @NotNull - public Module createModule(final Project project, final ModuleDescriptor descriptor, final Map sourceRootToPrefixMap, + private Module createModule(final ModuleDescriptor descriptor, final Map sourceRootToPrefixMap, final Map projectLibs, final ModifiableModuleModel moduleModel) throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException, ConfigurationException { @@ -210,9 +215,6 @@ public class ProjectFromSourcesBuilder extends ProjectBuilder implements SourceP final Module module = moduleModel.newModule(moduleFilePath, StdModuleTypes.JAVA); final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel(); setupRootModel(descriptor, modifiableModel, sourceRootToPrefixMap, projectLibs); - for (ProjectConfigurationUpdater updater : myUpdaters) { - updater.updateModule(descriptor, module, modifiableModel); - } modifiableModel.commit(); return module; } @@ -310,10 +312,8 @@ public class ProjectFromSourcesBuilder extends ProjectBuilder implements SourceP return available.contains(lib); } - public static interface ProjectConfigurationUpdater { - - void updateModule(final ModuleDescriptor descriptor, Module module, ModifiableRootModel rootModel); - + public interface ProjectConfigurationUpdater { + void updateProject(@NotNull Project project); } @Override diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/modes/CreateFromSourcesMode.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/modes/CreateFromSourcesMode.java index 1f46d71a13ed..c52e5a4ccf43 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/modes/CreateFromSourcesMode.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/modes/CreateFromSourcesMode.java @@ -70,14 +70,14 @@ public class CreateFromSourcesMode extends WizardMode { sequence.addCommonStep(new ModulesDetectionStep(projectBuilder, moduleInsight, icon, "reference.dialogs.new.project.fromCode.page2")); sequence.addCommonStep(factory.createProjectJdkStep(context)); - if (FacetDetectionStep.isEnabled(StdModuleTypes.JAVA)) { - FacetDetectionStep facetDetectionStep = new FacetDetectionStep(icon, StdModuleTypes.JAVA) { + if (FrameworkDetectionStep.isEnabled(StdModuleTypes.JAVA)) { + FrameworkDetectionStep frameworkDetectionStep = new FrameworkDetectionStep(icon, projectBuilder) { protected List getModuleDescriptors() { return projectBuilder.getModules(); } }; - projectBuilder.addConfigurationUpdater(facetDetectionStep); - sequence.addCommonStep(facetDetectionStep); + projectBuilder.addConfigurationUpdater(frameworkDetectionStep); + sequence.addCommonStep(frameworkDetectionStep); } return sequence; 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 15621fc8303a..1427cf440477 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/FrameworkDetectionContext.java @@ -18,12 +18,11 @@ package com.intellij.framework.detection; import com.intellij.facet.Facet; import com.intellij.facet.FacetConfiguration; import com.intellij.facet.FacetType; -import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootModel; -import com.intellij.openapi.roots.ui.configuration.FacetsProvider; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -32,11 +31,9 @@ import java.util.List; * @author nik */ public interface FrameworkDetectionContext { - @NotNull - Project getProject(); - @NotNull - FacetsProvider getFacetsProvider(); + @Nullable + VirtualFile getBaseDir(); @NotNull @@ -45,12 +42,12 @@ public interface FrameworkDetectionContext { @NotNull List createDetectedFacetDescriptions(@NotNull FacetType facetType, @NotNull Collection files, - @NotNull FacetConfigurationCreator creator); + @NotNull FacetConfigurationCreator creator); - abstract class FacetConfigurationCreator { + abstract class FacetConfigurationCreator { @NotNull public abstract List>> createConfigurations(@NotNull Collection files, @NotNull ModuleRootModel rootModel, - @NotNull Collection existentFacets); + @NotNull Collection existentFacetConfigurations); } } 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 new file mode 100644 index 000000000000..9362b12f6388 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionContextBase.java @@ -0,0 +1,49 @@ +/* + * 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; + +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 c4c33a0abfe6..176e021ea0c6 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,61 +20,36 @@ 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.FrameworkDetectionContext; 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.ModuleRootModel; import com.intellij.openapi.roots.ui.configuration.FacetsProvider; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.MultiMapBasedOnSet; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; /** * @author nik */ -public class FrameworkDetectionContextImpl implements FrameworkDetectionContext { +public class FrameworkDetectionContextImpl extends FrameworkDetectionContextBase { private final Project myProject; public FrameworkDetectionContextImpl(@NotNull Project project) { myProject = project; } - @NotNull - @Override - public Project getProject() { - return myProject; - } - - @NotNull - @Override - public FacetsProvider getFacetsProvider() { - return DefaultFacetsProvider.INSTANCE; - } - - @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 existentFacets) { - return Collections.singletonList(Pair.create(facetType.createDefaultConfiguration(), files)); - } - }); - } - @NotNull @Override public List createDetectedFacetDescriptions(@NotNull FacetType facetType, @NotNull Collection files, - @NotNull FacetConfigurationCreator creator) { + @NotNull FacetConfigurationCreator creator) { MultiMapBasedOnSet filesByModule = new MultiMapBasedOnSet(); for (VirtualFile file : files) { final Module module = ModuleUtil.findModuleForFile(file, myProject); @@ -83,17 +58,26 @@ public class FrameworkDetectionContextImpl implements FrameworkDetectionContext } } final List result = new ArrayList(); - final FacetsProvider provider = getFacetsProvider(); + final FacetsProvider provider = DefaultFacetsProvider.INSTANCE; for (Module module : filesByModule.keySet()) { final Collection facets = provider.getFacetsByType(module, facetType.getId()); if (facetType.isOnlyOneFacetAllowed() && !facets.isEmpty()) { continue; } - final List>> pairs = creator.createConfigurations(files, ModuleRootManager.getInstance(module), facets); + List existentConfigurations = new ArrayList(); + for (F facet : facets) { + //noinspection unchecked + existentConfigurations.add((C)facet.getConfiguration()); + } + final List>> pairs = creator.createConfigurations(files, ModuleRootManager.getInstance(module), existentConfigurations); for (Pair> pair : pairs) { result.add(new FacetBasedDetectedFrameworkDescription(module, pair.getFirst(), new HashSet(pair.getSecond()), facetType)); } } return result; } + + public VirtualFile getBaseDir() { + return myProject.getBaseDir(); + } } 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 eecbcd6aa9db..8614e2b16d52 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 @@ -21,7 +21,7 @@ import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.DetectionExcludesConfiguration; import com.intellij.framework.detection.FrameworkDetector; -import com.intellij.framework.detection.impl.ui.SetupDetectedFrameworksDialog; +import com.intellij.framework.detection.impl.ui.ConfigureDetectedFrameworksDialog; import com.intellij.notification.Notification; import com.intellij.notification.NotificationGroup; import com.intellij.notification.NotificationListener; @@ -210,7 +210,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen frameworksToId.put(description, id); } } - final SetupDetectedFrameworksDialog dialog = new SetupDetectedFrameworksDialog(myProject, descriptions); + final ConfigureDetectedFrameworksDialog dialog = new ConfigureDetectedFrameworksDialog(myProject, descriptions); dialog.show(); if (dialog.isOK()) { notification.expire(); @@ -220,8 +220,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen final PlatformModifiableModelsProvider provider = new PlatformModifiableModelsProvider(); for (DetectedFrameworkDescription description : selected) { description.configureFramework(provider); - final Collection files = description.getRelatedFiles(); - myDetectedFrameworksData.putExistentFrameworkFiles(frameworksToId.get(description), files); + myDetectedFrameworksData.putExistentFrameworkFiles(frameworksToId.get(description), description.getRelatedFiles()); } } finally { 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 new file mode 100644 index 000000000000..ba9fb4426226 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/FrameworkDetectionProcessor.java @@ -0,0 +1,102 @@ +/* + * 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; + +import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.FrameworkDetectionContext; +import com.intellij.framework.detection.FrameworkDetector; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.patterns.ElementPattern; +import com.intellij.util.containers.MultiMap; +import com.intellij.util.indexing.FileContent; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class FrameworkDetectionProcessor { + private final ProgressIndicator myProgressIndicator; + private final MultiMap myDetectorsByFileType; + private final FrameworkDetectionContext myContext; + + public FrameworkDetectionProcessor(ProgressIndicator progressIndicator, final FrameworkDetectionContext context) { + myProgressIndicator = progressIndicator; + final FrameworkDetector[] detectors = FrameworkDetector.EP_NAME.getExtensions(); + myDetectorsByFileType = new MultiMap(); + for (FrameworkDetector detector : detectors) { + myDetectorsByFileType.putValue(detector.getFileType(), new FrameworkDetectorData(detector)); + } + myContext = context; + } + + public List processRoots(List roots) { + for (File root : roots) { + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); + if (virtualFile == null) continue; + collectSuitableFiles(virtualFile); + } + List result = new ArrayList(); + for (FrameworkDetectorData data : myDetectorsByFileType.values()) { + result.addAll(data.myDetector.detect(data.mySuitableFiles, myContext)); + } + return result; + } + + private void collectSuitableFiles(@NotNull VirtualFile file) { + if (myProgressIndicator.isCanceled()) return; + + if (file.isDirectory()) { + file.getChildren();//initialize myChildren field to ensure that refresh will be really performed + file.refresh(false, false); + VirtualFile[] children = file.getChildren(); + for (VirtualFile child : children) { + collectSuitableFiles(child); + } + return; + } + + final FileType fileType = file.getFileType(); + 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); + } + } + } + + private static class FrameworkDetectorData { + private FrameworkDetector myDetector; + private final ElementPattern myFilePattern; + private final List mySuitableFiles = new ArrayList(); + + public FrameworkDetectorData(FrameworkDetector detector) { + myDetector = detector; + myFilePattern = detector.createSuitableFilePattern(); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/ConfigureDetectedFrameworksDialog.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/ConfigureDetectedFrameworksDialog.java new file mode 100644 index 000000000000..558c17974376 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/ConfigureDetectedFrameworksDialog.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.framework.detection.impl.ui; + +import com.intellij.framework.detection.DetectedFrameworkDescription; +import com.intellij.framework.detection.DetectionExcludesConfiguration; +import com.intellij.framework.detection.impl.FrameworkDetectionContextImpl; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; + +import javax.swing.*; +import java.util.List; + +/** + * @author nik + */ +public class ConfigureDetectedFrameworksDialog extends DialogWrapper { + private final DetectedFrameworksComponent myComponent; + private final Project myProject; + + public ConfigureDetectedFrameworksDialog(Project project, List descriptions) { + super(project, true); + myProject = project; + setTitle("Setup Frameworks"); + myComponent = new DetectedFrameworksComponent(new FrameworkDetectionContextImpl(project)); + myComponent.getTree().rebuildTree(descriptions); + init(); + } + + @Override + protected JComponent createCenterPanel() { + return myComponent.getMainPanel(); + } + + public List getSelectedFrameworks() { + return myComponent.getSelectedFrameworks(); + } + + @Override + protected void doOKAction() { + myComponent.processUncheckedNodes(DetectionExcludesConfiguration.getInstance(myProject)); + super.doOKAction(); + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworkNode.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworkNode.java index f2e848b3f496..f33652971c71 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworkNode.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworkNode.java @@ -98,7 +98,7 @@ class DetectedFrameworkNode extends DetectedFrameworkTreeNodeBase { @NotNull private String getRelativePath(@NotNull VirtualFile file) { - final VirtualFile dir = myContext.getProject().getBaseDir(); + final VirtualFile dir = myContext.getBaseDir(); if (dir != null) { final String path = VfsUtil.getRelativePath(dir, file, File.separatorChar); if (path != null) { diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.form b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.form similarity index 98% rename from platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.form rename to platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.form index 7a88de586c90..9b61f4a81728 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.form +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.form @@ -1,5 +1,5 @@ - + diff --git a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.java b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.java similarity index 77% rename from platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.java rename to platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.java index 8fa2b5185121..38e2ed455cc1 100644 --- a/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/SetupDetectedFrameworksDialog.java +++ b/platform/lang-impl/src/com/intellij/framework/detection/impl/ui/DetectedFrameworksComponent.java @@ -17,17 +17,14 @@ package com.intellij.framework.detection.impl.ui; import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.DetectionExcludesConfiguration; -import com.intellij.framework.detection.impl.FrameworkDetectionContextImpl; +import com.intellij.framework.detection.FrameworkDetectionContext; import com.intellij.ide.ui.ListCellRendererWrapper; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Splitter; import com.intellij.ui.CheckedTreeNode; import com.intellij.ui.EnumComboBoxModel; import com.intellij.ui.ScrollPaneFactory; import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.TreeSelectionEvent; @@ -41,7 +38,7 @@ import java.util.List; /** * @author nik */ -public class SetupDetectedFrameworksDialog extends DialogWrapper { +public class DetectedFrameworksComponent { private JPanel myMainPanel; private final DetectedFrameworksTree myTree; private JPanel myTreePanel; @@ -49,14 +46,9 @@ public class SetupDetectedFrameworksDialog extends DialogWrapper { private Splitter mySplitter; private JComboBox myGroupByComboBox; private JLabel myDescriptionLabel; - private final Project myProject; - public SetupDetectedFrameworksDialog(@NotNull Project project, @NotNull List descriptions) { - super(project, true); - myProject = project; - setTitle("Setup Frameworks"); - final FrameworkDetectionContextImpl context = new FrameworkDetectionContextImpl(project); - myTree = new DetectedFrameworksTree(descriptions, context, GroupByOption.TYPE) { + public DetectedFrameworksComponent(final FrameworkDetectionContext context) { + myTree = new DetectedFrameworksTree(context, GroupByOption.TYPE) { @Override protected void onNodeStateChanged(CheckedTreeNode node) { updateOptionsPanel(); @@ -77,10 +69,13 @@ public class SetupDetectedFrameworksDialog extends DialogWrapper { updateOptionsPanel(); } }); - init(); updateOptionsPanel(); } + public DetectedFrameworksTree getTree() { + return myTree; + } + private void updateOptionsPanel() { final DetectedFrameworkTreeNodeBase[] nodes = myTree.getSelectedNodes(DetectedFrameworkTreeNodeBase.class, null); if (nodes.length == 1) { @@ -94,31 +89,28 @@ public class SetupDetectedFrameworksDialog extends DialogWrapper { myDescriptionLabel.setText(""); } - @Override - protected JComponent createCenterPanel() { + public List getSelectedFrameworks() { + return Arrays.asList(myTree.getCheckedNodes(DetectedFrameworkDescription.class, null)); + } + + public JComponent getMainPanel() { return myMainPanel; } - @Override - protected void doOKAction() { - myTree.processUncheckedNodes(new Consumer() { + public void processUncheckedNodes(final DetectionExcludesConfiguration excludesConfiguration) { + getTree().processUncheckedNodes(new Consumer() { @Override public void consume(DetectedFrameworkTreeNodeBase node) { - node.disableDetection(DetectionExcludesConfiguration.getInstance(myProject)); + node.disableDetection(excludesConfiguration); } }); - super.doOKAction(); - } - - public List getSelectedFrameworks() { - return Arrays.asList(myTree.getCheckedNodes(DetectedFrameworkDescription.class, null)); } public static enum GroupByOption { TYPE, DIRECTORY } private class GroupByListCellRenderer extends ListCellRendererWrapper { public GroupByListCellRenderer() { - super(SetupDetectedFrameworksDialog.this.myGroupByComboBox); + super(DetectedFrameworksComponent.this.myGroupByComboBox); } @Override 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 30d3ea61dfcf..56fc901ff5dd 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 @@ -38,37 +38,22 @@ import java.util.Map; * @author nik */ public class DetectedFrameworksTree extends CheckboxTree { - private final List myDetectedFrameworks; + private List myDetectedFrameworks; private final FrameworkDetectionContext myContext; - private SetupDetectedFrameworksDialog.GroupByOption myGroupByOption; + private DetectedFrameworksComponent.GroupByOption myGroupByOption; - public DetectedFrameworksTree(List detectedFrameworks, - final FrameworkDetectionContext context, - SetupDetectedFrameworksDialog.GroupByOption groupByOption) { + public DetectedFrameworksTree(final FrameworkDetectionContext context, DetectedFrameworksComponent.GroupByOption groupByOption) { super(new DetectedFrameworksTreeRenderer(), new CheckedTreeNode(null), new CheckPolicy(true, true, true, false)); - myDetectedFrameworks = detectedFrameworks; myContext = context; myGroupByOption = groupByOption; setShowsRootHandles(false); setRootVisible(false); - createNodes(); - TreeUtil.expandAll(this); } - private void createNodes() { - CheckedTreeNode root = getRoot(); - if (myGroupByOption == SetupDetectedFrameworksDialog.GroupByOption.TYPE) { - createNodesGroupedByType(root); - } - else { - createNodesGroupedByDirectory(root); - } - } - - private void createNodesGroupedByDirectory(CheckedTreeNode root) { + private void createNodesGroupedByDirectory(CheckedTreeNode root, final List frameworks) { Map nodes = new HashMap(); List externalNodes = new ArrayList(); - for (DetectedFrameworkDescription framework : myDetectedFrameworks) { + for (DetectedFrameworkDescription framework : frameworks) { VirtualFile parent = VfsUtil.getCommonAncestor(framework.getRelatedFiles()); if (parent != null && !parent.isDirectory()) { parent = parent.getParent(); @@ -140,9 +125,9 @@ public class DetectedFrameworksTree extends CheckboxTree { return newNode; } - private void createNodesGroupedByType(CheckedTreeNode root) { + private void createNodesGroupedByType(CheckedTreeNode root, final List frameworks) { Map groupNodes = new HashMap(); - for (DetectedFrameworkDescription framework : myDetectedFrameworks) { + for (DetectedFrameworkDescription framework : frameworks) { final FrameworkType type = framework.getFrameworkType(); FrameworkTypeNode group = groupNodes.get(type); if (group == null) { @@ -158,13 +143,26 @@ public class DetectedFrameworksTree extends CheckboxTree { return ((CheckedTreeNode)getModel().getRoot()); } - public void changeGroupBy(SetupDetectedFrameworksDialog.GroupByOption option) { + public void changeGroupBy(DetectedFrameworksComponent.GroupByOption option) { if (myGroupByOption.equals(option)) return; myGroupByOption = option; - getRoot().removeAllChildren(); - createNodes(); - ((DefaultTreeModel)getModel()).nodeStructureChanged(getRoot()); + if (myDetectedFrameworks != null) { + rebuildTree(myDetectedFrameworks); + } + } + + public void rebuildTree(final List frameworks) { + final CheckedTreeNode root = getRoot(); + root.removeAllChildren(); + if (myGroupByOption == DetectedFrameworksComponent.GroupByOption.TYPE) { + createNodesGroupedByType(root, frameworks); + } + else { + createNodesGroupedByDirectory(root, frameworks); + } + ((DefaultTreeModel)getModel()).nodeStructureChanged(root); TreeUtil.expandAll(this); + myDetectedFrameworks = frameworks; } private static class DetectedFrameworksTreeRenderer extends CheckboxTreeCellRenderer { diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index 977a7f35f1b5..e947f0e4256b 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -62,10 +62,10 @@ notification.name.0.facets.detected={0} facets detected notification.name.0.facet.detected={0} facet detected facet.autodetection.several.facets.detected.text={0} facets detected. More... -progress.text.searching.facets=Searching for facets. Please wait. -message.text.stop.searching.for.facets={0} is currently searching for facets. Would you like to stop the search? -label.text.the.following.facets.are.detected=Several facets are detected in the project. Please review the following facets and exclude mistakenly detected. -label.text.no.facets.detected=No facets detected. +progress.text.searching.frameworks=Searching for frameworks. Please wait. +message.text.stop.searching.for.frameworks={0} is currently searching for frameworks. Would you like to stop the search? +label.text.the.following.frameworks.are.detected=Several frameworks are detected in the project. Please review the following items and exclude mistakenly detected. +label.text.no.frameworks.detected=No frameworks detected. dialog.title.facets.detected=New Facets Detected label.text.the.following.facets.are.detected.on.the.fly=Several facets are detected in the project. Please review the following facets and exclude mistakenly detected.