Search in sources :

Example 1 with DefaultProjectDependency

use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency in project atlas by alibaba.

the class DependencyGroup method getProjectBundleCompile.

private Map<String, Set<DependencyResult>> getProjectBundleCompile(Configuration configuration, Set<String> bundleAddedSets) {
    Map<String, Set<DependencyResult>> bundleMap = new HashMap<>();
    configuration.getAllDependencies().forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            if (dependency instanceof DefaultProjectDependency) {
                DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency;
                String key = "project " + ":" + projectDependency.getName();
                if (!bundleAddedSets.contains(key)) {
                    return;
                }
                Set<DependencyResult> compileSets = new HashSet<>();
                try {
                    Set<ResolvedArtifact> resolvedArtifacts = projectDependency.getDependencyProject().getConfigurations().getByName("compile").getResolvedConfiguration().getResolvedArtifacts();
                    projectDependency.getDependencyProject().getConfigurations().getByName("compile").getIncoming().getResolutionResult().getRoot().getDependencies().forEach(new Consumer<DependencyResult>() {

                        @Override
                        public void accept(DependencyResult dependencyResult) {
                            if (!mainDexs.contains(dependencyResult.toString())) {
                                compileSets.add(dependencyResult);
                                if (dependencyResult instanceof DefaultResolvedDependencyResult) {
                                    ModuleVersionIdentifier moduleVersionIdentifier = ((DefaultResolvedDependencyResult) dependencyResult).getSelected().getModuleVersion();
                                    for (ResolvedArtifact resolvedArtifact : resolvedArtifacts) {
                                        if (resolvedArtifact.getModuleVersion().getId().equals(moduleVersionIdentifier)) {
                                            bundleCompileId.put(moduleVersionIdentifier, resolvedArtifact);
                                        }
                                    }
                                }
                            }
                        }
                    });
                } catch (UnknownConfigurationException e) {
                }
                bundleMap.put(projectDependency.getGroup() + ":" + projectDependency.getName(), compileSets);
            }
        }
    });
    return bundleMap;
}
Also used : DefaultResolvedArtifact(org.gradle.api.internal.artifacts.DefaultResolvedArtifact) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Consumer(java.util.function.Consumer) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DefaultResolvedDependencyResult(org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult)

Example 2 with DefaultProjectDependency

use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency in project wildfly-swarm by wildfly-swarm.

the class GradleArtifactResolvingHelper method doResolve.

private Collection<ResolvedArtifact> doResolve(final Collection<ArtifactSpec> deps, boolean transitive) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration().setTransitive(transitive);
    final DependencySet dependencySet = config.getDependencies();
    deps.forEach(spec -> {
        if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
            dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
        } else {
            final DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
            final DefaultDependencyArtifact da = new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
            d.addArtifact(da);
            dependencySet.add(d);
        }
    });
    if (transitive) {
        return config.getResolvedConfiguration().getResolvedArtifacts();
    }
    return config.getResolvedConfiguration().getFirstLevelModuleDependencies().stream().map(dep -> dep.getModuleArtifacts()).flatMap(artifacts -> artifacts.stream()).collect(Collectors.toList());
}
Also used : Iterator(java.util.Iterator) Project(org.gradle.api.Project) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Collection(java.util.Collection) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Set(java.util.Set) DefaultProjectAccessListener(org.gradle.api.internal.project.DefaultProjectAccessListener) DependencySet(org.gradle.api.artifacts.DependencySet) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) Configuration(org.gradle.api.artifacts.Configuration) Map(java.util.Map) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Collections(java.util.Collections) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) Configuration(org.gradle.api.artifacts.Configuration) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectAccessListener(org.gradle.api.internal.project.DefaultProjectAccessListener)

Example 3 with DefaultProjectDependency

use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency in project atlas by alibaba.

the class UpdatePomTask method getExtraMap.

private Map<String, DependencyExtraInfo> getExtraMap() {
    Map<String, DependencyExtraInfo> dependencyExtraInfoMap = new HashMap<>();
    DependencySet dependencies = project.getConfigurations().getByName("compile").getDependencies();
    dependencies.forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            String group = dependency.getGroup();
            String name = dependency.getName();
            String scope = "compile";
            String type = "";
            if (dependency instanceof DefaultProjectDependency) {
                DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency;
                if (projectDependency.getDependencyProject().getPlugins().hasPlugin(LibraryPlugin.class)) {
                    type = "aar";
                }
            }
            dependencyExtraInfoMap.put(group + ":" + name, new DependencyExtraInfo(type, scope));
        }
    });
    return dependencyExtraInfoMap;
}
Also used : HashMap(java.util.HashMap) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) LibraryPlugin(com.android.build.gradle.LibraryPlugin)

Example 4 with DefaultProjectDependency

use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency in project atlas by alibaba.

the class AtlasProjectDependencyManager method addProjectDependency.

public static void addProjectDependency(Project project, String variantName) {
    Task task = project.getTasks().findByName("prepare" + variantName + "Dependencies");
    if (null == task) {
        return;
    }
    DependencySet dependencies = project.getConfigurations().getByName(AtlasPlugin.BUNDLE_COMPILE).getDependencies();
    if (null == dependencies) {
        return;
    }
    dependencies.forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            if (dependency instanceof DefaultProjectDependency) {
                Project subProject = ((DefaultProjectDependency) dependency).getDependencyProject();
                Task assembleTask = subProject.getTasks().findByName("assembleRelease");
                task.dependsOn(assembleTask);
            }
        }
    });
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency)4 DependencySet (org.gradle.api.artifacts.DependencySet)3 Project (org.gradle.api.Project)2 Dependency (org.gradle.api.artifacts.Dependency)2 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)2 LibraryPlugin (com.android.build.gradle.LibraryPlugin)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Task (org.gradle.api.Task)1 Configuration (org.gradle.api.artifacts.Configuration)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)1 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)1