use of com.intellij.openapi.roots.LibraryOrderEntry in project android by JetBrains.
the class AndroidModuleDependenciesSetupTest method testSetUpLibraryWithNewLibrary.
public void testSetUpLibraryWithNewLibrary() throws IOException {
File binaryPath = createTempFile("fakeLibrary", "jar");
File sourcePath = createTempFile("fakeLibrary-src", "jar");
when(myLibraryFilePaths.findSourceJarPath(binaryPath)).thenReturn(sourcePath);
String libraryName = binaryPath.getName();
Module module = getModule();
IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
File[] binaryPaths = { binaryPath };
myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, libraryName, COMPILE, binaryPath, binaryPaths, EMPTY_FILE_ARRAY);
// Apply changes before checking state.
ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
List<LibraryOrderEntry> libraryOrderEntries = getLibraryOrderEntries(module);
// Only one library should be in the library table.
assertThat(libraryOrderEntries).hasSize(1);
Library library = libraryOrderEntries.get(0).getLibrary();
assertNotNull(library);
assertEquals(libraryName, library.getName());
String[] binaryUrls = library.getUrls(CLASSES);
assertThat(binaryUrls).hasLength(1);
assertEquals(pathToIdeaUrl(binaryPath), binaryUrls[0]);
String[] sourceUrls = library.getUrls(SOURCES);
assertThat(sourceUrls).hasLength(1);
assertEquals(pathToIdeaUrl(sourcePath), sourceUrls[0]);
// Should not mark new libraries as "used"
verify(myLibraryRegistry, never()).markAsUsed(library, binaryPaths);
verify(myLibraryFilePaths).findSourceJarPath(binaryPath);
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project android by JetBrains.
the class AndroidModuleDependenciesSetupTest method getLibraryOrderEntries.
@NotNull
private static List<LibraryOrderEntry> getLibraryOrderEntries(@NotNull Module module) {
List<LibraryOrderEntry> libraryOrderEntries = new ArrayList<>();
OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry) {
libraryOrderEntries.add((LibraryOrderEntry) orderEntry);
}
}
return libraryOrderEntries;
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.
the class LibraryEditingUtil method getNotAddedSuitableLibrariesCondition.
public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
final OrderEntry[] orderEntries = rootModel.getOrderEntries();
final Set<Library> result = new HashSet<>(orderEntries.length);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
final LibraryImpl library = (LibraryImpl) ((LibraryOrderEntry) orderEntry).getLibrary();
if (library != null) {
final Library source = library.getSource();
result.add(source != null ? source : library);
}
}
}
return new Predicate<Library>() {
@Override
public boolean apply(Library library) {
if (result.contains(library))
return false;
if (library instanceof LibraryImpl) {
final Library source = ((LibraryImpl) library).getSource();
if (source != null && result.contains(source))
return false;
}
PersistentLibraryKind<?> kind = ((LibraryEx) library).getKind();
if (kind != null) {
LibraryType type = LibraryType.findByKind(kind);
if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
return false;
}
}
return true;
}
};
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.
the class AddNewModuleLibraryAction method createTableItem.
@Override
protected ClasspathTableItem<?> createTableItem(final Library item) {
final OrderEntry[] entries = myClasspathPanel.getRootModel().getOrderEntries();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
if (item.equals(libraryOrderEntry.getLibrary())) {
return ClasspathTableItem.createLibItem(libraryOrderEntry, myContext);
}
}
}
LOG.error("Unknown library " + item);
return null;
}
use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.
the class ChangeLibraryLevelInClasspathAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final OrderEntry entry = myPanel.getSelectedEntry();
if (!(entry instanceof LibraryOrderEntry))
return;
LibraryOrderEntry libraryEntry = (LibraryOrderEntry) entry;
final LibraryEx library = (LibraryEx) libraryEntry.getLibrary();
if (library == null)
return;
final Library copied = doCopy(library);
if (copied == null)
return;
if (!isConvertingToModuleLibrary()) {
OrderEntryUtil.replaceLibrary(myPanel.getRootModel(), library, copied);
} else {
OrderEntryUtil.replaceLibraryEntryByAdded(myPanel.getRootModel(), libraryEntry);
}
}
Aggregations