use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.
the class ChooseScopeAndCreateLibraryDialog method createLibraryAndAssociate.
@Nullable
private ErrorMessage createLibraryAndAssociate() {
String libraryName = myLibraryNameTextField.getText();
ScriptingLibraryModel libraryModel = myLibraryHelper.getOrCreateJsLibraryModel(libraryName);
try {
ScriptingLibraryMappings libraryMappings = ServiceManager.getService(myProject, JSLibraryMappings.class);
if (myModuleSelector.isAssociateWithProjectView()) {
if (myModuleSelector.isAssociateWithProjectRequested()) {
libraryMappings.associateWithProject(libraryModel.getName());
LOG.info("Library '" + libraryModel.getName() + "' has been successfully associated with the project");
} else {
libraryMappings.disassociateWithProject(libraryModel.getName());
}
} else {
for (Module module : myModuleSelector.getSelectedModules()) {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
VirtualFile[] roots = moduleRootManager.getContentRoots();
for (VirtualFile root : roots) {
libraryMappings.associate(root, libraryModel.getName(), false);
LOG.info("Library '" + libraryModel.getName() + "' has been associated with " + root);
}
}
}
myLibraryHelper.commit();
return null;
} catch (Exception ex) {
return new ErrorMessage("Unable to associate '" + libraryName + "' JavaScript library", ex);
}
}
use of com.intellij.openapi.roots.ModuleRootManager 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.ModuleRootManager in project intellij-plugins by JetBrains.
the class VFSUtil method findFileInModule.
private static void findFileInModule(final Set<VirtualFile> found, Module module, VFile file) {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
findInRoots(found, rootManager.getSourceRoots(), file.getSourcePath());
findInRoots(found, rootManager.getContentRoots(), file.getContentPath());
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.
the class LibraryCollector method collect.
/**
* We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
*/
public void collect(Module module) {
final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
final Sdk sdk = bc.getSdk();
assert sdk != null;
final SdkType sdkType;
try {
sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
} catch (Exception e) {
throw new RuntimeException(e);
}
final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
if (!isFlexmojosSdk) {
collectSdkLibraries(bc, sdk);
} else {
final String sdkHomePath = sdk.getHomePath();
LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
}
flexSdkVersion = sdk.getVersionString();
assert flexSdkVersion != null;
if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
flexSdkVersion = "4.6";
} else {
flexSdkVersion = flexSdkVersion.substring(0, 3);
}
globalCatalogForTests(bc);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry instanceof ModuleLibraryEntry) {
LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
if (orderEntry != null) {
collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
}
} else if (entry instanceof SharedLibraryEntry) {
com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
}
}
}
// IDEA-71055
// todo css-based themes
final List<String> themes = BCUtils.getThemes(module, bc);
for (String theme : themes) {
if (theme.endsWith(DOT_SWC)) {
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
if (file != null && uniqueGuard.add(file)) {
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
if (jarFile != null) {
addLibrary(jarFile, true);
}
}
}
}
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.
the class CreateFlexUnitTestDialog method findExistingTestSourceRoot.
@Nullable
private static PsiDirectory findExistingTestSourceRoot(final Module module) {
PsiDirectory testSourceRoot = null;
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
for (VirtualFile srcRoot : manager.getSourceRoots(true)) {
if (manager.getFileIndex().isInTestSourceContent(srcRoot)) {
testSourceRoot = PsiManager.getInstance(module.getProject()).findDirectory(srcRoot);
break;
}
}
return testSourceRoot;
}
Aggregations