use of com.android.ide.common.process.LoggedProcessOutputHandler in project atlas by alibaba.
the class ProcessAwoAndroidResources method doFullTaskAction.
@Override
protected void doFullTaskAction() throws IOException {
// we have to clean the source folder output in case the package name changed.
File srcOut = getSourceOutputDir();
if (srcOut != null) {
// FileUtils.emptyFolder(srcOut);
srcOut.delete();
srcOut.mkdirs();
}
@Nullable File resOutBaseNameFile = getPackageOutputFile();
// If are in instant run mode and we have an instant run enabled manifest
File instantRunManifest = getInstantRunManifestFile();
File manifestFileToPackage = instantRunBuildContext.isInInstantRunMode() && instantRunManifest != null && instantRunManifest.exists() ? instantRunManifest : getManifestFile();
// 增加awb模块编译所需要的额外参数
addAaptOptions();
AaptPackageProcessBuilder aaptPackageCommandBuilder = new AaptPackageProcessBuilder(manifestFileToPackage, getAaptOptions()).setAssetsFolder(getAssetsDir()).setResFolder(getResDir()).setLibraries(getLibraries()).setPackageForR(getPackageForR()).setSourceOutputDir(absolutePath(srcOut)).setSymbolOutputDir(absolutePath(getTextSymbolOutputDir())).setResPackageOutput(absolutePath(resOutBaseNameFile)).setProguardOutput(absolutePath(getProguardOutputFile())).setType(getType()).setDebuggable(getDebuggable()).setPseudoLocalesEnabled(getPseudoLocalesEnabled()).setResourceConfigs(getResourceConfigs()).setSplits(getSplits()).setPreferredDensity(getPreferredDensity());
@NonNull AtlasBuilder builder = (AtlasBuilder) getBuilder();
// MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
//
// ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(
// new ToolOutputParser(new AaptOutputParser(), getILogger()),
// builder.getErrorReporter());
ProcessOutputHandler processOutputHandler = new LoggedProcessOutputHandler(getILogger());
try {
builder.processAwbResources(aaptPackageCommandBuilder, getEnforceUniquePackageName(), processOutputHandler, getMainSymbolFile());
if (resOutBaseNameFile != null) {
if (instantRunBuildContext.isInInstantRunMode()) {
instantRunBuildContext.addChangedFile(InstantRunBuildContext.FileType.RESOURCES, resOutBaseNameFile);
// get the new manifest file CRC
JarFile jarFile = new JarFile(resOutBaseNameFile);
String currentIterationCRC = null;
try {
ZipEntry entry = jarFile.getEntry(SdkConstants.ANDROID_MANIFEST_XML);
if (entry != null) {
currentIterationCRC = String.valueOf(entry.getCrc());
}
} finally {
jarFile.close();
}
// check the manifest file binary format.
File crcFile = new File(instantRunSupportDir, "manifest.crc");
if (crcFile.exists() && currentIterationCRC != null) {
// compare its content with the new binary file crc.
String previousIterationCRC = Files.readFirstLine(crcFile, Charsets.UTF_8);
if (!currentIterationCRC.equals(previousIterationCRC)) {
instantRunBuildContext.close();
instantRunBuildContext.setVerifierResult(InstantRunVerifierStatus.BINARY_MANIFEST_FILE_CHANGE);
}
}
// write the new manifest file CRC.
Files.createParentDirs(crcFile);
Files.write(currentIterationCRC, crcFile, Charsets.UTF_8);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ProcessException e) {
throw new RuntimeException(e);
}
}
use of com.android.ide.common.process.LoggedProcessOutputHandler in project atlas by alibaba.
the class AtlasDesugarTransform method processNonCachedOnes.
private void processNonCachedOnes(List<Path> classpath) throws IOException {
int parallelExecutions = waitableExecutor.getParallelism();
int index = 0;
Multimap<Integer, AtlasDesugarTransform.InputEntry> procBuckets = ArrayListMultimap.create();
for (AtlasDesugarTransform.InputEntry pathPathEntry : cacheMisses) {
int bucketId = index % parallelExecutions;
procBuckets.put(bucketId, pathPathEntry);
index++;
}
List<Path> desugarBootclasspath = getBootclasspath();
for (Integer bucketId : procBuckets.keySet()) {
Callable<Void> callable = () -> {
Map<Path, Path> inToOut = Maps.newHashMap();
for (AtlasDesugarTransform.InputEntry e : procBuckets.get(bucketId)) {
inToOut.put(e.getInputPath(), e.getOutputPath());
}
DesugarProcessBuilder processBuilder = new DesugarProcessBuilder(desugarJar.get(), verbose, inToOut, classpath, desugarBootclasspath, minSdk, tmpDir);
boolean isWindows = SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS;
executor.execute(processBuilder.build(isWindows), new LoggedProcessOutputHandler(logger)).rethrowFailure().assertNormalExitValue();
// now copy to the cache because now we have the file
for (AtlasDesugarTransform.InputEntry e : procBuckets.get(bucketId)) {
if (e.getCache() != null && e.getInputs() != null) {
e.getCache().createFileInCacheIfAbsent(e.getInputs(), in -> Files.copy(e.getOutputPath(), in.toPath()));
}
}
return null;
};
waitableExecutor.execute(callable);
}
}
Aggregations