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