Search in sources :

Example 1 with Dependency

use of org.gradle.api.artifacts.Dependency 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 Dependency

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

the class DependencyManager method ensureConfigured.

private void ensureConfigured(Configuration config) {
    for (Dependency dependency : config.getAllDependencies()) {
        if (dependency instanceof ProjectDependency) {
            ProjectDependency projectDependency = (ProjectDependency) dependency;
            project.evaluationDependsOn(projectDependency.getDependencyProject().getPath());
            try {
                ensureConfigured(projectDependency.getProjectConfiguration());
            } catch (Throwable e) {
                throw new UnknownProjectException(String.format("Cannot evaluate module %s : %s", projectDependency.getName(), e.getMessage()), e);
            }
        }
    }
}
Also used : ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) UnknownProjectException(org.gradle.api.UnknownProjectException) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 3 with Dependency

use of org.gradle.api.artifacts.Dependency 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 4 with Dependency

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

the class CoffeeScriptBasePlugin method addJsConfiguration.

private Configuration addJsConfiguration(ConfigurationContainer configurations, final DependencyHandler dependencies, final CoffeeScriptExtension extension) {
    Configuration configuration = configurations.create(CoffeeScriptExtension.JS_CONFIGURATION_NAME);
    configuration.defaultDependencies(new Action<DependencySet>() {

        @Override
        public void execute(DependencySet configDependencies) {
            String notation = CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_GROUP + ":" + CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_MODULE + ":" + extension.getVersion() + "@js";
            Dependency dependency = dependencies.create(notation);
            configDependencies.add(dependency);
        }
    });
    return configuration;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DependencySet(org.gradle.api.artifacts.DependencySet) Dependency(org.gradle.api.artifacts.Dependency)

Example 5 with Dependency

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

the class ArtifactRepositoryPluginResolver method exists.

/*
     * Checks whether the implementation artifact exists in the backing artifact repository.
     */
private boolean exists(PluginRequestInternal request) {
    Dependency dependency = resolution.getDependencyHandler().create(getMarkerDependency(request));
    ConfigurationContainer configurations = resolution.getConfigurationContainer();
    Configuration configuration = configurations.detachedConfiguration(dependency);
    configuration.setTransitive(false);
    return !configuration.getResolvedConfiguration().hasError();
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)58 Configuration (org.gradle.api.artifacts.Configuration)20 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)16 File (java.io.File)13 Project (org.gradle.api.Project)13 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)12 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)8 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)6 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 DependencySet (org.gradle.api.artifacts.DependencySet)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 TaskDependency (org.gradle.api.tasks.TaskDependency)5 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 LinkedHashSet (java.util.LinkedHashSet)4