Search in sources :

Example 1 with ResolvedDependencyInfo

use of com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo in project atlas by alibaba.

the class DependencyResolver method addResolvedDependencyInfo.

/**
 * A recursive approach to dependency resolution
 *
 * @param parentDependency
 * @param resolvedDependenciesMap
 */
private void addResolvedDependencyInfo(ResolvedDependencyInfo parentDependency, Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap) {
    int indent = parentDependency.getIndent();
    ModuleVersionIdentifier identifier = parentDependency.getModuleVersionIdentifier();
    Collection<ResolvedDependencyInfo> childDependencies = resolvedDependenciesMap.get(identifier);
    // TODO here
    for (ResolvedDependencyInfo childDependency : childDependencies) {
        if (childDependency.getIndent() > indent) {
            // System.out.println(parentDependency + " indent " + indent + "->" + childDependency
            // +  " indent " + childDependency.getIndent());
            parentDependency.getChildren().add(childDependency);
            if (childDependency.getIndent() <= 1) {
                addResolvedDependencyInfo(childDependency, resolvedDependenciesMap);
            }
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)

Example 2 with ResolvedDependencyInfo

use of com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo in project atlas by alibaba.

the class AwbGenerator method createAwbBundle.

public AwbBundle createAwbBundle(LibVariantContext libVariantContext) throws IOException {
    String variantName = libVariantContext.getVariantName();
    AtlasDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName);
    // TODO 2.3
    if (null == libDependencyTree) {
        libDependencyTree = new AtlasDepTreeParser(libVariantContext.getProject(), new ExtraModelInfo(new ProjectOptions(libVariantContext.getProject()), null), new HashSet<>()).parseDependencyTree(libVariantContext.getVariantDependency());
        AtlasBuildContext.libDependencyTrees.put(variantName, libDependencyTree);
    }
    Project project = libVariantContext.getProject();
    String groupName = (String) project.getGroup();
    String name = "";
    String version = (String) project.getVersion();
    if (project.hasProperty("archivesBaseName")) {
        name = (String) project.getProperties().get("archivesBaseName");
    } else {
        name = project.getName();
    }
    File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-awb/" + computeArtifactPath(groupName, name, version));
    FileUtils.deleteDirectory(explodedDir);
    MavenCoordinates mavenCoordinates = new MavenCoordinatesImpl(groupName, name, version, "awb", "");
    ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(groupName, name, version, "awb");
    resolvedDependencyInfo.setVariantName(libVariantContext.getVariantName());
    AwbBundle awbBundle = new AwbBundle(resolvedDependencyInfo, DependencyConvertUtils.toAndroidLibrary(mavenCoordinates, libVariantContext.getBundleTask().getArchivePath(), explodedDir));
    awbBundle.getSoLibraries().addAll(libDependencyTree.getMainBundle().getSoLibraries());
    awbBundle.getAndroidLibraries().addAll(libDependencyTree.getMainBundle().getAndroidLibraries());
    awbBundle.getJavaLibraries().addAll(libDependencyTree.getMainBundle().getJavaLibraries());
    return awbBundle;
}
Also used : Project(org.gradle.api.Project) MavenCoordinates(com.android.builder.model.MavenCoordinates) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) AtlasDepTreeParser(com.taobao.android.builder.dependency.parser.AtlasDepTreeParser) ExtraModelInfo(com.android.build.gradle.internal.ExtraModelInfo) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) ProjectOptions(com.android.build.gradle.options.ProjectOptions) File(java.io.File)

Example 3 with ResolvedDependencyInfo

use of com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo in project atlas by alibaba.

the class AtlasDependencyTree method createDependencyJson.

