use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class JavaModuleBuilder method setupRootModel.
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
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);
}
}
}
}
if (myCompilerOutputPath != null) {
// should set only absolute paths
String canonicalPath;
try {
canonicalPath = FileUtil.resolveShortWindowsName(myCompilerOutputPath);
} catch (IOException e) {
canonicalPath = myCompilerOutputPath;
}
compilerModuleExtension.setCompilerOutputPath(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
} else {
compilerModuleExtension.inheritCompilerOutputPath(true);
}
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 intellij-community by JetBrains.
the class LibraryTest method testModification.
public void testModification() throws Exception {
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable();
final Library library = ApplicationManager.getApplication().runWriteAction((Computable<Library>) () -> libraryTable.createLibrary("NewLibrary"));
final boolean[] listenerNotifiedOnChange = new boolean[1];
library.getRootProvider().addRootSetChangedListener(wrapper -> listenerNotifiedOnChange[0] = true);
final Library.ModifiableModel model1 = library.getModifiableModel();
model1.addRoot("file://x.jar", OrderRootType.CLASSES);
model1.addRoot("file://x-src.jar", OrderRootType.SOURCES);
commit(model1);
assertTrue(listenerNotifiedOnChange[0]);
listenerNotifiedOnChange[0] = false;
final Library.ModifiableModel model2 = library.getModifiableModel();
model2.setName("library");
commit(model2);
assertFalse(listenerNotifiedOnChange[0]);
ApplicationManager.getApplication().runWriteAction(() -> libraryTable.removeLibrary(library));
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class LibraryTest method testJarDirectoriesSerialization.
public void testJarDirectoriesSerialization() {
LibraryTable table = getLibraryTable();
Library library = ApplicationManager.getApplication().runWriteAction((Computable<Library>) () -> table.createLibrary("jarDirs"));
Library.ModifiableModel model = library.getModifiableModel();
model.addJarDirectory("file://jar-dir", false, OrderRootType.CLASSES);
model.addJarDirectory("file://jar-dir-src", false, OrderRootType.SOURCES);
commit(model);
Element element = serialize(library);
PlatformTestUtil.assertElementEquals("<root>\n" + " <library name=\"jarDirs\">\n" + " <CLASSES>\n" + " <root url=\"file://jar-dir\" />\n" + " </CLASSES>\n" + " <JAVADOC />\n" + " <SOURCES>\n" + " <root url=\"file://jar-dir-src\" />\n" + " </SOURCES>\n" + " <jarDirectory url=\"file://jar-dir\" recursive=\"false\" />\n" + " <jarDirectory url=\"file://jar-dir-src\" recursive=\"false\" type=\"SOURCES\" />\n" + " </library>\n" + "</root>", element);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class RootsChangedTest method testGlobalLibraryEventsInUncommittedModel.
public void testGlobalLibraryEventsInUncommittedModel() throws Exception {
final LibraryTable globalLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable();
verifyLibraryTableEditingInUncommittedModel(globalLibraryTable);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class PackagingElementFactoryImpl method createLibraryElements.
@NotNull
@Override
public List<? extends PackagingElement<?>> createLibraryElements(@NotNull Library library) {
final LibraryTable table = library.getTable();
final String libraryName = library.getName();
if (table != null) {
return Collections.singletonList(createLibraryFiles(libraryName, table.getTableLevel(), null));
}
if (libraryName != null) {
final Module module = ((LibraryImpl) library).getModule();
if (module != null) {
return Collections.singletonList(createLibraryFiles(libraryName, LibraryTableImplUtil.MODULE_LEVEL, module.getName()));
}
}
final List<PackagingElement<?>> elements = new ArrayList<>();
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
final String path = FileUtil.toSystemIndependentName(PathUtil.getLocalPath(file));
elements.add(file.isDirectory() && file.isInLocalFileSystem() ? new DirectoryCopyPackagingElement(path) : new FileCopyPackagingElement(path));
}
return elements;
}
Aggregations