com.android.ide.common.process.ProcessOutputHandler Java Examples

The following examples show how to use com.android.ide.common.process.ProcessOutputHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts the bytecode to Dalvik format
 *
 * @param inputFile  the input file
 * @param outFile    the output file or folder if multi-dex is enabled.
 * @param multiDex   whether multidex is enabled.
 * @param dexOptions dex options
 * @throws IOException
 * @throws InterruptedException
 * @throws ProcessException
 */
public void preDexLibrary(
        @NonNull File inputFile,
        @NonNull File outFile,
        boolean multiDex,
        @NonNull DexOptions dexOptions,
        @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, ProcessException {
    checkState(mTargetInfo != null,
            "Cannot call preDexLibrary() before setTargetInfo() is called.");

    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    PreDexCache.getCache().preDexLibrary(
            inputFile,
            outFile,
            multiDex,
            dexOptions,
            buildToolInfo,
            mVerboseExec,
            mJavaProcessExecutor,
            processOutputHandler);
}
 
Example #2
Source File: ProcessAwbAndroidResources.java    From atlas with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #3
Source File: TPatchDiffResAPBuildTask.java    From atlas with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #4
Source File: AtlasD8Creator.java    From atlas with Apache License 2.0 6 votes vote down vote up
public AtlasD8Creator(Collection<File> inputFiles, File dexOutputFile, boolean multidex, File mainDexList, DexOptions dexOptions, int minSdkVersion, FileCache fileCache, ProcessOutputHandler processOutputHandler, VariantContext variantContext, AppVariantOutputContext variantOutputContext) {
    this.inputFiles = inputFiles;
    this.dexOut = dexOutputFile;
    this.multidex = multidex;
    this.mainDexList = mainDexList;
    this.dexOptions = dexOptions;
    this.processOutputHandler = processOutputHandler;
    this.fileCache = fileCache;
    this.miniSdk = minSdkVersion;
    this.isDebuggable = ((AppVariantContext) variantContext).getVariantData().getVariantConfiguration().getBuildType().isDebuggable();
   this.cacheHander =
            new AtlasDexArchiveBuilderCacheHander(variantContext.getProject(),
                    fileCache, dexOptions, minSdkVersion, isDebuggable, DexerTool.D8);
    this.variantContext = variantContext;
    this.appVariantOutputContext = variantOutputContext;
    dexArchiveBuilder = DexArchiveBuilder.createD8DexBuilder(minSdkVersion,isDebuggable);

}
 
Example #5
Source File: DexWrapperHook.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static ProcessResult run(
            @NonNull DexProcessBuilder processBuilder,
            @NonNull DexOptions dexOptions,
            @NonNull ProcessOutputHandler outputHandler) throws IOException, ProcessException {
        ProcessOutput output = outputHandler.createOutput();
        int res;
        try {
//            DxConsole.out = outputHandler.createOutput().getStandardOutput();
//            DxConsole.err = outputHandler.createOutput().getErrorOutput();
            DxConsole dxConsole = new DxConsole();
            Main.Arguments args = buildArguments(processBuilder, dexOptions, dxConsole);
            res = new Main().run(args);
        } finally {
            output.close();
        }

        outputHandler.handleOutput(output);
        return new DexProcessResult(res);
    }
 
Example #6
Source File: AidlProcessor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public AidlProcessor(
        @NonNull String aidlExecutable,
        @NonNull String frameworkLocation,
        @NonNull List<File> importFolders,
        @NonNull File sourceOutputDir,
        @Nullable File parcelableOutputDir,
        @NonNull DependencyFileProcessor dependencyFileProcessor,
        @NonNull ProcessExecutor processExecutor,
        @NonNull ProcessOutputHandler processOutputHandler) {
    mAidlExecutable = aidlExecutable;
    mFrameworkLocation = frameworkLocation;
    mImportFolders = importFolders;
    mSourceOutputDir = sourceOutputDir;
    mParcelableOutputDir = parcelableOutputDir;
    mDependencyFileProcessor = dependencyFileProcessor;
    mProcessExecutor = processExecutor;
    mProcessOutputHandler = processOutputHandler;
}
 
Example #7
Source File: AidlCompile.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Compiles a single file.
 *
 * @param sourceFolder            the file to compile.
 * @param file                    the file to compile.
 * @param importFolders           the import folders.
 * @param dependencyFileProcessor a DependencyFileProcessor
 */
private void compileSingleFile(
        @NonNull File sourceFolder,
        @NonNull File file,
        @Nullable List<File> importFolders,
        @NonNull DependencyFileProcessor dependencyFileProcessor,
        @NonNull ProcessOutputHandler processOutputHandler)
        throws InterruptedException, ProcessException, LoggedErrorException, IOException {
    getBuilder().compileAidlFile(
            sourceFolder,
            file,
            getSourceOutputDir(),
            getAidlParcelableDir(),
            importFolders,
            dependencyFileProcessor,
            processOutputHandler);
}
 
Example #8
Source File: GradleJavaProcessExecutor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public ProcessResult execute(
        @NonNull JavaProcessInfo javaProcessInfo,
        @NonNull ProcessOutputHandler processOutputHandler) {
    ProcessOutput output = processOutputHandler.createOutput();

    ExecResult result = project.javaexec(new ExecAction(javaProcessInfo, output));

    try {
        processOutputHandler.handleOutput(output);
    } catch (ProcessException e) {
        return new OutputHandlerFailedGradleProcessResult(e);
    }

    return new GradleProcessResult(result);
}
 
Example #9
Source File: GradleProcessExecutor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public ProcessResult execute(
        @NonNull ProcessInfo processInfo,
        @NonNull ProcessOutputHandler processOutputHandler) {
    ProcessOutput output = processOutputHandler.createOutput();

    final ExecResult result = project.exec(new ExecAction(processInfo, output));

    try {
        processOutputHandler.handleOutput(output);
    } catch (final ProcessException e) {
        return new OutputHandlerFailedGradleProcessResult(e);
    }

    return new GradleProcessResult(result);
}
 
Example #10
Source File: PreDex.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private PreDexTask(
        File outFolder,
        File file,
        Set<String> hashs,
        boolean multiDexEnabled,
        ProcessOutputHandler outputHandler) {
    this.mOutputHandler = outputHandler;
    this.outFolder = outFolder;
    this.fileToProcess = file;
    this.hashs = hashs;
    this.multiDexEnabled = multiDexEnabled;
}
 
Example #11
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an {@link PngCruncher} using aapt underneath
 *
 * @return an PngCruncher object
 */
@NonNull
public PngCruncher getAaptCruncher(ProcessOutputHandler processOutputHandler) {
    checkState(mTargetInfo != null,
            "Cannot call getAaptCruncher() before setTargetInfo() is called.");
    return new AaptCruncher(
            mTargetInfo.getBuildTools().getPath(BuildToolInfo.PathId.AAPT),
            mProcessExecutor,
            processOutputHandler);
}
 
Example #12
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Compiles the given aidl file.
 *
 * @param aidlFile                the AIDL file to compile
 * @param sourceOutputDir         the output dir in which to generate the source code
 * @param importFolders           all the import folders, including the source folders.
 * @param dependencyFileProcessor the dependencyFileProcessor to record the dependencies
 *                                of the compilation.
 * @throws IOException
 * @throws InterruptedException
 * @throws LoggedErrorException
 */
public void compileAidlFile(@NonNull File sourceFolder,
                            @NonNull File aidlFile,
                            @NonNull File sourceOutputDir,
                            @Nullable File parcelableOutputDir,
                            @NonNull List<File> importFolders,
                            @Nullable DependencyFileProcessor dependencyFileProcessor,
                            @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, LoggedErrorException, ProcessException {
    checkNotNull(aidlFile, "aidlFile cannot be null.");
    checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null.");
    checkNotNull(importFolders, "importFolders cannot be null.");
    checkState(mTargetInfo != null,
            "Cannot call compileAidlFile() before setTargetInfo() is called.");

    IAndroidTarget target = mTargetInfo.getTarget();
    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    String aidl = buildToolInfo.getPath(BuildToolInfo.PathId.AIDL);
    if (aidl == null || !new File(aidl).isFile()) {
        throw new IllegalStateException("aidl is missing");
    }

    AidlProcessor processor = new AidlProcessor(
            aidl,
            target.getPath(IAndroidTarget.ANDROID_AIDL),
            importFolders,
            sourceOutputDir,
            parcelableOutputDir,
            dependencyFileProcessor != null ?
                    dependencyFileProcessor : sNoOpDependencyFileProcessor,
            mProcessExecutor,
            processOutputHandler);

    processor.processFile(sourceFolder, aidlFile);
}
 
Example #13
Source File: AaptCruncher.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public AaptCruncher(
        @NonNull String aaptLocation,
        @NonNull ProcessExecutor processExecutor,
        @NonNull ProcessOutputHandler processOutputHandler) {
    mAaptLocation = aaptLocation;
    mProcessExecutor = processExecutor;
    mProcessOutputHandler = processOutputHandler;
}
 
Example #14
Source File: AtlasAapt.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new entry point to the original {@code aapt}.
 *
 * @param processExecutor      the executor for external processes
 * @param processOutputHandler the handler to process the executed process' output
 * @param buildToolInfo        the build tools to use
 * @param logger               logger to use
 * @param processMode          the process mode to run {@code aapt} on
 * @param cruncherProcesses    if using build tools that support crunching processes, how many
 *                             processes to use; if set to {@code 0}, the default number will be used
 */
public AtlasAapt(ProcessExecutor processExecutor,
                 ProcessOutputHandler processOutputHandler,
                 BuildToolInfo buildToolInfo,
                 ILogger logger,
                 PngProcessMode processMode,
                 int cruncherProcesses) {
    super(processExecutor,
          processOutputHandler,
          buildToolInfo,
          logger,
          processMode,
          cruncherProcesses);
}
 
Example #15
Source File: MergeResources.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Aapt makeAapt(
        BuildToolInfo buildToolInfo,
        AaptGeneration aaptGeneration,
        AndroidBuilder builder,
        boolean crunchPng,
        MergingLog blameLog) {
    ProcessOutputHandler teeOutputHandler =
            new TeeProcessOutputHandler(
                    blameLog != null
                            ? new ParsingProcessOutputHandler(
                            new ToolOutputParser(
                                    aaptGeneration == AaptGeneration.AAPT_V1
                                            ? new AaptOutputParser()
                                            : new Aapt2OutputParser(),
                                    builder.getLogger()),
                            new MergingLogRewriter(blameLog::find, builder.getErrorReporter()))
                            : new LoggedProcessOutputHandler(
                            new AaptGradleFactory.FilteringLogger(builder.getLogger())),
                    new LoggedProcessOutputHandler(new AaptGradleFactory.FilteringLogger(builder.getLogger())));

    return new AaptV1(
            builder.getProcessExecutor(),
            teeOutputHandler,
            buildToolInfo,
            new AaptGradleFactory.FilteringLogger(builder.getLogger()),
            crunchPng ? AaptV1.PngProcessMode.ALL : AaptV1.PngProcessMode.NO_CRUNCH,
            0);
}
 
Example #16
Source File: NinePatchOnlyCruncher.java    From bazel with Apache License 2.0 4 votes vote down vote up
public NinePatchOnlyCruncher(
    String aaptLocation,
    ProcessExecutor processExecutor,
    ProcessOutputHandler processOutputHandler) {
  super(aaptLocation, processExecutor, processOutputHandler);
}
 
Example #17
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Compiles all the aidl files found in the given source folders.
 *
 * @param sourceFolders           all the source folders to find files to compile
 * @param sourceOutputDir         the output dir in which to generate the source code
 * @param importFolders           import folders
 * @param dependencyFileProcessor the dependencyFileProcessor to record the dependencies
 *                                of the compilation.
 * @throws IOException
 * @throws InterruptedException
 * @throws LoggedErrorException
 */
public void compileAllAidlFiles(@NonNull List<File> sourceFolders,
                                @NonNull File sourceOutputDir,
                                @Nullable File parcelableOutputDir,
                                @NonNull List<File> importFolders,
                                @Nullable DependencyFileProcessor dependencyFileProcessor,
                                @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, InterruptedException, LoggedErrorException, ProcessException {
    checkNotNull(sourceFolders, "sourceFolders cannot be null.");
    checkNotNull(sourceOutputDir, "sourceOutputDir cannot be null.");
    checkNotNull(importFolders, "importFolders cannot be null.");
    checkState(mTargetInfo != null,
            "Cannot call compileAllAidlFiles() before setTargetInfo() is called.");

    IAndroidTarget target = mTargetInfo.getTarget();
    BuildToolInfo buildToolInfo = mTargetInfo.getBuildTools();

    String aidl = buildToolInfo.getPath(BuildToolInfo.PathId.AIDL);
    if (aidl == null || !new File(aidl).isFile()) {
        throw new IllegalStateException("aidl is missing");
    }

    List<File> fullImportList = Lists.newArrayListWithCapacity(
            sourceFolders.size() + importFolders.size());
    fullImportList.addAll(sourceFolders);
    fullImportList.addAll(importFolders);

    AidlProcessor processor = new AidlProcessor(
            aidl,
            target.getPath(IAndroidTarget.ANDROID_AIDL),
            fullImportList,
            sourceOutputDir,
            parcelableOutputDir,
            dependencyFileProcessor != null ?
                    dependencyFileProcessor : sNoOpDependencyFileProcessor,
            mProcessExecutor,
            processOutputHandler);

    SourceSearcher searcher = new SourceSearcher(sourceFolders, "aidl");
    searcher.setUseExecutor(true);
    searcher.search(processor);
}
 
Example #18
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public ProcessResult executeProcess(@NonNull ProcessInfo processInfo,
                                    @NonNull ProcessOutputHandler handler) {
    return mProcessExecutor.execute(processInfo, handler);
}
 
Example #19
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Converts the bytecode to Dalvik format
 *
 * @param inputFile       the input file
 * @param outFile         the output file or folder if multi-dex is enabled.
 * @param multiDex        whether multidex is enabled.
 * @param dexOptions      the dex options
 * @param buildToolInfo   the build tools info
 * @param verbose         verbose flag
 * @param processExecutor the java process executor
 * @return the list of generated files.
 * @throws ProcessException
 */
@NonNull
public static ImmutableList<File> preDexLibrary(
        @NonNull File inputFile,
        @NonNull File outFile,
        boolean multiDex,
        @NonNull DexOptions dexOptions,
        @NonNull BuildToolInfo buildToolInfo,
        boolean verbose,
        @NonNull JavaProcessExecutor processExecutor,
        @NonNull ProcessOutputHandler processOutputHandler)
        throws ProcessException {
    checkNotNull(inputFile, "inputFile cannot be null.");
    checkNotNull(outFile, "outFile cannot be null.");
    checkNotNull(dexOptions, "dexOptions cannot be null.");


    try {
        if (!checkLibraryClassesJar(inputFile)) {
            return ImmutableList.of();
        }
    } catch (IOException e) {
        throw new RuntimeException("Exception while checking library jar", e);
    }
    DexProcessBuilder builder = new DexProcessBuilder(outFile);

    builder.setVerbose(verbose)
            .setMultiDex(multiDex)
            .addInput(inputFile);

    JavaProcessInfo javaProcessInfo = builder.build(buildToolInfo, dexOptions);

    ProcessResult result = processExecutor.execute(javaProcessInfo, processOutputHandler);
    result.rethrowFailure().assertNormalExitValue();

    if (multiDex) {
        File[] files = outFile.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File file, String name) {
                return name.endsWith(DOT_DEX);
            }
        });

        if (files == null || files.length == 0) {
            throw new RuntimeException("No dex files created at " + outFile.getAbsolutePath());
        }

        return ImmutableList.copyOf(files);
    } else {
        return ImmutableList.of(outFile);
    }
}
 
