11package com .googlecode .androidannotations .helper ;
22
33import java .io .File ;
4- import java .io . IOException ;
4+ import java .net . URI ;
55import java .util .ArrayList ;
66import java .util .List ;
77
88import javax .annotation .processing .Filer ;
99import javax .annotation .processing .Messager ;
1010import javax .annotation .processing .ProcessingEnvironment ;
11- import javax .tools .JavaFileObject ;
1211import javax .tools .Diagnostic .Kind ;
12+ import javax .tools .JavaFileObject ;
1313import javax .xml .parsers .DocumentBuilder ;
1414import 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