use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class MavenModuleImporter method configSurefirePlugin.
private void configSurefirePlugin() {
// Remove "maven-surefire-plugin urls" library created by previous version of IDEA.
// todo remove this code after 01.06.2013
LibraryTable moduleLibraryTable = myRootModelAdapter.getRootModel().getModuleLibraryTable();
Library library = moduleLibraryTable.getLibraryByName(SUREFIRE_PLUGIN_LIBRARY_NAME);
if (library != null) {
moduleLibraryTable.removeLibrary(library);
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class LibrariesUtil method getGlobalLibraries.
public static Library[] getGlobalLibraries(Condition<Library> condition) {
LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable();
List<Library> libs = ContainerUtil.findAll(table.getLibraries(), condition);
return libs.toArray(new Library[libs.size()]);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class EclipseUserLibrariesHelper method readProjectLibrariesContent.
public static void readProjectLibrariesContent(@NotNull VirtualFile exportedFile, Project project, Collection<String> unknownLibraries) throws IOException, JDOMException {
if (!exportedFile.isValid()) {
return;
}
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
Element element = JDOMUtil.load(exportedFile.getInputStream());
WriteAction.run(() -> {
for (Element libElement : element.getChildren("library")) {
String libName = libElement.getAttributeValue("name");
Library libraryByName = libraryTable.getLibraryByName(libName);
if (libraryByName == null) {
LibraryTable.ModifiableModel model = libraryTable.getModifiableModel();
libraryByName = model.createLibrary(libName);
model.commit();
}
if (libraryByName != null) {
Library.ModifiableModel model = libraryByName.getModifiableModel();
for (Element a : libElement.getChildren("archive")) {
String rootPath = a.getAttributeValue("path");
// IDEA-138039 Eclipse import: Unix file system: user library gets wrong paths
LocalFileSystem fileSystem = LocalFileSystem.getInstance();
VirtualFile localFile = fileSystem.findFileByPath(rootPath);
if (rootPath.startsWith("/") && (localFile == null || !localFile.isValid())) {
// relative to workspace root
rootPath = project.getBaseDir().getPath() + rootPath;
localFile = fileSystem.findFileByPath(rootPath);
}
String url = localFile == null ? VfsUtilCore.pathToUrl(rootPath) : localFile.getUrl();
if (localFile != null) {
VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(localFile);
if (jarFile != null) {
url = jarFile.getUrl();
}
}
model.addRoot(url, OrderRootType.CLASSES);
}
model.commit();
}
//ignore finally found libraries
unknownLibraries.remove(libName);
}
});
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class AbstractConfigUtils method getProjectSDKLibraries.
public Library[] getProjectSDKLibraries(Project project) {
if (project == null || project.isDisposed())
return Library.EMPTY_ARRAY;
final LibraryTable table = ProjectLibraryTable.getInstance(project);
final List<Library> all = ContainerUtil.findAll(table.getLibraries(), LIB_SEARCH_CONDITION);
return all.toArray(new Library[all.size()]);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class ProjectFromSourcesBuilderImpl method setupRootModel.
private static void setupRootModel(ProjectDescriptor projectDescriptor, final ModuleDescriptor descriptor, final ModifiableRootModel rootModel, final Map<LibraryDescriptor, Library> projectLibs) {
final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExtension.setExcludeOutput(true);
rootModel.inheritSdk();
final Set<File> contentRoots = descriptor.getContentRoots();
for (File contentRoot : contentRoots) {
final LocalFileSystem lfs = LocalFileSystem.getInstance();
VirtualFile moduleContentRoot = lfs.refreshAndFindFileByPath(FileUtil.toSystemIndependentName(contentRoot.getPath()));
if (moduleContentRoot != null) {
final ContentEntry contentEntry = rootModel.addContentEntry(moduleContentRoot);
final Collection<DetectedSourceRoot> sourceRoots = descriptor.getSourceRoots(contentRoot);
for (DetectedSourceRoot srcRoot : sourceRoots) {
final String srcpath = FileUtil.toSystemIndependentName(srcRoot.getDirectory().getPath());
final VirtualFile sourceRoot = lfs.refreshAndFindFileByPath(srcpath);
if (sourceRoot != null) {
contentEntry.addSourceFolder(sourceRoot, shouldBeTestRoot(srcRoot.getDirectory()), getPackagePrefix(srcRoot));
}
}
}
}
compilerModuleExtension.inheritCompilerOutputPath(true);
final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
for (LibraryDescriptor libDescriptor : ModuleInsight.getLibraryDependencies(descriptor, projectDescriptor.getLibraries())) {
final Library projectLib = projectLibs.get(libDescriptor);
if (projectLib != null) {
rootModel.addLibraryEntry(projectLib);
} else {
// add as module library
final Collection<File> jars = libDescriptor.getJars();
for (File file : jars) {
Library library = moduleLibraryTable.createLibrary();
Library.ModifiableModel modifiableModel = library.getModifiableModel();
modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(file), OrderRootType.CLASSES);
modifiableModel.commit();
}
}
}
}
Aggregations