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