Search in sources :

Example 1 with DetectedFrameworkDescription

use of com.intellij.framework.detection.DetectedFrameworkDescription in project intellij-community by JetBrains.

the class FacetBasedDetectedFrameworkDescription method canSetupFramework.

@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;
}
Also used : DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription)

Example 2 with DetectedFrameworkDescription

use of com.intellij.framework.detection.DetectedFrameworkDescription in project intellij-community by JetBrains.

the class FrameworkDetectionContextImpl method createDetectedFacetDescriptions.

@NotNull
@Override
public <F extends Facet, C extends FacetConfiguration> List<? extends DetectedFrameworkDescription> createDetectedFacetDescriptions(@NotNull FacetBasedFrameworkDetector<F, C> detector, @NotNull Collection<VirtualFile> files) {
    MultiMap<Module, VirtualFile> filesByModule = MultiMap.createSet();
    for (VirtualFile file : files) {
        final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
        if (module != null) {
            filesByModule.putValue(module, file);
        }
    }
    final List<DetectedFrameworkDescription> result = new ArrayList<>();
    final FacetType<F, C> facetType = detector.getFacetType();
    final FacetsProvider provider = DefaultFacetsProvider.INSTANCE;
    for (Module module : filesByModule.keySet()) {
        final Collection<F> facets = provider.getFacetsByType(module, facetType.getId());
        if (!facetType.isSuitableModuleType(ModuleType.get(module)) || facetType.isOnlyOneFacetAllowed() && !facets.isEmpty()) {
            continue;
        }
        List<C> existentConfigurations = new ArrayList<>();
        for (F facet : facets) {
            //noinspection unchecked
            existentConfigurations.add((C) facet.getConfiguration());
        }
        final Collection<VirtualFile> moduleFiles = filesByModule.get(module);
        final List<Pair<C, Collection<VirtualFile>>> pairs = detector.createConfigurations(moduleFiles, existentConfigurations);
        for (Pair<C, Collection<VirtualFile>> pair : pairs) {
            result.add(new FacetBasedDetectedFrameworkDescriptionImpl<>(module, detector, pair.getFirst(), new HashSet<>(pair.getSecond())));
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) ArrayList(java.util.ArrayList) DefaultFacetsProvider(com.intellij.facet.impl.DefaultFacetsProvider) FacetsProvider(com.intellij.openapi.roots.ui.configuration.FacetsProvider) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with DetectedFrameworkDescription

use of com.intellij.framework.detection.DetectedFrameworkDescription in project intellij-community by JetBrains.

the class FrameworkDetectionManager method doRunDetection.

private void doRunDetection() {
    Set<Integer> detectorsToProcess;
    synchronized (myLock) {
        detectorsToProcess = new HashSet<>(myDetectorsToProcess);
        detectorsToProcess.addAll(myDetectorsToProcess);
        myDetectorsToProcess.clear();
    }
    if (detectorsToProcess.isEmpty())
        return;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting framework detectors: " + detectorsToProcess);
    }
    final FileBasedIndex index = FileBasedIndex.getInstance();
    List<DetectedFrameworkDescription> newDescriptions = new ArrayList<>();
    List<DetectedFrameworkDescription> oldDescriptions = new ArrayList<>();
    final DetectionExcludesConfiguration excludesConfiguration = DetectionExcludesConfiguration.getInstance(myProject);
    for (Integer id : detectorsToProcess) {
        final List<? extends DetectedFrameworkDescription> frameworks = runDetector(id, index, excludesConfiguration, true);
        oldDescriptions.addAll(frameworks);
        final Collection<? extends DetectedFrameworkDescription> updated = myDetectedFrameworksData.updateFrameworksList(id, frameworks);
        newDescriptions.addAll(updated);
        oldDescriptions.removeAll(updated);
        if (LOG.isDebugEnabled()) {
            LOG.debug(frameworks.size() + " frameworks detected, " + updated.size() + " changed");
        }
    }
    Set<String> frameworkNames = new HashSet<>();
    for (final DetectedFrameworkDescription description : FrameworkDetectionUtil.removeDisabled(newDescriptions, oldDescriptions)) {
        frameworkNames.add(description.getDetector().getFrameworkType().getPresentableName());
    }
    if (!frameworkNames.isEmpty()) {
        String names = StringUtil.join(frameworkNames, ", ");
        final String text = ProjectBundle.message("framework.detected.info.text", names, frameworkNames.size());
        FRAMEWORK_DETECTION_NOTIFICATION.createNotification("Frameworks detected", text, NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    showSetupFrameworksDialog(notification);
                }
            }
        }).notify(myProject);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DetectionExcludesConfiguration(com.intellij.framework.detection.DetectionExcludesConfiguration) NotificationListener(com.intellij.notification.NotificationListener)

