Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
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
Expand Up @@ -17,7 +17,9 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
Expand All @@ -38,6 +40,8 @@

public class AndroidManifestFinder {

private static final String ANDROID_MANIFEST_FILE = "androidManifestFile";

private static final int MAX_PARENTS_FROM_SOURCE_FOLDER = 10;

private ProcessingEnvironment processingEnv;
Expand Down Expand Up @@ -82,14 +86,34 @@ private AndroidManifest extractAndroidManifestThrowing() throws Exception {
return parseThrowing(androidManifestFile, libraryProject);
}

private File findManifestFileThrowing() throws Exception {
if (processingEnv.getOptions().containsKey(ANDROID_MANIFEST_FILE)) {
return findManifestInSpecifiedPath();
} else {
return findManifestInParentsDirectories();
}
}

private File findManifestInSpecifiedPath() {
String path = processingEnv.getOptions().get(ANDROID_MANIFEST_FILE);
File androidManifestFile = new File(path, "AndroidManifest.xml");
Messager messager = processingEnv.getMessager();
if (!androidManifestFile.exists()) {
throw new IllegalStateException("Could not find the AndroidManifest.xml file in specified path : " + path);
} else {
messager.printMessage(Kind.NOTE, "AndroidManifest.xml file found: " + androidManifestFile.toString());
}
return androidManifestFile;
}

/**
* We use a dirty trick to find the AndroidManifest.xml file, since it's not
* available in the classpath. The idea is quite simple : create a fake
* class file, retrieve its URI, and start going up in parent folders to
* find the AndroidManifest.xml file. Any better solution will be
* appreciated.
*/
private File findManifestFileThrowing() throws Exception {
private File findManifestInParentsDirectories() throws IOException, URISyntaxException {
Filer filer = processingEnv.getFiler();

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