Search in sources :

Example 11 with AwbBundle

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

the class PreparePackageIdsTask method generate.

/**
     * packageid 范围是 30 - 127
     */
@TaskAction
void generate() throws IOException {
    File packageIdFile = appVariantContext.getAtlasExtension().getTBuildConfig().getPackageIdFile();
    File apPackageIdFile = appVariantContext.apContext.getPackageIdFile();
    boolean isAutoPackageId = appVariantContext.getAtlasExtension().getTBuildConfig().isAutoPackageId();
    Map<String, String> autoConfigMap = new HashMap<String, String>();
    if (null != apPackageIdFile && apPackageIdFile.exists()) {
        autoConfigMap.putAll(loadPackageIdProperties(apPackageIdFile));
    } else if (null != packageIdFile && packageIdFile.exists()) {
        autoConfigMap.putAll(loadPackageIdProperties(packageIdFile));
    }
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
        if (autoConfigMap.containsKey(key)) {
            continue;
        }
        File customPackageIDFile = new File(awbBundle.getFolder(), "customPackageID.txt");
        String packageId = getCustomPackageId(customPackageIDFile);
        if (StringUtils.isNotEmpty(packageId) && StringUtils.isNumeric(packageId)) {
            autoConfigMap.put(key, packageId);
        } else {
            autoConfigMap.put(key, "");
        }
    }
    if (isAutoPackageId && autoConfigMap.containsValue("")) {
        //自动分配autoConfig
        List<String> keys = new ArrayList<String>(autoConfigMap.keySet());
        Collections.sort(keys);
        for (String key : keys) {
            if ("".equals(autoConfigMap.get(key))) {
                for (int i = 30; i <= 127; i++) {
                    if (!autoConfigMap.values().contains(String.valueOf(i))) {
                        autoConfigMap.put(key, String.valueOf(i));
                        break;
                    }
                }
            }
        }
    }
    AtlasBuildContext.customPackageIdMaps = autoConfigMap;
    //wite package Id file
    File outPkgFile = new File(getProject().getBuildDir(), "outputs/packageIdFile.properties");
    writeProperties(autoConfigMap, outPkgFile);
    appBuildInfo.setPackageIdFile(outPkgFile);
    //check value
    if (autoConfigMap.containsValue("")) {
        getLogger().error(JSON.toJSONString(autoConfigMap, true));
        throw new GradleException("packageId 配置错误,请检查");
    }
    if (autoConfigMap.size() != new HashSet(autoConfigMap.values()).size()) {
        //            getLogger().error(JSON.toJSONString(autoConfigMap, true));
        Map<String, PackageIdItem> idItemMap = new HashMap<String, PackageIdItem>();
        for (String key : autoConfigMap.keySet()) {
            String customPackageId = autoConfigMap.get(key);
            PackageIdItem packageIdItem = idItemMap.get(customPackageId);
            if (null == packageIdItem) {
                String[] split = customPackageId.split("\\.");
                packageIdItem = new PackageIdItem();
                packageIdItem.packageId = Integer.valueOf(split[0]);
                if (split.length > 1) {
                    packageIdItem.typeIdOffset = Integer.valueOf(split[1]);
                }
                idItemMap.put(customPackageId, packageIdItem);
            }
            packageIdItem.bundles.add(key);
        }
        Collection<PackageIdItem> collection = idItemMap.values();
        List<PackageIdItem> packageList = new ArrayList<PackageIdItem>(collection);
        Collections.sort(packageList, new Comparator<PackageIdItem>() {

            @Override
            public int compare(PackageIdItem o1, PackageIdItem o2) {
                return o1.packageId - o2.packageId;
            }
        });
        getLogger().error(JSON.toJSONString(packageList, true));
        throw new GradleException("packageId 配置错误,有重复,请检查");
    }
    // check if packageID is not used
    Map<String, String> autoConfigMap2 = new HashMap<>(autoConfigMap);
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
        autoConfigMap2.remove(key);
    }
    if (autoConfigMap2.size() > 0) {
        File outPkgFile2 = new File(getProject().getBuildDir(), "outputs/warning-unusedPackageIdFile.properties");
        writeProperties(autoConfigMap2, outPkgFile2);
    }
}
Also used : AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) GradleException(org.gradle.api.GradleException) 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 12 with AwbBundle

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

the class MergeAssetAwbsConfigAction method execute.

@Override
public void execute(MtlParallelTask parallelTask) {
    super.execute(parallelTask);
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    List<DefaultTask> tasks = new ArrayList<DefaultTask>();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        MergeAwbAssetConfigAction mergeAwbAssetConfigAction = new MergeAwbAssetConfigAction(appVariantContext, baseVariantOutputData, awbBundle);
        MergeSourceSetFolders mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbAssetConfigAction.getName(), mergeAwbAssetConfigAction.getType());
        mergeAwbAssetConfigAction.execute(mergeTask);
        tasks.add(mergeTask);
    }
    parallelTask.parallelTask = tasks;
    parallelTask.uniqueTaskName = getName();
}
Also used : ArrayList(java.util.ArrayList) DefaultTask(org.gradle.api.DefaultTask) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) MergeAwbAssetConfigAction(com.taobao.android.builder.tasks.bundle.MergeAwbAssetConfigAction) MergeSourceSetFolders(com.android.build.gradle.tasks.MergeSourceSetFolders)

