Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand All @@ -24,7 +25,7 @@ public final class AndroidManifest {

private final String applicationPackage;
private final List<String> componentQualifiedNames;
private final Map<String, String> metaDataQualifiedNames;
private final Map<String, MetaDataInfo> metaDataQualifiedNames;
private final List<String> permissionQualifiedNames;
private final String applicationClassName;
private final boolean libraryProject;
Expand All @@ -43,15 +44,15 @@ public String toString() {

// CHECKSTYLE:OFF

public static AndroidManifest createManifest(String applicationPackage, String applicationClassName, List<String> componentQualifiedNames, Map<String, String> metaDataQualifiedNames, List<String> permissionQualifiedNames, int minSdkVersion, int maxSdkVersion, int targetSdkVersion, boolean debugabble) {
public static AndroidManifest createManifest(String applicationPackage, String applicationClassName, List<String> componentQualifiedNames, Map<String, MetaDataInfo> metaDataQualifiedNames, List<String> permissionQualifiedNames, int minSdkVersion, int maxSdkVersion, int targetSdkVersion, boolean debugabble) {
return new AndroidManifest(false, applicationPackage, applicationClassName, componentQualifiedNames, metaDataQualifiedNames, permissionQualifiedNames, minSdkVersion, maxSdkVersion, targetSdkVersion, debugabble);
}

public static AndroidManifest createLibraryManifest(String applicationPackage, int minSdkVersion, int maxSdkVersion, int targetSdkVersion) {
return new AndroidManifest(true, applicationPackage, "", Collections.<String> emptyList(), new HashMap<String, String>(), Collections.<String> emptyList(), minSdkVersion, maxSdkVersion, targetSdkVersion, false);
return new AndroidManifest(true, applicationPackage, "", Collections.<String> emptyList(), new HashMap<String, MetaDataInfo>(), Collections.<String> emptyList(), minSdkVersion, maxSdkVersion, targetSdkVersion, false);
}

private AndroidManifest(boolean libraryProject, String applicationPackage, String applicationClassName, List<String> componentQualifiedNames, Map<String, String> metaDataQualifiedNames, List<String> permissionQualifiedNames, int minSdkVersion, int maxSdkVersion, int targetSdkVersion, boolean debuggable) {
private AndroidManifest(boolean libraryProject, String applicationPackage, String applicationClassName, List<String> componentQualifiedNames, Map<String, MetaDataInfo> metaDataQualifiedNames, List<String> permissionQualifiedNames, int minSdkVersion, int maxSdkVersion, int targetSdkVersion, boolean debuggable) {
this.libraryProject = libraryProject;
this.applicationPackage = applicationPackage;
this.applicationClassName = applicationClassName;
Expand All @@ -74,7 +75,7 @@ public List<String> getComponentQualifiedNames() {
return Collections.unmodifiableList(componentQualifiedNames);
}

public Map<String, String> getMetaDataQualifiedNames() {
public Map<String, MetaDataInfo> getMetaDataQualifiedNames() {
return Collections.unmodifiableMap(metaDataQualifiedNames);
}

Expand Down Expand Up @@ -106,4 +107,33 @@ public int getTargetSdkVersion() {
return targetSdkVersion;
}

public static final class MetaDataInfo {

private final String name;
private final String value;
private final String resource;

public MetaDataInfo(String name, String value, String resource) {
this.name = name;
this.value = value;
this.resource = resource;
}

public String getName() {
return name;
}

public String getValue() {
return value;
}

public String getResource() {
return resource;
}

@Override
public String toString() {
return "{" + "name='" + name + '\'' + ", value='" + value + '\'' + ", resource='" + resource + '\'' + '}';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
Expand Down Expand Up @@ -294,7 +295,7 @@ private AndroidManifest parse(File androidManifestFile, boolean libraryProject)
componentQualifiedNames.addAll(providerQualifiedNames);

NodeList metaDataNodes = documentElement.getElementsByTagName("meta-data");
Map<String, String> metaDataQualifiedNames = extractMetaDataQualifiedNames(metaDataNodes);
Map<String, AndroidManifest.MetaDataInfo> metaDataQualifiedNames = extractMetaDataQualifiedNames(metaDataNodes);

NodeList usesPermissionNodes = documentElement.getElementsByTagName("uses-permission");
List<String> usesPermissionQualifiedNames = extractUsesPermissionNames(usesPermissionNodes);
Expand Down Expand Up @@ -343,22 +344,26 @@ private List<String> extractComponentNames(String applicationPackage, NodeList c
return componentQualifiedNames;
}

private Map<String, String> extractMetaDataQualifiedNames(NodeList metaDataNodes) {
Map<String, String> metaDataQualifiedNames = new HashMap<String, String>();
private Map<String, AndroidManifest.MetaDataInfo> extractMetaDataQualifiedNames(NodeList metaDataNodes) {
Map<String, AndroidManifest.MetaDataInfo> metaDataQualifiedNames = new HashMap<String, AndroidManifest.MetaDataInfo>();

for (int i = 0; i < metaDataNodes.getLength(); i++) {
Node node = metaDataNodes.item(i);
Node nameAttribute = node.getAttributes().getNamedItem("android:name");
Node valueAttribute = node.getAttributes().getNamedItem("android:value");
Node resourceAttribute = node.getAttributes().getNamedItem("android:resource");

if (nameAttribute == null || valueAttribute == null) {
if (nameAttribute == null || (valueAttribute == null && resourceAttribute == null)) {
if (nameAttribute != null) {
LOGGER.warn("A malformed <meta-data> has been found in the manifest with name {}", nameAttribute.getNodeValue());
} else {
LOGGER.warn("A malformed <meta-data> has been found in the manifest");
}
} else {
metaDataQualifiedNames.put(nameAttribute.getNodeValue(), valueAttribute.getNodeValue());
String name = nameAttribute.getNodeValue();
String value = valueAttribute != null ? valueAttribute.getNodeValue() : null;
String resource = resourceAttribute != null ? resourceAttribute.getNodeValue() : null;
metaDataQualifiedNames.put(name, new AndroidManifest.MetaDataInfo(name, value, resource));
}
}

Expand Down