Search in sources :

Example 21 with ModuleVersionIdentifier

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

the class RepositoryChainDependencyToComponentIdResolver method resolve.

public void resolve(DependencyMetadata dependency, BuildableComponentIdResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    if (versionSelectorScheme.parseSelector(requested.getVersion()).isDynamic()) {
        dynamicRevisionResolver.resolve(dependency, result);
    } else {
        DefaultModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(requested.getGroup(), requested.getName(), requested.getVersion());
        ModuleVersionIdentifier mvId = moduleIdentifierFactory.moduleWithVersion(requested.getGroup(), requested.getName(), requested.getVersion());
        result.resolved(id, mvId);
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)

Example 22 with ModuleVersionIdentifier

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

the class AwoDependency method collectLibraryJars.

private void collectLibraryJars(LibVariantContext libVariantContext) {
    //TODO NPE protect
    Set<DependencyResult> providedDependencySet = getDependencyResults(libVariantContext, "providedCompile");
    Set<DependencyResult> compileDependencySet = getDependencyResults(libVariantContext, "compile");
    Set<DependencyResult> debugCompileDependencySet = getDependencyResults(libVariantContext, "debugCompile");
    if (null == providedDependencySet) {
        providedDependencySet = new HashSet<DependencyResult>();
    }
    if (null == compileDependencySet) {
        compileDependencySet = new HashSet<DependencyResult>();
    } else {
        compileDependencySet = new HashSet<DependencyResult>(compileDependencySet);
    }
    if (null != debugCompileDependencySet && !debugCompileDependencySet.isEmpty()) {
        try {
            ((HashSet<DependencyResult>) compileDependencySet).addAll(debugCompileDependencySet);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    Set<ResolvedDependencyResult> compileOnlyDependencySet = new HashSet<ResolvedDependencyResult>();
    for (DependencyResult resolvedDependencyResult : compileDependencySet) {
        if (resolvedDependencyResult instanceof ResolvedDependencyResult) {
            ModuleVersionIdentifier moduleVersion = ((ResolvedDependencyResult) resolvedDependencyResult).getSelected().getModuleVersion();
            String key = moduleVersion.getGroup() + "-" + moduleVersion.getName();
            boolean exclude = false;
            for (DependencyResult resolvedDependencyResult2 : providedDependencySet) {
                if (resolvedDependencyResult2 instanceof ResolvedDependencyResult) {
                    ModuleVersionIdentifier moduleVersion2 = ((ResolvedDependencyResult) resolvedDependencyResult2).getSelected().getModuleVersion();
                    String key2 = moduleVersion2.getGroup() + "-" + moduleVersion2.getName();
                    if (key.equals(key2)) {
                        exclude = true;
                        break;
                    }
                }
            }
            if (!exclude) {
                compileOnlyDependencySet.add((ResolvedDependencyResult) resolvedDependencyResult);
            }
        }
    }
    collectDependens(compileOnlyDependencySet);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) HashSet(java.util.HashSet)

Example 23 with ModuleVersionIdentifier

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

the class TDependencyManager method collectArtifacts.

/**
     * Collects the resolved artifacts and returns a configuration which contains them. If the
     * configuration has unresolved dependencies we check that we have the latest version of the
     * Google repository and the Android Support repository and we install them if not. After this,
     * the resolution is retried with a fresh copy of the configuration, that will contain the newly
     * updated repositories. If this passes, we return the correct configuration and we fill the
     * artifacts map.
     *
     * @param configuration the configuration from which we get the artifacts
     * @param artifacts     the map of artifacts that are being collected
     * @return a valid configuration that has only resolved dependencies.
     */
private Configuration collectArtifacts(Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) {
    Set<ResolvedArtifact> allArtifacts;
    // Make a copy because Gradle keeps a per configuration state of resolution that we
    // need to reset.
    Configuration configurationCopy = configuration.copyRecursive();
    Set<UnresolvedDependency> unresolvedDependencies = configuration.getResolvedConfiguration().getLenientConfiguration().getUnresolvedModuleDependencies();
    if (unresolvedDependencies.isEmpty()) {
        allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts();
    } else {
        if (!repositoriesUpdated && sdkLibData.useSdkDownload()) {
            List<String> repositoryPaths = new ArrayList<>();
            for (UnresolvedDependency dependency : unresolvedDependencies) {
                if (isGoogleOwnedDependency(dependency.getSelector())) {
                    repositoryPaths.add(getRepositoryPath(dependency.getSelector()));
                }
            }
            sdkLibData.setNeedsCacheReset(sdkHandler.checkResetCache());
            List<File> updatedRepositories = sdkHandler.getSdkLoader().updateRepositories(repositoryPaths, sdkLibData, logger);
            // resolution result.
            for (File updatedRepository : updatedRepositories) {
                project.getRepositories().maven(newRepo -> {
                    newRepo.setName("Updated " + updatedRepository.getPath());
                    newRepo.setUrl(updatedRepository.toURI());
                    newRepo.artifactUrls(project.getRootProject().file("sdk-manager"));
                });
            }
            repositoriesUpdated = true;
        }
        if (extraModelInfo.getMode() != STANDARD) {
            allArtifacts = configurationCopy.getResolvedConfiguration().getLenientConfiguration().getArtifacts(Specs.satisfyAll());
        } else {
            allArtifacts = configurationCopy.getResolvedConfiguration().getResolvedArtifacts();
        }
        // Modify the configuration to the one that passed.
        configuration = configurationCopy;
    }
    for (ResolvedArtifact artifact : allArtifacts) {
        ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
        List<ResolvedArtifact> moduleArtifacts = artifacts.get(id);
        if (moduleArtifacts == null) {
            moduleArtifacts = Lists.newArrayList();
            artifacts.put(id, moduleArtifacts);
        }
        if (!moduleArtifacts.contains(artifact)) {
            moduleArtifacts.add(artifact);
        }
    }
    return configuration;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) ArrayList(java.util.ArrayList) File(java.io.File)

Example 24 with ModuleVersionIdentifier

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

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

the class DefaultImmutableModuleIdentifierFactory method moduleWithVersion.

@Override
public ModuleVersionIdentifier moduleWithVersion(ModuleIdentifier mi, String version) {
    Map<String, ModuleVersionIdentifier> byVersion = idToVersions.get(mi);
    if (byVersion == null) {
        byVersion = idToVersions.get(mi);
        if (byVersion == null) {
            byVersion = Maps.newConcurrentMap();
            idToVersions.put(mi, byVersion);
        }
    }
    ModuleVersionIdentifier identifier = byVersion.get(version);
    if (identifier == null) {
        identifier = new DefaultModuleVersionIdentifier(mi, version);
        byVersion.put(version, identifier);
    }
    return identifier;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier)

Aggregations

ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)38 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)8 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)7 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)7 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)7 File (java.io.File)6 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)6 List (java.util.List)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)5 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)4 Module (org.gradle.api.internal.artifacts.Module)4 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)4 ImmutableList (com.google.common.collect.ImmutableList)3 Configuration (org.gradle.api.artifacts.Configuration)3 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)3 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)3 JarDependency (com.android.builder.dependency.JarDependency)2