@Nullable private JarInfo[] sortJars() { final DFSTBuilder<JarInfo> builder = new DFSTBuilder<JarInfo>(GraphGenerator.create(CachingSemiGraph.create(new JarsGraph()))); if (!builder.isAcyclic()) { final Pair<JarInfo, JarInfo> dependency = builder.getCircularDependency(); String message = "Cannot build: circular dependency found between '" + dependency.getFirst().getPresentableDestination() + "' and '" + dependency.getSecond().getPresentableDestination() + "'"; myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, message)); return null; } JarInfo[] jars = myJarsToBuild.toArray(new JarInfo[myJarsToBuild.size()]); Arrays.sort(jars, builder.comparator()); jars = ArrayUtil.reverseArray(jars); return jars; }
private Graph<PsiPackage> buildGraph() { final Graph<PsiPackage> graph = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<PsiPackage>() { public Collection<PsiPackage> getNodes() { return getAllScopePackages().values(); } public Iterator<PsiPackage> getIn(PsiPackage psiPack) { final Set<PsiPackage> psiPackages = myPackageDependencies.get(psiPack); if (psiPackages == null) { //for packs without java classes return new HashSet<PsiPackage>().iterator(); } return psiPackages.iterator(); } })); return graph; }
private static List<ConversionRunner> createConversionRunners(ConversionContextImpl context, final Set<String> performedConversionIds) { List<ConversionRunner> runners = new ArrayList<ConversionRunner>(); final ConverterProvider[] providers = ConverterProvider.EP_NAME.getExtensions(); for (ConverterProvider provider : providers) { if (!performedConversionIds.contains(provider.getId())) { runners.add(new ConversionRunner(provider, context)); } } final CachingSemiGraph<ConverterProvider> graph = CachingSemiGraph.create(new ConverterProvidersGraph(providers)); final DFSTBuilder<ConverterProvider> builder = new DFSTBuilder<ConverterProvider>(GraphGenerator.create(graph)); if (!builder.isAcyclic()) { final Pair<ConverterProvider,ConverterProvider> pair = builder.getCircularDependency(); LOG.error("cyclic dependencies between converters: " + pair.getFirst().getId() + " and " + pair.getSecond().getId()); } final Comparator<ConverterProvider> comparator = builder.comparator(); Collections.sort(runners, new Comparator<ConversionRunner>() { @Override public int compare(ConversionRunner o1, ConversionRunner o2) { return comparator.compare(o1.getProvider(), o2.getProvider()); } }); return runners; }
private Graph<Compiler> createCompilerGraph(final List<Compiler> compilers) { return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<Compiler>() { public Collection<Compiler> getNodes() { return compilers; } public Iterator<Compiler> getIn(Compiler compiler) { final Set<FileType> compilerInput = myCompilerToInputTypes.get(compiler); if (compilerInput == null || compilerInput.isEmpty()) { return Collections.<Compiler>emptySet().iterator(); } final Set<Compiler> inCompilers = new HashSet<Compiler>(); for (Map.Entry<Compiler, Set<FileType>> entry : myCompilerToOutputTypes.entrySet()) { final Set<FileType> outputs = entry.getValue(); Compiler comp = entry.getKey(); if (outputs != null && ContainerUtil.intersects(compilerInput, outputs)) { inCompilers.add(comp); } } return inCompilers.iterator(); } })); }
@Nullable private JarInfo[] sortJars() { final DFSTBuilder<JarInfo> builder = new DFSTBuilder<JarInfo>(GraphGenerator.create(CachingSemiGraph.create(new JarsGraph()))); if (!builder.isAcyclic()) { final Pair<JarInfo, JarInfo> dependency = builder.getCircularDependency(); String message = CompilerBundle.message("packaging.compiler.error.cannot.build.circular.dependency.found.between.0.and.1", dependency.getFirst().getPresentableDestination(), dependency.getSecond().getPresentableDestination()); myContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1); return null; } JarInfo[] jars = myJarsToBuild.toArray(new JarInfo[myJarsToBuild.size()]); Arrays.sort(jars, builder.comparator()); jars = ArrayUtil.reverseArray(jars); return jars; }
@Nullable private ArchivePackageInfo[] sortArchives() { final DFSTBuilder<ArchivePackageInfo> builder = new DFSTBuilder<>(GraphGenerator.create(CachingSemiGraph.create(new ArchivesGraph()))); if (!builder.isAcyclic()) { final Pair<ArchivePackageInfo, ArchivePackageInfo> dependency = builder.getCircularDependency(); String message = CompilerBundle .message("packaging.compiler.error.cannot.build.circular.dependency.found.between.0.and.1", dependency.getFirst().getPresentableDestination(), dependency.getSecond().getPresentableDestination()); myContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1); return null; } ArchivePackageInfo[] archives = myArchivesToBuild.toArray(new ArchivePackageInfo[myArchivesToBuild.size()]); Arrays.sort(archives, builder.comparator()); archives = ArrayUtil.reverseArray(archives); return archives; }
private Graph<PsiJavaPackage> buildGraph() { final Graph<PsiJavaPackage> graph = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<PsiJavaPackage>() { public Collection<PsiJavaPackage> getNodes() { return getAllScopePackages().values(); } public Iterator<PsiJavaPackage> getIn(PsiJavaPackage psiPack) { final Set<PsiJavaPackage> psiPackages = myPackageDependencies.get(psiPack); if (psiPackages == null) { //for packs without java classes return new HashSet<PsiJavaPackage>().iterator(); } return psiPackages.iterator(); } })); return graph; }
public static Comparator<FrameworkSupportInModuleProvider> getFrameworkSupportProvidersComparator(final List<FrameworkSupportInModuleProvider> types) { DFSTBuilder<FrameworkSupportInModuleProvider> builder = new DFSTBuilder<FrameworkSupportInModuleProvider>(GraphGenerator.create(CachingSemiGraph.create(new ProvidersGraph(types)))); if (!builder.isAcyclic()) { Couple<FrameworkSupportInModuleProvider> pair = builder.getCircularDependency(); LOG.error("Circular dependency between types '" + pair.getFirst().getFrameworkType().getId() + "' and '" + pair.getSecond().getFrameworkType().getId() + "' was found."); } return builder.comparator(); }
private Graph<Module> moduleGraph(final boolean includeTests) { return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<Module>() { @Override public Collection<Module> getNodes() { return myModules.values(); } @Override public Iterator<Module> getIn(Module m) { Module[] dependentModules = ModuleRootManager.getInstance(m).getDependencies(includeTests); return Arrays.asList(dependentModules).iterator(); } })); }
private boolean initialize(@Nullable Project project) { if (myBaseProfile != null) { myBaseProfile.initInspectionTools(project); } final List<InspectionToolWrapper> tools; try { tools = createTools(project); } catch (ProcessCanceledException ignored) { return false; } final Map<String, List<String>> dependencies = new HashMap<String, List<String>>(); for (InspectionToolWrapper toolWrapper : tools) { addTool(project, toolWrapper, dependencies); } final GraphGenerator<String> graphGenerator = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<String>() { @Override public Collection<String> getNodes() { return dependencies.keySet(); } @Override public Iterator<String> getIn(String n) { return dependencies.get(n).iterator(); } })); DFSTBuilder<String> builder = new DFSTBuilder<String>(graphGenerator); if (builder.isAcyclic()) { final List<String> scopes = builder.getSortedNodes(); myScopesOrder = ArrayUtil.toStringArray(scopes); } if (mySource != null) { copyToolsConfigurations(mySource, project); } return true; }
private Graph<Module> getModuleGraph(final boolean includeTests) { return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<Module>() { @Override public Collection<Module> getNodes() { return ContainerUtil.list(getModules()); } @Override public Iterator<Module> getIn(Module m) { Module[] dependentModules = getModifiableRootModel(m).getModuleDependencies(includeTests); return Arrays.asList(dependentModules).iterator(); } })); }
@NotNull private static Graph<PluginId> createPluginIdGraph(@NotNull final Map<PluginId, ? extends IdeaPluginDescriptor> idToDescriptorMap) { final List<PluginId> ids = new ArrayList<PluginId>(idToDescriptorMap.keySet()); // this magic ensures that the dependent plugins always follow their dependencies in lexicographic order // needed to make sure that extensions are always in the same order Collections.sort(ids, new Comparator<PluginId>() { @Override public int compare(@NotNull PluginId o1, @NotNull PluginId o2) { return o2.getIdString().compareTo(o1.getIdString()); } }); return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<PluginId>() { @Override public Collection<PluginId> getNodes() { return ids; } @Override public Iterator<PluginId> getIn(PluginId pluginId) { final IdeaPluginDescriptor descriptor = idToDescriptorMap.get(pluginId); List<PluginId> plugins = new ArrayList<PluginId>(); for (PluginId dependentPluginId : descriptor.getDependentPluginIds()) { // check for missing optional dependency IdeaPluginDescriptor dep = idToDescriptorMap.get(dependentPluginId); if (dep != null) { plugins.add(dep.getPluginId()); } } return plugins.iterator(); } })); }
public static Comparator<FrameworkSupportInModuleProvider> getFrameworkSupportProvidersComparator(final List<FrameworkSupportInModuleProvider> types) { DFSTBuilder<FrameworkSupportInModuleProvider> builder = new DFSTBuilder<FrameworkSupportInModuleProvider>(GraphGenerator.create(CachingSemiGraph.create(new ProvidersGraph(types)))); if (!builder.isAcyclic()) { Pair<FrameworkSupportInModuleProvider, FrameworkSupportInModuleProvider> pair = builder.getCircularDependency(); LOG.error("Circular dependency between types '" + pair.getFirst().getFrameworkType().getId() + "' and '" + pair.getSecond().getFrameworkType().getId() + "' was found."); } return builder.comparator(); }
private Graph<Module> moduleGraph(final boolean includeTests) { return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<Module>() { @Override public Collection<Module> getNodes() { return myPathToModule.values(); } @Override public Iterator<Module> getIn(Module m) { Module[] dependentModules = ModuleRootManager.getInstance(m).getDependencies(includeTests); return Arrays.asList(dependentModules).iterator(); } })); }
private static Graph<PluginId> createPluginIdGraph(final Map<PluginId, IdeaPluginDescriptorImpl> idToDescriptorMap) { final List<PluginId> ids = new ArrayList<PluginId>(idToDescriptorMap.keySet()); // this magic ensures that the dependent plugins always follow their dependencies in lexicographic order // needed to make sure that extensions are always in the same order Collections.sort(ids, new Comparator<PluginId>() { @Override public int compare(PluginId o1, PluginId o2) { return o2.getIdString().compareTo(o1.getIdString()); } }); return GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<PluginId>() { @Override public Collection<PluginId> getNodes() { return ids; } @Override public Iterator<PluginId> getIn(PluginId pluginId) { final IdeaPluginDescriptor descriptor = idToDescriptorMap.get(pluginId); ArrayList<PluginId> plugins = new ArrayList<PluginId>(); for (PluginId dependentPluginId : descriptor.getDependentPluginIds()) { // check for missing optional dependency if (idToDescriptorMap.containsKey(dependentPluginId)) { plugins.add(dependentPluginId); } } return plugins.iterator(); } })); }
private GraphGenerator<JpsArtifact> createArtifactsGraph() { return GraphGenerator.create(CachingSemiGraph.create(new ArtifactsGraph(myModel))); }
private synchronized void initializeChunks(@NotNull CompileContext context) { if (myTargetChunks != null) { return; } final List<? extends BuildTarget<?>> allTargets = getAllTargets(); TargetOutputIndex outputIndex = new TargetOutputIndexImpl(allTargets, context); for (BuildTarget<?> target : allTargets) { myDependencies.put(target, target.computeDependencies(this, outputIndex)); } GraphGenerator<BuildTarget<?>> graph = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<BuildTarget<?>>() { @Override public Collection<BuildTarget<?>> getNodes() { return myAllTargets; } @Override public Iterator<BuildTarget<?>> getIn(BuildTarget<?> n) { return myDependencies.get(n).iterator(); } })); final DFSTBuilder<BuildTarget<?>> builder = new DFSTBuilder<BuildTarget<?>>(graph); final TIntArrayList sccs = builder.getSCCs(); myTargetChunks = new ArrayList<BuildTargetChunk>(sccs.size()); sccs.forEach(new TIntProcedure() { int myTNumber = 0; public boolean execute(int size) { final Set<BuildTarget<?>> chunkNodes = new LinkedHashSet<BuildTarget<?>>(); for (int j = 0; j < size; j++) { final BuildTarget<?> node = builder.getNodeByTNumber(myTNumber + j); chunkNodes.add(node); } myTargetChunks.add(new BuildTargetChunk(chunkNodes)); myTNumber += size; return true; } }); }
private GraphGenerator<String> createArtifactsGraph() { final ArtifactManager artifactManager = ArtifactManager.getInstance(myProject); return GraphGenerator.create(CachingSemiGraph.create(new ArtifactsGraph(artifactManager))); }
private boolean initialize(@Nullable Project project) { if (myBaseProfile != null) { myBaseProfile.initInspectionTools(project); } final List<InspectionToolWrapper> tools; try { tools = createTools(project); } catch (ProcessCanceledException ignored) { return false; } final Map<String, List<String>> dependencies = new HashMap<String, List<String>>(); for (InspectionToolWrapper toolWrapper : tools) { final String shortName = toolWrapper.getShortName(); HighlightDisplayKey key = HighlightDisplayKey.find(shortName); if (key == null) { final InspectionEP extension = toolWrapper.getExtension(); Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<String>(toolWrapper.getDisplayName()) : new Computable<String>() { @Override public String compute() { return extension.getDisplayName(); } }; if (toolWrapper instanceof LocalInspectionToolWrapper) { key = HighlightDisplayKey.register(shortName, computable, ((LocalInspectionToolWrapper)toolWrapper).getID(), ((LocalInspectionToolWrapper)toolWrapper).getAlternativeID()); } else { key = HighlightDisplayKey.register(shortName, computable); } } LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size()); HighlightDisplayLevel level = myBaseProfile != null ? myBaseProfile.getErrorLevel(key, project) : toolWrapper.getDefaultLevel(); boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault(); final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled); final Element element = myUninstalledInspectionsSettings.remove(shortName); try { if (element != null) { toolsList.readExternal(element, this, dependencies); } else if (!myUninstalledInspectionsSettings.containsKey(InspectionElementsMerger.getMergedMarkerName(shortName))) { final InspectionElementsMerger merger = getMergers().get(shortName); if (merger != null) { final Element merged = merger.merge(myUninstalledInspectionsSettings); if (merged != null) { toolsList.readExternal(merged, this, dependencies); } } } } catch (InvalidDataException e) { LOG.error("Can't read settings for " + toolWrapper, e); } myTools.put(toolWrapper.getShortName(), toolsList); } final GraphGenerator<String> graphGenerator = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<String>() { @Override public Collection<String> getNodes() { return dependencies.keySet(); } @Override public Iterator<String> getIn(String n) { return dependencies.get(n).iterator(); } })); DFSTBuilder<String> builder = new DFSTBuilder<String>(graphGenerator); if (builder.isAcyclic()) { final List<String> scopes = builder.getSortedNodes(); myScopesOrder = ArrayUtil.toStringArray(scopes); } if (mySource != null) { copyToolsConfigurations(mySource, project); } return true; }