use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class BytecodeAnalysisIntegrationTest method setUpExternalUpAnnotations.
private void setUpExternalUpAnnotations() {
String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
assertNotNull(annotationsDir);
ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {
@Override
public void finished() {
}
@Override
public void consume(ModifiableRootModel modifiableRootModel) {
LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
Library[] libs = libraryTable.getLibraries();
for (Library library : libs) {
Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
libraryModel.commit();
}
Sdk sdk = modifiableRootModel.getSdk();
if (sdk != null) {
Sdk clone;
try {
clone = (Sdk) sdk.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
SdkModificator sdkModificator = clone.getSdkModificator();
sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
sdkModificator.commitChanges();
modifiableRootModel.setSdk(clone);
}
}
});
VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() {
});
annotationsDir.refresh(false, true);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class ArtifactEditorContextImpl method selectLibrary.
@Override
public void selectLibrary(@NotNull Library library) {
final LibraryTable table = library.getTable();
if (table != null) {
ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
} else {
final Module module = ((LibraryImpl) library).getModule();
if (module != null) {
final ModuleRootModel rootModel = myParent.getModulesProvider().getRootModel(module);
final String libraryName = library.getName();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (entry instanceof ModuleLibraryOrderEntryImpl) {
final ModuleLibraryOrderEntryImpl libraryEntry = (ModuleLibraryOrderEntryImpl) entry;
if (libraryName != null && libraryName.equals(libraryEntry.getLibraryName()) || libraryName == null && library.equals(libraryEntry.getLibrary())) {
ProjectStructureConfigurable.getInstance(getProject()).selectOrderEntry(module, libraryEntry);
return;
}
}
}
}
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class ClsGenericsHighlightingTest method commitLibraryModel.
protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) {
LibraryTable libraryTable = model.getModuleLibraryTable();
Library library = libraryTable.createLibrary("test");
Library.ModifiableModel libraryModel = library.getModifiableModel();
for (String annotationsDir : libraryPath) {
String path = testDataPath + "/libs/" + annotationsDir;
VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
assertNotNull(libJarLocal);
VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
assertNotNull(jarRoot);
libraryModel.addRoot(jarRoot, jarRoot.getName().contains("-sources") ? OrderRootType.SOURCES : OrderRootType.CLASSES);
}
libraryModel.commit();
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class EclipseImportBuilder method createEclipseLibrary.
private static void createEclipseLibrary(final Project project, final Collection<String> libraries, final String libraryName) {
if (libraries.contains(libraryName)) {
final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public Icon getIcon(final VirtualFile file) {
return looksLikeEclipse(file) ? dressIcon(file, EclipseIcons.Eclipse) : super.getIcon(file);
}
private boolean looksLikeEclipse(final VirtualFile file) {
return file.findChild(".eclipseproduct") != null;
}
};
fileChooserDescriptor.setTitle(EclipseBundle.message("eclipse.create.library.title"));
fileChooserDescriptor.setDescription(EclipseBundle.message("eclipse.create.library.description", libraryName));
final VirtualFile file = FileChooser.chooseFile(fileChooserDescriptor, project, null);
if (file != null) {
final VirtualFile pluginsDir = file.findChild("plugins");
if (pluginsDir != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.APPLICATION_LEVEL, project);
assert table != null;
final LibraryTable.ModifiableModel tableModel = table.getModifiableModel();
final Library library = tableModel.createLibrary(libraryName);
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addJarDirectory(pluginsDir, true);
libraryModel.commit();
tableModel.commit();
});
libraries.remove(libraryName);
}
}
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class EclipseClasspathReader method findLibraryByName.
public static Library findLibraryByName(Project project, String name) {
final LibraryTablesRegistrar tablesRegistrar = LibraryTablesRegistrar.getInstance();
Library lib = tablesRegistrar.getLibraryTable().getLibraryByName(name);
if (lib == null) {
lib = tablesRegistrar.getLibraryTable(project).getLibraryByName(name);
}
if (lib == null) {
for (LibraryTable table : tablesRegistrar.getCustomLibraryTables()) {
lib = table.getLibraryByName(name);
if (lib != null) {
break;
}
}
}
return lib;
}
Aggregations