Search in sources :

Example 1 with ExecutorServicesHelper

use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper 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 ExecutorServicesHelper

use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.

the class MtlParallelTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException {
    if (null == parallelTask || parallelTask.isEmpty()) {
        return;
    }
    if (concurrent) {
        String taskName = uniqueTaskName;
        if (StringUtils.isEmpty(taskName)) {
            taskName = parallelTask.get(0).getClass().getSimpleName();
        }
        ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
        List<Runnable> runnables = new ArrayList<>();
        for (final DefaultTask task : parallelTask) {
            runnables.add(new Runnable() {

                @Override
                public void run() {
                    task.execute();
                }
            });
        }
        executorServicesHelper.execute(runnables);
    } else {
        for (final DefaultTask task : parallelTask) {
            task.execute();
        }
    }
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ArrayList(java.util.ArrayList) DefaultTask(org.gradle.api.DefaultTask) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with ExecutorServicesHelper

use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.

the class JavacAwbsTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    AwbJavaCompileConfigAction awbJavaCompileConfigAction = new AwbJavaCompileConfigAction(awbBundle, appVariantOutputContext);
                    JavaCompile awbJavaCompile = TaskCreater.create(getProject(), awbJavaCompileConfigAction.getName(), awbJavaCompileConfigAction.getType());
                    awbJavaCompileConfigAction.execute(awbJavaCompile);
                    awbJavaCompile.execute();
                    AwbTransform awbTransform = appVariantOutputContext.getAwbTransformMap().get(awbBundle.getName());
                    awbTransform.setInputDir(awbJavaCompile.getDestinationDir());
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("javac " + awbBundle.getName() + " failed");
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with ExecutorServicesHelper

use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.

the class PrepareAwbTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException, IOException, DocumentException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    Set<SoLibrary> soLibraries = androidDependencyTree.getALLSoLibDependencies();
    for (final SoLibrary soLibrary : soLibraries) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(soLibrary.getSoLibFile(), soLibrary.getFolder(), false);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
    List<AwbBundle> awbBundles = androidDependencyTree.getAwbBundles();
    for (final AwbBundle awbBundle : awbBundles) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(awbBundle.getBundle(), awbBundle.getFolder(), true);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
    Set<AarBundle> aarBundles = androidDependencyTree.getALLAarDependencies();
    for (final AarBundle aarBundle : aarBundles) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                prepare(aarBundle.getBundle(), aarBundle.getFolder(), true);
            }
        });
    }
    executorServicesHelper.execute(runnables);
    runnables.clear();
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ArrayList(java.util.ArrayList) AarBundle(com.taobao.android.builder.dependency.model.AarBundle) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) SoLibrary(com.taobao.android.builder.dependency.model.SoLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with ExecutorServicesHelper

use of com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper in project atlas by alibaba.

the class PreProcessManifestTask method preProcess.

@TaskAction
public void preProcess() throws IOException, DocumentException, InterruptedException {
    getLogger().info("[MTLPlugin]Start PreProcess Lib manifest files,main manifestFile is:" + getMainManifestFile());
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("preProcessDex", getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    ManifestFileObject mainManifestFileObject = ManifestFileUtils.getManifestFileObject(mainManifestFile);
    mainManifestFileObject.init();
    for (File file : getLibraryManifests()) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    ManifestFileUtils.updatePreProcessManifestFile(file, mainManifestFileObject, true);
                } catch (Throwable e) {
                    throw new GradleException("preprocess manifest", e);
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
    //ManifestFileUtils.preProcessManifests(getMainManifestFile(), getLibraryManifests(), true);
    //BundleInfoUtils.setupAwbBundleInfos(appVariantOutputContext.getVariantContext());
    //collectBundleInfo();
    addAwbManifest2Merge();
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) ManifestFileObject(com.taobao.android.builder.tools.manifest.ManifestFileObject) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)7 ArrayList (java.util.ArrayList)7 TaskAction (org.gradle.api.tasks.TaskAction)7 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)6 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)5 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)5 File (java.io.File)4 GradleException (org.gradle.api.GradleException)4 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 VariantOutputScope (com.android.build.gradle.internal.scope.VariantOutputScope)1 AtlasBuilder (com.android.builder.core.AtlasBuilder)1 ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)1 DexParser (com.android.ide.common.blame.parser.DexParser)1 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)1 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)1 Predicate (com.google.common.base.Predicate)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AarBundle (com.taobao.android.builder.dependency.model.AarBundle)1