use of com.intellij.openapi.roots.SourceFolder in project android by JetBrains.
the class ContentEntriesSetup method addSourceFolder.
private static void addSourceFolder(@NotNull ContentEntry contentEntry, @NotNull File folderPath, @NotNull JpsModuleSourceRootType type, boolean generated) {
String url = pathToIdeaUrl(folderPath);
SourceFolder sourceFolder = contentEntry.addSourceFolder(url, type);
if (generated) {
JpsModuleSourceRoot sourceRoot = sourceFolder.getJpsElement();
JpsElement properties = sourceRoot.getProperties();
if (properties instanceof JavaSourceRootProperties) {
((JavaSourceRootProperties) properties).setForGeneratedSources(true);
}
}
}
use of com.intellij.openapi.roots.SourceFolder in project android by JetBrains.
the class IdeFrameFixture method getSourceFolderRelativePaths.
/**
* Returns a list of system independent paths
*/
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceType) {
Set<String> paths = Sets.newHashSet();
Module module = getModule(moduleName);
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(PathUtil.toSystemIndependentName(relativePath));
}
}
}
} finally {
rootModel.dispose();
}
}
});
return paths;
}
use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.
the class JavaDirectoryIconProvider method getIcon.
@Override
@Nullable
public Icon getIcon(@NotNull PsiElement element, int flags) {
if (element instanceof PsiDirectory) {
final PsiDirectory psiDirectory = (PsiDirectory) element;
final VirtualFile vFile = psiDirectory.getVirtualFile();
final Project project = psiDirectory.getProject();
SourceFolder sourceFolder;
Icon symbolIcon;
if (vFile.getParent() == null && vFile.getFileSystem() instanceof ArchiveFileSystem) {
symbolIcon = PlatformIcons.JAR_ICON;
} else if (ProjectRootsUtil.isModuleContentRoot(vFile, project)) {
Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile);
symbolIcon = module != null ? ModuleType.get(module).getIcon() : PlatformIcons.CONTENT_ROOT_ICON_CLOSED;
} else if ((sourceFolder = ProjectRootsUtil.getModuleSourceRoot(vFile, project)) != null) {
symbolIcon = SourceRootPresentation.getSourceRootIcon(sourceFolder);
} else if (JrtFileSystem.isModuleRoot(vFile)) {
symbolIcon = AllIcons.Nodes.JavaModuleRoot;
} else if (JavaDirectoryService.getInstance().getPackage(psiDirectory) != null) {
symbolIcon = PlatformIcons.PACKAGE_ICON;
} else if (!Registry.is("ide.hide.excluded.files") && ProjectRootManager.getInstance(project).getFileIndex().isExcluded(vFile)) {
symbolIcon = AllIcons.Modules.ExcludeRoot;
} else {
symbolIcon = PlatformIcons.DIRECTORY_CLOSED_ICON;
}
return ElementBase.createLayeredIcon(element, symbolIcon, 0);
}
return null;
}
use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.
the class ContentRootDataService method createSourceRootIfAbsent.
private static void createSourceRootIfAbsent(@NotNull ContentEntry entry, @NotNull final SourceRoot root, @NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceRootType, boolean generated, boolean createEmptyContentRootDirectories) {
SourceFolder[] folders = entry.getSourceFolders();
for (SourceFolder folder : folders) {
VirtualFile file = folder.getFile();
if (file == null) {
continue;
}
if (ExternalSystemApiUtil.getLocalFileSystemPath(file).equals(root.getPath())) {
final JpsModuleSourceRootType<?> folderRootType = folder.getRootType();
if (JavaSourceRootType.SOURCE.equals(folderRootType) || sourceRootType.equals(folderRootType)) {
return;
}
if (JavaSourceRootType.TEST_SOURCE.equals(folderRootType) && JavaResourceRootType.TEST_RESOURCE.equals(sourceRootType)) {
return;
}
entry.removeSourceFolder(folder);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Importing %s for content root '%s' of module '%s'", root, entry.getUrl(), moduleName));
}
SourceFolder sourceFolder = entry.addSourceFolder(toVfsUrl(root.getPath()), sourceRootType);
if (!StringUtil.isEmpty(root.getPackagePrefix())) {
sourceFolder.setPackagePrefix(root.getPackagePrefix());
}
if (generated) {
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
if (properties != null) {
properties.setForGeneratedSources(true);
}
}
if (createEmptyContentRootDirectories) {
ExternalSystemApiUtil.doWriteAction(() -> {
try {
VfsUtil.createDirectoryIfMissing(root.getPath());
} catch (IOException e) {
LOG.warn(String.format("Unable to create directory for the path: %s", root.getPath()), e);
}
});
}
}
use of com.intellij.openapi.roots.SourceFolder 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;
}
Aggregations