public DependencyJson createDependencyJson(boolean printFileSize) {
    DependencyJson dependencyJson = new DependencyJson();
    for (ResolvedDependencyInfo dep : mResolvedDependencies) {
        String value = dep.getDependencyString(printFileSize);
        if ("awb".equalsIgnoreCase(dep.getType())) {
            ArrayList<String> awbDeps = dependencyJson.getAwbs().get(value);
            if (null == awbDeps) {
                awbDeps = new ArrayList<String>();
            }
            addChildDependency(awbDeps, dep, printFileSize);
            dependencyJson.getAwbs().put(value, awbDeps);
        } else {
            dependencyJson.getMainDex().add(value);
            addChildDependency(dependencyJson.getMainDex(), dep, printFileSize);
        }
    }
    return dependencyJson;
}
Also used : ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson)

Example 4 with ResolvedDependencyInfo

use of com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo in project atlas by alibaba.

the class AtlasDependencyTree method addChildDependency.

private void addChildDependency(List<String> deps, ResolvedDependencyInfo dependencyInfo, boolean printFileSize) {
    for (ResolvedDependencyInfo child : dependencyInfo.getChildren()) {
        String childValue = child.getDependencyString(printFileSize);
        deps.add(childValue);
        addChildDependency(deps, child, printFileSize);
    }
}
Also used : ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)

Example 5 with ResolvedDependencyInfo

use of com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo in project atlas by alibaba.

the class DependencyResolver method resolveAllDependencies.

/**
 * Relying on arbitration
 */
private List<ResolvedDependencyInfo> resolveAllDependencies(Multimap<String, ResolvedDependencyInfo> dependenciesMap) {
    List<ResolvedDependencyInfo> allResolvedDependencyInfos = new ArrayList<>();
    // The post-arbitration dependencies. The structure is the parent class - subclass
    Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap = LinkedHashMultimap.create();
    Map<ModuleVersionIdentifier, ResolvedDependencyInfo> directDependencies = new HashMap<ModuleVersionIdentifier, ResolvedDependencyInfo>();
    for (String key : dependenciesMap.keySet()) {
        Collection<ResolvedDependencyInfo> dependencyLevels = dependenciesMap.get(key);
        if (dependencyLevels.size() > 0) {
            List<ResolvedDependencyInfo> resolvedDependencyInfos = Lists.newArrayList();
            resolvedDependencyInfos.addAll(dependencyLevels);
            Collections.sort(resolvedDependencyInfos);
            ResolvedDependencyInfo resolvedDependencyInfo = resolvedDependencyInfos.get(0);
            ResolvedDependencyInfo parent = resolvedDependencyInfo.getParent();
            // Children are not required to add information to the resolvedDependenciesMap
            resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
            if (null != parent) {
                // If the parent is dependent, then the current dependency is added to the dependency of the parent
                resolvedDependenciesMap.put(parent.getModuleVersionIdentifier(), resolvedDependencyInfo);
            } else {
                // If there is no parent dependency, it is a primary dependency
                directDependencies.put(resolvedDependencyInfo.getModuleVersionIdentifier(), resolvedDependencyInfo);
            }
        }
    }
    for (ModuleVersionIdentifier key : directDependencies.keySet()) {
        ResolvedDependencyInfo resolvedDependencyInfo = directDependencies.get(key);
        // Empty the children
        resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
        addResolvedDependencyInfo(resolvedDependencyInfo, resolvedDependenciesMap);
        allResolvedDependencyInfos.add(resolvedDependencyInfo);
    }
    return allResolvedDependencyInfos;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)

Aggregations

ResolvedDependencyInfo (com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)8 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 MavenCoordinates (com.android.builder.model.MavenCoordinates)2 CircleDependencyCheck (com.taobao.android.builder.dependency.parser.CircleDependencyCheck)2 File (java.io.File)2 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)2 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)2 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)1 ProjectOptions (com.android.build.gradle.options.ProjectOptions)1 MavenCoordinatesImpl (com.android.builder.dependency.MavenCoordinatesImpl)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 DependencyJson (com.taobao.android.builder.dependency.output.DependencyJson)1 AtlasDepTreeParser (com.taobao.android.builder.dependency.parser.AtlasDepTreeParser)1 Project (org.gradle.api.Project)1 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)1