Skip to content

Commit 21a144e

Browse files
committed
Fix AndroidManifest meta-data parsing
1 parent 5b4cd40 commit 21a144e

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/AndroidManifest.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3+
* Copyright (C) 2016 the AndroidAnnotations project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
56
* use this file except in compliance with the License. You may obtain a copy of
@@ -24,7 +25,7 @@ public final class AndroidManifest {
2425

2526
private final String applicationPackage;
2627
private final List<String> componentQualifiedNames;
27-
private final Map<String, String> metaDataQualifiedNames;
28+
private final Map<String, MetaDataInfo> metaDataQualifiedNames;
2829
private final List<String> permissionQualifiedNames;
2930
private final String applicationClassName;
3031
private final boolean libraryProject;
@@ -43,15 +44,15 @@ public String toString() {
4344

4445
// CHECKSTYLE:OFF
4546

46-
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) {
47+
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) {
4748
return new AndroidManifest(false, applicationPackage, applicationClassName, componentQualifiedNames, metaDataQualifiedNames, permissionQualifiedNames, minSdkVersion, maxSdkVersion, targetSdkVersion, debugabble);
4849
}
4950

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

54-
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) {
55+
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) {
5556
this.libraryProject = libraryProject;
5657
this.applicationPackage = applicationPackage;
5758
this.applicationClassName = applicationClassName;
@@ -74,7 +75,7 @@ public List<String> getComponentQualifiedNames() {
7475
return Collections.unmodifiableList(componentQualifiedNames);
7576
}
7677

77-
public Map<String, String> getMetaDataQualifiedNames() {
78+
public Map<String, MetaDataInfo> getMetaDataQualifiedNames() {
7879
return Collections.unmodifiableMap(metaDataQualifiedNames);
7980
}
8081

@@ -106,4 +107,33 @@ public int getTargetSdkVersion() {
106107
return targetSdkVersion;
107108
}
108109

110+
public static final class MetaDataInfo {
111+
112+
private final String name;
113+
private final String value;
114+
private final String resource;
115+
116+
public MetaDataInfo(String name, String value, String resource) {
117+
this.name = name;
118+
this.value = value;
119+
this.resource = resource;
120+
}
121+
122+
public String getName() {
123+
return name;
124+
}
125+
126+
public String getValue() {
127+
return value;
128+
}
129+
130+
public String getResource() {
131+
return resource;
132+
}
133+
134+
@Override
135+
public String toString() {
136+
return "{" + "name='" + name + '\'' + ", value='" + value + '\'' + ", resource='" + resource + '\'' + '}';
137+
}
138+
}
109139
}

AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
3+
* Copyright (C) 2016 the AndroidAnnotations project
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
56
* use this file except in compliance with the License. You may obtain a copy of
@@ -294,7 +295,7 @@ private AndroidManifest parse(File androidManifestFile, boolean libraryProject)
294295
componentQualifiedNames.addAll(providerQualifiedNames);
295296

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

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

346-
private Map<String, String> extractMetaDataQualifiedNames(NodeList metaDataNodes) {
347-
Map<String, String> metaDataQualifiedNames = new HashMap<String, String>();
347+
private Map<String, AndroidManifest.MetaDataInfo> extractMetaDataQualifiedNames(NodeList metaDataNodes) {
348+
Map<String, AndroidManifest.MetaDataInfo> metaDataQualifiedNames = new HashMap<String, AndroidManifest.MetaDataInfo>();
348349

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

354-
if (nameAttribute == null || valueAttribute == null) {
356+
if (nameAttribute == null || (valueAttribute == null && resourceAttribute == null)) {
355357
if (nameAttribute != null) {
356358
LOGGER.warn("A malformed <meta-data> has been found in the manifest with name {}", nameAttribute.getNodeValue());
357359
} else {
358360
LOGGER.warn("A malformed <meta-data> has been found in the manifest");
359361
}
360362
} else {
361-
metaDataQualifiedNames.put(nameAttribute.getNodeValue(), valueAttribute.getNodeValue());
363+
String name = nameAttribute.getNodeValue();
364+
String value = valueAttribute != null ? valueAttribute.getNodeValue() : null;
365+
String resource = resourceAttribute != null ? resourceAttribute.getNodeValue() : null;
366+
metaDataQualifiedNames.put(name, new AndroidManifest.MetaDataInfo(name, value, resource));
362367
}
363368
}
364369

0 commit comments

Comments
 (0)