Search in sources :

Example 1 with IdeaDependencyScope

use of org.gradle.tooling.model.idea.IdeaDependencyScope in project android by JetBrains.

the class JavaModuleDependency method copy.

@Nullable
public static JavaModuleDependency copy(IdeaModuleDependency original) {
    IdeaModule module = original.getDependencyModule();
    if (module != null && isNotEmpty(module.getName())) {
        String scope = null;
        IdeaDependencyScope originalScope = original.getScope();
        if (originalScope != null) {
            scope = originalScope.getScope();
        }
        return new JavaModuleDependency(module.getName(), scope, original.getExported());
    }
    return null;
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) IdeaDependencyScope(org.gradle.tooling.model.idea.IdeaDependencyScope) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IdeaDependencyScope

use of org.gradle.tooling.model.idea.IdeaDependencyScope in project android by JetBrains.

the class JarLibraryDependencyTest method testCopyWithResolvedDependency.

@Test
public void testCopyWithResolvedDependency() {
    FileStub binaryPath = new FileStub("fake.jar", true);
    FileStub sourcePath = new FileStub("fake-src.jar", true);
    FileStub javadocPath = new FileStub("fake-javadoc.jar", true);
    IdeaDependencyScope scope = mock(IdeaDependencyScope.class);
    GradleModuleVersion moduleVersion = mock(GradleModuleVersion.class);
    when(myOriginalDependency.getFile()).thenReturn(binaryPath);
    when(myOriginalDependency.getSource()).thenReturn(sourcePath);
    when(myOriginalDependency.getJavadoc()).thenReturn(javadocPath);
    when(myOriginalDependency.getScope()).thenReturn(scope);
    when(myOriginalDependency.getGradleModuleVersion()).thenReturn(moduleVersion);
    when(scope.getScope()).thenReturn("compile");
    JarLibraryDependency dependency = JarLibraryDependency.copy(myOriginalDependency);
    assertNotNull(dependency);
    assertEquals("fake", dependency.getName());
    assertEquals("compile", dependency.getScope());
    assertSame(binaryPath, dependency.getBinaryPath());
    assertSame(sourcePath, dependency.getSourcePath());
    assertSame(javadocPath, dependency.getJavadocPath());
    assertSame(moduleVersion, dependency.getModuleVersion());
    assertTrue(dependency.isResolved());
}
Also used : IdeaDependencyScope(org.gradle.tooling.model.idea.IdeaDependencyScope) GradleModuleVersion(org.gradle.tooling.model.GradleModuleVersion) Test(org.junit.Test)

Example 3 with IdeaDependencyScope

use of org.gradle.tooling.model.idea.IdeaDependencyScope in project android by JetBrains.

the class JarLibraryDependency method copy.

@Nullable
public static JarLibraryDependency copy(@NotNull IdeaSingleEntryLibraryDependency original) {
    File binaryPath = original.getFile();
    if (binaryPath != null) {
        String scope = null;
        IdeaDependencyScope originalScope = original.getScope();
        if (originalScope != null) {
            scope = originalScope.getScope();
        }
        boolean resolved = isResolved(original);
        String name;
        if (resolved) {
            // Gradle API doesn't provide library name at the moment.
            name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(binaryPath.getPath());
        } else {
            name = getUnresolvedDependencyName(original);
            if (name == null) {
                return null;
            }
        }
        return new JarLibraryDependency(name, binaryPath, original.getSource(), original.getJavadoc(), scope, original.getGradleModuleVersion(), resolved);
    }
    return null;
}
Also used : IdeaDependencyScope(org.gradle.tooling.model.idea.IdeaDependencyScope) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IdeaDependencyScope

use of org.gradle.tooling.model.idea.IdeaDependencyScope in project android by JetBrains.

the class JavaModuleDependencyTest method testCopy.

@Test
public void testCopy() {
    String moduleName = "lib";
    IdeaDependencyScope scope = createMock(IdeaDependencyScope.class);
    expect(myOriginalDependency.getDependencyModule()).andStubReturn(myIdeaModule);
    expect(myIdeaModule.getName()).andStubReturn(moduleName);
    expect(myOriginalDependency.getScope()).andStubReturn(scope);
    expect(myOriginalDependency.getExported()).andStubReturn(true);
    expect(scope.getScope()).andStubReturn("compile");
    replay(myOriginalDependency, myIdeaModule, scope);
    JavaModuleDependency copy = JavaModuleDependency.copy(myOriginalDependency);
    assertNotNull(copy);
    assertEquals(moduleName, copy.getModuleName());
    assertSame("compile", copy.getScope());
    assertTrue(copy.isExported());
    verify(myOriginalDependency, myIdeaModule, scope);
}
Also used : IdeaDependencyScope(org.gradle.tooling.model.idea.IdeaDependencyScope) Test(org.junit.Test)

Aggregations

IdeaDependencyScope (org.gradle.tooling.model.idea.IdeaDependencyScope)4 Nullable (org.jetbrains.annotations.Nullable)2 Test (org.junit.Test)2 File (java.io.File)1 GradleModuleVersion (org.gradle.tooling.model.GradleModuleVersion)1 IdeaModule (org.gradle.tooling.model.idea.IdeaModule)1