Search in sources :

Example 16 with AtlasDependencyTree

use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.

the class ApkInjectInfoCreator method creteInjectParam.

public InjectParam creteInjectParam(AppVariantContext appVariantContext) throws Exception {
    InjectParam injectParam = new InjectParam();
    injectParam.removePreverify = !appVariantContext.getAtlasExtension().getTBuildConfig().getDoPreverify();
    injectParam.version = appVariantContext.getVariantConfiguration().getVersionName();
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    List<BasicBundleInfo> basicBundleInfos = new ArrayList<BasicBundleInfo>();
    Map<String, BasicBundleInfo> basicBundleInfoMap = new HashMap<>();
    List<String> mainDexDependencies = atlasDependencyTree.getMainBundle().getAllDependencies();
    Collections.sort(mainDexDependencies, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    String mainMd532 = MD5Util.getMD5(StringUtils.join(mainDexDependencies));
    String md5base36 = new BigInteger(mainMd532.substring(8, 24), 16).toString(36);
    injectParam.unit_tag = md5base36;
    appVariantContext.unit_tag = md5base36;
    // Depends on whether the change is sent
    DependencyDiff dependencyDiff = appVariantContext.getDependencyDiff();
    Map<String, String> baseTagMap = appVariantContext.getBaseUnitTagMap();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        // if (awbBundle.isMBundle){
        // continue;
        // }
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        BasicBundleInfo basicBundleInfo = new BasicBundleInfo();
        basicBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        basicBundleInfo.setVersion(bundleInfo.getVersion());
        basicBundleInfo.setPkgName(bundleInfo.getPkgName());
        // set unique_tag
        String bundleDependencyMd532 = MD5Util.getMD5(StringUtils.join(awbBundle.getAllDependencies()));
        String bundleUnitTag = "";
        if (null != dependencyDiff && !dependencyDiff.isDiffBundle(awbBundle)) {
            bundleUnitTag = baseTagMap.get(awbBundle.getPackageName());
        }
        if (StringUtils.isEmpty(bundleUnitTag)) {
            String bundleMd532 = MD5Util.getMD5(mainMd532 + bundleDependencyMd532);
            bundleUnitTag = new BigInteger(bundleMd532.substring(8, 24), 16).toString(36);
        }
        basicBundleInfo.setUnique_tag(bundleUnitTag);
        bundleInfo.setUnique_tag(bundleUnitTag);
        if (!bundleInfo.getIsInternal()) {
            basicBundleInfo.setIsInternal(false);
        }
        if (awbBundle.isMBundle) {
            basicBundleInfo.setIsMBundle(true);
        }
        if (!bundleInfo.getActivities().isEmpty()) {
            basicBundleInfo.setActivities(bundleInfo.getActivities());
        }
        if (!bundleInfo.getContentProviders().isEmpty()) {
            basicBundleInfo.setContentProviders(bundleInfo.getContentProviders());
        }
        if (!bundleInfo.getDependency().isEmpty()) {
            basicBundleInfo.setDependency(bundleInfo.getDependency());
        }
        if (!bundleInfo.getReceivers().isEmpty()) {
            basicBundleInfo.setReceivers(bundleInfo.getReceivers());
        }
        if (!bundleInfo.getServices().isEmpty()) {
            basicBundleInfo.setServices(bundleInfo.getServices());
        }
        if (!bundleInfo.getRemoteFragments().isEmpty()) {
            basicBundleInfo.setRemoteFragments(bundleInfo.getRemoteFragments());
        }
        if (!bundleInfo.getRemoteViews().isEmpty()) {
            basicBundleInfo.setRemoteViews(bundleInfo.getRemoteViews());
        }
        if (!bundleInfo.getRemoteTransactors().isEmpty()) {
            basicBundleInfo.setRemoteTransactors(bundleInfo.getRemoteTransactors());
        }
        basicBundleInfos.add(basicBundleInfo);
        basicBundleInfoMap.put(bundleInfo.getPkgName(), basicBundleInfo);
    }
    // Collections.sort(basicBundleInfos, (o1, o2) -> {
    // if (o1.getDependency().contains(o2.getPkgName())){
    // return -1;
    // }else {
    // return 1;
    // }
    // });
    basicBundleInfos.forEach(basicBundleInfo -> checkDependency(basicBundleInfo, atlasDependencyTree.getAwbBundles()));
    injectParam.bundleInfo = JSON.toJSONString(basicBundleInfos);
    // FIXME MOVE TO MTL-PLUGIN
    // List<String> autoStartBundles = new ArrayList<String>(appVariantContext.getAtlasExtension().getTBuildConfig
    // ().getAutoStartBundles());
    // 
    // UpdateConfig updateConfig = appVariantContext.getAtlasExtension().getUpdateConfig();
    // if (updateConfig.enabled) {
    // injectParam.group = updateConfig.getProductName();
    // injectParam.outApp = updateConfig.isOutApp();
    // autoStartBundles.add(0, updateConfig.getSdkPkgName());
    // }
    // 
    injectParam.group = appVariantContext.getAtlasExtension().getTBuildConfig().getGroup();
    injectParam.autoStartBundles = StringUtils.join(appVariantContext.getAtlasExtension().getTBuildConfig().getAutoStartBundles(), ",");
    injectParam.preLaunch = appVariantContext.getAtlasExtension().getTBuildConfig().getPreLaunch();
    mergeBundleInfos(appVariantContext, injectParam, basicBundleInfos, basicBundleInfoMap);
    return injectParam;
}
Also used : HashMap(java.util.HashMap) DependencyDiff(com.taobao.android.builder.dependency.diff.DependencyDiff) ArrayList(java.util.ArrayList) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) BigInteger(java.math.BigInteger) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 17 with AtlasDependencyTree

