Search in sources :

Example 1 with ToolOutputParser

use of com.android.ide.common.blame.parser.ToolOutputParser in project atlas by alibaba.

the class PackageAwbsTask method createAwbPackages.

/**
     * 生成so的目录
     */
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    final ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    final AtomicLong dexTotalTime = new AtomicLong(0);
    final AtomicLong packageTotalTime = new AtomicLong(0);
    final Map<String, Long[]> monitors = new HashMap<String, Long[]>();
    long startTime = System.currentTimeMillis();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    long start = System.currentTimeMillis();
                    //create dex
                    File dexOutputFile = appVariantContext.getAwbDexOutput(awbBundle.getName());
                    emptyFolder(dexOutputFile);
                    // if some of our .jar input files exist, just reset the inputDir to null
                    AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
                    List<File> inputFiles = new ArrayList<File>();
                    inputFiles.addAll(awbTransform.getInputFiles());
                    inputFiles.addAll(awbTransform.getInputLibraries());
                    if (null != awbTransform.getInputDir()) {
                        inputFiles.add(awbTransform.getInputDir());
                    }
                    AtlasBuildContext.androidBuilder.convertByteCode(inputFiles, dexOutputFile, appVariantContext.getVariantData().getVariantConfiguration().isMultiDexEnabled(), null, androidConfig.getDexOptions(), true, outputHandler);
                    //create package
                    long endDex = System.currentTimeMillis();
                    //PACKAGE APP:
                    File resourceFile = appVariantOutputContext.getAwbAndroidResourcesMap().get(awbBundle.getName()).getPackageOutputFile();
                    Set<File> dexFolders = new HashSet<File>();
                    dexFolders.add(dexOutputFile);
                    Set<File> jniFolders = Sets.newHashSet();
                    if (appVariantOutputContext.getAwbJniFolder(awbBundle) != null && appVariantOutputContext.getAwbJniFolder(awbBundle).exists()) {
                        jniFolders.add(appVariantOutputContext.getAwbJniFolder(awbBundle));
                    }
                    Set<File> javaResourcesLocations = Sets.newHashSet();
                    if (appVariantContext.getAtlasExtension().getTBuildConfig().getMergeAwbJavaRes()) {
                        javaResourcesLocations.addAll(awbBundle.getLibraryJars());
                    }
                    //getBuilder().packageCodeSplitApk();
                    getBuilder().oldPackageApk(resourceFile.getAbsolutePath(), dexFolders, javaResourcesLocations, jniFolders, null, getAbiFilters(), config.getBuildType().isJniDebuggable(), null, getOutputFile(awbBundle), config.getMinSdkVersion().getApiLevel(), new Predicate<String>() {

                        @Override
                        public boolean apply(@Nullable String s) {
                            return false;
                        }
                    });
                    long endPackage = System.currentTimeMillis();
                    dexTotalTime.addAndGet(endDex - start);
                    packageTotalTime.addAndGet(endPackage - endDex);
                    monitors.put(awbBundle.getName(), new Long[] { endDex - start, endPackage - endDex });
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("package " + awbBundle.getName() + " failed");
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
    if (getLogger().isInfoEnabled()) {
        getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
        getLogger().info("totalTime is " + (System.currentTimeMillis() - startTime));
        getLogger().info("dexTotalTime is " + dexTotalTime);
        getLogger().info("packageTotalTime is " + packageTotalTime);
        String format = "[packageawb]  bundle:%50s  dexTime: %10d  packageTime: %10d ";
        for (String bundle : monitors.keySet()) {
            Long[] value = monitors.get(bundle);
            getLogger().info(String.format(format, bundle, value[0], value[1]));
        }
        getLogger().info(">>>>> packageAwbs >>>>>>>>>>>>");
    }
}
Also used : HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) Predicate(com.google.common.base.Predicate) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) ArrayList(java.util.ArrayList) List(java.util.List) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) AtomicLong(java.util.concurrent.atomic.AtomicLong) DexParser(com.android.ide.common.blame.parser.DexParser) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) GradleException(org.gradle.api.GradleException) AtomicLong(java.util.concurrent.atomic.AtomicLong) File(java.io.File) Nullable(javax.annotation.Nullable) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with ToolOutputParser

use of com.android.ide.common.blame.parser.ToolOutputParser in project atlas by alibaba.

the class AwbDexTask method doTaskAction.

