Search in sources :

Example 51 with ProjectComponentIdentifier

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

the class AtlasDependencyGraph method computeMavenCoordinates.

@NonNull
private static MavenCoordinates computeMavenCoordinates(@NonNull ResolvedArtifactResult artifact) {
    // instance should be a hashable.
    AtlasDependencyGraph.HashableResolvedArtifactResult hashableResult = (AtlasDependencyGraph.HashableResolvedArtifactResult) artifact;
    ComponentIdentifier id = artifact.getId().getComponentIdentifier();
    final File artifactFile = artifact.getFile();
    final String fileName = artifactFile.getName();
    String extension = hashableResult.getDependencyType().getExtension();
    if (id instanceof ModuleComponentIdentifier) {
        ModuleComponentIdentifier moduleComponentId = (ModuleComponentIdentifier) id;
        final String module = moduleComponentId.getModule();
        final String version = moduleComponentId.getVersion();
        String classifier = null;
        if (!artifact.getFile().isDirectory()) {
            // attempts to compute classifier based on the filename.
            String pattern = "^" + module + "-" + version + "-(.+)\\." + extension + "$";
            Pattern p = Pattern.compile(pattern);
            Matcher m = p.matcher(fileName);
            if (m.matches()) {
                classifier = m.group(1);
            }
        }
        return new MavenCoordinatesImpl(moduleComponentId.getGroup(), module, version, extension, classifier);
    } else if (id instanceof ProjectComponentIdentifier) {
        return new MavenCoordinatesImpl("artifacts", ((ProjectComponentIdentifier) id).getProjectPath(), "unspecified");
    } else if (id instanceof OpaqueComponentArtifactIdentifier) {
        // We have a file based dependency
        if (hashableResult.getDependencyType() == DependencyType.JAVA) {
            return getMavenCoordForLocalFile(artifactFile);
        } else {
            // local aar?
            assert artifactFile.isDirectory();
            return getMavenCoordForLocalFile(artifactFile);
        }
    }
    throw new RuntimeException("Don't know how to compute maven coordinate for artifact '" + artifact.getId().getDisplayName() + "' with component identifier of type '" + id.getClass() + "'.");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) NonNull(com.android.annotations.NonNull)

Example 52 with ProjectComponentIdentifier

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

the class DependencyResolver method resolveDependency.

/**
 * Analytical dependence
 *  @param parent
 * @param resolvedComponentResult
 * @param artifacts
 * @param configDependencies
 * @param indent
 * @param mainBundle
 */
private void resolveDependency(ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node, Multimap<String, ResolvedDependencyInfo> dependenciesMap, Set<String> resolvedDependencies, boolean mainBundle) {
    ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
    // }
    if (!ids.contains(moduleVersion.getGroup() + ":" + moduleVersion.getName())) {
        artifacts.put(moduleVersion, Lists.newArrayList((DependencyGroup.bundleCompileId.get(moduleVersion))));
    }
    // now loop on all the artifact for this modules.
    List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
    ComponentIdentifier id = resolvedComponentResult.getId();
    String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
    // If you can find multiple dependencies at the same time, you can't judge for the time being that it's really useful
    if (null != moduleArtifacts) {
        for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
            String key = moduleVersion.getGroup() + ":" + moduleVersion.getName();
            // remove android.jar
            if (key.equals("com.google.android:android")) {
                continue;
            }
            if (mainDependencies.contains(key)) {
                continue;
            }
            if (resolvedDependencies.contains(key)) {
                continue;
            }
            // 
            resolvedDependencies.add(key);
            boolean isAwbBundle = bundleProvidedMap.containsKey(key);
            Set<String> providedDirectDep = bundleProvidedMap.get(key);
            ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), !mainBundle ? "awb" : resolvedArtifact.getType(), resolvedArtifact.getClassifier());
            resolvedDependencyInfo.setIndent(indent);
            resolvedDependencyInfo.setGradlePath(gradlePath);
            resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
            String path = AtlasDepHelper.computeArtifactPath(moduleVersion, resolvedArtifact);
            String name = AtlasDepHelper.computeArtifactName(moduleVersion, resolvedArtifact);
            MavenCoordinates mavenCoordinates = DependencyConvertUtils.convert(resolvedArtifact, !mainBundle ? DependencyConvertUtils.Type.AWB : DependencyConvertUtils.Type.AAR);
            File explodedDir = DependencyLocationManager.getExploreDir(project, mavenCoordinates, resolvedArtifact.getFile(), !mainBundle ? "awb" : resolvedArtifact.getType().toLowerCase(), path);
            resolvedDependencyInfo.setExplodedDir(explodedDir);
            resolvedDependencyInfo.setDependencyName(name);
            if (null == parent) {
                parent = resolvedDependencyInfo;
            } else {
                resolvedDependencyInfo.setParent(parent);
                parent.getChildren().add(resolvedDependencyInfo);
            }
            Set<DependencyResult> dependencyResults = null;
            Set<? extends DependencyResult> dependencies = (Set<DependencyResult>) resolvedComponentResult.getDependencies();
            if (bundleCompileMap.containsKey(resolvedDependencyInfo.getGroup() + ":" + resolvedDependencyInfo.getName())) {
                dependencyResults = bundleCompileMap.get(parent.getGroup() + ":" + parent.getName());
            }
            Set<DependencyResult> combineDependencies = combine(dependencyResults, dependencies);
            if (null != combineDependencies) {
                for (DependencyResult dep : combineDependencies) {
                    if (dep instanceof ResolvedDependencyResult) {
                        ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
                        if (isAwbBundle && providedDirectDep.contains(childResolvedComponentResult.getModuleVersion().getGroup() + ":" + childResolvedComponentResult.getModuleVersion().getName())) {
                            continue;
                        }
                        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(parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode, dependenciesMap, resolvedDependencies, true);
                        }
                    }
                }
            }
            addDependencyInfo(resolvedDependencyInfo, null, dependenciesMap);
        }
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) 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) MavenCoordinates(com.android.builder.model.MavenCoordinates) CircleDependencyCheck(com.taobao.android.builder.dependency.parser.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)

Aggregations

ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)52 File (java.io.File)12 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)12 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)9 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)9 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)7 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)6 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)6 Project (org.gradle.api.Project)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)5 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 LocalComponentRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.LocalComponentRegistry)5 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3