Search in sources :

Example 1 with SelfResolvingDependency

use of org.gradle.api.artifacts.SelfResolvingDependency in project atlas by alibaba.

the class TDependencyManager method gatherDependencies.

@NonNull
private DependencyContainer gatherDependencies(@NonNull Configuration configuration, @NonNull final VariantDependencies variantDeps, @NonNull Multimap<AndroidLibrary, Configuration> reverseLibMap, @NonNull Set<String> currentUnresolvedDependencies, @Nullable String testedProjectPath, @NonNull Set<String> artifactSet, @NonNull ScopeType scopeType) {
    // collect the artifacts first.
    Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts = Maps.newHashMap();
    configuration = collectArtifacts(configuration, artifacts);
    // keep a map of modules already processed so that we don't go through sections of the
    // graph that have been seen elsewhere.
    Map<ModuleVersionIdentifier, List<LibraryDependency>> foundLibraries = Maps.newHashMap();
    Map<ModuleVersionIdentifier, List<JarDependency>> foundJars = Maps.newHashMap();
    // get the graph for the Android and Jar dependencies. This does not include
    // local jars.
    List<LibraryDependency> libraryDependencies = Lists.newArrayList();
    List<JarDependency> jarDependencies = Lists.newArrayList();
    Set<? extends DependencyResult> dependencyResultSet = configuration.getIncoming().getResolutionResult().getRoot().getDependencies();
    for (DependencyResult dependencyResult : dependencyResultSet) {
        if (dependencyResult instanceof ResolvedDependencyResult) {
            addDependency(((ResolvedDependencyResult) dependencyResult).getSelected(), variantDeps, configuration, libraryDependencies, jarDependencies, foundLibraries, foundJars, artifacts, reverseLibMap, currentUnresolvedDependencies, testedProjectPath, Collections.emptyList(), artifactSet, scopeType, false, /*forceProvided*/
            0);
        } else if (dependencyResult instanceof UnresolvedDependencyResult) {
            ComponentSelector attempted = ((UnresolvedDependencyResult) dependencyResult).getAttempted();
            if (attempted != null) {
                currentUnresolvedDependencies.add(attempted.toString());
            }
        }
    }
    // also need to process local jar files, as they are not processed by the
    // resolvedConfiguration result. This only includes the local jar files for this project.
    List<JarDependency> localJars = Lists.newArrayList();
    for (Dependency dependency : configuration.getAllDependencies()) {
        if (dependency instanceof SelfResolvingDependency && !(dependency instanceof ProjectDependency)) {
            Set<File> files = ((SelfResolvingDependency) dependency).resolve();
            for (File localJarFile : files) {
                if (DEBUG_DEPENDENCY) {
                    System.out.println("LOCAL " + configuration.getName() + ": " + localJarFile.getName());
                }
                // only accept local jar, no other types.
                if (!localJarFile.getName().toLowerCase(Locale.getDefault()).endsWith(DOT_JAR)) {
                    variantDeps.getChecker().handleIssue(localJarFile.getAbsolutePath(), SyncIssue.TYPE_NON_JAR_LOCAL_DEP, SyncIssue.SEVERITY_ERROR, String.format("Project %s: Only Jar-type local dependencies are supported. Cannot handle: %s", project.getName(), localJarFile.getAbsolutePath()));
                } else {
                    JarDependency localJar;
                    switch(scopeType) {
                        case PACKAGE:
                            localJar = new JarDependency(localJarFile);
                            artifactSet.add(computeVersionLessCoordinateKey(localJar.getResolvedCoordinates()));
                            break;
                        case COMPILE:
                            MavenCoordinates coord = JarDependency.getCoordForLocalJar(localJarFile);
                            boolean provided = !artifactSet.contains(computeVersionLessCoordinateKey(coord));
                            localJar = new JarDependency(localJarFile, ImmutableList.of(), coord, null, provided);
                            break;
                        case COMPILE_ONLY:
                            // if we only have the compile scope, ignore computation of the
                            // provided bits.
                            localJar = new JarDependency(localJarFile);
                            break;
                        default:
                            throw new RuntimeException("unsupported ProvidedComputationAction");
                    }
                    localJars.add(localJar);
                }
            }
        }
    }
    return new DependencyContainerImpl(libraryDependencies, jarDependencies, localJars);
}
Also used : UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) JarDependency(com.android.builder.dependency.JarDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) DependencyContainerImpl(com.android.builder.dependency.DependencyContainerImpl) LibraryDependency(com.android.builder.dependency.LibraryDependency) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) JarDependency(com.android.builder.dependency.JarDependency) Dependency(org.gradle.api.artifacts.Dependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) MavenCoordinates(com.android.builder.model.MavenCoordinates) LibraryDependency(com.android.builder.dependency.LibraryDependency) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) File(java.io.File) NonNull(com.android.annotations.NonNull)

Example 2 with SelfResolvingDependency

use of org.gradle.api.artifacts.SelfResolvingDependency in project gradle by gradle.

the class DefaultSelfResolvingDependencyTest method contentsAreEqualWhenFileSetsAreEqual.

