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;
}
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;
}
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);
}
}
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());
}
}
}
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);
}
Aggregations