Example 13 with AwbBundle

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

the class MergeResAwbsConfigAction method execute.

@Override
public void execute(MtlParallelTask parallelTask) {
    super.execute(parallelTask);
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    List<DefaultTask> tasks = new ArrayList<DefaultTask>();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        MergeAwbResourceConfigAction mergeAwbResourceConfigAction = new MergeAwbResourceConfigAction(appVariantContext, baseVariantOutputData, awbBundle);
        final MergeResources mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbResourceConfigAction.getName(), mergeAwbResourceConfigAction.getType());
        mergeAwbResourceConfigAction.execute(mergeTask);
        tasks.add(mergeTask);
        mergeTask.doLast(new Action<Task>() {

            @Override
            public void execute(Task task) {
                File publicRes = new File(awbBundle.getResFolder(), "values/public.xml");
                if (publicRes.exists()) {
                    try {
                        FileUtils.copyFile(publicRes, new File(mergeTask.getOutputDir(), "values/public.xml"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
    parallelTask.parallelTask = tasks;
    parallelTask.uniqueTaskName = getName();
    parallelTask.concurrent = true;
}
Also used : MergeResources(com.android.build.gradle.tasks.MergeResources) MtlParallelTask(com.taobao.android.builder.tasks.app.MtlParallelTask) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) MergeAwbResourceConfigAction(com.taobao.android.builder.tasks.bundle.MergeAwbResourceConfigAction) ArrayList(java.util.ArrayList) DefaultTask(org.gradle.api.DefaultTask) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) IOException(java.io.IOException) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Example 14 with AwbBundle

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

the class BundleInfoUtils method getBundleInfoList.

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

Example 15 with AwbBundle

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

the class ApkInjectInfoCreator method creteInjectParam.

public InjectParam creteInjectParam(AppVariantContext appVariantContext) throws IOException, DocumentException {
    InjectParam injectParam = new InjectParam();
    injectParam.removePreverify = !appVariantContext.getAtlasExtension().getTBuildConfig().getDoPreverify();
    injectParam.version = appVariantContext.getVariantConfiguration().getVersionName();
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    List<BasicBundleInfo> basicBundleInfos = new ArrayList<BasicBundleInfo>();
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        BundleInfo muppBundleInfo = awbBundle.bundleInfo;
        BasicBundleInfo basicBundleInfo = new BasicBundleInfo();
        basicBundleInfo.setApplicationName(muppBundleInfo.getApplicationName());
        basicBundleInfo.setVersion(muppBundleInfo.getVersion());
        basicBundleInfo.setPkgName(muppBundleInfo.getPkgName());
        if (!muppBundleInfo.getIsInternal()) {
            basicBundleInfo.setIsInternal(false);
        }
        if (!muppBundleInfo.getActivities().isEmpty()) {
            basicBundleInfo.setActivities(muppBundleInfo.getActivities());
        }
        if (!muppBundleInfo.getContentProviders().isEmpty()) {
            basicBundleInfo.setContentProviders(muppBundleInfo.getContentProviders());
        }
        if (!muppBundleInfo.getDependency().isEmpty()) {
            basicBundleInfo.setDependency(muppBundleInfo.getDependency());
        }
        if (!muppBundleInfo.getReceivers().isEmpty()) {
            basicBundleInfo.setReceivers(muppBundleInfo.getReceivers());
        }
        if (!muppBundleInfo.getServices().isEmpty()) {
            basicBundleInfo.setServices(muppBundleInfo.getServices());
        }
        basicBundleInfos.add(basicBundleInfo);
    }
    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.autoStartBundles = StringUtils.join(appVariantContext.getAtlasExtension().getTBuildConfig().getAutoStartBundles(), ",");
    injectParam.preLaunch = appVariantContext.getAtlasExtension().getTBuildConfig().getPreLaunch();
    return injectParam;
}
Also used : 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) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Aggregations

AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)25 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)19 ArrayList (java.util.ArrayList)13 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)10 File (java.io.File)10 TaskAction (org.gradle.api.tasks.TaskAction)10 SoLibrary (com.taobao.android.builder.dependency.model.SoLibrary)6 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)5 DefaultTask (org.gradle.api.DefaultTask)5 GradleException (org.gradle.api.GradleException)5 AndroidLibrary (com.android.builder.model.AndroidLibrary)4 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)4 AarBundle (com.taobao.android.builder.dependency.model.AarBundle)3 HashSet (java.util.HashSet)3 DataBindingBuilder (android.databinding.tool.DataBindingBuilder)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 JarDependency (com.android.builder.dependency.JarDependency)2 LibraryDependency (com.android.builder.dependency.LibraryDependency)2 JavaLibrary (com.android.builder.model.JavaLibrary)2 IOException (java.io.IOException)2