Search in sources :

Example 11 with FileCache

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

the class AwbDexsMerger method merge.

public void merge(AwbBundle awbBundle) {
    File file = variantOutputContext.getVariantContext().getAwbDexAchiveOutput(awbBundle);
    List<File> awbDexFiles = new ArrayList<>();
    if (!file.exists() || !file.isDirectory()) {
        return;
    }
    awbDexFiles.addAll(org.apache.commons.io.FileUtils.listFiles(file, new String[] { "jar", "dex" }, true));
    File[] mergeDexs = file.listFiles(pathname -> pathname.getName().endsWith(".jar") || pathname.isDirectory());
    sort(awbDexFiles);
    File outPutFolder = variantOutputContext.getAwbDexOutput(awbBundle.getName());
    try {
        FileUtils.cleanOutputDir(outPutFolder);
    } catch (IOException e) {
        e.printStackTrace();
    }
    FileCache.Inputs buildCacheInputs = getBuildCacheInputs(awbDexFiles, dexingType, dexMerger, null, minSdkVersion, isDebuggable, awbBundle.getName(), ID);
    ProcessOutput output = outputHandler.createOutput();
    FileCache fileCache = BuildCacheUtils.createBuildCacheIfEnabled(variantOutputContext.getVariantContext().getProject(), variantOutputContext.getScope().getGlobalScope().getProjectOptions());
    if (fileCache == null) {
        try {
            fileCache = FileCache.getInstanceWithMultiProcessLocking(new File(AndroidLocation.getFolder(), "atlas-buildCache"));
        } catch (AndroidLocation.AndroidLocationException e) {
            e.printStackTrace();
        }
    }
    if (variantOutputContext.getVariantContext().getAtlasExtension().getTBuildConfig().getMergeBundlesDex() && !awbBundle.isRemote && awbBundle.isMBundle) {
        allDexsArchives.addAll(Arrays.asList(mergeDexs));
        return;
    }
    try {
        FileCache.QueryResult result = fileCache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
            List<ForkJoinTask<Void>> mergeTasks = new ArrayList<ForkJoinTask<Void>>();
            mergeTasks.addAll(handleLegacyAndMonoDex(Arrays.asList(mergeDexs), output, outPutFolder, null));
            mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());
            cacheHandler.handleMissActionResult(outPutFolder, in);
            if (output != null) {
                try {
                    outputHandler.handleOutput(output);
                } catch (ProcessException e) {
                // ignore this one
                }
            }
        });
        cacheHandler.handleQueryResult(result, outPutFolder, awbBundle.getName());
        if (awbBundle.isMBundle) {
            org.apache.commons.io.FileUtils.moveFile(new File(outPutFolder, CLASSES_DEX), new File(mainDexOut, "classes" + atomicInteger.incrementAndGet() + ".dex"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) ForkJoinTask(java.util.concurrent.ForkJoinTask) IOException(java.io.IOException) IOException(java.io.IOException) ProcessException(com.android.ide.common.process.ProcessException) FileCache(com.android.builder.utils.FileCache) ProcessException(com.android.ide.common.process.ProcessException) ProcessOutput(com.android.ide.common.process.ProcessOutput) File(java.io.File) AndroidLocation(com.android.prefs.AndroidLocation)

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