Search in sources :

Example 6 with FileCache

use of com.android.builder.utils.FileCache 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)

Example 7 with FileCache

use of com.android.builder.utils.FileCache in project atlas by alibaba.

the class AtlasDesugarTransform method initDesugarJar.

/**
 * Set this location of extracted desugar jar that is used for processing.
 */
private static void initDesugarJar(@Nullable FileCache cache) throws IOException {
    if (isDesugarJarInitialized()) {
        return;
    }
    URL url = DesugarProcessBuilder.class.getClassLoader().getResource(DESUGAR_JAR);
    Preconditions.checkNotNull(url);
    Path extractedDesugar = null;
    if (cache != null) {
        try {
            String fileHash;
            try (HashingInputStream stream = new HashingInputStream(Hashing.sha256(), url.openStream())) {
                fileHash = stream.hash().toString();
            }
            FileCache.Inputs inputs = new FileCache.Inputs.Builder(FileCache.Command.EXTRACT_DESUGAR_JAR).putString("pluginVersion", Version.ANDROID_GRADLE_PLUGIN_VERSION).putString("jarUrl", url.toString()).putString("fileHash", fileHash).build();
            File cachedFile = cache.createFileInCacheIfAbsent(inputs, file -> copyDesugarJar(url, file.toPath())).getCachedFile();
            Preconditions.checkNotNull(cachedFile);
            extractedDesugar = cachedFile.toPath();
        } catch (IOException | ExecutionException e) {
            logger.error(e, "Unable to cache Desugar jar. Extracting to temp dir.");
        }
    }
    synchronized (desugarJar) {
        if (isDesugarJarInitialized()) {
            return;
        }
        if (extractedDesugar == null) {
            extractedDesugar = PathUtils.createTmpToRemoveOnShutdown(DESUGAR_JAR);
            copyDesugarJar(url, extractedDesugar);
        }
        desugarJar.set(extractedDesugar);
    }
}
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) DesugarProcessBuilder(com.android.builder.core.DesugarProcessBuilder) IOException(java.io.IOException) URL(java.net.URL) HashingInputStream(com.google.common.hash.HashingInputStream) FileCache(com.android.builder.utils.FileCache) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) DesugarProcessBuilder(com.android.builder.core.DesugarProcessBuilder)

Example 8 with FileCache

use of com.android.builder.utils.FileCache in project atlas by alibaba.

the class TransformReplacer method replaceDexArchiveBuilderTransform.

public void replaceDexArchiveBuilderTransform(BaseVariantOutput vod) {
    List<TransformTask> list = TransformManager.findTransformTaskByTransformType(variantContext, DexArchiveBuilderTransform.class);
    DefaultDexOptions dexOptions = variantContext.getAppExtension().getDexOptions();
    boolean minified = variantContext.getScope().getCodeShrinker() != null;
    ProjectOptions projectOptions = variantContext.getScope().getGlobalScope().getProjectOptions();
    FileCache userLevelCache = getUserDexCache(minified, dexOptions.getPreDexLibraries());
    for (TransformTask transformTask : list) {
        AtlasDexArchiveBuilderTransform atlasDexArchiveBuilderTransform = new AtlasDexArchiveBuilderTransform(variantContext, vod, dexOptions, variantContext.getScope().getGlobalScope().getAndroidBuilder().getErrorReporter(), userLevelCache, variantContext.getScope().getMinSdkVersion().getFeatureLevel(), variantContext.getScope().getDexer(), projectOptions.get(BooleanOption.ENABLE_GRADLE_WORKERS), projectOptions.get(IntegerOption.DEXING_READ_BUFFER_SIZE), projectOptions.get(IntegerOption.DEXING_WRITE_BUFFER_SIZE), variantContext.getScope().getVariantConfiguration().getBuildType().isDebuggable());
        atlasDexArchiveBuilderTransform.setTransformTask(transformTask);
        ReflectUtils.updateField(transformTask, "transform", atlasDexArchiveBuilderTransform);
        if (variantContext.getScope().getInstantRunBuildContext().isInInstantRunMode() && variantContext.getVariantConfiguration().getMinSdkVersion().getApiLevel() < 21) {
            transformTask.doLast(task -> {
                task.getLogger().info("generate maindexList......");
                generateMainDexList(variantContext.getScope());
            });
        }
    }
}
Also used : AtlasDexArchiveBuilderTransform(com.taobao.android.builder.tasks.transform.dex.AtlasDexArchiveBuilderTransform) TransformTask(com.android.build.gradle.internal.pipeline.TransformTask) DefaultDexOptions(com.android.builder.core.DefaultDexOptions) ProjectOptions(com.android.build.gradle.options.ProjectOptions) FileCache(com.android.builder.utils.FileCache)

