Search in sources :

Example 1 with ArtifactBundleInfo

use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.

the class DiffBundleInfoTask method getMainArtifactBundInfo.

private static ArtifactBundleInfo getMainArtifactBundInfo(File manifestFile) {
    ArtifactBundleInfo mainBundleInfo = new ArtifactBundleInfo();
    SAXReader reader = new SAXReader();
    // 读取XML文件
    Document document = null;
    try {
        document = reader.read(manifestFile);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage(), e);
    }
    // 得到根节点
    Element root = document.getRootElement();
    List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
    for (Node node : metadataNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute.getValue().equals("label")) {
            Attribute labelAttribute = element.attribute("value");
            mainBundleInfo.setName(labelAttribute.getValue());
        }
    }
    List<? extends Node> applicatNodes = root.selectNodes("//application");
    for (Node node : applicatNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            mainBundleInfo.setApplicationName(attribute.getValue());
        }
    }
    if ("manifest".equalsIgnoreCase(root.getName())) {
        List<Attribute> attributes = root.attributes();
        for (Attribute attr : attributes) {
            if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
                String versionName = attr.getValue();
                mainBundleInfo.setVersion(versionName);
            }
        }
    }
    String pkgName = root.attributeValue("package");
    mainBundleInfo.setPkgName(pkgName);
    return mainBundleInfo;
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) SAXReader(org.dom4j.io.SAXReader) GradleException(org.gradle.api.GradleException)

Example 2 with ArtifactBundleInfo

use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.

the class TPatchTool method createIncrementPatchFiles.

/**
     * 生成增量的patch文件
     */
private BuildPatchInfos createIncrementPatchFiles(String productionName, File curTPatchFile, File targetDirectory, File newApkUnzipFolder, PatchInfo curPatchInfo, String patchHistoryUrl) throws IOException, PatchException {
    BuildPatchInfos historyBuildPatchInfos = null;
    if (!StringUtils.isEmpty(patchHistoryUrl)) {
        String patchHisUrl = patchHistoryUrl + "?baseVersion=" + baseApkVersion + "&productIdentifier=" + productionName;
        String response = HttpClientUtils.getUrl(patchHisUrl);
        historyBuildPatchInfos = JSON.parseObject(response, BuildPatchInfos.class);
    }
    Map<String, File> awbBundleMap = new HashMap<String, File>();
    for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
        String bundleFileSoName = "lib" + artifactBundleInfo.getPkgName().replace('.', '_') + ".so";
        File bundleFile = new File(newApkUnzipFolder, "lib" + File.separator + "armeabi" + File.separator + bundleFileSoName);
        if (bundleFile.exists()) {
            awbBundleMap.put(artifactBundleInfo.getArtifactId(), bundleFile);
        }
    }
    PatchFileBuilder patchFileBuilder = new PatchFileBuilder(historyBuildPatchInfos, curTPatchFile, curPatchInfo, awbBundleMap, targetDirectory, baseApkVersion);
    patchFileBuilder.setNoPatchBundles(noPatchBundles);
    return patchFileBuilder.createHistoryTPatches(diffBundleDex, logger);
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BuildPatchInfos(com.taobao.android.object.BuildPatchInfos) File(java.io.File) PatchFileBuilder(com.taobao.android.tpatch.builder.PatchFileBuilder)

Example 3 with ArtifactBundleInfo

use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.

the class TPatchTool method createBasePatchInfo.

/**
     * 获取基准patch包的patchInfo对象
     *
     * @param fileName
     * @return
     */
public PatchInfo createBasePatchInfo(String fileName) {
    PatchInfo patchInfo = new PatchInfo();
    patchInfo.setPatchVersion(newApkVersion);
    patchInfo.setTargetVersion(baseApkVersion);
    patchInfo.setFileName(fileName);
    for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
        if (artifactBundleInfo.getMainBundle()) {
            if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) {
                PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
                patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
                patchBundleInfo.setMainBundle(true);
                patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
                patchBundleInfo.setName(mainBundleName);
                patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
                patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
                patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
                patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
                //                    patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
                patchInfo.getBundles().add(patchBundleInfo);
                continue;
            }
        } else if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || DiffType.ADD.equals(artifactBundleInfo.getDiffType())) {
            PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
            patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
            patchBundleInfo.setMainBundle(false);
            patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
            patchBundleInfo.setName(artifactBundleInfo.getName());
            patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
            patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
            patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
            patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
            //                patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
            patchInfo.getBundles().add(patchBundleInfo);
        }
    }
    return patchInfo;
}
Also used : PatchBundleInfo(com.taobao.android.object.PatchBundleInfo) ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) PatchInfo(com.taobao.android.object.PatchInfo)

Example 4 with ArtifactBundleInfo

use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.

the class BasePatchTool method isModifyBundle.

/**
     * 判断当前bundle是否有变化
     *
     * @param bundleSoFileName
     * @return
     */
public boolean isModifyBundle(String bundleSoFileName) {
    for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
        String packageName = artifactBundleInfo.getPkgName();
        if (null == packageName) {
            return false;
        }
        String bundleName = "lib" + packageName.replace('.', '_') + ".so";
        if (bundleName.equals(bundleSoFileName)) {
            if (null != logger) {
                logger.info("[BundleDiffType]" + bundleSoFileName + ":" + artifactBundleInfo.getDiffType());
            }
            if (DiffType.ADD.equals(artifactBundleInfo.getDiffType()) || DiffType.MODIFY.equals(artifactBundleInfo.getDiffType())) {
                return true;
            }
        }
    }
    return false;
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo)

Example 5 with ArtifactBundleInfo

use of com.taobao.android.object.ArtifactBundleInfo 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);
    }
    // 1. 首先添加主bundle
    ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
    mainBundleInfo.setBaseVersion(apVersion);
    mainBundleInfo.setMainBundle(true);
    mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
    if (dependencyDiff.getMainDexDiffs().size() > 0) {
        mainBundleInfo.setDiffType(DiffType.MODIFY);
    } else {
        mainBundleInfo.setDiffType(DiffType.NONE);
    }
    artifactBundleInfos.add(mainBundleInfo);
    // 2. 添加各自的bundle
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
    for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
        awbBundleInfo.setMainBundle(false);
        awbBundleInfo.setDependency(bundleInfo.getDependency());
        awbBundleInfo.setPkgName(bundleInfo.getPkgName());
        awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
        awbBundleInfo.setName(bundleInfo.getName());
        String version = bundleInfo.getVersion();
        if (version.indexOf("@") > 0) {
            String[] arr = version.split("@");
            version = arr[arr.length - 1];
        }
        awbBundleInfo.setVersion(version);
        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);
        }
        artifactBundleInfos.add(awbBundleInfo);
    }
    return artifactBundleInfos;
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) GradleException(org.gradle.api.GradleException) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) File(java.io.File) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) HashSet(java.util.HashSet)

Aggregations

ArtifactBundleInfo (com.taobao.android.object.ArtifactBundleInfo)5 File (java.io.File)2 GradleException (org.gradle.api.GradleException)2 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)1 BuildPatchInfos (com.taobao.android.object.BuildPatchInfos)1 PatchBundleInfo (com.taobao.android.object.PatchBundleInfo)1 PatchInfo (com.taobao.android.object.PatchInfo)1 PatchFileBuilder (com.taobao.android.tpatch.builder.PatchFileBuilder)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SAXReader (org.dom4j.io.SAXReader)1