use of com.android.ide.common.process.ProcessException 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.ProcessException 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