Search in sources :

Example 6 with ProcessOutputHandler

use of com.android.ide.common.process.ProcessOutputHandler in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method makeAapt.

private Aapt makeAapt(AaptGeneration aaptGeneration) throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);
    ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(aaptGeneration == AaptGeneration.AAPT_V1 ? new AaptOutputParser() : new Aapt2OutputParser(), getILogger()), new MergingLogRewriter(mergingLog::find, builder.getErrorReporter()));
    return AaptGradleFactory.make(aaptGeneration, builder, processOutputHandler, fileCache, true, com.android.utils.FileUtils.mkdirs(new File(appVariantContext.getScope().getIncrementalDir(getName()), "aapt-temp")), aaptOptions.getCruncherProcesses());
}
Also used : MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) MergingLog(com.android.ide.common.blame.MergingLog) AndroidBuilder(com.android.builder.core.AndroidBuilder) Aapt2OutputParser(com.android.ide.common.blame.parser.aapt.Aapt2OutputParser) AaptOutputParser(com.android.ide.common.blame.parser.aapt.AaptOutputParser) File(java.io.File) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Example 7 with ProcessOutputHandler

use of com.android.ide.common.process.ProcessOutputHandler 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;
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) DexArchiveBuilderTransform(com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform) ProcessException(com.android.ide.common.process.ProcessException) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DexParser(com.android.ide.common.blame.parser.DexParser) ProcessOutput(com.android.ide.common.process.ProcessOutput) JarFile(java.util.jar.JarFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Example 8 with ProcessOutputHandler

use of com.android.ide.common.process.ProcessOutputHandler in project atlas by alibaba.

the class Dex method doTaskAction.

private void doTaskAction(@Nullable Collection<File> inputFiles, @Nullable File inputDir, boolean incremental) throws IOException, ProcessException, InterruptedException {
    File outFolder = getOutputFolder();
    if (!incremental) {
        FileUtils.deleteDirectoryContents(outFolder);
    }
    File tmpFolder = getTmpFolder();
    tmpFolder.mkdirs();
    // if some of our .jar input files exist, just reset the inputDir to null
    for (File inputFile : inputFiles) {
        if (inputFile.exists()) {
            inputDir = null;
        }
    }
    if (inputDir != null) {
        inputFiles = getProject().files(inputDir).getFiles();
    }
    final ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
    List<File> inputDexFiles = new ArrayList<File>();
    inputDexFiles.addAll(inputFiles);
    inputDexFiles.addAll(getLibraries());
    getBuilder().getDexByteCodeConverter().convertByteCode(inputDexFiles, outFolder, getMultiDexEnabled(), getMainDexListFile(), getDexOptions(), outputHandler, 14);
    File dexBaseFile = getDexBaseFile();
    if (dexBaseFile != null) {
        ZipFile files = new ZipFile(dexBaseFile);
        ZipEntry entry = files.getEntry("classes.dex");
        if (entry == null) {
            throw new DexException("Expected classes.dex in " + dexBaseFile);
        }
        File file = new File(outFolder, "classes.dex");
        com.taobao.android.dex.Dex merged = new DexMerger(new com.taobao.android.dex.Dex[] { new com.taobao.android.dex.Dex(file), new com.taobao.android.dex.Dex(files.getInputStream(entry)) }, CollisionPolicy.KEEP_FIRST).merge();
        merged.writeTo(file);
    }
}
Also used : DexException(com.taobao.android.dex.DexException) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) DexMerger(com.taobao.android.dx.merge.DexMerger) ZipFile(java.util.zip.ZipFile) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DexParser(com.android.ide.common.blame.parser.DexParser) ZipFile(java.util.zip.ZipFile) File(java.io.File) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Aggregations

ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)8 ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)6 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)6 File (java.io.File)5 DexParser (com.android.ide.common.blame.parser.DexParser)4 JarFile (java.util.jar.JarFile)4 ProcessException (com.android.ide.common.process.ProcessException)3 DexArchiveBuilderTransform (com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform)2 AndroidBuilder (com.android.builder.core.AndroidBuilder)2 MergingLog (com.android.ide.common.blame.MergingLog)2 MergingLogRewriter (com.android.ide.common.blame.MergingLogRewriter)2 Aapt2OutputParser (com.android.ide.common.blame.parser.aapt.Aapt2OutputParser)2 AaptOutputParser (com.android.ide.common.blame.parser.aapt.AaptOutputParser)2 LoggedProcessOutputHandler (com.android.ide.common.process.LoggedProcessOutputHandler)2 ProcessOutput (com.android.ide.common.process.ProcessOutput)2 ZipEntry (java.util.zip.ZipEntry)2 InputFile (org.gradle.api.tasks.InputFile)2 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 AaptOptions (com.android.build.gradle.internal.dsl.AaptOptions)1