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;
}
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;
}
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);
}
Aggregations