use of com.intellij.openapi.roots.ContentEntry 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.ContentEntry in project intellij-plugins by JetBrains.
the class FlashBuilderModuleImporter method handleRawSourcePath.
private void handleRawSourcePath(final ModifiableRootModel rootModel, final FlashBuilderProject fbProject, final String mainContentEntryUrl, final ContentEntry mainContentEntry, final Collection<ContentEntry> otherContentEntries, final String rawSourcePath) {
final String sourcePath = getAbsolutePathWithLinksHandled(fbProject, rawSourcePath);
final String sourceUrl = VfsUtilCore.pathToUrl(sourcePath);
if (FileUtil.isAncestor(new File(VfsUtilCore.urlToPath(mainContentEntryUrl)), new File(VfsUtilCore.urlToPath(sourceUrl)), false)) {
addSourceRoot(mainContentEntry, sourceUrl);
} else {
for (final ContentEntry otherContentEntry : otherContentEntries) {
if (FileUtil.isAncestor(new File(VfsUtilCore.urlToPath(mainContentEntryUrl)), new File(VfsUtilCore.urlToPath(sourceUrl)), false)) {
addSourceRoot(otherContentEntry, sourceUrl);
return;
}
}
final ContentEntry newContentEntry = rootModel.addContentEntry(sourceUrl);
addSourceRoot(newContentEntry, sourceUrl);
otherContentEntries.add(newContentEntry);
}
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by JetBrains.
the class FlashBuilderModuleImporter method setupRoots.
private void setupRoots(final ModifiableRootModel rootModel, final FlashBuilderProject fbProject) {
final String mainContentEntryUrl = VfsUtilCore.pathToUrl(fbProject.getProjectRootPath());
final ContentEntry mainContentEntry = rootModel.addContentEntry(mainContentEntryUrl);
final Collection<ContentEntry> otherContentEntries = new ArrayList<>();
final Collection<String> sourcePaths = fbProject.getSourcePaths();
if (sourcePaths.isEmpty()) {
final VirtualFile contentRoot = mainContentEntry.getFile();
final String mainClass = fbProject.getMainAppClassName();
if (contentRoot != null && !StringUtil.isEmpty(mainClass) && (contentRoot.findChild(mainClass + ".mxml") != null || contentRoot.findChild(mainClass + ".as") != null)) {
mainContentEntry.addSourceFolder(mainContentEntry.getUrl(), false);
}
} else {
final List<String> locales = FlexCommonUtils.getOptionValues(fbProject.getAdditionalCompilerOptions(), "locale", "compiler.locale");
final List<String> moreSourcePaths = FlexCommonUtils.getOptionValues(fbProject.getAdditionalCompilerOptions(), "source-path", "compiler.source-path");
for (final String rawSourcePath : sourcePaths) {
if (rawSourcePath.contains(FlexCommonUtils.LOCALE_TOKEN)) {
for (String locale : locales) {
handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, rawSourcePath.replace(FlexCommonUtils.LOCALE_TOKEN, locale));
}
} else {
handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, rawSourcePath);
}
}
for (String sourcePath : moreSourcePaths) {
if (sourcePath.contains(FlexCommonUtils.LOCALE_TOKEN)) {
for (String locale : locales) {
final String path = getPathToSourceRootSetInAdditionalOptions(sourcePath.replace(FlexCommonUtils.LOCALE_TOKEN, locale), mainContentEntryUrl, mainContentEntry);
if (path != null) {
handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, path);
}
}
} else {
final String path = getPathToSourceRootSetInAdditionalOptions(sourcePath, mainContentEntryUrl, mainContentEntry);
if (path != null) {
handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, path);
}
}
}
}
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-community by JetBrains.
the class MultiModuleEditingTest method testRootsEditing.
public void testRootsEditing() {
final MessageBusConnection connection = myProject.getMessageBus().connect();
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
final MyModuleListener moduleListener = new MyModuleListener();
connection.subscribe(ProjectTopics.MODULES, moduleListener);
final Module moduleA;
final Module moduleB;
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelB.addModuleOrderEntry(moduleA);
final ContentEntry contentEntryA = rootModelA.addContentEntry(getVirtualFileInTestData("a"));
contentEntryA.addSourceFolder(getVirtualFileInTestData("a/src"), false);
final ContentEntry contentEntryB = rootModelB.addContentEntry(getVirtualFileInTestData("b"));
contentEntryB.addSourceFolder(getVirtualFileInTestData("b/src"), false);
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB, rootModelA }, moduleModel));
}
final JavaPsiFacade psiManager = getJavaFacade();
assertNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleA)));
assertNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleB)));
assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleA)));
assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleScope(moduleB)));
assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
moduleManager.disposeModule(moduleB);
moduleManager.disposeModule(moduleA);
moduleListener.assertCorrectEvents(new String[][] { { "+b", "+a" }, { "-b" }, { "-a" } });
connection.disconnect();
}
use of com.intellij.openapi.roots.ContentEntry in project intellij-community by JetBrains.
the class ConfigurationsTest method addSourcePath.
private static void addSourcePath(Module module, String path, boolean testSource) {
final ContentEntry entry = ModuleRootManager.getInstance(module).getContentEntries()[0];
VirtualFile child = entry.getFile().findChild(path);
assertNotNull(child);
PsiTestUtil.addSourceRoot(module, child, testSource);
}
Aggregations