use of com.intellij.openapi.roots.libraries.LibraryTable in project ballerina by ballerina-lang.
the class BallerinaModuleLibrariesInitializer method attachLibraries.
private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!libraryRoots.isEmpty()) {
ApplicationManager.getApplication().runWriteAction(() -> {
ModuleRootManager model = ModuleRootManager.getInstance(myModule);
LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (ballerinaLibraryEntry != null && ballerinaLibraryEntry.isValid()) {
Library library = ballerinaLibraryEntry.getLibrary();
if (library != null && !((LibraryEx) library).isDisposed()) {
fillLibrary(library, libraryRoots, exclusions);
}
} else {
LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject());
Library library = libraryTable.createLibrary(getLibraryName());
fillLibrary(library, libraryRoots, exclusions);
ModuleRootModificationUtil.addDependency(myModule, library);
}
});
showNotification(myModule.getProject());
} else {
removeLibraryIfNeeded();
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project ballerina by ballerina-lang.
the class BallerinaModuleLibrariesInitializer method removeLibraryIfNeeded.
private void removeLibraryIfNeeded() {
ApplicationManager.getApplication().assertIsDispatchThread();
ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (ballerinaLibraryEntry != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
Library library = ballerinaLibraryEntry.getLibrary();
if (library != null) {
LibraryTable table = library.getTable();
if (table != null) {
table.removeLibrary(library);
model.removeOrderEntry(ballerinaLibraryEntry);
modelsProvider.commitModuleModifiableModel(model);
}
} else {
modelsProvider.disposeModuleModifiableModel(model);
}
});
} else {
ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project Perl5-IDEA by Camelcade.
the class PerlModuleBuilder method setupRootModel.
@Override
public void setupRootModel(ModifiableRootModel rootModel) {
final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExtension.setExcludeOutput(true);
if (myJdk != null) {
rootModel.setSdk(myJdk);
} else {
rootModel.inheritSdk();
}
ContentEntry contentEntry = doAddContentEntry(rootModel);
if (contentEntry != null) {
final List<Pair<String, String>> sourcePaths = getSourcePaths();
if (sourcePaths != null) {
for (final Pair<String, String> sourcePath : sourcePaths) {
String first = sourcePath.first;
new File(first).mkdirs();
final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
if (sourceRoot != null) {
contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
}
}
}
}
LibraryTable libraryTable = rootModel.getModuleLibraryTable();
for (Pair<String, String> libInfo : myModuleLibraries) {
final String moduleLibraryPath = libInfo.first;
final String sourceLibraryPath = libInfo.second;
Library library = libraryTable.createLibrary();
Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES);
if (sourceLibraryPath != null) {
modifiableModel.addRoot(getUrlByPath(sourceLibraryPath), OrderRootType.SOURCES);
}
modifiableModel.commit();
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project moe-ide-integration by multi-os-engine.
the class ModuleObserver method checkMOEDependencies.
private void checkMOEDependencies(@NotNull final Module module) {
final String home = MOESdkPlugin.getSdkRootPath(module);
if (home == null || home.isEmpty()) {
LOG.debug("Unable to find MOE home");
return;
}
ModuleRootManager manager = ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = manager.getModifiableModel();
final LibraryTable libraryTable = rootModel.getModuleLibraryTable();
ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() {
@Override
public void run() {
for (String jar : MOE_JARS) {
Library library = libraryTable.getLibraryByName("Maven: " + jar);
if (library != null) {
String jarPath = home + File.separator + MOE_JARS_PATH + File.separator + jar;
String[] urls = library.getUrls(OrderRootType.CLASSES);
if (urls.length > 0) {
String url = urls[0];
String newUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, jarPath) + JarFileSystem.JAR_SEPARATOR;
if (!url.equals(newUrl)) {
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.removeRoot(url, OrderRootType.CLASSES);
libraryModel.addRoot(newUrl, OrderRootType.CLASSES);
libraryModel.commit();
}
}
}
}
rootModel.commit();
}
});
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij by bazelbuild.
the class BlazeKotlinSyncPlugin method updateProjectStructure.
/**
* Attaches sources to Kotlin external artifacts, add missing mandatory std libraries and perform
* last bit of Kotlin configuration.
*/
@Override
public void updateProjectStructure(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, @Nullable BlazeProjectData oldBlazeProjectData, ModuleEditor moduleEditor, Module workspaceModule, ModifiableRootModel workspaceModifiableModel) {
if (!blazeProjectData.workspaceLanguageSettings.isLanguageActive(LanguageClass.KOTLIN)) {
return;
}
LibraryTable.ModifiableModel libraryTable = ProjectLibraryTable.getInstance(project).getModifiableModel();
externalKotlinLibraries(blazeProjectData).forEach(lib -> {
Library library = libraryTable.getLibraryByName(lib.key.getIntelliJLibraryName());
if (library == null) {
library = libraryTable.createLibrary(lib.key.getIntelliJLibraryName());
}
Library.ModifiableModel modifiableIjLibrary = library.getModifiableModel();
maybeAttachSourceJars(blazeProjectData.artifactLocationDecoder, lib, modifiableIjLibrary);
modifiableIjLibrary.commit();
});
libraryTable.commit();
KotlinJavaModuleConfigurator.Companion.getInstance().configureSilently(project);
}
Aggregations