use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class MavenRootModelAdapter method addSystemDependency.
public void addSystemDependency(MavenArtifact artifact, DependencyScope scope) {
assert MavenConstants.SCOPE_SYSTEM.equals(artifact.getScope());
String libraryName = artifact.getLibraryName();
Library library = myRootModel.getModuleLibraryTable().getLibraryByName(libraryName);
if (library == null) {
library = myRootModel.getModuleLibraryTable().createLibrary(libraryName);
}
LibraryOrderEntry orderEntry = myRootModel.findLibraryOrderEntry(library);
assert orderEntry != null;
orderEntry.setScope(scope);
Library.ModifiableModel modifiableModel = library.getModifiableModel();
updateUrl(modifiableModel, OrderRootType.CLASSES, artifact, null, null, true);
modifiableModel.commit();
if (myOrderEntriesBeforeJdk.contains(libraryName)) {
moveLastOrderEntryBeforeJdk();
}
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RepositoryLibrarySupport method addSupport.
public void addSupport(@NotNull Module module, @NotNull final ModifiableRootModel rootModel, @NotNull ModifiableModelsProvider modifiableModelsProvider) {
LibraryTable.ModifiableModel modifiableModel = modifiableModelsProvider.getLibraryTableModifiableModel(module.getProject());
Library library = Iterables.find(Arrays.asList(modifiableModel.getLibraries()), new Predicate<Library>() {
@Override
public boolean apply(@Nullable Library library) {
return isLibraryEqualsToSelected(library);
}
}, null);
if (library == null) {
library = createNewLibrary(module, modifiableModel);
} else {
modifiableModelsProvider.disposeLibraryTableModifiableModel(modifiableModel);
}
final DependencyScope dependencyScope = LibraryDependencyScopeSuggester.getDefaultScope(library);
final ModifiableRootModel moduleModifiableModel = modifiableModelsProvider.getModuleModifiableModel(module);
LibraryOrderEntry foundEntry = (LibraryOrderEntry) Iterables.find(Arrays.asList(moduleModifiableModel.getOrderEntries()), new Predicate<OrderEntry>() {
@Override
public boolean apply(@Nullable OrderEntry entry) {
return entry instanceof LibraryOrderEntry && ((LibraryOrderEntry) entry).getScope() == dependencyScope && isLibraryEqualsToSelected(((LibraryOrderEntry) entry).getLibrary());
}
}, null);
modifiableModelsProvider.disposeModuleModifiableModel(moduleModifiableModel);
if (foundEntry == null) {
rootModel.addLibraryEntry(library).setScope(dependencyScope);
}
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RepositoryLibrarySynchronizer method collectLibraries.
private static Collection<Library> collectLibraries(@NotNull final Project project, @NotNull final Predicate<Library> predicate) {
final HashSet<Library> result = new HashSet<>();
ApplicationManager.getApplication().runReadAction(() -> {
for (final Module module : ModuleManager.getInstance(project).getModules()) {
OrderEnumerator.orderEntries(module).withoutSdk().forEachLibrary(library -> {
if (predicate.apply(library)) {
result.add(library);
}
return true;
});
}
for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
if (predicate.apply(library)) {
result.add(library);
}
}
});
return result;
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RepositoryLibrarySynchronizer method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
StartupManager.getInstance(project).registerPostStartupActivity(new DumbAwareRunnable() {
@Override
public void run() {
ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {
@Override
public void run() {
final Collection<Library> libraries = collectLibraries(project, new Predicate<Library>() {
@Override
public boolean apply(Library library) {
if (!(library instanceof LibraryEx)) {
return false;
}
LibraryEx libraryEx = (LibraryEx) library;
return libraryEx.getKind() == RepositoryLibraryType.REPOSITORY_LIBRARY_KIND && libraryEx.getProperties() instanceof RepositoryLibraryProperties && isLibraryNeedToBeReloaded(libraryEx, (RepositoryLibraryProperties) libraryEx.getProperties());
}
});
for (Library library : libraries) {
final LibraryEx libraryEx = (LibraryEx) library;
RepositoryUtils.reloadDependencies(project, libraryEx);
}
}
}, project.getDisposed());
}
});
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class GroovyFacetUtil method tryToSetUpGroovyFacetOnTheFly.
public static boolean tryToSetUpGroovyFacetOnTheFly(final Module module) {
final Project project = module.getProject();
GroovyConfigUtils utils = GroovyConfigUtils.getInstance();
final Library[] libraries = utils.getAllSDKLibraries(project);
if (libraries.length > 0) {
final Library library = libraries[0];
int result = Messages.showOkCancelDialog(GroovyBundle.message("groovy.like.library.found.text", module.getName(), library.getName(), utils.getSDKLibVersion(library)), GroovyBundle.message("groovy.like.library.found"), JetgroovyIcons.Groovy.Groovy_32x32);
if (result == Messages.OK) {
WriteAction.run(() -> {
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
LibraryOrderEntry entry = model.addLibraryEntry(libraries[0]);
LibrariesUtil.placeEntryToCorrectPlace(model, entry);
model.commit();
});
return true;
}
}
return false;
}
Aggregations