Search in sources :

Example 1 with DesugarProcessBuilder

use of com.android.builder.core.DesugarProcessBuilder 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);
    }
}
Also used : Path(java.nio.file.Path) java.util(java.util) SdkConstants(com.android.SdkConstants) DesugarProcessBuilder(com.android.builder.core.DesugarProcessBuilder) URL(java.net.URL) Version(com.android.builder.Version) Hashing(com.google.common.hash.Hashing) HashingInputStream(com.google.common.hash.HashingInputStream) Callable(java.util.concurrent.Callable) PathUtils(com.android.utils.PathUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) StandardCopyOption(java.nio.file.StandardCopyOption) AtlasBuildContext(com.taobao.android.builder.AtlasBuildContext) com.google.common.collect(com.google.common.collect) Path(java.nio.file.Path) LoggerWrapper(com.android.build.gradle.internal.LoggerWrapper) Files(java.nio.file.Files) Nullable(com.android.annotations.Nullable) WaitableExecutor(com.android.ide.common.internal.WaitableExecutor) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) FileCache(com.android.builder.utils.FileCache) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) TransformManager(com.android.build.gradle.internal.pipeline.TransformManager) ExecutionException(java.util.concurrent.ExecutionException) TransformInputUtil(com.android.build.gradle.internal.transforms.TransformInputUtil) JavaProcessExecutor(com.android.ide.common.process.JavaProcessExecutor) WorkerExecutor(org.gradle.workers.WorkerExecutor) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) NonNull(com.android.annotations.NonNull) com.android.build.api.transform(com.android.build.api.transform) DesugarTransform(com.android.build.gradle.internal.transforms.DesugarTransform) Preconditions(com.google.common.base.Preconditions) ProcessException(com.android.ide.common.process.ProcessException) DesugarWorkerItem(com.android.build.gradle.internal.transforms.DesugarWorkerItem) InputStream(java.io.InputStream) LoggedProcessOutputHandler(com.android.ide.common.process.LoggedProcessOutputHandler) DesugarProcessBuilder(com.android.builder.core.DesugarProcessBuilder)

Aggregations

SdkConstants (com.android.SdkConstants)1 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 com.android.build.api.transform (com.android.build.api.transform)1 LoggerWrapper (com.android.build.gradle.internal.LoggerWrapper)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 TransformManager (com.android.build.gradle.internal.pipeline.TransformManager)1 DesugarTransform (com.android.build.gradle.internal.transforms.DesugarTransform)1 DesugarWorkerItem (com.android.build.gradle.internal.transforms.DesugarWorkerItem)1 TransformInputUtil (com.android.build.gradle.internal.transforms.TransformInputUtil)1 Version (com.android.builder.Version)1 DesugarProcessBuilder (com.android.builder.core.DesugarProcessBuilder)1 FileCache (com.android.builder.utils.FileCache)1 WaitableExecutor (com.android.ide.common.internal.WaitableExecutor)1 JavaProcessExecutor (com.android.ide.common.process.JavaProcessExecutor)1 LoggedProcessOutputHandler (com.android.ide.common.process.LoggedProcessOutputHandler)1 ProcessException (com.android.ide.common.process.ProcessException)1 PathUtils (com.android.utils.PathUtils)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1