Example 4 with DetectedFrameworkDescription

use of com.intellij.framework.detection.DetectedFrameworkDescription in project intellij-community by JetBrains.

the class FrameworkDetectionManager method showSetupFrameworksDialog.

private void showSetupFrameworksDialog(Notification notification) {
    List<? extends DetectedFrameworkDescription> descriptions;
    try {
        descriptions = getValidDetectedFrameworks();
    } catch (IndexNotReadyException e) {
        DumbService.getInstance(myProject).showDumbModeNotification("Information about detected frameworks is not available until indices are built");
        return;
    }
    if (descriptions.isEmpty()) {
        Messages.showInfoMessage(myProject, "No frameworks are detected", "Framework Detection");
        return;
    }
    final ConfigureDetectedFrameworksDialog dialog = new ConfigureDetectedFrameworksDialog(myProject, descriptions);
    if (dialog.showAndGet()) {
        notification.expire();
        List<DetectedFrameworkDescription> selected = dialog.getSelectedFrameworks();
        FrameworkDetectionUtil.setupFrameworks(selected, new PlatformModifiableModelsProvider(), new DefaultModulesProvider(myProject));
        for (DetectedFrameworkDescription description : selected) {
            final int detectorId = FrameworkDetectorRegistry.getInstance().getDetectorId(description.getDetector());
            myDetectedFrameworksData.putExistentFrameworkFiles(detectorId, description.getRelatedFiles());
        }
    }
}
Also used : ConfigureDetectedFrameworksDialog(com.intellij.framework.detection.impl.ui.ConfigureDetectedFrameworksDialog) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) PlatformModifiableModelsProvider(com.intellij.openapi.roots.PlatformModifiableModelsProvider) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 5 with DetectedFrameworkDescription

use of com.intellij.framework.detection.DetectedFrameworkDescription in project intellij-community by JetBrains.

the class FrameworkDetectionProcessor method processRoots.

public List<? extends DetectedFrameworkDescription> processRoots(List<File> roots) {
    myProcessedFiles = new HashSet<>();
    for (File root : roots) {
        VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root);
        if (virtualFile == null)
            continue;
        collectSuitableFiles(virtualFile);
    }
    List<DetectedFrameworkDescription> result = new ArrayList<>();
    for (FrameworkDetectorData data : myDetectorsByFileType.values()) {
        result.addAll(data.myDetector.detect(data.mySuitableFiles, myContext));
    }
    return FrameworkDetectionUtil.removeDisabled(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DetectedFrameworkDescription(com.intellij.framework.detection.DetectedFrameworkDescription) ArrayList(java.util.ArrayList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

DetectedFrameworkDescription (com.intellij.framework.detection.DetectedFrameworkDescription)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 DetectionExcludesConfiguration (com.intellij.framework.detection.DetectionExcludesConfiguration)2 Pair (com.intellij.openapi.util.Pair)2 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)2 File (java.io.File)2 DefaultFacetsProvider (com.intellij.facet.impl.DefaultFacetsProvider)1 FrameworkType (com.intellij.framework.FrameworkType)1 ConfigureDetectedFrameworksDialog (com.intellij.framework.detection.impl.ui.ConfigureDetectedFrameworksDialog)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Module (com.intellij.openapi.module.Module)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 PlatformModifiableModelsProvider (com.intellij.openapi.roots.PlatformModifiableModelsProvider)1 DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)1 FacetsProvider (com.intellij.openapi.roots.ui.configuration.FacetsProvider)1 CheckedTreeNode (com.intellij.ui.CheckedTreeNode)1 MultiMap (com.intellij.util.containers.MultiMap)1