use of com.intellij.openapi.roots.libraries.Library in project android by JetBrains.
the class AndroidModuleDependenciesSetupTest method createLibrary.
@NotNull
private Library createLibrary(@NotNull File binaryPath, @NotNull File sourcePath) {
LibraryTable libraryTable = ProjectLibraryTable.getInstance(getProject());
LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();
Library library = libraryTableModel.createLibrary(binaryPath.getName());
Application application = ApplicationManager.getApplication();
application.runWriteAction(libraryTableModel::commit);
Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(pathToIdeaUrl(binaryPath), CLASSES);
libraryModel.addRoot(pathToIdeaUrl(sourcePath), SOURCES);
application.runWriteAction(libraryModel::commit);
return library;
}
use of com.intellij.openapi.roots.libraries.Library 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.libraries.Library in project android by JetBrains.
the class SyncLibraryRegistryTest method testMarkAsUsedWhenDisposed.
public void testMarkAsUsedWhenDisposed() {
SyncLibraryRegistry libraryRegistry = SyncLibraryRegistry.getInstance(getProject());
Disposer.dispose(libraryRegistry);
Library library = mock(Library.class);
try {
libraryRegistry.markAsUsed(library, EMPTY_FILE_ARRAY);
fail("Expecting error due to disposed instance");
} catch (IllegalStateException ignored) {
// expected
}
}
use of com.intellij.openapi.roots.libraries.Library in project android by JetBrains.
the class SyncLibraryRegistryTest method testGetLibrariesToUpdateWhenUrlsChanged.
public void testGetLibrariesToUpdateWhenUrlsChanged() throws IOException {
File fakeJarPath = createTempFile("fake.jar", null);
Library library = simulateProjectHasLibrary(fakeJarPath);
File newJarPath = createTempFile("fake2.jar", null);
SyncLibraryRegistry libraryRegistry = SyncLibraryRegistry.getInstance(getProject());
libraryRegistry.markAsUsed(library, newJarPath);
List<LibraryToUpdate> librariesToUpdate = libraryRegistry.getLibrariesToUpdate();
assertThat(librariesToUpdate).hasSize(1);
LibraryToUpdate libraryToUpdate = librariesToUpdate.get(0);
assertSame(library, libraryToUpdate.getLibrary());
assertThat(libraryToUpdate.getNewBinaryUrls()).containsExactly(pathToUrl(newJarPath.getPath()));
}
use of com.intellij.openapi.roots.libraries.Library in project android by JetBrains.
the class SyncLibraryRegistryTest method testGetLibrariesToUpdateWhenUrlsWereAdded.
public void testGetLibrariesToUpdateWhenUrlsWereAdded() throws IOException {
File fakeJarPath = createTempFile("fake.jar", null);
Library library = simulateProjectHasLibrary(fakeJarPath);
File newJarPath = createTempFile("fake2.jar", null);
SyncLibraryRegistry libraryRegistry = SyncLibraryRegistry.getInstance(getProject());
libraryRegistry.markAsUsed(library, fakeJarPath, newJarPath);
List<LibraryToUpdate> librariesToUpdate = libraryRegistry.getLibrariesToUpdate();
assertThat(librariesToUpdate).hasSize(1);
LibraryToUpdate libraryToUpdate = librariesToUpdate.get(0);
assertSame(library, libraryToUpdate.getLibrary());
assertThat(libraryToUpdate.getNewBinaryUrls()).containsExactly(pathToIdeaUrl(fakeJarPath), pathToIdeaUrl(newJarPath));
}
Aggregations