private void doTaskAction(@Nullable Collection<File> inputFiles, @Nullable File inputDir, boolean incremental) throws InterruptedException, ProcessException, IOException {
    File outFolder = getOutputFolder();
    if (!incremental) {
        emptyFolder(outFolder);
    }
    // if some of our .jar input files exist, just reset the inputDir to null
    for (File inputFile : inputFiles) {
        if (inputFile.exists()) {
            inputDir = null;
        }
    }
    if (inputDir != null) {
        inputFiles = getProject().files(inputDir).getFiles();
    }
    ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, getILogger()), new ToolOutputParser(new DexParser(), getILogger()), getBuilder().getErrorReporter());
    getBuilder().convertByteCode(inputFiles, getOutputFolder(), getMultiDexEnabled(), getMainDexListFile(), getDexOptions(), getOptimize(), outputHandler);
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DexParser(com.android.ide.common.blame.parser.DexParser) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Example 3 with ToolOutputParser

use of com.android.ide.common.blame.parser.ToolOutputParser in project atlas by alibaba.

the class TPatchDiffResAPBuildTask method doAction.

@TaskAction
protected void doAction() throws IOException {
    manifestFile = getManifestFile();
    aaptOptions = getAaptOptions();
    diffResDir = getDiffResDir();
    resourceConfigs = getResourceConfigs();
    preferredDensity = getPreferredDensity();
    //TODO  minifyManifest
    File miniManifest = new File(packageOutputFile.getParentFile(), "AndroidManifest.xml");
    try {
        ManifestFileUtils.minifyManifest(manifestFile, miniManifest);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage());
    }
    File assetsFolder = new File(diffResDir, "assets");
    File resFolder = new File(diffResDir, "res");
    if (!assetsFolder.exists()) {
        assetsFolder.mkdirs();
    }
    if (!resFolder.exists()) {
        resFolder.mkdirs();
    }
    AaptPackageProcessBuilder aaptPackageCommandBuilder = new AaptPackageProcessBuilder(miniManifest, aaptOptions).setAssetsFolder(assetsFolder).setResFolder(resFolder).setLibraries(libraries).setPackageForR(packageForR).setResPackageOutput(packageOutputFile.getAbsolutePath()).setType(type).setDebuggable(debuggable).setPseudoLocalesEnabled(pseudoLocalesEnabled).setResourceConfigs(resourceConfigs).setSplits(splits).setPreferredDensity(preferredDensity);
    @NonNull AndroidBuilder builder = getBuilder();
    MergingLog mergingLog = new MergingLog(mergeBlameLogFolder);
    ProcessOutputHandler processOutputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new AaptOutputParser(), getILogger()), new MergingLogRewriter(mergingLog, builder.getErrorReporter()));
    try {
        if (builder instanceof AtlasBuilder) {
            ((AtlasBuilder) builder).processResources(aaptPackageCommandBuilder, enforceUniquePackageName, processOutputHandler);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ProcessException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) MergingLog(com.android.ide.common.blame.MergingLog) AaptOutputParser(com.android.ide.common.blame.parser.aapt.AaptOutputParser) IOException(java.io.IOException) MergingLogRewriter(com.android.ide.common.blame.MergingLogRewriter) ProcessException(com.android.ide.common.process.ProcessException) AaptPackageProcessBuilder(com.android.builder.core.AaptPackageProcessBuilder) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DocumentException(org.dom4j.DocumentException) GradleException(org.gradle.api.GradleException) NonNull(com.android.annotations.NonNull) AndroidBuilder(com.android.builder.core.AndroidBuilder) AtlasBuilder(com.android.builder.core.AtlasBuilder) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)3 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)3 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)3 File (java.io.File)3 DexParser (com.android.ide.common.blame.parser.DexParser)2 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)2 GradleException (org.gradle.api.GradleException)2 InputFile (org.gradle.api.tasks.InputFile)2 TaskAction (org.gradle.api.tasks.TaskAction)2 NonNull (com.android.annotations.NonNull)1 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)1 AaptPackageProcessBuilder (com.android.builder.core.AaptPackageProcessBuilder)1 AndroidBuilder (com.android.builder.core.AndroidBuilder)1 AtlasBuilder (com.android.builder.core.AtlasBuilder)1 MergingLog (com.android.ide.common.blame.MergingLog)1 MergingLogRewriter (com.android.ide.common.blame.MergingLogRewriter)1 AaptOutputParser (com.android.ide.common.blame.parser.aapt.AaptOutputParser)1 ProcessException (com.android.ide.common.process.ProcessException)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1