Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 7477c8f

Browse files
committed
AndroidManifestFinder now take cares of all systems URIs, even with spaces inside the path. The trick was to use a file:// scheme instead of a file: scheme or no scheme. Closes issue 42.
1 parent 26b47fd commit 7477c8f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.googlecode.androidannotations.helper;
22

33
import java.io.File;
4-
import java.io.IOException;
4+
import java.net.URI;
55
import java.util.ArrayList;
66
import java.util.List;
77

88
import javax.annotation.processing.Filer;
99
import javax.annotation.processing.Messager;
1010
import javax.annotation.processing.ProcessingEnvironment;
11-
import javax.tools.JavaFileObject;
1211
import javax.tools.Diagnostic.Kind;
12+
import javax.tools.JavaFileObject;
1313
import javax.xml.parsers.DocumentBuilder;
1414
import javax.xml.parsers.DocumentBuilderFactory;
1515

@@ -32,6 +32,9 @@ public AndroidManifest extractAndroidManifest() {
3232
try {
3333
return extractAndroidManifestThrowing();
3434
} catch (Exception e) {
35+
if (e instanceof RuntimeException) {
36+
throw (RuntimeException) e;
37+
}
3538
throw new RuntimeException(e);
3639
}
3740
}
@@ -48,20 +51,28 @@ private AndroidManifest extractAndroidManifestThrowing() throws Exception {
4851
* find the AndroidManifest.xml file. Any better solution will be
4952
* appreciated.
5053
*/
51-
private File findManifestFileThrowing() throws IOException {
54+
private File findManifestFileThrowing() throws Exception {
5255
Filer filer = processingEnv.getFiler();
5356

5457
JavaFileObject dummySourceFile = filer.createSourceFile("dummy" + System.currentTimeMillis());
5558
String dummySourceFilePath = dummySourceFile.toUri().toString();
5659

5760
if (dummySourceFilePath.startsWith("file:")) {
58-
dummySourceFilePath = dummySourceFilePath.substring("file:".length());
61+
if (!dummySourceFilePath.startsWith("file://")) {
62+
dummySourceFilePath = "file://" + dummySourceFilePath.substring("file:".length());
63+
}
64+
} else {
65+
dummySourceFilePath = "file://" + dummySourceFilePath;
5966
}
6067

6168
Messager messager = processingEnv.getMessager();
6269
messager.printMessage(Kind.NOTE, "Dummy source file: " + dummySourceFilePath);
6370

64-
File sourcesGenerationFolder = new File(dummySourceFilePath).getParentFile();
71+
URI cleanURI = new URI(dummySourceFilePath);
72+
73+
File dummyFile = new File(cleanURI);
74+
75+
File sourcesGenerationFolder = dummyFile.getParentFile();
6576

6677
File projectRoot = sourcesGenerationFolder.getParentFile();
6778

@@ -80,7 +91,7 @@ private File findManifestFileThrowing() throws IOException {
8091
}
8192

8293
if (!androidManifestFile.exists()) {
83-
throw new IllegalStateException("Could not find the AndroidManifest.xml file, going up from path " + sourcesGenerationFolder.getAbsolutePath() + " found using dummy file [" + dummySourceFilePath + "] (max atempts: " + MAX_PARENTS_FROM_SOURCE_FOLDER + ")");
94+
throw new IllegalStateException("Could not find the AndroidManifest.xml file, going up from path [" + sourcesGenerationFolder.getAbsolutePath() + "] found using dummy file [" + dummySourceFilePath + "] (max atempts: " + MAX_PARENTS_FROM_SOURCE_FOLDER + ")");
8495
} else {
8596
messager.printMessage(Kind.NOTE, "AndroidManifest.xml file found: " + androidManifestFile.toString());
8697
}

0 commit comments

Comments
 (0)