Search in sources :

Example 11 with BundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.

the class BundleInfoUtils method getBundleInfoMap.

private static Map<String, BundleInfo> getBundleInfoMap(AppVariantContext appVariantContext) throws IOException {
    File baseBunfleInfoFile = new File(appVariantContext.getScope().getGlobalScope().getProject().getProjectDir(), "bundleBaseInfoFile.json");
    // Use the file replacement in the plug-in
    Map<String, BundleInfo> bundleFileMap = Maps.newHashMap();
    if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists() && baseBunfleInfoFile.canRead()) {
        String bundleBaseInfo = FileUtils.readFileToString(baseBunfleInfoFile, "utf-8");
        bundleFileMap = JSON.parseObject(bundleBaseInfo, new TypeReference<Map<String, BundleInfo>>() {
        });
    }
    List<AwbBundle> awbBundles = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantData().getName()).getAwbBundles();
    List<String> duplicatedBundleInfo = new ArrayList<>();
    Set<String> pkgNames = new HashSet<>();
    for (AwbBundle awbBundle : awbBundles) {
        pkgNames.add(awbBundle.getPackageName());
        String name = awbBundle.getResolvedCoordinates().getArtifactId();
        File bundleBaseInfoFile = new File(awbBundle.getAndroidLibrary().getFolder(), "bundleBaseInfoFile.json");
        if (bundleBaseInfoFile.exists()) {
            String json = FileUtils.readFileToString(bundleBaseInfoFile, "utf-8");
            BundleInfo bundleInfo = JSON.parseObject(json, BundleInfo.class);
            if (bundleFileMap.containsKey(name)) {
                appVariantContext.getProject().getLogger().error("bundleBaseInfoFile>>>" + name + " has declared bundleBaseInfoFile");
                duplicatedBundleInfo.add(name);
                for (String dependency : bundleInfo.getDependency()) {
                    if (!bundleFileMap.get(name).getDependency().contains(dependency))
                        bundleFileMap.get(name).getDependency().add(dependency);
                }
            } else {
                bundleFileMap.put(name, bundleInfo);
            }
        }
    }
    bundleFileMap.values().forEach(bundleInfo -> {
        List<String> removedBundles = new ArrayList<>();
        List<String> deps = bundleInfo.getDependency();
        for (String s : deps) {
            if (!pkgNames.contains(s)) {
                removedBundles.add(s);
            }
        }
        deps.removeAll(removedBundles);
    });
    if (duplicatedBundleInfo.size() > 0) {
        FileUtils.writeLines(new File(appVariantContext.getProject().getBuildDir(), "outputs/warning-dupbundleinfo.properties"), duplicatedBundleInfo);
    }
    return bundleFileMap;
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) TypeReference(com.alibaba.fastjson.TypeReference) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Example 12 with BundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.

the class BundleInfoUtils method update.

/**
 * Resolve the manifest file and get BundleInfo
 *
 * @return
 */
private static void update(AwbBundle awbBundle, Map<String, BundleInfo> bundleInfoMap, AppVariantContext appVariantContext, String apkVersion, String baseVersion) throws DocumentException {
    String artifactId = awbBundle.getResolvedCoordinates().getArtifactId();
    BundleInfo bundleInfo = bundleInfoMap.get(artifactId);
    if (null != bundleInfo) {
        awbBundle.bundleInfo = bundleInfo;
    } else {
        bundleInfo = awbBundle.bundleInfo;
    }
    bundleInfo.setIsMBundle(awbBundle.isMBundle);
    if (appVariantContext.getAtlasExtension().getTBuildConfig().getInsideOfApkBundles().size() > 0) {
        awbBundle.isRemote = !appVariantContext.getAtlasExtension().getTBuildConfig().getInsideOfApkBundles().contains(artifactId);
    } else if (appVariantContext.getAtlasExtension().getTBuildConfig().getOutOfApkBundles().size() > 0) {
        awbBundle.isRemote = appVariantContext.getAtlasExtension().getTBuildConfig().getOutOfApkBundles().contains(artifactId);
    }
    bundleInfo.setIsInternal(!awbBundle.isRemote);
    bundleInfo.setVersion(baseVersion + "@" + awbBundle.getResolvedCoordinates().getVersion());
    bundleInfo.setPkgName(awbBundle.getPackageName());
    String applicationName = ManifestFileUtils.getApplicationName(awbBundle.getManifest());
    if (StringUtils.isNotEmpty(applicationName)) {
        if (applicationName.startsWith(".")) {
            applicationName = awbBundle.getPackageName() + applicationName;
        }
        bundleInfo.setApplicationName(applicationName);
    }
    ManifestHelper.collectBundleInfo(appVariantContext, bundleInfo, awbBundle.getManifest(), awbBundle.getAndroidLibraries());
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)

Example 13 with BundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.

the class BundleInfoUtils method setupAwbBundleInfos.

public static void setupAwbBundleInfos(AppVariantContext appVariantContext) throws IOException, DocumentException {
    String apkVersion = appVariantContext.getVariantConfiguration().getVersionName();
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    /**
     * name Is artifictId
     */
    Map<String, BundleInfo> bundleInfoMap = getBundleInfoMap(appVariantContext);
    String baseVersion = apkVersion;
    if (null != appVariantContext.apContext && null != appVariantContext.apContext.getBaseManifest() && appVariantContext.apContext.getBaseManifest().exists()) {
        baseVersion = ManifestFileUtils.getVersionName(appVariantContext.apContext.getBaseManifest());
    }
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        update(awbBundle, bundleInfoMap, appVariantContext, apkVersion, baseVersion);
        if (appVariantContext.getAtlasExtension().getTBuildConfig().getDisabledBundleDependency()) {
            awbBundle.bundleInfo.getDependency().clear();
        }
    }
}
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)

