Search in sources :

Example 1 with AndroidLibraryStub

use of com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub in project android by JetBrains.

the class DependenciesExtractorTest method testExtractFromWithLibraryAar.

public void testExtractFromWithLibraryAar() {
    String rootDirPath = myAndroidProject.getRootDir().getPath();
    File bundle = new File(rootDirPath, "bundle.aar");
    File libJar = new File(rootDirPath, FileUtil.join("bundle_aar", "library.jar"));
    AndroidLibraryStub library = new AndroidLibraryStub(bundle, libJar);
    myVariant.getMainArtifact().getDependencies().addLibrary(library);
    myVariant.getInstrumentTestArtifact().getDependencies().addLibrary(library);
    Collection<LibraryDependency> dependencies = myDependenciesExtractor.extractFrom(myAndroidModel).onLibraries();
    assertEquals(1, dependencies.size());
    LibraryDependency dependency = ContainerUtil.getFirstItem(dependencies);
    assertNotNull(dependency);
    assertEquals("bundle", dependency.getName());
    // Make sure that is a "compile" dependency, even if specified as "test".
    assertEquals(DependencyScope.COMPILE, dependency.getScope());
    File[] binaryPaths = dependency.getPaths(LibraryDependency.PathType.BINARY);
    assertThat(binaryPaths).hasLength(2);
    assertThat(binaryPaths).asList().contains(libJar);
}
Also used : AndroidLibraryStub(com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub) File(java.io.File)

Example 2 with AndroidLibraryStub

use of com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub in project android by JetBrains.

the class DependenciesExtractorTest method testExtractFromWithLibraryLocalJar.

public void testExtractFromWithLibraryLocalJar() {
    String rootDirPath = myAndroidProject.getRootDir().getPath();
    File bundle = new File(rootDirPath, "bundle.aar");
    File libJar = new File(rootDirPath, FileUtil.join("bundle_aar", "library.jar"));
    File resFolder = new File(rootDirPath, FileUtil.join("bundle_aar", "res"));
    AndroidLibraryStub library = new AndroidLibraryStub(bundle, libJar);
    File localJar = new File(rootDirPath, "local.jar");
    library.addLocalJar(localJar);
    myVariant.getMainArtifact().getDependencies().addLibrary(library);
    myVariant.getInstrumentTestArtifact().getDependencies().addLibrary(library);
    List<LibraryDependency> dependencies = Lists.newArrayList(myDependenciesExtractor.extractFrom(myAndroidModel).onLibraries());
    assertEquals(1, dependencies.size());
    LibraryDependency dependency = dependencies.get(0);
    assertNotNull(dependency);
    assertEquals("bundle", dependency.getName());
    File[] binaryPaths = dependency.getPaths(LibraryDependency.PathType.BINARY);
    assertThat(binaryPaths).hasLength(3);
    assertThat(binaryPaths).asList().containsAllOf(localJar, libJar, resFolder);
}
Also used : AndroidLibraryStub(com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub) File(java.io.File)

Example 3 with AndroidLibraryStub

use of com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub in project android by JetBrains.

the class DependenciesExtractorTest method testExtractFromWithLibraryProject.

public void testExtractFromWithLibraryProject() {
    String rootDirPath = myAndroidProject.getRootDir().getPath();
    File bundle = new File(rootDirPath, "bundle.aar");
    File libJar = new File(rootDirPath, FileUtil.join("bundle_aar", "library.jar"));
    File resFolder = new File(rootDirPath, FileUtil.join("bundle_aar", "res"));
    String gradlePath = "abc:xyz:library";
    AndroidLibraryStub library = new AndroidLibraryStub(bundle, libJar, gradlePath);
    myVariant.getMainArtifact().getDependencies().addLibrary(library);
    myVariant.getInstrumentTestArtifact().getDependencies().addLibrary(library);
    Collection<ModuleDependency> dependencies = myDependenciesExtractor.extractFrom(myAndroidModel).onModules();
    assertEquals(1, dependencies.size());
    ModuleDependency dependency = ContainerUtil.getFirstItem(dependencies);
    assertNotNull(dependency);
    assertEquals(gradlePath, dependency.getGradlePath());
    // Make sure that is a "compile" dependency, even if specified as "test".
    assertEquals(DependencyScope.COMPILE, dependency.getScope());
    LibraryDependency backup = dependency.getBackupDependency();
    assertNotNull(backup);
    assertEquals("bundle", backup.getName());
    assertEquals(DependencyScope.COMPILE, backup.getScope());
    File[] backupBinaryPaths = backup.getPaths(LibraryDependency.PathType.BINARY);
    assertThat(backupBinaryPaths).hasLength(2);
    assertThat(backupBinaryPaths).asList().containsAllOf(libJar, resFolder);
}
Also used : AndroidLibraryStub(com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub) File(java.io.File)

Example 4 with AndroidLibraryStub

use of com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub in project android by JetBrains.

the class ProjectResourceRepositoryTest method addArchiveLibraries.

private void addArchiveLibraries() {
    // Add in some Android projects too
    // make it a Gradle project
    myFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
    AndroidProjectStub androidProject = TestProjects.createFlavorsProject();
    VariantStub variant = androidProject.getFirstVariant();
    assertNotNull(variant);
    File rootDir = androidProject.getRootDir();
    AndroidModuleModel androidModel = new AndroidModuleModel(androidProject.getName(), rootDir, androidProject, variant.getName());
    myFacet.setAndroidModel(androidModel);
    File bundle = new File(rootDir, "bundle.aar");
    File libJar = new File(rootDir, "bundle_aar" + File.separatorChar + "library.jar");
    AndroidLibraryStub library = new AndroidLibraryStub(bundle, libJar);
    variant.getMainArtifact().getDependencies().addLibrary(library);
}
Also used : AndroidProjectStub(com.android.tools.idea.gradle.stubs.android.AndroidProjectStub) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) VariantStub(com.android.tools.idea.gradle.stubs.android.VariantStub) AndroidLibraryStub(com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Aggregations

AndroidLibraryStub (com.android.tools.idea.gradle.stubs.android.AndroidLibraryStub)4 File (java.io.File)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidProjectStub (com.android.tools.idea.gradle.stubs.android.AndroidProjectStub)1 VariantStub (com.android.tools.idea.gradle.stubs.android.VariantStub)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1