Search in sources :

Example 1 with DependencyJson

use of com.taobao.android.builder.dependency.output.DependencyJson in project atlas by alibaba.

the class DiffDependencyTask method doTask.

@TaskAction
public void doTask() throws IOException {
    apDependenciesFile = getApDependenciesFile();
    diffOutFile = getDiffOutFile();
    DependencyJson apDependencyJson = JSON.parseObject(FileUtils.readFileToString(apDependenciesFile), DependencyJson.class);
    Set<String> apMainDependencies = Sets.newHashSet();
    for (String mainDep : apDependencyJson.getMainDex()) {
        String name = mainDep.substring(0, mainDep.lastIndexOf(":"));
        apMainDependencies.add(name);
    }
    AwbBundle awbBundle = libVariantContext.getAwbBundle();
    //aars
    if (null != awbBundle.getLibraryDependencies()) {
        for (int index = 0; index < awbBundle.getLibraryDependencies().size(); index++) {
            AndroidLibrary libraryDependency = awbBundle.getLibraryDependencies().get(index);
            MavenCoordinates mavenCoordinates = libraryDependency.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getLibraryDependencies().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    //solibs
    if (null != awbBundle.getSoLibraries()) {
        for (int index = 0; index < awbBundle.getSoLibraries().size(); index++) {
            SoLibrary soLibrary = awbBundle.getSoLibraries().get(index);
            MavenCoordinates mavenCoordinates = soLibrary.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                awbBundle.getSoLibraries().remove(index);
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    // jars
    if (null != awbBundle.getJavaDependencies()) {
        Iterator<? extends JavaLibrary> iterator = awbBundle.getJavaDependencies().iterator();
        while (iterator.hasNext()) {
            JavaLibrary jarInfo = iterator.next();
            MavenCoordinates mavenCoordinates = jarInfo.getResolvedCoordinates();
            String name = getMavenName(mavenCoordinates);
            if (apMainDependencies.contains(name)) {
                getLogger().info("[Remove]" + name);
                iterator.remove();
            } else {
                inAwbDependencies.add(name);
            }
        }
    }
    FileUtils.writeStringToFile(diffOutFile, StringUtils.join(inAwbDependencies, "\n"));
}
Also used : MavenCoordinates(com.android.builder.model.MavenCoordinates) JavaLibrary(com.android.builder.model.JavaLibrary) AndroidLibrary(com.android.builder.model.AndroidLibrary) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with DependencyJson

use of com.taobao.android.builder.dependency.output.DependencyJson in project atlas by alibaba.

the class DependencyCompareUtils method diff.

/**
 * Get the difference in dependency between the two versions
 *
 * @param baseDependecyFile
 * @param newDependencyJson
 * @return
 */
public static DependencyDiff diff(File baseDependecyFile, DependencyJson newDependencyJson) throws IOException {
    String baseDependencyStr = FileUtils.readFileToString(baseDependecyFile);
    DependencyJson baseDependencyJson = JSON.parseObject(baseDependencyStr, DependencyJson.class);
    return diff(baseDependencyJson, newDependencyJson);
}
Also used : DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson)

Example 3 with DependencyJson

use of com.taobao.android.builder.dependency.output.DependencyJson in project atlas by alibaba.

the class LogDependenciesTask method generate.

@TaskAction
void generate() {
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == atlasDependencyTree) {
        return;
    }
    File treeFile = new File(getProject().getBuildDir(), "outputs/dependencyTree-" + getVariantName() + ".json");
    File treeFileWithFileSize = new File(getProject().getBuildDir(), "outputs/dependencyTree-fileSize-" + getVariantName() + ".json");
    File dependenciesFile = new File(getProject().getBuildDir(), "outputs/dependencies.txt");
    File versionProperties = new File(getProject().getBuildDir(), "outputs/version.properties");
    File buildInfo = new File(getProject().getBuildDir(), "outputs/build.txt");
    File pluginDependencies = new File(getProject().getBuildDir(), "outputs/pluginDependencies.txt");
    File atlasConfig = new File(getProject().getBuildDir(), "outputs/atlasConfig.json");
    appBuildInfo.setDependencyTreeFile(treeFile);
    appBuildInfo.setDependenciesFile(dependenciesFile);
    appBuildInfo.setVersionPropertiesFile(versionProperties);
    appBuildInfo.setBuildInfoFile(buildInfo);
    treeFile.delete();
    dependenciesFile.delete();
    versionProperties.delete();
    buildInfo.delete();
    treeFile.getParentFile().mkdirs();
    try {
        DependencyJson dependencyJson = atlasDependencyTree.getDependencyJson();
        Collections.sort(dependencyJson.getMainDex());
        FileUtils.write(treeFile, JSON.toJSONString(dependencyJson, true));
        dependencyJson = atlasDependencyTree.createDependencyJson(true);
        Collections.sort(dependencyJson.getMainDex());
        FileUtils.write(treeFileWithFileSize, JSON.toJSONString(dependencyJson, true));
        // add to ap
        appBuildInfo.getOtherFilesMap().put("awo/dependencyTree.json", treeFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Output runtime plug-in dependency list
    try {
        // ClassLoader cl = ClassLoader.getSystemClassLoader();
        URL[] urls = ((URLClassLoader) LogDependenciesTask.class.getClassLoader()).getURLs();
        List<String> libraries = new ArrayList<>();
        for (URL url : urls) {
            libraries.add(url.getFile());
        }
        FileUtils.writeLines(pluginDependencies, libraries);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileUtils.writeStringToFile(dependenciesFile, JSON.toJSONString(atlasDependencyTree.getDependencyJson()));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileUtils.writeLines(versionProperties, getSortVersionList(atlasDependencyTree));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        List<String> lines = new ArrayList<>();
        lines.add("gradleVersion:" + getProject().getGradle().getGradleVersion());
        lines.add("androidPluginVersion:" + com.android.builder.Version.ANDROID_GRADLE_PLUGIN_VERSION);
        lines.add("buildToolsVersion:" + appVariantContext.getAppExtension().getBuildToolsVersion());
        lines.add("compileSdkVersion:" + appVariantContext.getAppExtension().getCompileSdkVersion());
        lines.add("atlasPluginVersion:" + FileNameUtils.getJarVersionName(LogDependenciesTask.class));
        lines.addAll(AtlasBuildContext.sBuilderAdapter.buildInfos);
        FileUtils.writeLines(buildInfo, lines);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileUtils.write(atlasConfig, JSON.toJSONString(new AtlasExtensionOutput(appVariantContext.getAtlasExtension(), appVariantContext.getBuildType().getName()), true));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (null != AtlasBuildContext.conflictDependencies && !AtlasBuildContext.conflictDependencies.isEmpty()) {
        try {
            FileUtils.writeLines(new File(getProject().getBuildDir(), "outputs/warning-dependencyConflict.properties"), AtlasBuildContext.conflictDependencies);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (appVariantContext.getAtlasExtension().getTBuildConfig().isAbortIfDependencyConflict()) {
            throw new GradleException("Rely on conflict, specific see warning - dependencyConflict. Properties");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) IOException(java.io.IOException) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) URL(java.net.URL) AtlasExtensionOutput(com.taobao.android.builder.tools.guide.AtlasExtensionOutput) URLClassLoader(java.net.URLClassLoader) GradleException(org.gradle.api.GradleException) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with DependencyJson

use of com.taobao.android.builder.dependency.output.DependencyJson in project atlas by alibaba.

the class AppVariantContext method getDependencyDiff.

public DependencyDiff getDependencyDiff() throws IOException {
    if (null != this.dependencyDiff) {
        return this.dependencyDiff;
    }
    if (null != this.apContext.getApExploredFolder() && this.apContext.getApExploredFolder().exists()) {
        DependencyJson dependencyJson = AtlasBuildContext.androidDependencyTrees.get(this.getVariantData().getName()).getDependencyJson();
        File baseDependencyFile = new File(this.apContext.getApExploredFolder(), "dependencies.txt");
        if (baseDependencyFile.exists()) {
            DependencyDiff dependencyDiff = DependencyCompareUtils.diff(baseDependencyFile, dependencyJson);
            this.dependencyDiff = dependencyDiff;
            return dependencyDiff;
        }
    }
    return null;
}
Also used : DependencyDiff(com.taobao.android.builder.dependency.diff.DependencyDiff) DependencyJson(com.taobao.android.builder.dependency.output.DependencyJson) File(java.io.File)

Example 5 with DependencyJson

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

Aggregations

DependencyJson (com.taobao.android.builder.dependency.output.DependencyJson)8 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)2 File (java.io.File)2 HashSet (java.util.HashSet)2 TaskAction (org.gradle.api.tasks.TaskAction)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 JavaLibrary (com.android.builder.model.JavaLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 DependencyDiff (com.taobao.android.builder.dependency.diff.DependencyDiff)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)1 ResolvedDependencyInfo (com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo)1 AtlasExtensionOutput (com.taobao.android.builder.tools.guide.AtlasExtensionOutput)1 IOException (java.io.IOException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 GradleException (org.gradle.api.GradleException)1