use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class SimpleClasspathElementFactory method createElements.
public static List<SimpleClasspathElement> createElements(@Nullable Project project, @NotNull Element element) {
final String name = element.getAttributeValue(GlobalLibraryReferenceElement.NAME_ATTRIBUTE);
final String level = element.getAttributeValue(GlobalLibraryReferenceElement.LEVEL_ATTRIBUTE);
final String url = element.getChildText(SingleRootClasspathElement.URL_ELEMENT);
if (!StringUtil.isEmpty(url)) {
return Collections.<SimpleClasspathElement>singletonList(new SingleRootClasspathElement(url));
}
if (name == null || level == null) {
return Collections.emptyList();
}
if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
return Collections.<SimpleClasspathElement>singletonList(new GlobalLibraryReferenceElement(name));
}
//this is needed only for backward compatibility with version before 8
if (project != null) {
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, project);
if (libraryTable != null) {
final Library library = libraryTable.getLibraryByName(name);
if (library != null) {
return createElements(library);
}
}
}
return Collections.emptyList();
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class LibraryTest method testNativePathSerialization.
public void testNativePathSerialization() {
LibraryTable table = getLibraryTable();
Library library = new WriteAction<Library>() {
@Override
protected void run(@NotNull Result<Library> result) throws Throwable {
Library res = table.createLibrary("native");
result.setResult(res);
}
}.execute().throwException().getResultObject();
Library.ModifiableModel model = library.getModifiableModel();
model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
commit(model);
Element element = serialize(library);
PlatformTestUtil.assertElementEquals("<root><library name=\"native\"><CLASSES /><JAVADOC />" + "<NATIVE><root url=\"file://native-lib-root\" /></NATIVE>" + "<SOURCES /></library></root>", element);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-plugins by JetBrains.
the class JstdLibraryUtil method doInit.
private static void doInit(@NotNull final Project project) {
ApplicationManager.getApplication().runReadAction(() -> {
JSLibraryManager libraryManager = JSLibraryManager.getInstance(project);
LibraryTable libraryTable = libraryManager.getLibraryTable(ScriptingLibraryModel.LibraryLevel.GLOBAL);
libraryTable.addListener(new MyLibraryChangeWatcher());
});
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.
the class ArtifactsByConfigurationModuleSetupStepTest method testDoSetUpModuleWithCompiledJar.
public void testDoSetUpModuleWithCompiledJar() throws IOException {
Module module = getModule();
String moduleName = module.getName();
File buildFolderPath = createTempDir("build");
File jarFilePath = new File(buildFolderPath, moduleName + ".jar");
createIfDoesntExist(jarFilePath);
Project project = getProject();
IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
Map<String, Set<File>> artifactsByConfiguration = new HashMap<>();
artifactsByConfiguration.put("default", Collections.singleton(jarFilePath));
JavaModuleModel model = new JavaModuleModel(moduleName, Collections.emptyList(), Collections.emptyList(), artifactsByConfiguration, null, buildFolderPath, null, true, false);
mySetupStep.doSetUpModule(module, modelsProvider, model, null, null);
ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
Library[] libraries = libraryTable.getLibraries();
assertThat(libraries).isEmpty();
assertAbout(libraryDependencies()).that(module).isEmpty();
// No libraries were created, nothing should be marked as "used".
verify(myLibraryRegistry, never()).markAsUsed(any(), any());
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.
the class ArtifactsByConfigurationModuleSetupStepTest method assertJarIsLibrary.
private void assertJarIsLibrary(@NotNull File jarFilePath) {
LibraryTable libraryTable = ProjectLibraryTable.getInstance(getProject());
Library[] libraries = libraryTable.getLibraries();
assertThat(libraries).hasLength(1);
Library library = libraries[0];
String libraryName = library.getName();
assertNotNull(libraryName);
assertEquals(createLibraryName(jarFilePath), libraryName);
String[] urls = library.getUrls(CLASSES);
assertThat(urls).hasLength(1);
assertEquals(pathToUrl(jarFilePath.getPath()), urls[0]);
assertAbout(libraryDependencies()).that(getModule()).contains(libraryName);
}
Aggregations