@Test
public void contentsAreEqualWhenFileSetsAreEqual() {
    SelfResolvingDependency equalDependency = new DefaultSelfResolvingDependency(source);
    SelfResolvingDependency differentSource = new DefaultSelfResolvingDependency(context.mock(FileCollectionInternal.class, "other"));
    Dependency differentType = context.mock(Dependency.class);
    assertTrue(dependency.contentEquals(dependency));
    assertTrue(dependency.contentEquals(equalDependency));
    assertFalse(dependency.contentEquals(differentSource));
    assertFalse(dependency.contentEquals(differentType));
}
Also used : SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) TaskDependency(org.gradle.api.tasks.TaskDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) Dependency(org.gradle.api.artifacts.Dependency) Test(org.junit.Test)

Example 3 with SelfResolvingDependency

use of org.gradle.api.artifacts.SelfResolvingDependency in project gradle by gradle.

the class DependencyClassPathNotationConverter method convert.

public void convert(DependencyFactory.ClassPathNotation notation, NotationConvertResult<? super SelfResolvingDependency> result) throws TypeConversionException {
    SelfResolvingDependency dependency = internCache.get(notation);
    if (dependency == null) {
        internCacheWriteLock.lock();
        try {
            dependency = maybeCreateUnderLock(notation);
        } finally {
            internCacheWriteLock.unlock();
        }
    }
    result.converted(dependency);
}
Also used : DefaultSelfResolvingDependency(org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency)

Example 4 with SelfResolvingDependency

use of org.gradle.api.artifacts.SelfResolvingDependency in project gradle by gradle.

the class DependencyClassPathNotationConverter method maybeCreateUnderLock.

private SelfResolvingDependency maybeCreateUnderLock(DependencyFactory.ClassPathNotation notation) {
    SelfResolvingDependency dependency = internCache.get(notation);
    if (dependency == null) {
        Collection<File> classpath = classPathRegistry.getClassPath(notation.name()).getAsFiles();
        boolean runningFromInstallation = currentGradleInstallation.getInstallation() != null;
        FileCollectionInternal files;
        if (runningFromInstallation && notation.equals(GRADLE_API)) {
            files = gradleApiFileCollection(classpath);
        } else if (runningFromInstallation && notation.equals(GRADLE_TEST_KIT)) {
            files = gradleTestKitFileCollection(classpath);
        } else {
            files = fileResolver.resolveFiles(classpath);
        }
        dependency = instantiator.newInstance(DefaultSelfResolvingDependency.class, new OpaqueComponentIdentifier(notation.displayName), files);
        internCache.put(notation, dependency);
    }
    return dependency;
}
Also used : DefaultSelfResolvingDependency(org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) OpaqueComponentIdentifier(org.gradle.internal.component.local.model.OpaqueComponentIdentifier) File(java.io.File) DefaultSelfResolvingDependency(org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency)

Example 5 with SelfResolvingDependency

use of org.gradle.api.artifacts.SelfResolvingDependency in project gradle by gradle.

the class DefaultIdeDependencyResolver method getIdeLocalFileDependencies.

/**
     * Gets IDE local file dependencies.
     *
     * @param configuration Configuration
     * @return IDE local file dependencies
     */
public List<IdeLocalFileDependency> getIdeLocalFileDependencies(Configuration configuration) {
    List<SelfResolvingDependency> externalDependencies = new ArrayList<SelfResolvingDependency>();
    findAllExternalDependencies(externalDependencies, new ArrayList<Dependency>(), configuration);
    List<IdeLocalFileDependency> ideLocalFileDependencies = new ArrayList<IdeLocalFileDependency>();
    for (SelfResolvingDependency externalDependency : externalDependencies) {
        Set<File> resolvedFiles = externalDependency.resolve(configuration.isTransitive());
        for (File resolvedFile : resolvedFiles) {
            IdeLocalFileDependency ideLocalFileDependency = new IdeLocalFileDependency(resolvedFile);
            ideLocalFileDependencies.add(ideLocalFileDependency);
        }
    }
    return ideLocalFileDependencies;
}
Also used : IdeLocalFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeLocalFileDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ArrayList(java.util.ArrayList) UnresolvedIdeRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.UnresolvedIdeRepoFileDependency) SelfResolvingDependency(org.gradle.api.artifacts.SelfResolvingDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) IdeLocalFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeLocalFileDependency) IdeProjectDependency(org.gradle.plugins.ide.internal.resolver.model.IdeProjectDependency) IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) Dependency(org.gradle.api.artifacts.Dependency) File(java.io.File)

Aggregations

SelfResolvingDependency (org.gradle.api.artifacts.SelfResolvingDependency)5 File (java.io.File)3 Dependency (org.gradle.api.artifacts.Dependency)3 ArrayList (java.util.ArrayList)2 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)2 DefaultSelfResolvingDependency (org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency)2 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2 NonNull (com.android.annotations.NonNull)1 DependencyContainerImpl (com.android.builder.dependency.DependencyContainerImpl)1 JarDependency (com.android.builder.dependency.JarDependency)1 LibraryDependency (com.android.builder.dependency.LibraryDependency)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 UnresolvedDependency (org.gradle.api.artifacts.UnresolvedDependency)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)1 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)1 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)1