use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.
the class IdeFrameFixture method getSourceFolderRelativePaths.
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
final Set<String> paths = new HashSet<>();
Module module = getModule(moduleName);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
try {
for (ContentEntry contentEntry : rootModel.getContentEntries()) {
for (SourceFolder folder : contentEntry.getSourceFolders()) {
JpsModuleSourceRootType<?> rootType = folder.getRootType();
if (rootType.equals(sourceType)) {
String path = urlToPath(folder.getUrl());
String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
paths.add(relativePath);
}
}
}
} finally {
rootModel.dispose();
}
}
});
return paths;
}
use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.
the class MavenFoldersImporter method configSourceFolders.
private void configSourceFolders() {
final MultiMap<JpsModuleSourceRootType<?>, String> roots = new LinkedMultiMap<>();
roots.putValues(JavaSourceRootType.SOURCE, myMavenProject.getSources());
roots.putValues(JavaSourceRootType.TEST_SOURCE, myMavenProject.getTestSources());
for (MavenImporter each : MavenImporter.getSuitableImporters(myMavenProject)) {
each.collectSourceRoots(myMavenProject, (s, type) -> roots.putValue(type, s));
}
for (MavenResource each : myMavenProject.getResources()) {
roots.putValue(JavaResourceRootType.RESOURCE, each.getDirectory());
}
for (MavenResource each : myMavenProject.getTestResources()) {
roots.putValue(JavaResourceRootType.TEST_RESOURCE, each.getDirectory());
}
addBuilderHelperPaths("add-source", roots.getModifiable(JavaSourceRootType.SOURCE));
addBuilderHelperPaths("add-test-source", roots.getModifiable(JavaSourceRootType.TEST_SOURCE));
List<String> addedPaths = new ArrayList<>();
for (JpsModuleSourceRootType<?> type : roots.keySet()) {
for (String path : roots.get(type)) {
addSourceFolderIfNotOverlap(path, type, addedPaths);
}
}
}
use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method addSourceRootsAndLibDirectory.
@Nullable
private static Consumer<ModifiableRootModel> addSourceRootsAndLibDirectory(@NotNull final VirtualFile root, final MvcProjectStructure structure) {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule);
Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots = new HashMap<>();
for (ContentEntry entry : moduleRootManager.getContentEntries()) {
for (SourceFolder folder : entry.getSourceFolders()) {
sourceRoots.put(folder.getFile(), folder.getRootType());
}
}
root.refresh(false, true);
final List<Consumer<ContentEntry>> actions = ContainerUtil.newArrayList();
for (Map.Entry<JpsModuleSourceRootType<?>, Collection<String>> entry : structure.getSourceFolders().entrySet()) {
JpsModuleSourceRootType<?> rootType = entry.getKey();
for (String src : entry.getValue()) {
addSourceFolder(root, src, rootType, actions, sourceRoots);
}
}
for (final String src : structure.getInvalidSourceFolders()) {
removeSrcFolderFromRoots(root.findFileByRelativePath(src), actions, sourceRoots);
}
for (final VirtualFile excluded : structure.getExcludedFolders(root)) {
if (moduleRootManager.getFileIndex().isInContent(excluded)) {
actions.add(contentEntry -> contentEntry.addExcludeFolder(excluded));
}
}
final Consumer<ModifiableRootModel> modifyLib = addJarDirectory(root, structure.myModule, structure.getUserLibraryName());
if (actions.isEmpty() && modifyLib == null && findContentEntry(moduleRootManager, root) != null) {
return null;
}
return model -> {
ContentEntry contentEntry = findContentEntry(model, root);
if (contentEntry == null) {
contentEntry = model.addContentEntry(root);
}
for (final Consumer<ContentEntry> action : actions) {
action.consume(contentEntry);
}
if (modifyLib != null) {
modifyLib.consume(model);
}
};
}
Aggregations