use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.

the class BundleInfoUtils method getBundleInfoList.

@NotNull
public static List<BundleInfo> getBundleInfoList(AppVariantContext appVariantContext) {
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    List<BundleInfo> bundleInfoList = new ArrayList<BundleInfo>();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        bundleInfoList.add(awbBundle.bundleInfo);
    }
    return bundleInfoList;
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with AtlasDependencyTree

use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.

the class AtlasDataBindingMergeArtifactsTransform method processAwbsDataBindings.

private void processAwbsDataBindings() throws IOException {
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getVariantName());
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        File awbDataBindDepsOutDir = variantContext.getAwbDataBindingMergeArtifacts(awbBundle);
        for (AndroidLibrary androidLibrary : awbBundle.getAndroidLibraries()) {
            File artifactFolder = new File(androidLibrary.getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
            if (artifactFolder.exists() && artifactFolder.listFiles() != null) {
                for (String artifactName : artifactFolder.list()) {
                    if (isResource(artifactName)) {
                        FileUtils.copyFile(new File(artifactFolder, artifactName), new File(awbDataBindDepsOutDir, artifactName));
                    }
                }
            }
        }
        File awbDataBindDir = new File(awbBundle.getAndroidLibrary().getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
        if (awbDataBindDir.exists() && awbDataBindDir.listFiles() != null) {
            for (String artifactName : awbDataBindDir.list()) {
                if (isResource(artifactName)) {
                    FileUtils.copyFile(new File(awbDataBindDir, artifactName), new File(awbDataBindDepsOutDir, artifactName));
                }
            }
        }
    }
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) File(java.io.File)

Example 19 with AtlasDependencyTree

use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.

the class AtlasDexArchiveBuilderTransform method processAwbDexArchive.

