Search in sources :

Example 1 with ManifestInfo

use of com.taobao.android.builder.tools.manifest.ManifestInfo in project atlas by alibaba.

the class StandardizeLibManifestTask method getManifestFileObject.

/**
 * Get the contents of the mainifest file
 *
 * @param manifestFile
 * @return
 */
public static ManifestInfo getManifestFileObject(File manifestFile) throws DocumentException {
    ManifestInfo manifestFileObject = new ManifestInfo();
    manifestFileObject.setManifestFile(manifestFile);
    if (manifestFile.exists()) {
        // Read the XML file
        Document document = XmlHelper.readXml(manifestFile);
        // Get the root node
        Element root = document.getRootElement();
        for (Attribute attribute : root.attributes()) {
            if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                manifestFileObject.addManifestProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
            } else {
                manifestFileObject.addManifestProperty(attribute.getName(), attribute.getValue());
            }
        }
        Element useSdkElement = root.element("uses-sdk");
        Element applicationElement = root.element("application");
        if (null != useSdkElement) {
            for (Attribute attribute : useSdkElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addUseSdkProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addUseSdkProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
        if (null != applicationElement) {
            for (Attribute attribute : applicationElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addApplicationProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addApplicationProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
    }
    manifestFileObject.init();
    return manifestFileObject;
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) ManifestInfo(com.taobao.android.builder.tools.manifest.ManifestInfo) Document(org.dom4j.Document)

Example 2 with ManifestInfo

use of com.taobao.android.builder.tools.manifest.ManifestInfo in project atlas by alibaba.

the class FeatureLibManifestTask method taskAction.

@TaskAction
public void taskAction() throws DocumentException, IOException {
    mainManifestFile = variantConfiguration.getMainManifest();
    ManifestInfo mainManifestFileObject = getManifestFileObject(mainManifestFile);
    final Set<ResolvedArtifactResult> artifacts = manifests.getArtifacts();
    List<ManifestProvider> providers = Lists.newArrayListWithCapacity(artifacts.size() + 2);
    for (ResolvedArtifactResult artifact : artifacts) {
        File manifestFile = artifact.getFile();
        File modifyManifest = featureVariantContext.getModifiedManifest(artifact);
        ManifestFileUtils.updatePreProcessManifestFile(modifyManifest, manifestFile, mainManifestFileObject, true, featureVariantContext.getAtlasExtension().getTBuildConfig().isIncremental());
        providers.add(new MergeManifests.ConfigAction.ManifestProviderImpl(modifyManifest, MergeManifests.getArtifactName(artifact)));
    }
    if (featureManifests != null) {
        final Set<ResolvedArtifactResult> featureArtifacts = featureManifests.getArtifacts();
        for (ResolvedArtifactResult artifact : featureArtifacts) {
            File directory = artifact.getFile();
            File modifyManifest = featureVariantContext.getModifiedManifest(artifact);
            Collection<BuildOutput> splitOutputs = BuildOutputs.load(VariantScope.TaskOutputType.MERGED_MANIFESTS, directory);
            if (splitOutputs.isEmpty()) {
                throw new GradleException("Could not load manifest from " + directory);
            }
            ManifestFileUtils.updatePreProcessManifestFile(modifyManifest, splitOutputs.iterator().next().getOutputFile(), mainManifestFileObject, true, featureVariantContext.getAtlasExtension().getTBuildConfig().isIncremental());
            providers.add(new MergeManifests.ConfigAction.ManifestProviderImpl(modifyManifest, MergeManifests.getArtifactName(artifact)));
        }
    }
    AtlasBuildContext.androidBuilderMap.get(getProject()).manifestProviders = providers;
}
Also used : BuildOutput(com.android.build.gradle.internal.scope.BuildOutput) GradleException(org.gradle.api.GradleException) ManifestInfo(com.taobao.android.builder.tools.manifest.ManifestInfo) ResolvedArtifactResult(org.gradle.api.artifacts.result.ResolvedArtifactResult) File(java.io.File) ManifestProvider(com.android.manifmerger.ManifestProvider) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with ManifestInfo

use of com.taobao.android.builder.tools.manifest.ManifestInfo in project atlas by alibaba.

the class StandardizeLibManifestTask method preProcess.

@TaskAction
public void preProcess() throws IOException, DocumentException, InterruptedException {
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantName());
    androidLibraries = dependencyTree.getAllAndroidLibrarys();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("StandardizeLibManifestTask", getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    ManifestInfo mainManifestFileObject = getManifestFileObject(mainManifestFile);
    appVariantContext.getModifyManifestDir().mkdirs();
    for (AndroidLibrary androidLibrary : androidLibraries) {
        File file = androidLibrary.getManifest();
        if (!file.exists()) {
            getLogger().error(androidLibrary.getResolvedCoordinates().toString() + " not has manifest : " + file.getAbsolutePath());
            return;
        }
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    File modifyManifest = appVariantContext.getModifyManifest(androidLibrary);
                    // getLogger().error(file.getAbsolutePath() + " -> " + modifyManifest
                    // .getAbsolutePath());
                    ManifestFileUtils.updatePreProcessManifestFile(modifyManifest, file, mainManifestFileObject, appVariantContext.getAtlasExtension().getTBuildConfig().isUpdateSdkVersion(), appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental());
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("preprocess manifest failed " + file.getAbsolutePath(), e);
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AndroidLibrary(com.android.builder.model.AndroidLibrary) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) ManifestInfo(com.taobao.android.builder.tools.manifest.ManifestInfo) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)

Aggregations

ManifestInfo (com.taobao.android.builder.tools.manifest.ManifestInfo)3 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)2 File (java.io.File)2 GradleException (org.gradle.api.GradleException)2 BuildOutput (com.android.build.gradle.internal.scope.BuildOutput)1 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 ManifestProvider (com.android.manifmerger.ManifestProvider)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)1 ArrayList (java.util.ArrayList)1 Attribute (org.dom4j.Attribute)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)1 TaskAction (org.gradle.api.tasks.TaskAction)1