Search in sources :

Example 1 with LibraryToUpdate

use of com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate 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()));
}
Also used : LibraryToUpdate(com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 2 with LibraryToUpdate

use of com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate 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));
}
Also used : LibraryToUpdate(com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 3 with LibraryToUpdate

use of com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate in project android by JetBrains.

the class SyncLibraryRegistryTest method testGetLibrariesToUpdateWhenUrlsWereRemoved.

public void testGetLibrariesToUpdateWhenUrlsWereRemoved() throws IOException {
    File jarPath1 = createTempFile("fake1.jar", null);
    File jarPath2 = createTempFile("fake2.jar", null);
    Library library = simulateProjectHasLibrary(jarPath1, jarPath2);
    SyncLibraryRegistry libraryRegistry = SyncLibraryRegistry.getInstance(getProject());
    libraryRegistry.markAsUsed(library, jarPath1);
    List<LibraryToUpdate> librariesToUpdate = libraryRegistry.getLibrariesToUpdate();
    assertThat(librariesToUpdate).hasSize(1);
    LibraryToUpdate libraryToUpdate = librariesToUpdate.get(0);
    assertSame(library, libraryToUpdate.getLibrary());
    assertThat(libraryToUpdate.getNewBinaryUrls()).containsExactly(pathToUrl(jarPath1.getPath()));
}
Also used : LibraryToUpdate(com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 4 with LibraryToUpdate

use of com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate in project android by JetBrains.

the class LibraryCleanupStepTest method testCleanUpProject.

public void testCleanUpProject() throws Exception {
    Library libraryToRemove = mock(Library.class);
    when(myLibraryRegistry.getLibrariesToRemove()).thenReturn(Collections.singleton(libraryToRemove));
    Library changedLibrary = mock(Library.class);
    LibraryToUpdate libraryToUpdate = new LibraryToUpdate(changedLibrary, Collections.singletonList("jar:/new.jar"));
    when(myLibraryRegistry.getLibrariesToUpdate()).thenReturn(Collections.singletonList(libraryToUpdate));
    Library.ModifiableModel libraryToUpdateModel = mock(Library.ModifiableModel.class);
    when(myModelsProvider.getModifiableLibraryModel(changedLibrary)).thenReturn(libraryToUpdateModel);
    when(libraryToUpdateModel.getUrls(CLASSES)).thenReturn(new String[] { "jar:/existing.jar" });
    myCleanupStep.cleanUpProject(getProject(), myModelsProvider, null);
    // Verify library got removed
    verify(myModelsProvider).removeLibrary(libraryToRemove);
    // Verify URLs got updated
    verify(libraryToUpdateModel).removeRoot("jar:/existing.jar", CLASSES);
    verify(libraryToUpdateModel).addRoot("jar:/new.jar", CLASSES);
    //noinspection SSBasedInspection
    verify(myLibraryRegistry).dispose();
}
Also used : LibraryToUpdate(com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryToUpdate (com.android.tools.idea.gradle.project.sync.setup.module.SyncLibraryRegistry.LibraryToUpdate)4 Library (com.intellij.openapi.roots.libraries.Library)4 File (java.io.File)3