use of com.intellij.openapi.roots.libraries.LibraryTable in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoModuleLibrariesInitializer method removeLibraryIfNeeded.
private void removeLibraryIfNeeded() {
ApplicationManager.getApplication().assertIsDispatchThread();
ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (goLibraryEntry != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
Library library = goLibraryEntry.getLibrary();
if (library != null) {
LibraryTable table = library.getTable();
if (table != null) {
table.removeLibrary(library);
model.removeOrderEntry(goLibraryEntry);
modelsProvider.commitModuleModifiableModel(model);
}
} else {
modelsProvider.disposeModuleModifiableModel(model);
}
});
} else {
ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.
the class GradleSyncTest method shouldUseLibrary.
@Test
public void shouldUseLibrary() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
// Make sure the library was added.
LibraryTable libraryTable = ProjectLibraryTable.getInstance(project);
String libraryName = "org.apache.http.legacy-" + TestUtils.getLatestAndroidPlatform();
Library library = libraryTable.getLibraryByName(libraryName);
// Verify that the library has the right j
VirtualFile[] jarFiles = library.getFiles(CLASSES);
assertThat(jarFiles).asList().hasSize(1);
VirtualFile jarFile = jarFiles[0];
assertEquals("org.apache.http.legacy.jar", jarFile.getName());
// Verify that the module depends on the library
Module appModule = ideFrame.getModule("app");
AtomicBoolean dependencyFound = new AtomicBoolean();
new ReadAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(appModule).getModifiableModel();
try {
for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
if (orderEntry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryDependency = (LibraryOrderEntry) orderEntry;
if (libraryDependency.getLibrary() == library) {
dependencyFound.set(true);
}
}
}
} finally {
modifiableModel.dispose();
}
}
}.execute();
assertTrue("Module app should depend on library '" + library.getName() + "'", dependencyFound.get());
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project android by JetBrains.
the class TestArtifactSearchScopesTest method testNotExcludeLibrariesInMainArtifact.
public void testNotExcludeLibrariesInMainArtifact() throws Exception {
TestArtifactSearchScopes scopes = loadMultiProjectAndTestScopes();
LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myFixture.getProject());
Library gson = libraryTable.getLibraryByName("gson-2.2.4");
// In the beginning only unit test exclude gson
assertScopeContainsLibrary(scopes.getUnitTestExcludeScope(), gson, true);
assertScopeContainsLibrary(scopes.getAndroidTestExcludeScope(), gson, false);
// Now add gson to unit test dependencies as well
VirtualFile buildFile = getGradleBuildFile(scopes.getModule());
assertNotNull(buildFile);
appendToFile(virtualToIoFile(buildFile), "\n\ndependencies { compile 'com.google.code.gson:gson:2.2.4' }\n");
final CountDownLatch latch = new CountDownLatch(1);
GradleSyncListener postSetupListener = new GradleSyncListener.Adapter() {
@Override
public void syncSucceeded(@NotNull Project project) {
latch.countDown();
}
@Override
public void syncFailed(@NotNull Project project, @NotNull String errorMessage) {
latch.countDown();
}
};
GradleSyncState.subscribe(getProject(), postSetupListener);
runWriteCommandAction(getProject(), () -> {
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setGenerateSourcesOnSuccess(false);
GradleSyncInvoker.getInstance().requestProjectSync(getProject(), request, null);
});
latch.await();
// Now both test should not exclude gson
scopes = TestArtifactSearchScopes.get(scopes.getModule());
assertNotNull(scopes);
gson = libraryTable.getLibraryByName("gson-2.2.4");
assertScopeContainsLibrary(scopes.getUnitTestExcludeScope(), gson, false);
assertScopeContainsLibrary(scopes.getAndroidTestExcludeScope(), gson, false);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-plugins by JetBrains.
the class FlexTestUtils method createConfigEditor.
public static FlexProjectConfigurationEditor createConfigEditor(final Module... modules) {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Map<Module, ModifiableRootModel> models = new FactoryMap<Module, ModifiableRootModel>() {
@Override
protected ModifiableRootModel create(final Module module) {
final ModifiableRootModel result = ModuleRootManager.getInstance(module).getModifiableModel();
Disposer.register(module, new Disposable() {
@Override
public void dispose() {
if (!result.isDisposed()) {
result.dispose();
}
}
});
return result;
}
};
return new FlexProjectConfigurationEditor(modules[0].getProject(), new FlexProjectConfigurationEditor.ProjectModifiableModelProvider() {
@Override
public Module[] getModules() {
return modules;
}
@Override
public ModifiableRootModel getModuleModifiableModel(Module module) {
return models.get(module);
}
@Override
public void addListener(FlexBCConfigurator.Listener listener, Disposable parentDisposable) {
// ignore
}
@Override
public void commitModifiableModels() throws ConfigurationException {
ApplicationManager.getApplication().runWriteAction(() -> {
for (ModifiableRootModel model : models.values()) {
if (model.isChanged()) {
model.commit();
}
}
});
}
public Library findSourceLibraryForLiveName(final String name, final String level) {
return findSourceLibrary(name, level);
}
public Library findSourceLibrary(final String name, final String level) {
return getLibrariesTable(level).getLibraryByName(name);
}
private LibraryTable getLibrariesTable(final String level) {
if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
return ApplicationLibraryTable.getApplicationTable();
} else {
assert LibraryTablesRegistrar.PROJECT_LEVEL.equals(level);
return ProjectLibraryTable.getInstance(modules[0].getProject());
}
}
});
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-plugins by JetBrains.
the class FlexTestUtils method doAddFlexLibrary.
private static void doAddFlexLibrary(boolean isProjectLibrary, Module module, String libraryName, boolean overwrite, String libraryRoot, @Nullable String classesPath, @Nullable String sourcesPath, @Nullable String asdocPath, LinkageType linkageType) {
ModifiableRootModel moduleModifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
WriteAction.run(() -> {
try {
// first let's create Flex library
final LibraryTable libraryTable;
if (isProjectLibrary) {
libraryTable = ProjectLibraryTable.getInstance(module.getProject());
} else {
libraryTable = moduleModifiableModel.getModuleLibraryTable();
}
Library library = libraryTable.getLibraryByName(libraryName);
if (library != null && overwrite) {
libraryTable.removeLibrary(library);
library = null;
}
if (library == null) {
LibraryTable.ModifiableModel libraryTableModifiableModel = libraryTable.getModifiableModel();
library = libraryTableModifiableModel.createLibrary(libraryName, FlexLibraryType.FLEX_LIBRARY);
LibraryEx.ModifiableModelEx libraryModel = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
libraryModel.setProperties(new FlexLibraryProperties(FlexLibraryIdGenerator.generateId()));
addRootIfNotNull(libraryRoot, classesPath, libraryModel, OrderRootType.CLASSES, ".swc", ".zip");
addRootIfNotNull(libraryRoot, sourcesPath, libraryModel, OrderRootType.SOURCES, ".zip");
addRootIfNotNull(libraryRoot, asdocPath, libraryModel, JavadocOrderRootType.getInstance(), ".zip");
libraryModel.commit();
libraryTableModifiableModel.commit();
}
moduleModifiableModel.commit();
// then add Flex library to build configuration dependency
final String committedLibraryId;
if (isProjectLibrary) {
committedLibraryId = FlexProjectRootsUtil.getLibraryId(ProjectLibraryTable.getInstance(module.getProject()).getLibraryByName(libraryName));
} else {
final OrderEntry entry = ContainerUtil.find(ModuleRootManager.getInstance(module).getOrderEntries(), orderEntry -> orderEntry instanceof LibraryOrderEntry && ((LibraryOrderEntry) orderEntry).getLibraryName().equals(libraryName));
committedLibraryId = FlexProjectRootsUtil.getLibraryId(((LibraryOrderEntry) entry).getLibrary());
}
if (ModuleType.get(module) == FlexModuleType.getInstance()) {
modifyConfigs(module.getProject(), e -> {
final ModifiableFlexBuildConfiguration[] bcs = e.getConfigurations(module);
final ModifiableDependencyEntry dependencyEntry;
if (isProjectLibrary) {
dependencyEntry = e.createSharedLibraryEntry(bcs[0].getDependencies(), libraryName, LibraryTablesRegistrar.PROJECT_LEVEL);
} else {
dependencyEntry = e.createModuleLibraryEntry(bcs[0].getDependencies(), committedLibraryId);
}
dependencyEntry.getDependencyType().setLinkageType(linkageType);
bcs[0].getDependencies().getModifiableEntries().add(dependencyEntry);
});
}
} finally {
if (!moduleModifiableModel.isDisposed()) {
moduleModifiableModel.dispose();
}
}
});
}
Aggregations