Search in sources :

Example 1 with LoggedProcessOutputHandler

use of com.android.ide.common.process.LoggedProcessOutputHandler 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 2 with LoggedProcessOutputHandler

use of com.android.ide.common.process.LoggedProcessOutputHandler 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

NonNull (com.android.annotations.NonNull)2 Nullable (com.android.annotations.Nullable)2 LoggedProcessOutputHandler (com.android.ide.common.process.LoggedProcessOutputHandler)2 ProcessException (com.android.ide.common.process.ProcessException)2 File (java.io.File)2 IOException (java.io.IOException)2 SdkConstants (com.android.SdkConstants)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 AaptPackageProcessBuilder (com.android.builder.core.AaptPackageProcessBuilder)1 AtlasBuilder (com.android.builder.core.AtlasBuilder)1 DesugarProcessBuilder (com.android.builder.core.DesugarProcessBuilder)1 FileCache (com.android.builder.utils.FileCache)1 WaitableExecutor (com.android.ide.common.internal.WaitableExecutor)1