Search in sources :

Example 1 with ProjectDependency

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

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

use of org.gradle.api.artifacts.ProjectDependency in project gradle-eta by typelead.

the class DefaultEtaConfiguration method searchForEtaProjectDependencies.

public static List<String> searchForEtaProjectDependencies(final Project project, final Configuration configuration) {
    List<String> allMavenDependencies = new ArrayList<String>();
    for (Dependency dependency : configuration.getAllDependencies()) {
        if (dependency instanceof ProjectDependency) {
            final ProjectDependency projectDependency = (ProjectDependency) dependency;
            final Project targetProject = projectDependency.getDependencyProject();
            final String targetConfiguration = projectDependency.getTargetConfiguration();
            List<String> mavenDependencies;
            if (targetProject.getPlugins().hasPlugin(EtaBasePlugin.class)) {
                mavenDependencies = ConfigurationUtils.getEtaConfiguration(targetProject, targetConfiguration).getAllResolvedDependencies(project);
            } else {
                mavenDependencies = searchForEtaProjectDependencies(project, ConfigurationUtils.getConfiguration(targetProject, targetConfiguration));
            }
            allMavenDependencies.addAll(mavenDependencies);
        }
    }
    return allMavenDependencies;
}
Also used : Project(org.gradle.api.Project) ArrayList(java.util.ArrayList) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 4 with ProjectDependency

use of org.gradle.api.artifacts.ProjectDependency in project gradle-eta by typelead.

the class EtaInjectDependencies method injectProjectDependencies.

private void injectProjectDependencies(final Project project, final DependencyHandler dependencies, Configuration configuration) {
    final String configurationName = configuration.getName();
    for (Dependency dependency : configuration.getDependencies()) {
        if (dependency instanceof ProjectDependency) {
            final ProjectDependency projectDependency = (ProjectDependency) dependency;
            final Project targetProject = projectDependency.getDependencyProject();
            final String targetConfiguration = projectDependency.getTargetConfiguration();
            List<String> mavenDependencies;
            if (targetProject.getPlugins().hasPlugin(EtaBasePlugin.class)) {
                mavenDependencies = ConfigurationUtils.getEtaConfiguration(targetProject, targetConfiguration).getAllResolvedDependencies(project);
            } else {
                mavenDependencies = DefaultEtaConfiguration.searchForEtaProjectDependencies(project, ConfigurationUtils.getConfiguration(targetProject, targetConfiguration));
            }
            for (String mavenDependency : mavenDependencies) {
                dependencies.add(configurationName, mavenDependency);
            }
        }
    }
    for (Configuration parent : configuration.getExtendsFrom()) {
        injectProjectDependencies(project, dependencies, parent);
    }
}
Also used : Project(org.gradle.api.Project) Configuration(org.gradle.api.artifacts.Configuration) DefaultEtaConfiguration(com.typelead.gradle.eta.internal.DefaultEtaConfiguration) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) Dependency(org.gradle.api.artifacts.Dependency) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 5 with ProjectDependency

use of org.gradle.api.artifacts.ProjectDependency in project spring-boot by spring-projects.

the class AbstractBootArchiveTests method addContent.

@SuppressWarnings("unchecked")
void addContent() throws IOException {
    this.task.getMainClass().set("com.example.Main");
    File classesJavaMain = new File(this.temp, "classes/java/main");
    File applicationClass = new File(classesJavaMain, "com/example/Application.class");
    applicationClass.getParentFile().mkdirs();
    applicationClass.createNewFile();
    File resourcesMain = new File(this.temp, "resources/main");
    File applicationProperties = new File(resourcesMain, "application.properties");
    applicationProperties.getParentFile().mkdirs();
    applicationProperties.createNewFile();
    File staticResources = new File(resourcesMain, "static");
    staticResources.mkdir();
    File css = new File(staticResources, "test.css");
    css.createNewFile();
    this.task.classpath(classesJavaMain, resourcesMain, jarFile("first-library.jar"), jarFile("second-library.jar"), jarFile("third-library-SNAPSHOT.jar"), jarFile("first-project-library.jar"), jarFile("second-project-library-SNAPSHOT.jar"));
    Set<ResolvedArtifact> artifacts = new LinkedHashSet<>();
    artifacts.add(mockLibraryArtifact("first-library.jar", "com.example", "first-library", "1.0.0"));
    artifacts.add(mockLibraryArtifact("second-library.jar", "com.example", "second-library", "1.0.0"));
    artifacts.add(mockLibraryArtifact("third-library-SNAPSHOT.jar", "com.example", "third-library", "1.0.0.SNAPSHOT"));
    artifacts.add(mockProjectArtifact("first-project-library.jar", "com.example", "first-project-library", "1.0.0"));
    artifacts.add(mockProjectArtifact("second-project-library-SNAPSHOT.jar", "com.example", "second-project-library", "1.0.0.SNAPSHOT"));
    ResolvedConfiguration resolvedConfiguration = mock(ResolvedConfiguration.class);
    given(resolvedConfiguration.getResolvedArtifacts()).willReturn(artifacts);
    Configuration configuration = mock(Configuration.class);
    given(configuration.getResolvedConfiguration()).willReturn(resolvedConfiguration);
    ResolvableDependencies resolvableDependencies = mock(ResolvableDependencies.class);
    given(configuration.getIncoming()).willReturn(resolvableDependencies);
    DependencySet dependencies = mock(DependencySet.class);
    DomainObjectSet<ProjectDependency> projectDependencies = mock(DomainObjectSet.class);
    given(dependencies.withType(ProjectDependency.class)).willReturn(projectDependencies);
    given(configuration.getAllDependencies()).willReturn(dependencies);
    willAnswer((invocation) -> {
        invocation.getArgument(0, Action.class).execute(resolvableDependencies);
        return null;
    }).given(resolvableDependencies).afterResolve(any(Action.class));
    given(configuration.getIncoming()).willReturn(resolvableDependencies);
    populateResolvedDependencies(configuration);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ZipCopyAction(org.gradle.api.internal.file.archive.ZipCopyAction) Action(org.gradle.api.Action) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) DependencySet(org.gradle.api.artifacts.DependencySet) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) JarFile(java.util.jar.JarFile) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) ResolvableDependencies(org.gradle.api.artifacts.ResolvableDependencies)

Aggregations

ProjectDependency (org.gradle.api.artifacts.ProjectDependency)18 Dependency (org.gradle.api.artifacts.Dependency)7 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)6 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 Configuration (org.gradle.api.artifacts.Configuration)4 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)3 DefaultEtaConfiguration (com.typelead.gradle.eta.internal.DefaultEtaConfiguration)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 Project (org.gradle.api.Project)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 UsageContext (org.gradle.api.internal.component.UsageContext)3 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)3 File (java.io.File)2 Collectors (java.util.stream.Collectors)2 Action (org.gradle.api.Action)2 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)2