use of com.android.builder.utils.FileCache in project atlas by alibaba.
the class AwbDexsMerger method merge.
public void merge(AwbBundle awbBundle) {
File file = variantOutputContext.getVariantContext().getAwbDexAchiveOutput(awbBundle);
List<File> awbDexFiles = new ArrayList<>();
if (!file.exists() || !file.isDirectory()) {
return;
}
awbDexFiles.addAll(org.apache.commons.io.FileUtils.listFiles(file, new String[] { "jar", "dex" }, true));
File[] mergeDexs = file.listFiles(pathname -> pathname.getName().endsWith(".jar") || pathname.isDirectory());
sort(awbDexFiles);
File outPutFolder = variantOutputContext.getAwbDexOutput(awbBundle.getName());
try {
FileUtils.cleanOutputDir(outPutFolder);
} catch (IOException e) {
e.printStackTrace();
}
FileCache.Inputs buildCacheInputs = getBuildCacheInputs(awbDexFiles, dexingType, dexMerger, null, minSdkVersion, isDebuggable, awbBundle.getName(), ID);
ProcessOutput output = outputHandler.createOutput();
FileCache fileCache = BuildCacheUtils.createBuildCacheIfEnabled(variantOutputContext.getVariantContext().getProject(), variantOutputContext.getScope().getGlobalScope().getProjectOptions());
if (fileCache == null) {
try {
fileCache = FileCache.getInstanceWithMultiProcessLocking(new File(AndroidLocation.getFolder(), "atlas-buildCache"));
} catch (AndroidLocation.AndroidLocationException e) {
e.printStackTrace();
}
}
if (variantOutputContext.getVariantContext().getAtlasExtension().getTBuildConfig().getMergeBundlesDex() && !awbBundle.isRemote && awbBundle.isMBundle) {
allDexsArchives.addAll(Arrays.asList(mergeDexs));
return;
}
try {
FileCache.QueryResult result = fileCache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
List<ForkJoinTask<Void>> mergeTasks = new ArrayList<ForkJoinTask<Void>>();
mergeTasks.addAll(handleLegacyAndMonoDex(Arrays.asList(mergeDexs), output, outPutFolder, null));
mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());
cacheHandler.handleMissActionResult(outPutFolder, in);
if (output != null) {
try {
outputHandler.handleOutput(output);
} catch (ProcessException e) {
// ignore this one
}
}
});
cacheHandler.handleQueryResult(result, outPutFolder, awbBundle.getName());
if (awbBundle.isMBundle) {
org.apache.commons.io.FileUtils.moveFile(new File(outPutFolder, CLASSES_DEX), new File(mainDexOut, "classes" + atomicInteger.incrementAndGet() + ".dex"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations