Search in sources :

Example 1 with ProcessOutputHandler

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

the class AtlasBuilder method processResources.

@Override
public void processResources(Aapt aapt, Builder aaptConfigBuilder, boolean enforceUniquePackageName) throws IOException, InterruptedException, ProcessException {
    if (aapt instanceof AaptV1) {
        try {
            getTargetInfo();
            AaptOptions aaptOptions = (AaptOptions) FieldUtils.readField(aaptConfigBuilder.build(), "mAaptOptions", true);
            ProcessExecutor processExecutor = (ProcessExecutor) FieldUtils.readField(aapt, "mProcessExecutor", true);
            ProcessOutputHandler processOutputHandler = (ProcessOutputHandler) FieldUtils.readField(aapt, "mProcessOutputHandler", true);
            BuildToolInfo buildToolInfo = (BuildToolInfo) FieldUtils.readField(aapt, "mBuildToolInfo", true);
            PngProcessMode processMode = (PngProcessMode) FieldUtils.readField(aapt, "mProcessMode", true);
            int cruncherProcesses = aaptOptions.getCruncherProcesses();
            aapt = new AtlasAapt(processExecutor, processOutputHandler, buildToolInfo, getLogger(), processMode, cruncherProcesses);
        } catch (Throwable e) {
            throw new GradleException("aapt exception", e);
        }
    }
    super.processResources(aapt, aaptConfigBuilder, enforceUniquePackageName);
}
Also used : ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) PngProcessMode(com.android.builder.internal.aapt.v1.AaptV1.PngProcessMode) BuildToolInfo(com.android.sdklib.BuildToolInfo) AaptOptions(com.android.build.gradle.internal.dsl.AaptOptions) GradleException(org.gradle.api.GradleException) AaptV1(com.android.builder.internal.aapt.v1.AaptV1) ProcessExecutor(com.android.ide.common.process.ProcessExecutor) JavaProcessExecutor(com.android.ide.common.process.JavaProcessExecutor)

Example 2 with ProcessOutputHandler

use of com.android.ide.common.process.ProcessOutputHandler 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);
    }
}
Also used : LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ProcessException(com.android.ide.common.process.ProcessException) AaptPackageProcessBuilder(com.android.builder.core.AaptPackageProcessBuilder) NonNull(com.android.annotations.NonNull) AtlasBuilder(com.android.builder.core.AtlasBuilder) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) JarFile(java.util.jar.JarFile) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) Nullable(com.android.annotations.Nullable)

Example 3 with ProcessOutputHandler

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

the class AwbDexTask method doTaskAction.

private void doTaskAction(@Nullable Collection<File> inputFiles, @Nullable File inputDir, boolean incremental) throws InterruptedException, ProcessException, IOException {
    File outFolder = getOutputFolder();
    if (!incremental) {
        emptyFolder(outFolder);
    }
    // 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();
    }
    ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
    getBuilder().convertByteCode(inputFiles, getOutputFolder(), getMultiDexEnabled(), getMainDexListFile(), getDexOptions(), getOptimize(), outputHandler);
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DexParser(com.android.ide.common.blame.parser.DexParser) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Example 4 with ProcessOutputHandler

use of com.android.ide.common.process.ProcessOutputHandler 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;
}
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 5 with ProcessOutputHandler

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

the class ProcessAwbAndroidResources method makeAapt.

private Aapt makeAapt() throws IOException {
    AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(getMergeBlameLogFolder());
    FileCache fileCache = appVariantContext.getScope().getGlobalScope().getBuildCache();
    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, FileUtils.mkdirs(new File(getIncrementalFolder(), "awb-aapt-temp/" + awbBundle.getName())), aaptOptions.getCruncherProcesses());
}
Also used : MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) 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) JarFile(java.util.jar.JarFile) File(java.io.File) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) FileCache(com.android.builder.utils.FileCache)

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