Search in sources :

Example 6 with Chunk

use of com.intellij.util.Chunk in project intellij-community by JetBrains.

the class ModuleCompilerUtilTest method testDoNotReportTestsCyclesIncludedIntoProductionCycles.

public void testDoNotReportTestsCyclesIncludedIntoProductionCycles() throws IOException {
    Module a = createModule("a");
    Module b = createModule("b");
    PsiTestUtil.addSourceRoot(a, myTempDirTestFixture.findOrCreateDir("a-main"));
    PsiTestUtil.addSourceRoot(a, myTempDirTestFixture.findOrCreateDir("a-tests"), true);
    PsiTestUtil.addSourceRoot(b, myTempDirTestFixture.findOrCreateDir("b-main"));
    PsiTestUtil.addSourceRoot(b, myTempDirTestFixture.findOrCreateDir("b-tests"), true);
    ModuleRootModificationUtil.addDependency(a, b);
    ModuleRootModificationUtil.addDependency(b, a);
    List<Chunk<ModuleSourceSet>> cycles = ModuleCompilerUtil.getCyclicDependencies(myProject, Arrays.asList(a, b));
    assertEquals(1, cycles.size());
}
Also used : Module(com.intellij.openapi.module.Module) Chunk(com.intellij.util.Chunk)

Example 7 with Chunk

use of com.intellij.util.Chunk in project intellij-community by JetBrains.

the class ModuleCompilerUtil method addingDependencyFormsCircularity.

/**
   * @return pair of modules which become circular after adding dependency, or null if all remains OK
   */
@Nullable
public static Couple<Module> addingDependencyFormsCircularity(@NotNull Module currentModule, @NotNull Module toDependOn) {
    assert currentModule != toDependOn;
    // whatsa lotsa of @&#^%$ codes-a!
    final Map<Module, ModifiableRootModel> models = new LinkedHashMap<>();
    Project project = currentModule.getProject();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        models.put(module, model);
    }
    ModifiableRootModel currentModel = models.get(currentModule);
    ModifiableRootModel toDependOnModel = models.get(toDependOn);
    Collection<Chunk<ModifiableRootModel>> nodesBefore = buildChunks(models);
    for (Chunk<ModifiableRootModel> chunk : nodesBefore) {
        // they circular already
        if (chunk.containsNode(toDependOnModel) && chunk.containsNode(currentModel))
            return null;
    }
    try {
        currentModel.addModuleOrderEntry(toDependOn);
        Collection<Chunk<ModifiableRootModel>> nodesAfter = buildChunks(models);
        for (Chunk<ModifiableRootModel> chunk : nodesAfter) {
            if (chunk.containsNode(toDependOnModel) && chunk.containsNode(currentModel)) {
                List<ModifiableRootModel> nodes = ContainerUtil.collect(chunk.getNodes().iterator());
                // graph algorithms collections are inherently unstable, so sort to return always the same modules to avoid blinking tests
                nodes.sort(Comparator.comparing(m -> m.getModule().getName()));
                return Couple.of(nodes.get(0).getModule(), nodes.get(1).getModule());
            }
        }
    } finally {
        for (ModifiableRootModel model : models.values()) {
            model.dispose();
        }
    }
    return null;
}
Also used : Chunk(com.intellij.util.Chunk) java.util(java.util) Couple(com.intellij.openapi.util.Couple) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) ModuleManager(com.intellij.openapi.module.ModuleManager) com.intellij.util.graph(com.intellij.util.graph) ContainerUtil(com.intellij.util.containers.ContainerUtil) com.intellij.openapi.roots(com.intellij.openapi.roots) Nullable(org.jetbrains.annotations.Nullable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) ModulesProvider(com.intellij.openapi.roots.ui.configuration.ModulesProvider) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) Chunk(com.intellij.util.Chunk) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Chunk (com.intellij.util.Chunk)7 Module (com.intellij.openapi.module.Module)5 Project (com.intellij.openapi.project.Project)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)2 NotNull (org.jetbrains.annotations.NotNull)2 ModuleSourceSet (com.intellij.compiler.ModuleSourceSet)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 com.intellij.openapi.roots (com.intellij.openapi.roots)1 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)1 ProjectSdksModel (com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel)1 MultiLineLabelUI (com.intellij.openapi.ui.MultiLineLabelUI)1 Couple (com.intellij.openapi.util.Couple)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 com.intellij.util.graph (com.intellij.util.graph)1 InboundSemiGraph (com.intellij.util.graph.InboundSemiGraph)1