Example #20
Source File: PreDexCache.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Pre-dex a given library to a given output with a specific version of the build-tools.
 * @param inputFile the jar to pre-dex
 * @param outFile the output file or folder (if multi-dex is enabled). must exist
 * @param multiDex whether mutli-dex is enabled.
 * @param dexOptions the dex options to run pre-dex
 * @param buildToolInfo the build tools info
 * @param verbose verbose flag
 * @param processExecutor the process executor
 * @throws IOException
 * @throws ProcessException
 * @throws InterruptedException
 */
public void preDexLibrary(
        @NonNull File inputFile,
        @NonNull File outFile,
                 boolean multiDex,
        @NonNull DexOptions dexOptions,
        @NonNull BuildToolInfo buildToolInfo,
        boolean verbose,
        @NonNull JavaProcessExecutor processExecutor,
        @NonNull ProcessOutputHandler processOutputHandler)
        throws IOException, ProcessException, InterruptedException {
    checkState(!multiDex || outFile.isDirectory());

    DexKey itemKey = DexKey.of(
            inputFile,
            buildToolInfo.getRevision());

    Pair<Item, Boolean> pair = getItem(itemKey);
    Item item = pair.getFirst();

    // if this is a new item
    if (pair.getSecond()) {
        try {
            // haven't process this file yet so do it and record it.
            List<File> files = AndroidBuilder.preDexLibrary(
                    inputFile,
                    outFile,
                    multiDex,
                    dexOptions,
                    buildToolInfo,
                    verbose,
                    processExecutor,
                    processOutputHandler);

            item.getOutputFiles().clear();
            item.getOutputFiles().addAll(files);

            incrementMisses();
        } catch (ProcessException exception) {
            // in case of error, delete (now obsolete) output file
            outFile.delete();
            // and rethrow the error
            throw exception;
        } finally {
            // enable other threads to use the output of this pre-dex.
            // if something was thrown they'll handle the missing output file.
            item.getLatch().countDown();
        }
    } else {
        // wait until the file is pre-dexed by the first thread.
        item.getLatch().await();

        // check that the generated file actually exists
        if (item.areOutputFilesPresent()) {
            if (multiDex) {
                // output should be a folder
                for (File sourceFile : item.getOutputFiles()) {
                    File destFile = new File(outFile, sourceFile.getName());
                    checkSame(sourceFile, destFile);
                    Files.copy(sourceFile, destFile);
                }

            } else {
                // file already pre-dex, just copy the output.
                if (item.getOutputFiles().isEmpty()) {
                    throw new RuntimeException(item.toString());
                }
                checkSame(item.getOutputFiles().get(0), outFile);
                Files.copy(item.getOutputFiles().get(0), outFile);
            }
            incrementHits();

        }
    }
}
 
Example #21
Source File: AtlasDexArchiveBuilderTransform.java    From atlas with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #22
Source File: AtlasDexArchiveBuilderTransform.java    From atlas with Apache License 2.0 4 votes vote down vote up
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;
}