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");
}
}
}
Aggregations