Example 9 with FileCache

use of com.android.builder.utils.FileCache in project atlas by alibaba.

the class AtlasDexArchiveBuilderCacheHander method getCachedVersionIfPresent.

@Nullable
public File getCachedVersionIfPresent(File input) throws Exception {
    assert input.isFile();
    FileCache cache = getBuildCache(input, true, userLevelCache);
    if (cache == null) {
        return null;
    }
    FileCache.Inputs buildCacheInputs = getBuildCacheInputs(input, dexOptions, dexer, minSdkVersion, isDebuggable);
    return cache.cacheEntryExists(buildCacheInputs) ? cache.getFileInCache(buildCacheInputs) : null;
}
Also used : FileCache(com.android.builder.utils.FileCache) Nullable(com.android.annotations.Nullable)

Example 10 with FileCache

use of com.android.builder.utils.FileCache in project atlas by alibaba.

the class AtlasDexArchiveBuilderCacheHander method populateCache.

public void populateCache(File input, File out) throws Exception {
    FileCache cache = getBuildCache(input, true, userLevelCache);
    if (cache != null) {
        FileCache.Inputs buildCacheInputs = AtlasDexArchiveBuilderCacheHander.getBuildCacheInputs(input, dexOptions, dexer, minSdkVersion, isDebuggable);
        FileCache.QueryResult result = cache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
            Files.copy(out.toPath(), in.toPath());
        });
        if (result.getQueryEvent().equals(FileCache.QueryEvent.CORRUPTED)) {
            Verify.verifyNotNull(result.getCauseOfCorruption());
            logger.info("The build cache at '%1$s' contained an invalid cache entry.\n" + "Cause: %2$s\n" + "We have recreated the cache entry.\n" + "%3$s", cache.getCacheDirectory().getAbsolutePath(), Throwables.getStackTraceAsString(result.getCauseOfCorruption()), BuildCacheUtils.BUILD_CACHE_TROUBLESHOOTING_MESSAGE);
        } else if (result.getQueryEvent().equals(FileCache.QueryEvent.MISSED)) {
            logger.warning("miss D8 cache:" + input.getAbsolutePath());
        } else if (result.getQueryEvent().equals(FileCache.QueryEvent.HIT)) {
            logger.warning("hit D8 cache:" + input.getAbsolutePath());
        }
    }
}
Also used : FileCache(com.android.builder.utils.FileCache)

Aggregations

FileCache (com.android.builder.utils.FileCache)11 Nullable (com.android.annotations.Nullable)3 ProcessException (com.android.ide.common.process.ProcessException)3 File (java.io.File)3 JarFile (java.util.jar.JarFile)3 ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)2 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)2 LoggedProcessOutputHandler (com.android.ide.common.process.LoggedProcessOutputHandler)2 ProcessOutput (com.android.ide.common.process.ProcessOutput)2 AndroidLocation (com.android.prefs.AndroidLocation)2 IOException (java.io.IOException)2 SdkConstants (com.android.SdkConstants)1 NonNull (com.android.annotations.NonNull)1 com.android.build.api.transform (com.android.build.api.transform)1 QualifiedContent (com.android.build.api.transform.QualifiedContent)1 LoggerWrapper (com.android.build.gradle.internal.LoggerWrapper)1 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)1 TransformManager (com.android.build.gradle.internal.pipeline.TransformManager)1