Search in sources :

Example 16 with ResolvedArtifact

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

the class TDependencyManager method resolveDependency.

/**
     * 解析依赖
     *
     * @param resolvedDependencyContainer
     * @param parent
     * @param resolvedComponentResult
     * @param artifacts
     * @param configDependencies
     * @param indent
     */
private void resolveDependency(ResolvedDependencyContainer resolvedDependencyContainer, ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node, Set<String> resolvedModules) {
    ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
    if (configDependencies.getChecker().checkForExclusion(moduleVersion)) {
        return;
    }
    if (moduleVersion.getName().equals("support-annotations") && moduleVersion.getGroup().equals("com.android.support")) {
        configDependencies.setAnnotationsPresent(true);
    }
    // now loop on all the artifact for this modules.
    List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
    if (null == moduleArtifacts) {
        return;
    }
    ComponentIdentifier id = resolvedComponentResult.getId();
    String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
    // 如果同时找到多个依赖,暂时没法判断是那个真正有用
    for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
        ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), resolvedArtifact.getType(), resolvedArtifact.getClassifier());
        resolvedDependencyInfo.setIndent(indent);
        resolvedDependencyInfo.setGradlePath(gradlePath);
        resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
        //String parentVersionString = parent.getType();
        String moduleVersonString = moduleVersion.toString() + "." + resolvedArtifact.getType() + "." + resolvedArtifact.getClassifier() + "." + indent;
        if (null != parent) {
            if ("awb".equals(parent.getType())) {
                moduleVersonString = parent.toString() + "->" + moduleVersonString;
            }
        }
        if (resolvedModules.contains(moduleVersonString)) {
            logger.info(moduleVersonString);
            continue;
        } else {
            resolvedModules.add(moduleVersonString);
        }
        String path = computeArtifactPath(moduleVersion, resolvedArtifact);
        String name = computeArtifactName(moduleVersion, resolvedArtifact);
        File explodedDir = project.file(project.getBuildDir() + "/" + FD_INTERMEDIATES + "/exploded-" + resolvedArtifact.getType().toLowerCase() + "/" + path);
        resolvedDependencyInfo.setExplodedDir(explodedDir);
        resolvedDependencyInfo.setDependencyName(name);
        if (null == parent) {
            parent = resolvedDependencyInfo;
        } else {
            if (null == resolvedDependencyInfo.getParent()) {
                resolvedDependencyInfo.setParent(parent);
            }
            parent.getChildren().add(resolvedDependencyInfo);
        }
        Set<? extends DependencyResult> dependencies = resolvedComponentResult.getDependencies();
        for (DependencyResult dep : dependencies) {
            if (dep instanceof ResolvedDependencyResult) {
                ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
                CircleDependencyCheck.DependencyNode childNode = circleDependencyCheck.addDependency(childResolvedComponentResult.getModuleVersion(), node, indent + 1);
                CircleDependencyCheck.CircleResult circleResult = circleDependencyCheck.checkCircle(logger);
                if (circleResult.hasCircle) {
                    logger.warning("[CircleDependency]" + StringUtils.join(circleResult.detail, ";"));
                } else {
                    resolveDependency(resolvedDependencyContainer, parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode, resolvedModules);
                }
            }
        }
        resolvedDependencyContainer.addDependency(resolvedDependencyInfo);
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedDependencyInfo(com.taobao.android.builder.dependency.ResolvedDependencyInfo) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) CircleDependencyCheck(com.taobao.android.builder.dependency.CircleDependencyCheck) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) File(java.io.File) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult)

Example 17 with ResolvedArtifact

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

the class DependencyConvertUtils method toApLibrary.

public static ApLibrary toApLibrary(ResolvedDependencyInfo resolvedDependencyInfo) {
    assertType(Type.AP, resolvedDependencyInfo);
    ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact();
    ApLibrary apLibrary = new ApLibrary(convert(artifact), artifact.getFile(), resolvedDependencyInfo.getExplodedDir());
    return apLibrary;
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ApLibrary(com.taobao.android.builder.dependency.model.ApLibrary)

Example 18 with ResolvedArtifact

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

the class DependencyConvertUtils method toJarDependency.

/**
     * 转换为jar依赖
     *
     * @param resolvedDependencyInfo
     * @return
     */
private static JarDependency toJarDependency(ResolvedDependencyInfo resolvedDependencyInfo, boolean containChild) {
    assertType(Type.JAR, resolvedDependencyInfo);
    ResolvedArtifact artifact = resolvedDependencyInfo.getResolvedArtifact();
    List<JarDependency> dependencies = Lists.newArrayList();
    if (containChild) {
        collectChildren(resolvedDependencyInfo, Lists.<LibraryDependency>newArrayList(), dependencies, Lists.<SoLibrary>newArrayList());
    }
    JarDependency jarInfo = new JarDependency(artifact.getFile(), dependencies, convert(artifact), resolvedDependencyInfo.getGradlePath(), false);
    return jarInfo;
}
Also used : JarDependency(com.android.builder.dependency.JarDependency) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact)

Example 19 with ResolvedArtifact

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

the class ProjectLibraries method getLibraries.

private Set<GradleLibrary> getLibraries(String configurationName, LibraryScope scope) {
    Configuration configuration = (configurationName == null ? null : this.project.getConfigurations().findByName(configurationName));
    if (configuration == null) {
        return null;
    }
    Set<GradleLibrary> libraries = new LinkedHashSet<>();
    for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
        libraries.add(new ResolvedArtifactLibrary(artifact, scope));
    }
    libraries.addAll(getLibrariesForFileDependencies(configuration, scope));
    return libraries;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration)

Aggregations

ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)19 File (java.io.File)6 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)6 LinkedHashSet (java.util.LinkedHashSet)5 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)4 ArrayList (java.util.ArrayList)3 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)3 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)3 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)3 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3 JarDependency (com.android.builder.dependency.JarDependency)2 Configuration (org.gradle.api.artifacts.Configuration)2 ResolvedDependency (org.gradle.api.artifacts.ResolvedDependency)2 LibraryDependency (com.android.builder.dependency.LibraryDependency)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 CircleDependencyCheck (com.taobao.android.builder.dependency.CircleDependencyCheck)1