Skip to content

Commit eb358eb

Browse files
committed
Merge pull request androidannotations#342 from pvardanega/AA164
Find AndroidManifest.xml by absolute path. Fixes androidannotations#164.
2 parents 81f2d9f + b43105e commit eb358eb

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/helper/AndroidManifestFinder.java‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import java.io.File;
1919
import java.io.FileInputStream;
20+
import java.io.IOException;
2021
import java.net.URI;
22+
import java.net.URISyntaxException;
2123
import java.util.ArrayList;
2224
import java.util.List;
2325
import java.util.Properties;
@@ -38,6 +40,8 @@
3840

3941
public class AndroidManifestFinder {
4042

43+
private static final String ANDROID_MANIFEST_FILE = "androidManifestFile";
44+
4145
private static final int MAX_PARENTS_FROM_SOURCE_FOLDER = 10;
4246

4347
private ProcessingEnvironment processingEnv;
@@ -82,14 +86,34 @@ private AndroidManifest extractAndroidManifestThrowing() throws Exception {
8286
return parseThrowing(androidManifestFile, libraryProject);
8387
}
8488

89+
private File findManifestFileThrowing() throws Exception {
90+
if (processingEnv.getOptions().containsKey(ANDROID_MANIFEST_FILE)) {
91+
return findManifestInSpecifiedPath();
92+
} else {
93+
return findManifestInParentsDirectories();
94+
}
95+
}
96+
97+
private File findManifestInSpecifiedPath() {
98+
String path = processingEnv.getOptions().get(ANDROID_MANIFEST_FILE);
99+
File androidManifestFile = new File(path, "AndroidManifest.xml");
100+
Messager messager = processingEnv.getMessager();
101+
if (!androidManifestFile.exists()) {
102+
throw new IllegalStateException("Could not find the AndroidManifest.xml file in specified path : " + path);
103+
} else {
104+
messager.printMessage(Kind.NOTE, "AndroidManifest.xml file found: " + androidManifestFile.toString());
105+
}
106+
return androidManifestFile;
107+
}
108+
85109
/**
86110
* We use a dirty trick to find the AndroidManifest.xml file, since it's not
87111
* available in the classpath. The idea is quite simple : create a fake
88112
* class file, retrieve its URI, and start going up in parent folders to
89113
* find the AndroidManifest.xml file. Any better solution will be
90114
* appreciated.
91115
*/
92-
private File findManifestFileThrowing() throws Exception {
116+
private File findManifestInParentsDirectories() throws IOException, URISyntaxException {
93117
Filer filer = processingEnv.getFiler();
94118

95119
JavaFileObject dummySourceFile = filer.createSourceFile("dummy" + System.currentTimeMillis());

0 commit comments

Comments
 (0)