Example 14 with BundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.

the class BundleInfoUtils method writeBundleInfo.

public static File writeBundleInfo(AppVariantContext appVariantContext) throws IOException, DocumentException {
    List<BundleInfo> bundleInfoList = getBundleInfoList(appVariantContext);
    File bundleInfoFile = new File(appVariantContext.getProject().getBuildDir(), "outputs/bundleInfo-" + appVariantContext.getVariantConfiguration().getVersionName() + ".json");
    File bundleInfoFile2 = new File(appVariantContext.getProject().getBuildDir(), "outputs/pretty-bundleInfo-" + appVariantContext.getVariantConfiguration().getVersionName() + ".json");
    try {
        FileUtils.write(bundleInfoFile, JSON.toJSONString(bundleInfoList, false));
        FileUtils.write(bundleInfoFile2, JSON.toJSONString(bundleInfoList, true));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bundleInfoFile;
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) IOException(java.io.IOException) File(java.io.File)

Example 15 with BundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.

the class DiffBundleInfoTask method getArtifactBundleInfo.

private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff, File mainfestFile, File apDir) throws IOException, DocumentException {
    Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
    if (null == apDir) {
        throw new GradleException("No Ap dependency found!");
    }
    File apManifest = new File(apDir, "AndroidManifest.xml");
    String apVersion = null;
    try {
        apVersion = ManifestFileUtils.getVersionName(apManifest);
    } catch (Exception e) {
        throw new GradleException(e.getMessage(), e);
    }
    Map<String, String> tagMap = new HashMap<>();
    JSONObject jsonObject = (JSONObject) JSON.parse(FileUtils.readFileToString(new File(apDir, "atlasFrameworkProperties.json")));
    JSONArray jsonArray = jsonObject.getJSONArray("bundleInfo");
    for (JSONObject obj : jsonArray.toArray(new JSONObject[0])) {
        tagMap.put(obj.getString("pkgName"), obj.getString("unique_tag"));
    }
    // 2. Add your own bundle
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
    List<AwbBundle> modifyMbundles = new ArrayList<>();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
        awbBundleInfo.setMainBundle(false);
        awbBundleInfo.setDependency(newDependency(bundleInfo.getDependency(), appVariantOutputContext.getVariantContext()));
        awbBundleInfo.setPkgName(bundleInfo.getPkgName());
        awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
        awbBundleInfo.setName(bundleInfo.getName());
        // History bundle's tag todo
        awbBundleInfo.setSrcUnitTag(tagMap.get(bundleInfo.getPkgName()));
        awbBundleInfo.setUnitTag(bundleInfo.getUnique_tag());
        String version = bundleInfo.getVersion();
        if (version.indexOf("@") > 0) {
            String[] arr = version.split("@");
            version = arr[arr.length - 1];
        }
        awbBundleInfo.setVersion(version);
        // TODO
        bundleInfo.getUnique_tag();
        String libBundleName = getBundleName(awbBundle);
        if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
            if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
                awbBundleInfo.setDiffType(DiffType.ADD);
            } else {
                awbBundleInfo.setDiffType(DiffType.MODIFY);
            }
        } else {
            awbBundleInfo.setDiffType(DiffType.NONE);
        }
        if (awbBundle.isMBundle) {
            if (awbBundleInfo.getDiffType() == DiffType.ADD || awbBundleInfo.getDiffType() == DiffType.MODIFY) {
                modifyMbundles.add(awbBundle);
            }
            continue;
        }
        artifactBundleInfos.add(awbBundleInfo);
    }
    // 1. First add the main bundle
    ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
    mainBundleInfo.setBaseVersion(apVersion);
    mainBundleInfo.setMainBundle(true);
    mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
    if (dependencyDiff.getMainDexDiffs().size() > 0 || modifyMbundles.size() > 0) {
        mainBundleInfo.setDiffType(DiffType.MODIFY);
    } else {
        mainBundleInfo.setDiffType(DiffType.NONE);
    }
    mainBundleInfo.setSrcUnitTag(jsonObject.getString("unit_tag"));
    mainBundleInfo.setUnitTag(appVariantOutputContext.getVariantContext().unit_tag);
    artifactBundleInfos.add(mainBundleInfo);
    return artifactBundleInfos;
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) JSONArray(com.alibaba.fastjson.JSONArray) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) JSONObject(com.alibaba.fastjson.JSONObject) GradleException(org.gradle.api.GradleException) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File)

Aggregations

BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)15 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)9 File (java.io.File)7 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)5 HashMap (java.util.HashMap)5 GradleException (org.gradle.api.GradleException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 BundleItem (com.taobao.android.builder.tools.bundleinfo.BundleItem)3 TypeReference (com.alibaba.fastjson.TypeReference)2 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)2 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 Map (java.util.Map)2 JarFile (java.util.jar.JarFile)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)1 VariantScope (com.android.build.gradle.internal.scope.VariantScope)1 BaseTask (com.android.build.gradle.internal.tasks.BaseTask)1