use of com.intellij.util.Chunk in project intellij-community by JetBrains.
the class CompileDriver method validateCompilerConfiguration.
private boolean validateCompilerConfiguration(final CompileScope scope) {
try {
final Module[] scopeModules = scope.getAffectedModules();
final List<String> modulesWithoutOutputPathSpecified = new ArrayList<>();
final List<String> modulesWithoutJdkAssigned = new ArrayList<>();
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
for (final Module module : scopeModules) {
if (!compilerManager.isValidationEnabled(module)) {
continue;
}
final boolean hasSources = hasSources(module, JavaSourceRootType.SOURCE);
final boolean hasTestSources = hasSources(module, JavaSourceRootType.TEST_SOURCE);
if (!hasSources && !hasTestSources) {
// todo still there may be problems with this approach if some generated files are attributed by this module
continue;
}
final Sdk jdk = ModuleRootManager.getInstance(module).getSdk();
if (jdk == null) {
modulesWithoutJdkAssigned.add(module.getName());
}
final String outputPath = getModuleOutputPath(module, false);
final String testsOutputPath = getModuleOutputPath(module, true);
if (outputPath == null && testsOutputPath == null) {
modulesWithoutOutputPathSpecified.add(module.getName());
} else {
if (outputPath == null) {
if (hasSources) {
modulesWithoutOutputPathSpecified.add(module.getName());
}
}
if (testsOutputPath == null) {
if (hasTestSources) {
modulesWithoutOutputPathSpecified.add(module.getName());
}
}
}
}
if (!modulesWithoutJdkAssigned.isEmpty()) {
showNotSpecifiedError("error.jdk.not.specified", modulesWithoutJdkAssigned, ProjectBundle.message("modules.classpath.title"));
return false;
}
if (!modulesWithoutOutputPathSpecified.isEmpty()) {
showNotSpecifiedError("error.output.not.specified", modulesWithoutOutputPathSpecified, CommonContentEntriesEditor.NAME);
return false;
}
final List<Chunk<ModuleSourceSet>> chunks = ModuleCompilerUtil.getCyclicDependencies(myProject, Arrays.asList(scopeModules));
for (final Chunk<ModuleSourceSet> chunk : chunks) {
final Set<ModuleSourceSet> sourceSets = chunk.getNodes();
if (sourceSets.size() <= 1) {
// no need to check one-module chunks
continue;
}
Sdk jdk = null;
LanguageLevel languageLevel = null;
for (final ModuleSourceSet sourceSet : sourceSets) {
Module module = sourceSet.getModule();
final Sdk moduleJdk = ModuleRootManager.getInstance(module).getSdk();
if (jdk == null) {
jdk = moduleJdk;
} else {
if (!jdk.equals(moduleJdk)) {
showCyclicModulesHaveDifferentJdksError(ModuleSourceSet.getModules(sourceSets));
return false;
}
}
LanguageLevel moduleLanguageLevel = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
if (languageLevel == null) {
languageLevel = moduleLanguageLevel;
} else {
if (!languageLevel.equals(moduleLanguageLevel)) {
showCyclicModulesHaveDifferentLanguageLevel(ModuleSourceSet.getModules(sourceSets));
return false;
}
}
}
}
return true;
} catch (Throwable e) {
LOG.info(e);
return false;
}
}
use of com.intellij.util.Chunk in project intellij-community by JetBrains.
the class ModuleCompilerUtil method getCyclicDependencies.
@NotNull
public static List<Chunk<ModuleSourceSet>> getCyclicDependencies(@NotNull Project project, @NotNull List<Module> modules) {
Collection<Chunk<ModuleSourceSet>> chunks = computeSourceSetCycles(new DefaultModulesProvider(project));
final Set<Module> modulesSet = new HashSet<>(modules);
return ContainerUtil.filter(chunks, chunk -> {
for (ModuleSourceSet sourceSet : chunk.getNodes()) {
if (modulesSet.contains(sourceSet.getModule())) {
return true;
}
}
return false;
});
}
use of com.intellij.util.Chunk in project intellij-community by JetBrains.
the class GeneralProjectSettingsElement method check.
@Override
public void check(ProjectStructureProblemsHolder problemsHolder) {
final Project project = myContext.getProject();
if (containsModuleWithInheritedSdk()) {
ProjectSdksModel model = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
Sdk sdk = model.getProjectSdk();
if (sdk == null) {
PlaceInProjectStructureBase place = new PlaceInProjectStructureBase(project, ProjectStructureConfigurable.getInstance(project).createProjectConfigurablePlace(), this);
problemsHolder.registerProblem(ProjectBundle.message("project.roots.project.jdk.problem.message"), null, ProjectStructureProblemType.error("project-sdk-not-defined"), place, null);
}
}
List<Chunk<ModuleSourceSet>> sourceSetCycles = ModuleCompilerUtil.computeSourceSetCycles(myContext.getModulesConfigurator());
List<String> cycles = new ArrayList<>();
for (Chunk<ModuleSourceSet> chunk : sourceSetCycles) {
final Set<ModuleSourceSet> sourceSets = chunk.getNodes();
List<String> names = new ArrayList<>();
for (ModuleSourceSet sourceSet : sourceSets) {
String name = sourceSet.getDisplayName();
names.add(names.isEmpty() ? name : StringUtil.decapitalize(name));
}
cycles.add(StringUtil.join(names, ", "));
}
if (!cycles.isEmpty()) {
final PlaceInProjectStructureBase place = new PlaceInProjectStructureBase(project, ProjectStructureConfigurable.getInstance(project).createModulesPlace(), this);
final String message;
final String description;
if (cycles.size() > 1) {
message = "Circular dependencies";
@NonNls final String br = "<br> ";
StringBuilder cyclesString = new StringBuilder();
for (int i = 0; i < cycles.size(); i++) {
cyclesString.append(br).append(i + 1).append(". ").append(cycles.get(i));
}
description = ProjectBundle.message("module.circular.dependency.warning.description", cyclesString);
} else {
message = ProjectBundle.message("module.circular.dependency.warning.short", StringUtil.decapitalize(cycles.get(0)));
description = null;
}
problemsHolder.registerProblem(new ProjectStructureProblemDescription(message, description, place, ProjectStructureProblemType.warning("module-circular-dependency"), Collections.<ConfigurationErrorQuickFix>emptyList()));
}
}
use of com.intellij.util.Chunk in project intellij-community by JetBrains.
the class GenerationOptionsImpl method createModuleChunks.
private ModuleChunk[] createModuleChunks(String[] representativeModuleNames) {
final Set<String> mainModuleNames = new HashSet<>(Arrays.asList(representativeModuleNames));
final Graph<Chunk<Module>> chunkGraph = ModuleCompilerUtil.toChunkGraph(ModuleManager.getInstance(myProject).moduleGraph());
final Map<Chunk<Module>, ModuleChunk> map = new HashMap<>();
final Map<ModuleChunk, Chunk<Module>> reverseMap = new HashMap<>();
for (final Chunk<Module> chunk : chunkGraph.getNodes()) {
final Set<Module> modules = chunk.getNodes();
final ModuleChunk moduleChunk = new ModuleChunk(modules.toArray(new Module[modules.size()]));
for (final Module module : modules) {
if (mainModuleNames.contains(module.getName())) {
moduleChunk.setMainModule(module);
break;
}
}
map.put(chunk, moduleChunk);
reverseMap.put(moduleChunk, chunk);
}
final Graph<ModuleChunk> moduleChunkGraph = GraphGenerator.generate(CachingSemiGraph.cache(new InboundSemiGraph<ModuleChunk>() {
public Collection<ModuleChunk> getNodes() {
return map.values();
}
public Iterator<ModuleChunk> getIn(ModuleChunk n) {
final Chunk<Module> chunk = reverseMap.get(n);
final Iterator<Chunk<Module>> in = chunkGraph.getIn(chunk);
return new Iterator<ModuleChunk>() {
public boolean hasNext() {
return in.hasNext();
}
public ModuleChunk next() {
return map.get(in.next());
}
public void remove() {
throw new IncorrectOperationException("Method is not supported");
}
};
}
}));
final Collection<ModuleChunk> nodes = moduleChunkGraph.getNodes();
final ModuleChunk[] moduleChunks = nodes.toArray(new ModuleChunk[nodes.size()]);
for (ModuleChunk moduleChunk : moduleChunks) {
final Iterator<ModuleChunk> depsIterator = moduleChunkGraph.getIn(moduleChunk);
List<ModuleChunk> deps = new ArrayList<>();
while (depsIterator.hasNext()) {
deps.add(depsIterator.next());
}
moduleChunk.setDependentChunks(deps.toArray(new ModuleChunk[deps.size()]));
ContainerUtil.addAll(myCustomCompilers, moduleChunk.getCustomCompilers());
}
Arrays.sort(moduleChunks, new ChunksComparator());
if (generateSingleFile) {
final File baseDir = BuildProperties.getProjectBaseDir(myProject);
for (ModuleChunk chunk : moduleChunks) {
chunk.setBaseDir(baseDir);
}
}
return moduleChunks;
}
use of com.intellij.util.Chunk in project intellij-community by JetBrains.
the class GenerateAntBuildDialog method initChunksPanel.
private void initChunksPanel() {
List<Chunk<Module>> chunks = getCycleChunks();
if (chunks.isEmpty()) {
return;
}
myChunksPanel.setLayout(new BorderLayout());
myChunksPanel.setBorder(IdeBorderFactory.createTitledBorder(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.title"), true));
JLabel textLabel = new JLabel(CompilerBundle.message("generate.ant.build.dialog.cyclic.modules.table.description"));
textLabel.setUI(new MultiLineLabelUI());
textLabel.setBorder(IdeBorderFactory.createEmptyBorder(4, 4, 6, 4));
myChunksPanel.add(textLabel, BorderLayout.NORTH);
myTableModel = new MyTableModel(chunks);
myTable = new Table(myTableModel);
final MyTableCellRenderer cellRenderer = new MyTableCellRenderer();
final TableColumn nameColumn = myTable.getColumnModel().getColumn(MyTableModel.NAME_COLUMN);
nameColumn.setCellEditor(ComboBoxTableCellEditor.INSTANCE);
nameColumn.setCellRenderer(cellRenderer);
final TableColumn labelColumn = myTable.getColumnModel().getColumn(MyTableModel.NUMBER_COLUMN);
labelColumn.setCellRenderer(cellRenderer);
final Dimension preferredSize = new Dimension(myTable.getPreferredSize());
preferredSize.height = (myTableModel.getRowCount() + 2) * myTable.getRowHeight() + myTable.getTableHeader().getHeight();
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable);
scrollPane.setPreferredSize(preferredSize);
myChunksPanel.add(scrollPane, BorderLayout.CENTER);
}
Aggregations