Search in sources :

Example 1 with AtlasExtensionOutput

use of com.taobao.android.builder.tools.guide.AtlasExtensionOutput 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)

Aggregations

AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 DependencyJson (com.taobao.android.builder.dependency.output.DependencyJson)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 AtlasExtensionOutput (com.taobao.android.builder.tools.guide.AtlasExtensionOutput)1 File (java.io.File)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 TaskAction (org.gradle.api.tasks.TaskAction)1