private void processAwbDexArchive(TransformInvocation transformInvocation, List<QualifiedContent> listFiles) throws Exception {
    File awbApkOutputDir = ((AppVariantContext) variantContext).getAwbApkOutputDir();
    FileUtils.cleanOutputDir(awbApkOutputDir);
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getScope().getFullVariantName());
    if (null == atlasDependencyTree) {
        return;
    }
    for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        Multimap<QualifiedContent, File> cacheableItems = HashMultimap.create();
        List<QualifiedContent> qualifiedContents = new LinkedList<>();
        long start = System.currentTimeMillis();
        // if some of our .jar input files exist, just reset the inputDir to null
        AwbTransform awbTransform = variantContext.getAppVariantOutputContext(ApkDataUtils.get(variantOutput)).getAwbTransformMap().get(awbBundle.getName());
        List<File> inputFiles = new ArrayList<File>();
        inputFiles.addAll(awbTransform.getInputFiles());
        inputFiles.addAll(awbTransform.getInputLibraries());
        if (null != awbTransform.getInputDirs()) {
            inputFiles.addAll(awbTransform.getInputDirs());
        }
        for (File file : inputFiles) {
            logger.warning(awbBundle.getName() + ":" + file.getAbsolutePath());
            boolean find = false;
            for (QualifiedContent content : listFiles) {
                if (content.getFile().getAbsolutePath().equals(file.getAbsolutePath())) {
                    find = true;
                    qualifiedContents.add(content);
                    break;
                }
            }
            if (!find) {
                if (file.isDirectory()) {
                    DirectoryInput directoryInput = TransformInputUtils.makeDirectoryInput(file, variantContext);
                    qualifiedContents.add(directoryInput);
                } else if (file.isFile()) {
                    JarInput jarInput = TransformInputUtils.makeJarInput(file, variantContext);
                    qualifiedContents.add(jarInput);
                }
            }
        }
        for (QualifiedContent qualifiedContent : qualifiedContents) {
            if (qualifiedContent.getFile().isDirectory()) {
                List<File> awbFiles = convertAwbToDexArchive(transformInvocation.getContext(), qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle), transformInvocation.isIncremental(), true);
                cacheableItems.putAll(qualifiedContent, awbFiles);
            } else {
                List<File> jarFiles = processAwbJarInput(transformInvocation.getContext(), transformInvocation.isIncremental(), (JarInput) qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle));
                cacheableItems.putAll(qualifiedContent, jarFiles);
            }
        }
        cacheItems.putAll(cacheableItems);
    }
}
Also used : AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JarFile(java.util.jar.JarFile) AppVariantContext(com.android.build.gradle.internal.api.AppVariantContext)

Example 20 with AtlasDependencyTree

use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.

the class AtlasTransformUtils method getTransformInputs.

public static Collection<File> getTransformInputs(AppVariantContext appVariantContext, TransformInvocation invocation) {
    ImmutableSet.Builder<File> builder = ImmutableSet.builder();
    Collection<File> transformInputs = TransformInputUtil.getAllFiles(invocation.getInputs());
    builder.addAll(transformInputs);
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantConfiguration().getFullName());
    if (atlasDependencyTree.getAwbBundles().size() > 0) {
        BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
        AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
        Collection<AwbTransform> awbTransforms = appVariantOutputContext.getAwbTransformMap().values();
        awbTransforms.forEach(awbTransform -> {
            builder.addAll(awbTransform.getInputLibraries());
        });
    }
    return builder.build();
}
Also used : BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) ImmutableSet(com.google.common.collect.ImmutableSet) AwbTransform(com.android.build.gradle.internal.api.AwbTransform) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) File(java.io.File) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree)

Aggregations

AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)38 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)26 File (java.io.File)21 ArrayList (java.util.ArrayList)16 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)13 GradleException (org.gradle.api.GradleException)13 TaskAction (org.gradle.api.tasks.TaskAction)12 IOException (java.io.IOException)11 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)8 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)7 VariantScope (com.android.build.gradle.internal.scope.VariantScope)7 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)6 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)6 JarFile (java.util.jar.JarFile)6 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)5 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)4 DefaultTask (org.gradle.api.DefaultTask)4 TaskContainerAdaptor (com.android.build.gradle.internal.TaskContainerAdaptor)3 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)3 Task (org.gradle.api.Task)3