mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new framework detection: detection for sub-frameworks
This commit is contained in:
+11
-2
@@ -17,15 +17,19 @@ package com.intellij.ide.util.importProject;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetConfiguration;
|
||||
import com.intellij.facet.FacetTypeId;
|
||||
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.FacetsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -49,9 +53,14 @@ public class FacetBasedDetectedFrameworkDescriptionInWizard<F extends Facet, C e
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider) {
|
||||
public void setupFramework(@NotNull ModifiableModelsProvider modifiableModelsProvider, @NotNull ModulesProvider modulesProvider) {
|
||||
Module module = modulesProvider.getModule(getModuleName());
|
||||
LOG.assertTrue(module != null, getModuleName());
|
||||
doConfigure(modifiableModelsProvider, module);
|
||||
doSetup(modifiableModelsProvider, module);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<? extends Facet> getExistentFacets(FacetTypeId<?> underlyingFacetType) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ 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.FrameworkDetectionUtil;
|
||||
import com.intellij.framework.detection.impl.ui.DetectedFrameworksComponent;
|
||||
import com.intellij.ide.util.newProjectWizard.ProjectFromSourcesBuilder;
|
||||
import com.intellij.ide.util.projectWizard.AbstractStepWithProgress;
|
||||
@@ -30,8 +31,6 @@ 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 org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -45,7 +44,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FrameworkDetectionStep extends AbstractStepWithProgress<List<DetectedFrameworkDescription>>
|
||||
public abstract class FrameworkDetectionStep extends AbstractStepWithProgress<List<? extends DetectedFrameworkDescription>>
|
||||
implements ProjectFromSourcesBuilder.ProjectConfigurationUpdater {
|
||||
private final Icon myIcon;
|
||||
private List<File> myLastRoots = null;
|
||||
@@ -89,7 +88,7 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress<Li
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
protected List<DetectedFrameworkDescription> calculate() {
|
||||
protected List<? extends DetectedFrameworkDescription> calculate() {
|
||||
myLastRoots = getRoots();
|
||||
|
||||
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
@@ -113,7 +112,7 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress<Li
|
||||
return roots;
|
||||
}
|
||||
|
||||
protected void onFinished(final List<DetectedFrameworkDescription> result, final boolean canceled) {
|
||||
protected void onFinished(final List<? extends DetectedFrameworkDescription> result, final boolean canceled) {
|
||||
myDetectedFrameworksComponent.getTree().rebuildTree(result);
|
||||
if (result.isEmpty()) {
|
||||
myFrameworksDetectedLabel.setText(ProjectBundle.message("label.text.no.frameworks.detected"));
|
||||
@@ -137,10 +136,7 @@ public abstract class FrameworkDetectionStep extends AbstractStepWithProgress<Li
|
||||
}
|
||||
|
||||
public void updateProject(@NotNull Project project) {
|
||||
final PlatformModifiableModelsProvider modelsProvider = new PlatformModifiableModelsProvider();
|
||||
for (DetectedFrameworkDescription description : myDetectedFrameworksComponent.getSelectedFrameworks()) {
|
||||
description.configureFramework(modelsProvider, new DefaultModulesProvider(project));
|
||||
}
|
||||
FrameworkDetectionUtil.setupFrameworks(myDetectedFrameworksComponent.getSelectedFrameworks(), project);
|
||||
myDetectedFrameworksComponent.processUncheckedNodes(DetectionExcludesConfiguration.getInstance(project));
|
||||
}
|
||||
}
|
||||
|
||||
+11
-1
@@ -20,6 +20,7 @@ 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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -36,7 +37,16 @@ public abstract class DetectedFrameworkDescription {
|
||||
@NotNull
|
||||
public abstract String getSetupDescription();
|
||||
|
||||
public abstract void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider);
|
||||
@Nullable
|
||||
public FrameworkType getUnderlyingType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canSetupFramework(@NotNull Collection<? extends DetectedFrameworkDescription> allDetectedFrameworks) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void setupFramework(@NotNull ModifiableModelsProvider modifiableModelsProvider, @NotNull ModulesProvider modulesProvider);
|
||||
|
||||
public abstract boolean equals(Object obj);
|
||||
|
||||
|
||||
+5
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -53,4 +54,8 @@ public abstract class FacetBasedFrameworkDetector<F extends Facet, C extends Fac
|
||||
public FrameworkType getFrameworkType() {
|
||||
return new FrameworkType(getFacetType().getStringId(), getFacetType().getPresentableName(), getFacetType().getIcon());
|
||||
}
|
||||
|
||||
public boolean isSuitableUnderlyingFacetConfiguration(FacetConfiguration underlying, C configuration, Set<VirtualFile> files) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,4 @@ public interface FrameworkDetectionContext {
|
||||
<F extends Facet, C extends FacetConfiguration>
|
||||
List<? extends DetectedFrameworkDescription> createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector<F, C> detector,
|
||||
@NotNull Collection<VirtualFile> files);
|
||||
|
||||
abstract class FacetConfigurationCreator<F extends Facet, C extends FacetConfiguration> {
|
||||
}
|
||||
}
|
||||
|
||||
+63
-2
@@ -19,10 +19,14 @@ 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.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.text.UniqueNameGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
@@ -31,6 +35,7 @@ import java.util.Set;
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class FacetBasedDetectedFrameworkDescription<F extends Facet, C extends FacetConfiguration> extends DetectedFrameworkDescription {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.framework.detection.impl.FacetBasedDetectedFrameworkDescription");
|
||||
private final FacetBasedFrameworkDetector<F, C> myDetector;
|
||||
private final C myConfiguration;
|
||||
private final Set<VirtualFile> myRelatedFiles;
|
||||
@@ -57,6 +62,12 @@ public abstract class FacetBasedDetectedFrameworkDescription<F extends Facet, C
|
||||
return myFrameworkType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameworkType getUnderlyingType() {
|
||||
final FacetTypeId<?> underlyingTypeId = myFacetType.getUnderlyingFacetType();
|
||||
return underlyingTypeId != null ? createFrameworkType(FacetTypeRegistry.getInstance().findFacetType(underlyingTypeId)) : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<? extends VirtualFile> getRelatedFiles() {
|
||||
@@ -75,14 +86,64 @@ public abstract class FacetBasedDetectedFrameworkDescription<F extends Facet, C
|
||||
|
||||
protected abstract String getModuleName();
|
||||
|
||||
protected void doConfigure(ModifiableModelsProvider modifiableModelsProvider, final Module module) {
|
||||
@Override
|
||||
public boolean canSetupFramework(@NotNull Collection<? extends DetectedFrameworkDescription> allDetectedFrameworks) {
|
||||
final FacetTypeId<?> underlyingId = myFacetType.getUnderlyingFacetType();
|
||||
if (underlyingId == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Collection<? extends Facet> facets = getExistentFacets(underlyingId);
|
||||
for (Facet facet : facets) {
|
||||
if (myDetector.isSuitableUnderlyingFacetConfiguration(facet.getConfiguration(), myConfiguration, myRelatedFiles)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (DetectedFrameworkDescription framework : allDetectedFrameworks) {
|
||||
if (framework instanceof FacetBasedDetectedFrameworkDescription<?, ?>) {
|
||||
final FacetBasedDetectedFrameworkDescription<?, ?> description = (FacetBasedDetectedFrameworkDescription<?, ?>)framework;
|
||||
if (underlyingId.equals(description.myFacetType.getId()) &&
|
||||
myDetector.isSuitableUnderlyingFacetConfiguration(description.getConfiguration(), myConfiguration, myRelatedFiles)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Collection<? extends Facet> getExistentFacets(FacetTypeId<?> underlyingFacetType);
|
||||
|
||||
protected void doSetup(ModifiableModelsProvider modifiableModelsProvider, final Module module) {
|
||||
final ModifiableFacetModel model = modifiableModelsProvider.getFacetModifiableModel(module);
|
||||
final F facet = FacetManager.getInstance(module).createFacet(myFacetType, myFacetType.getDefaultFacetName(), myConfiguration, null);
|
||||
final String name = UniqueNameGenerator.generateUniqueName(myFacetType.getDefaultFacetName(), new Condition<String>() {
|
||||
@Override
|
||||
public boolean value(String s) {
|
||||
return FacetManager.getInstance(module).findFacet(myFacetType.getId(), s) == null;
|
||||
}
|
||||
});
|
||||
final F facet = FacetManager.getInstance(module).createFacet(myFacetType, name, myConfiguration,
|
||||
findUnderlyingFacet(module));
|
||||
model.addFacet(facet);
|
||||
modifiableModelsProvider.commitFacetModifiableModel(module, model);
|
||||
myDetector.setupFacet(facet);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Facet findUnderlyingFacet(Module module) {
|
||||
final FacetTypeId<?> underlyingTypeId = myFacetType.getUnderlyingFacetType();
|
||||
if (underlyingTypeId == null) return null;
|
||||
|
||||
final Collection<? extends Facet> parentFacets = FacetManager.getInstance(module).getFacetsByType(underlyingTypeId);
|
||||
for (Facet facet : parentFacets) {
|
||||
if (myDetector.isSuitableUnderlyingFacetConfiguration(facet.getConfiguration(), myConfiguration, myRelatedFiles)) {
|
||||
return facet;
|
||||
}
|
||||
}
|
||||
LOG.error("Cannot find suitable underlying facet in " + parentFacets);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof FacetBasedDetectedFrameworkDescription)) {
|
||||
|
||||
+11
-4
@@ -17,15 +17,17 @@ package com.intellij.framework.detection.impl;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetConfiguration;
|
||||
import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.FacetManager;
|
||||
import com.intellij.facet.FacetTypeId;
|
||||
import com.intellij.framework.detection.FacetBasedFrameworkDetector;
|
||||
import com.intellij.framework.detection.FrameworkDetectionContext;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -46,7 +48,12 @@ public class FacetBasedDetectedFrameworkDescriptionImpl<F extends Facet, C exten
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureFramework(ModifiableModelsProvider modifiableModelsProvider, ModulesProvider modulesProvider) {
|
||||
doConfigure(modifiableModelsProvider, myModule);
|
||||
public void setupFramework(@NotNull ModifiableModelsProvider modifiableModelsProvider, @NotNull ModulesProvider modulesProvider) {
|
||||
doSetup(modifiableModelsProvider, myModule);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Collection<? extends Facet> getExistentFacets(FacetTypeId<?> underlyingFacetType) {
|
||||
return FacetManager.getInstance(myModule).getFacetsByType(underlyingFacetType);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-18
@@ -26,9 +26,7 @@ import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationGroup;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -36,8 +34,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
|
||||
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.ui.Messages;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -222,7 +218,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen
|
||||
|
||||
private void showSetupFrameworksDialog(Notification notification) {
|
||||
IdentityHashMap<DetectedFrameworkDescription, Integer> frameworksToId = new IdentityHashMap<DetectedFrameworkDescription, Integer>();
|
||||
List<DetectedFrameworkDescription> descriptions = getValidDetectedFrameworks(frameworksToId);
|
||||
List<? extends DetectedFrameworkDescription> descriptions = getValidDetectedFrameworks(frameworksToId);
|
||||
if (descriptions.isEmpty()) {
|
||||
Messages.showInfoMessage(myProject, "No frameworks are detected", "Framework Detection");
|
||||
return;
|
||||
@@ -232,21 +228,14 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen
|
||||
if (dialog.isOK()) {
|
||||
notification.expire();
|
||||
List<DetectedFrameworkDescription> selected = dialog.getSelectedFrameworks();
|
||||
AccessToken token = WriteAction.start();
|
||||
try {
|
||||
final PlatformModifiableModelsProvider provider = new PlatformModifiableModelsProvider();
|
||||
for (DetectedFrameworkDescription description : selected) {
|
||||
description.configureFramework(provider, new DefaultModulesProvider(myProject));
|
||||
myDetectedFrameworksData.putExistentFrameworkFiles(frameworksToId.get(description), description.getRelatedFiles());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
token.finish();
|
||||
FrameworkDetectionUtil.setupFrameworks(selected, myProject);
|
||||
for (DetectedFrameworkDescription description : selected) {
|
||||
myDetectedFrameworksData.putExistentFrameworkFiles(frameworksToId.get(description), description.getRelatedFiles());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<DetectedFrameworkDescription> getValidDetectedFrameworks(IdentityHashMap<DetectedFrameworkDescription, Integer> frameworksToId) {
|
||||
private List<? extends DetectedFrameworkDescription> getValidDetectedFrameworks(IdentityHashMap<DetectedFrameworkDescription, Integer> frameworksToId) {
|
||||
final MultiMap<Integer,DetectedFrameworkDescription> frameworksMap = myDetectedFrameworksData.getDetectedFrameworks();
|
||||
List<DetectedFrameworkDescription> descriptions = new ArrayList<DetectedFrameworkDescription>();
|
||||
final FileBasedIndex index = FileBasedIndex.getInstance();
|
||||
@@ -277,7 +266,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen
|
||||
frameworksToId.put(framework, id);
|
||||
}
|
||||
}
|
||||
return descriptions;
|
||||
return FrameworkDetectionUtil.removeDisabled(descriptions);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@@ -287,7 +276,7 @@ public class FrameworkDetectionManager extends AbstractProjectComponent implemen
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public List<DetectedFrameworkDescription> getDetectedFrameworks() {
|
||||
public List<? extends DetectedFrameworkDescription> getDetectedFrameworks() {
|
||||
return getValidDetectedFrameworks(new IdentityHashMap<DetectedFrameworkDescription, Integer>());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ public class FrameworkDetectionProcessor {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public List<DetectedFrameworkDescription> processRoots(List<File> roots) {
|
||||
public List<? extends DetectedFrameworkDescription> processRoots(List<File> roots) {
|
||||
myProcessedFiles = new HashSet<VirtualFile>();
|
||||
for (File root : roots) {
|
||||
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
|
||||
@@ -67,7 +67,7 @@ public class FrameworkDetectionProcessor {
|
||||
for (FrameworkDetectorData data : myDetectorsByFileType.values()) {
|
||||
result.addAll(data.myDetector.detect(data.mySuitableFiles, myContext));
|
||||
}
|
||||
return result;
|
||||
return FrameworkDetectionUtil.removeDisabled(result);
|
||||
}
|
||||
|
||||
private void collectSuitableFiles(@NotNull VirtualFile file) {
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.PlatformModifiableModelsProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class FrameworkDetectionUtil {
|
||||
private FrameworkDetectionUtil() {
|
||||
}
|
||||
|
||||
public static List<DetectedFrameworkDescription> getDisabledDescriptions(@NotNull List<? extends DetectedFrameworkDescription> allDescriptions) {
|
||||
List<DetectedFrameworkDescription> disabled = new ArrayList<DetectedFrameworkDescription>();
|
||||
for (DetectedFrameworkDescription description : allDescriptions) {
|
||||
if (!description.canSetupFramework(allDescriptions)) {
|
||||
disabled.add(description);
|
||||
}
|
||||
}
|
||||
if (!disabled.isEmpty()) {
|
||||
List<DetectedFrameworkDescription> remaining = new ArrayList<DetectedFrameworkDescription>(allDescriptions);
|
||||
remaining.removeAll(disabled);
|
||||
disabled.addAll(getDisabledDescriptions(remaining));
|
||||
}
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public static List<? extends DetectedFrameworkDescription> removeDisabled(@NotNull List<? extends DetectedFrameworkDescription> allDescriptions) {
|
||||
final List<DetectedFrameworkDescription> disabled = getDisabledDescriptions(allDescriptions);
|
||||
if (disabled.isEmpty()) return allDescriptions;
|
||||
final List<DetectedFrameworkDescription> descriptions = new ArrayList<DetectedFrameworkDescription>(allDescriptions);
|
||||
descriptions.removeAll(disabled);
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
public static void setupFrameworks(List<? extends DetectedFrameworkDescription> descriptions, final Project project) {
|
||||
AccessToken token = WriteAction.start();
|
||||
try {
|
||||
final PlatformModifiableModelsProvider provider = new PlatformModifiableModelsProvider();
|
||||
final DefaultModulesProvider modulesProvider = new DefaultModulesProvider(project);
|
||||
List<DetectedFrameworkDescription> sortedDescriptions = new ArrayList<DetectedFrameworkDescription>();
|
||||
for (DetectedFrameworkDescription description : descriptions) {
|
||||
if (description.getUnderlyingType() == null) {
|
||||
sortedDescriptions.add(description);
|
||||
}
|
||||
}
|
||||
for (DetectedFrameworkDescription description : descriptions) {
|
||||
if (description.getUnderlyingType() != null) {
|
||||
sortedDescriptions.add(description);
|
||||
}
|
||||
}
|
||||
for (DetectedFrameworkDescription description : sortedDescriptions) {
|
||||
description.setupFramework(provider, modulesProvider);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
token.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class ConfigureDetectedFrameworksDialog extends DialogWrapper {
|
||||
private final DetectedFrameworksComponent myComponent;
|
||||
private final Project myProject;
|
||||
|
||||
public ConfigureDetectedFrameworksDialog(Project project, List<DetectedFrameworkDescription> descriptions) {
|
||||
public ConfigureDetectedFrameworksDialog(Project project, List<? extends DetectedFrameworkDescription> descriptions) {
|
||||
super(project, true);
|
||||
myProject = project;
|
||||
setTitle("Setup Frameworks");
|
||||
|
||||
+1
@@ -51,6 +51,7 @@ public class DetectedFrameworksComponent {
|
||||
myTree = new DetectedFrameworksTree(context, GroupByOption.TYPE) {
|
||||
@Override
|
||||
protected void onNodeStateChanged(CheckedTreeNode node) {
|
||||
super.onNodeStateChanged(node);
|
||||
updateOptionsPanel();
|
||||
}
|
||||
};
|
||||
|
||||
+19
-8
@@ -18,6 +18,7 @@ package com.intellij.framework.detection.impl.ui;
|
||||
import com.intellij.framework.FrameworkType;
|
||||
import com.intellij.framework.detection.DetectedFrameworkDescription;
|
||||
import com.intellij.framework.detection.FrameworkDetectionContext;
|
||||
import com.intellij.framework.detection.impl.FrameworkDetectionUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.CheckboxTree;
|
||||
@@ -27,18 +28,16 @@ import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class DetectedFrameworksTree extends CheckboxTree {
|
||||
private List<DetectedFrameworkDescription> myDetectedFrameworks;
|
||||
private List<? extends DetectedFrameworkDescription> myDetectedFrameworks;
|
||||
private final FrameworkDetectionContext myContext;
|
||||
private DetectedFrameworksComponent.GroupByOption myGroupByOption;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class DetectedFrameworksTree extends CheckboxTree {
|
||||
setRootVisible(false);
|
||||
}
|
||||
|
||||
private void createNodesGroupedByDirectory(CheckedTreeNode root, final List<DetectedFrameworkDescription> frameworks) {
|
||||
private void createNodesGroupedByDirectory(CheckedTreeNode root, final List<? extends DetectedFrameworkDescription> frameworks) {
|
||||
Map<VirtualFile, FrameworkDirectoryNode> nodes = new HashMap<VirtualFile, FrameworkDirectoryNode>();
|
||||
List<DetectedFrameworkNode> externalNodes = new ArrayList<DetectedFrameworkNode>();
|
||||
for (DetectedFrameworkDescription framework : frameworks) {
|
||||
@@ -93,6 +92,18 @@ public class DetectedFrameworksTree extends CheckboxTree {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNodeStateChanged(CheckedTreeNode node) {
|
||||
final List<DetectedFrameworkDescription> checked = Arrays.asList(getCheckedNodes(DetectedFrameworkDescription.class, null));
|
||||
final List<DetectedFrameworkDescription> disabled = FrameworkDetectionUtil.getDisabledDescriptions(checked);
|
||||
for (DetectedFrameworkDescription description : disabled) {
|
||||
final DefaultMutableTreeNode treeNode = TreeUtil.findNodeWithObject(getRoot(), description);
|
||||
if (treeNode instanceof CheckedTreeNode) {
|
||||
((CheckedTreeNode)treeNode).setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static FrameworkDirectoryNode collapseDirectoryNode(FrameworkDirectoryNode node) {
|
||||
if (node.getChildCount() == 1) {
|
||||
final TreeNode child = node.getChildAt(0);
|
||||
@@ -129,7 +140,7 @@ public class DetectedFrameworksTree extends CheckboxTree {
|
||||
return newNode;
|
||||
}
|
||||
|
||||
private void createNodesGroupedByType(CheckedTreeNode root, final List<DetectedFrameworkDescription> frameworks) {
|
||||
private void createNodesGroupedByType(CheckedTreeNode root, final List<? extends DetectedFrameworkDescription> frameworks) {
|
||||
Map<FrameworkType, FrameworkTypeNode> groupNodes = new HashMap<FrameworkType, FrameworkTypeNode>();
|
||||
for (DetectedFrameworkDescription framework : frameworks) {
|
||||
final FrameworkType type = framework.getFrameworkType();
|
||||
@@ -155,7 +166,7 @@ public class DetectedFrameworksTree extends CheckboxTree {
|
||||
}
|
||||
}
|
||||
|
||||
public void rebuildTree(final List<DetectedFrameworkDescription> frameworks) {
|
||||
public void rebuildTree(final List<? extends DetectedFrameworkDescription> frameworks) {
|
||||
final CheckedTreeNode root = getRoot();
|
||||
root.removeAllChildren();
|
||||
if (myGroupByOption == DetectedFrameworksComponent.GroupByOption.TYPE) {
|
||||
|
||||
Reference in New Issue
Block a user