use of com.intellij.openapi.roots.libraries.Library 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.Library in project intellij-community by JetBrains.
the class EclipseClasspathReader method addNamedLibrary.
@Override
protected void addNamedLibrary(final ModifiableRootModel rootModel, final Collection<String> unknownLibraries, final boolean exported, final String name, final boolean applicationLevel) {
Library lib = findLibraryByName(myProject, name);
if (lib != null) {
rootModel.addLibraryEntry(lib).setExported(exported);
} else {
unknownLibraries.add(name);
rootModel.addInvalidLibrary(name, applicationLevel ? LibraryTablesRegistrar.APPLICATION_LEVEL : LibraryTablesRegistrar.PROJECT_LEVEL).setExported(exported);
}
}
use of com.intellij.openapi.roots.libraries.Library 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;
}
use of com.intellij.openapi.roots.libraries.Library 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.Library in project intellij-community by JetBrains.
the class LibraryCompositionSettings method addLibraries.
@Nullable
public Library addLibraries(@NotNull final ModifiableRootModel rootModel, @NotNull final List<Library> addedLibraries, @Nullable final LibrariesContainer librariesContainer) {
Library newLibrary = createLibrary(rootModel, librariesContainer);
if (newLibrary != null) {
addedLibraries.add(newLibrary);
DependencyScope scope = LibraryDependencyScopeSuggester.getDefaultScope(newLibrary);
if (getLibraryLevel() != LibrariesContainer.LibraryLevel.MODULE) {
rootModel.addLibraryEntry(newLibrary).setScope(scope);
} else {
LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(newLibrary);
assert orderEntry != null;
orderEntry.setScope(scope);
}
}
if (mySelectedLibrary != null) {
addedLibraries.add(mySelectedLibrary);
rootModel.addLibraryEntry(mySelectedLibrary).setScope(LibraryDependencyScopeSuggester.getDefaultScope(mySelectedLibrary));
}
if (myLibraryProvider != null) {
Library library = myLibraryProvider.createLibrary(myLibraryDescription.getSuitableLibraryKinds());
addedLibraries.add(library);
rootModel.addLibraryEntry(library).setScope(LibraryDependencyScopeSuggester.getDefaultScope(library));
}
return newLibrary;
}
Aggregations