Search in sources :

Example 6 with ExecutorServicesHelper

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

the class ProcessResAwbsTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    final VariantOutputScope outputScope = appVariantOutputContext.getOutputScope();
    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() {
                File symbolLocation = new File(outputScope.getGlobalScope().getIntermediatesDir(), "awb-symbols/" + outputScope.getVariantScope().getVariantConfiguration().getDirName() + "/" + awbBundle.getName());
                //把资源写入ap中,给debug用
                if ("debug".equals(appVariantOutputContext.getVariantContext().getBaseVariantData().getName())) {
                    appVariantOutputContext.appBuildInfo.getOtherFilesMap().put("awo/" + awbBundle.getPackageName() + ".R.txt", new File(symbolLocation, "R.txt"));
                }
                ProcessAwbAndroidResources.ConfigAction configAction = new ProcessAwbAndroidResources.ConfigAction(outputScope, symbolLocation, true, awbBundle, (AtlasBuilder) getBuilder(), appVariantOutputContext);
                ProcessAwbAndroidResources processAwbAndroidResources = TaskCreater.create(getProject(), configAction.getName(), configAction.getType());
                configAction.execute(processAwbAndroidResources);
                processAwbAndroidResources.execute();
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) VariantOutputScope(com.android.build.gradle.internal.scope.VariantOutputScope) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AtlasBuilder(com.android.builder.core.AtlasBuilder) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with ExecutorServicesHelper

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

the class DataBindingRenameTask method createAwbPackages.

/**
     * 生成so的目录
     */
@TaskAction
void createAwbPackages() 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 {
                    File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
                    String packageName = ManifestFileUtils.getPackage(awbBundle.getOrgManifestFile());
                    String appName = appVariantContext.getVariantConfiguration().getOriginalApplicationId();
                    //删除那些已经存在的类
                    File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
                    if (!dataMapperClazz.exists()) {
                        throw new GradleException("missing datamapper class");
                    }
                    FileInputStream fileInputStream = new FileInputStream(dataMapperClazz);
                    ClassReader in1 = new ClassReader(fileInputStream);
                    ClassWriter cw = new ClassWriter(0);
                    Map<String, String> reMapping = new HashedMap();
                    reMapping.put(appName.replace(".", "/") + "/BR", packageName.replace(".", "/") + "/BR");
                    RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
                    in1.accept(remappingClassAdapter, 8);
                    ClassReader in2 = new ClassReader(cw.toByteArray());
                    ClassWriter cw2 = new ClassWriter(0);
                    Set<String> renames = new HashSet<String>();
                    renames.add("android/databinding/DataBinderMapper");
                    in2.accept(new ClassRenamer(cw2, renames, packageName.replace(".", "/") + "/DataBinderMapper"), 8);
                    File destClass = new File(dataBindingClazzFolder, packageName.replace(".", "/") + "/DataBinderMapper.class");
                    destClass.getParentFile().mkdirs();
                    FileOutputStream fileOutputStream = new FileOutputStream(destClass);
                    fileOutputStream.write(cw2.toByteArray());
                    IOUtils.closeQuietly(fileOutputStream);
                    IOUtils.closeQuietly(fileInputStream);
                    FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
                    FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "com/android/databinding"));
                    File appDir = new File(dataBindingClazzFolder, appName.replace(".", "/"));
                    if (appDir.exists()) {
                        File[] files = appDir.listFiles(new FileFilter() {

                            @Override
                            public boolean accept(File pathname) {
                                return pathname.isFile() && !pathname.isDirectory();
                            }
                        });
                        for (File tmp : files) {
                            FileUtils.forceDelete(tmp);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("package awb failed");
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) FileInputStream(java.io.FileInputStream) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) SimpleRemapper(org.objectweb.asm.commons.SimpleRemapper) RemappingClassAdapter(org.objectweb.asm.commons.RemappingClassAdapter) GradleException(org.gradle.api.GradleException) FileOutputStream(java.io.FileOutputStream) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) HashedMap(org.apache.commons.collections.map.HashedMap) FileFilter(java.io.FileFilter) File(java.io.File) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) 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