Search in sources :

Example 1 with MavenCoordinatesImpl

use of com.android.builder.dependency.MavenCoordinatesImpl in project atlas by alibaba.

the class AtlasLibTaskManager method createAwbBundle.

private AwbBundle createAwbBundle(LibVariantContext libVariantContext, String variantName) throws IOException {
    AndroidDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName);
    if (null == libDependencyTree) {
        dependencyManager.resolveDependencyForConfig(libVariantContext.getVariantDependency(), true);
        libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName);
    }
    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);
    AwbBundle awbBundle = new AwbBundle(libVariantContext.getBundleTask().getArchivePath(), explodedDir, new ArrayList<LibraryDependency>(), new ArrayList<JarDependency>(), groupName + ":" + name, libVariantContext.getVariantName(), project.getPath(), null, new MavenCoordinatesImpl(groupName, name, version));
    new AwoDependency(libVariantContext).parseDependency(libDependencyTree, awbBundle);
    return awbBundle;
}
Also used : JarDependency(com.android.builder.dependency.JarDependency) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) AwoDependency(com.taobao.android.builder.tasks.awo.utils.AwoDependency) LibraryDependency(com.android.builder.dependency.LibraryDependency) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Example 2 with MavenCoordinatesImpl

use of com.android.builder.dependency.MavenCoordinatesImpl 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 MavenCoordinatesImpl

use of com.android.builder.dependency.MavenCoordinatesImpl 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)

Aggregations

MavenCoordinatesImpl (com.android.builder.dependency.MavenCoordinatesImpl)3 File (java.io.File)3 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)2 NonNull (com.android.annotations.NonNull)1 ExtraModelInfo (com.android.build.gradle.internal.ExtraModelInfo)1 ProjectOptions (com.android.build.gradle.options.ProjectOptions)1 JarDependency (com.android.builder.dependency.JarDependency)1 LibraryDependency (com.android.builder.dependency.LibraryDependency)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 AtlasDepTreeParser (com.taobao.android.builder.dependency.parser.AtlasDepTreeParser)1 ResolvedDependencyInfo (com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)1 AwoDependency (com.taobao.android.builder.tasks.awo.utils.AwoDependency)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Project (org.gradle.api.Project)1 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)1