use of com.android.ide.common.process.ProcessOutput in project atlas by alibaba.
the class AtlasDexArchiveBuilderTransform method convertAwbToDexArchive.
private List<File> convertAwbToDexArchive(@NonNull Context context, @NonNull QualifiedContent input, @NonNull File outputProvider, boolean isIncremental, boolean awb) throws Exception {
int count = 0;
if (input.getFile().isFile()) {
count = computerClassCount(input.getFile());
} else if (input.getFile().isDirectory()) {
count = 1;
}
logger.verbose("Dexing {}", input.getFile().getAbsolutePath());
ImmutableList.Builder<File> dexArchives = ImmutableList.builder();
for (int bucketId = 0; bucketId < count; bucketId++) {
File preDexOutputFile = getAwbPreDexFile(outputProvider, input, bucketId);
if (input.getFile().isDirectory()) {
File cachedVersion = cacheHandler.getCachedVersionIfPresent(input.getFile());
dexArchives.add(preDexOutputFile);
if (cachedVersion != null) {
FileUtils.copyDirectoryContentToDirectory(cachedVersion, preDexOutputFile);
return dexArchives.build();
}
}
if (preDexOutputFile.isDirectory() && preDexOutputFile.exists()) {
FileUtils.cleanOutputDir(preDexOutputFile);
} else {
FileUtils.deleteIfExists(preDexOutputFile);
}
AtlasDexArchiveBuilderTransform.DexConversionParameters parameters = new AtlasDexArchiveBuilderTransform.DexConversionParameters(input, preDexOutputFile, NUMBER_OF_BUCKETS, bucketId, minSdkVersion, dexOptions.getAdditionalParameters(), inBufferSize, outBufferSize, dexer, isDebuggable, false, awb);
if (useGradleWorkers) {
context.getWorkerExecutor().submit(DexArchiveBuilderTransform.DexConversionWorkAction.class, configuration -> {
configuration.setIsolationMode(IsolationMode.NONE);
configuration.setParams(parameters);
});
} else {
executor.execute(() -> {
ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, logger), new ToolOutputParser(new DexParser(), logger), errorReporter);
ProcessOutput output = null;
try (Closeable ignored = output = outputHandler.createOutput()) {
launchProcessing(parameters, output.getStandardOutput(), output.getErrorOutput());
} finally {
if (output != null) {
try {
outputHandler.handleOutput(output);
} catch (ProcessException e) {
// ignore this one
}
}
}
return null;
});
}
}
List<File> files = dexArchives.build();
return files;
}
use of com.android.ide.common.process.ProcessOutput in project atlas by alibaba.
the class AtlasMainDexMerger method merge.
public void merge(List<File> mainDexFiles, File outputDir, File[][] mergeDexs) {
sort(mainDexFiles);
FileCache.Inputs buildCacheInputs = getBuildCacheInputs(mainDexFiles, dexingType, dexMerger, mainDexListFile == null ? null : mainDexListFile.getSingleFile(), minSdkVersion, isDebuggable, "maindex", 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()) {
allDexsArchives.addAll(Arrays.asList(mergeDexs[0]));
return;
}
try {
FileCache.QueryResult result = fileCache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
List<ForkJoinTask<Void>> mergeTasks = new ArrayList();
if (dexingType == DexingType.NATIVE_MULTIDEX) {
mergeTasks.addAll(handleNativeMultiDex(Arrays.asList(mergeDexs[0]), output, outputDir, mainDexListFile == null ? null : mainDexListFile.getSingleFile()));
} else {
mergeTasks.addAll(handleLegacyAndMonoDex(Arrays.asList(mergeDexs[0]), output, outputDir, mainDexListFile == null ? null : mainDexListFile.getSingleFile()));
}
mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());
cacheHandler.handleMissActionResult(outputDir, in);
if (output != null) {
try {
outputHandler.handleOutput(output);
} catch (ProcessException e) {
// ignore this one
}
}
});
cacheHandler.handleQueryResult(result, outputDir, "maindex");
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.android.ide.common.process.ProcessOutput in project atlas by alibaba.
the class AtlasDexArchiveBuilderTransform method convertToDexArchive.
private List<File> convertToDexArchive(@NonNull Context context, @NonNull QualifiedContent input, @NonNull TransformOutputProvider outputProvider, boolean isIncremental) throws Exception {
logger.verbose("Dexing {}", input.getFile().getAbsolutePath());
ImmutableList.Builder<File> dexArchives = ImmutableList.builder();
for (int bucketId = 0; bucketId < NUMBER_OF_BUCKETS; bucketId++) {
File preDexOutputFile = getPreDexFile(outputProvider, input, bucketId);
if (input.getFile().isDirectory()) {
File cachedVersion = cacheHandler.getCachedVersionIfPresent(input.getFile());
dexArchives.add(preDexOutputFile);
if (cachedVersion != null) {
FileUtils.copyDirectoryContentToDirectory(cachedVersion, preDexOutputFile);
return dexArchives.build();
}
}
if (preDexOutputFile.isDirectory() && preDexOutputFile.exists()) {
FileUtils.cleanOutputDir(preDexOutputFile);
} else {
FileUtils.deleteIfExists(preDexOutputFile);
}
AtlasDexArchiveBuilderTransform.DexConversionParameters parameters = new AtlasDexArchiveBuilderTransform.DexConversionParameters(input, preDexOutputFile, NUMBER_OF_BUCKETS, bucketId, minSdkVersion, dexOptions.getAdditionalParameters(), inBufferSize, outBufferSize, dexer, isDebuggable, isIncremental, false);
if (useGradleWorkers) {
context.getWorkerExecutor().submit(DexArchiveBuilderTransform.DexConversionWorkAction.class, configuration -> {
configuration.setIsolationMode(IsolationMode.NONE);
configuration.setParams(parameters);
});
} else {
executor.execute(() -> {
ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, logger), new ToolOutputParser(new DexParser(), logger), errorReporter);
ProcessOutput output = null;
try (Closeable ignored = output = outputHandler.createOutput()) {
launchProcessing(parameters, output.getStandardOutput(), output.getErrorOutput());
} finally {
if (output != null) {
try {
outputHandler.handleOutput(output);
} catch (ProcessException e) {
// ignore this one
}
}
}
return null;
});
}
}
List<File> files = dexArchives.build();
return files;
}
use of com.android.ide.common.process.ProcessOutput in project atlas by alibaba.
the class AtlasDexMerger method mergeAll.
public void mergeAll(TransformInvocation transformInvocation) throws IOException {
ProcessOutput output = outputHandler.createOutput();
for (File file : allDexsArchives) {
logger.warning("mergeAll File:" + file.getAbsolutePath());
}
TransformOutputProvider outputProvider = transformInvocation.getOutputProvider();
File outputDir = getDexOutputLocation(outputProvider, "main", TransformManager.SCOPE_FULL_PROJECT);
File finalDexDir = new File(outputDir.getParentFile(), "temp");
finalDexDir.mkdirs();
List<ForkJoinTask<Void>> mergeTasks = new ArrayList();
if (dexingType == DexingType.NATIVE_MULTIDEX) {
mergeTasks.addAll(handleNativeMultiDex(allDexsArchives, output, finalDexDir, null));
} else {
mergeTasks.addAll(handleLegacyAndMonoDex(allDexsArchives, output, finalDexDir, mainDexListFile == null ? null : mainDexListFile.getSingleFile()));
}
mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());
FileUtils.deleteDirectory(outputDir);
FileUtils.moveDirectory(finalDexDir, outputDir);
}
use of com.android.ide.common.process.ProcessOutput 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