AndroidManifestParserpublic class AndroidManifestParser extends Object
Fields Summary |
---|
private static final String | ATTRIBUTE_PACKAGE | private static final String | ATTRIBUTE_NAME | private static final String | ATTRIBUTE_PROCESS | private static final String | ATTRIBUTE_DEBUGGABLE | private static final String | ATTRIBUTE_MIN_SDK_VERSION | private static final String | ATTRIBUTE_TARGET_PACKAGE | private static final String | ATTRIBUTE_EXPORTED | private static final String | NODE_MANIFEST | private static final String | NODE_APPLICATION | private static final String | NODE_ACTIVITY | private static final String | NODE_SERVICE | private static final String | NODE_RECEIVER | private static final String | NODE_PROVIDER | private static final String | NODE_INTENT | private static final String | NODE_ACTION | private static final String | NODE_CATEGORY | private static final String | NODE_USES_SDK | private static final String | NODE_INSTRUMENTATION | private static final String | NODE_USES_LIBRARY | private static final int | LEVEL_MANIFEST | private static final int | LEVEL_APPLICATION | private static final int | LEVEL_ACTIVITY | private static final int | LEVEL_INTENT_FILTER | private static final int | LEVEL_CATEGORY | private static final String | ACTION_MAIN | private static final String | CATEGORY_LAUNCHER | public static final int | INVALID_MIN_SDK | private static SAXParserFactory | sParserFactory | private final String | mJavaPackage | private final Activity[] | mActivities | private final Activity | mLauncherActivity | private final String[] | mProcesses | private final Boolean | mDebuggable | private final int | mApiLevelRequirement | private final Instrumentation[] | mInstrumentations | private final String[] | mLibraries |
Constructors Summary |
---|
private AndroidManifestParser(String javaPackage, Activity[] activities, Activity launcherActivity, String[] processes, Boolean debuggable, int apiLevelRequirement, Instrumentation[] instrumentations, String[] libraries)Private constructor to enforce using
{@link #parse(IJavaProject, XmlErrorListener, boolean, boolean)},
{@link #parse(IJavaProject, IFile, XmlErrorListener, boolean, boolean)},
or {@link #parseForError(IJavaProject, IFile, XmlErrorListener)} to get an
{@link AndroidManifestParser} object.
mJavaPackage = javaPackage;
mActivities = activities;
mLauncherActivity = launcherActivity;
mProcesses = processes;
mDebuggable = debuggable;
mApiLevelRequirement = apiLevelRequirement;
mInstrumentations = instrumentations;
mLibraries = libraries;
|
Methods Summary |
---|
public static java.lang.String | combinePackageAndClassName(java.lang.String javaPackage, java.lang.String className)Combines a java package, with a class value from the manifest to make a fully qualified
class name
if (className == null || className.length() == 0) {
return javaPackage;
}
if (javaPackage == null || javaPackage.length() == 0) {
return className;
}
// the class name can be a subpackage (starts with a '.'
// char), a simple class name (no dot), or a full java package
boolean startWithDot = (className.charAt(0) == '.");
boolean hasDot = (className.indexOf('.") != -1);
if (startWithDot || hasDot == false) {
// add the concatenation of the package and class name
if (startWithDot) {
return javaPackage + className;
} else {
return javaPackage + '." + className;
}
} else {
// just add the class as it should be a fully qualified java name.
return className;
}
| public static java.lang.String | extractActivityName(java.lang.String fullActivityName, java.lang.String packageName)Given a fully qualified activity name (e.g. com.foo.test.MyClass) and given a project
package base name (e.g. com.foo), returns the relative activity name that would be used
the "name" attribute of an "activity" element.
if (packageName != null && fullActivityName != null) {
if (packageName.length() > 0 && fullActivityName.startsWith(packageName)) {
String name = fullActivityName.substring(packageName.length());
if (name.length() > 0 && name.charAt(0) == '.") {
return name;
}
}
}
return fullActivityName;
| public com.android.ide.eclipse.common.project.AndroidManifestParser$Activity[] | getActivities()Returns the list of activities found in the manifest.
return mActivities;
| public int | getApiLevelRequirement()Returns the minSdkVersion attribute, or {@link #INVALID_MIN_SDK}
if it's not set.
return mApiLevelRequirement;
| public java.lang.Boolean | getDebuggable()Returns the debuggable attribute value or null if it is not set.
return mDebuggable;
| public com.android.ide.eclipse.common.project.AndroidManifestParser$Instrumentation[] | getInstrumentations()Returns the list of instrumentations found in the manifest.
return mInstrumentations;
| public com.android.ide.eclipse.common.project.AndroidManifestParser$Activity | getLauncherActivity()Returns the name of one activity found in the manifest, that is configured to show
up in the HOME screen.
return mLauncherActivity;
| public static org.eclipse.core.resources.IFile | getManifest(org.eclipse.core.resources.IProject project)Returns an IFile object representing the manifest for the specified
project.
IResource r = project.findMember(AndroidConstants.WS_SEP
+ AndroidConstants.FN_ANDROID_MANIFEST);
if (r == null || r.exists() == false || (r instanceof IFile) == false) {
return null;
}
return (IFile) r;
| public java.lang.String | getPackage()Returns the package defined in the manifest, if found.
return mJavaPackage;
| public java.lang.String[] | getProcesses()Returns the list of process names declared by the manifest.
return mProcesses;
| public java.lang.String[] | getUsesLibraries()Returns the list of libraries in use found in the manifest.
return mLibraries;
| public static com.android.ide.eclipse.common.project.AndroidManifestParser | parse(org.eclipse.jdt.core.IJavaProject javaProject, org.eclipse.core.resources.IFile manifestFile, com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener errorListener, boolean gatherData, boolean markErrors)Parses the Android Manifest, and returns an object containing the result of the parsing.
This method is useful to parse a specific {@link IFile} in a Java project.
If you only want to gather data, consider {@link #parseForData(IFile)} instead.
sParserFactory = SAXParserFactory.newInstance();
sParserFactory.setNamespaceAware(true);
try {
SAXParser parser = sParserFactory.newSAXParser();
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
errorListener, gatherData, javaProject, markErrors);
parser.parse(new InputSource(manifestFile.getContents()), manifestHandler);
// get the result from the handler
return new AndroidManifestParser(manifestHandler.getPackage(),
manifestHandler.getActivities(),
manifestHandler.getLauncherActivity(),
manifestHandler.getProcesses(),
manifestHandler.getDebuggable(),
manifestHandler.getApiLevelRequirement(),
manifestHandler.getInstrumentations(),
manifestHandler.getUsesLibraries());
} catch (ParserConfigurationException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Bad parser configuration for %s: %s",
manifestFile.getFullPath(),
e.getMessage());
} catch (SAXException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Parser exception for %s: %s",
manifestFile.getFullPath(),
e.getMessage());
} catch (IOException e) {
// Don't log a console error when failing to read a non-existing file
if (!(e instanceof FileNotFoundException)) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"I/O error for %s: %s",
manifestFile.getFullPath(),
e.getMessage());
}
}
return null;
| private static com.android.ide.eclipse.common.project.AndroidManifestParser | parse(java.io.File manifestFile)Parses the Android Manifest, and returns an object containing the result of the parsing.
This version parses a real {@link File} file given by an actual path, which is useful for
parsing a file that is not part of an Eclipse Java project.
It assumes errors cannot be marked on the file and that data gathering is enabled.
try {
SAXParser parser = sParserFactory.newSAXParser();
ManifestHandler manifestHandler = new ManifestHandler(
null, //manifestFile
null, //errorListener
true, //gatherData
null, //javaProject
false //markErrors
);
parser.parse(new InputSource(new FileReader(manifestFile)), manifestHandler);
// get the result from the handler
return new AndroidManifestParser(manifestHandler.getPackage(),
manifestHandler.getActivities(),
manifestHandler.getLauncherActivity(),
manifestHandler.getProcesses(),
manifestHandler.getDebuggable(),
manifestHandler.getApiLevelRequirement(),
manifestHandler.getInstrumentations(),
manifestHandler.getUsesLibraries());
} catch (ParserConfigurationException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Bad parser configuration for %s: %s",
manifestFile.getAbsolutePath(),
e.getMessage());
} catch (SAXException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Parser exception for %s: %s",
manifestFile.getAbsolutePath(),
e.getMessage());
} catch (IOException e) {
// Don't log a console error when failing to read a non-existing file
if (!(e instanceof FileNotFoundException)) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"I/O error for %s: %s",
manifestFile.getAbsolutePath(),
e.getMessage());
}
}
return null;
| public static com.android.ide.eclipse.common.project.AndroidManifestParser | parse(org.eclipse.jdt.core.IJavaProject javaProject, com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener errorListener, boolean gatherData, boolean markErrors)Parses the Android Manifest for the specified project, and returns an object containing
the result of the parsing.
IFile manifestFile = getManifest(javaProject.getProject());
try {
SAXParser parser = sParserFactory.newSAXParser();
if (manifestFile != null) {
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
errorListener, gatherData, javaProject, markErrors);
parser.parse(new InputSource(manifestFile.getContents()), manifestHandler);
// get the result from the handler
return new AndroidManifestParser(manifestHandler.getPackage(),
manifestHandler.getActivities(), manifestHandler.getLauncherActivity(),
manifestHandler.getProcesses(), manifestHandler.getDebuggable(),
manifestHandler.getApiLevelRequirement(),
manifestHandler.getInstrumentations(), manifestHandler.getUsesLibraries());
}
} catch (ParserConfigurationException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Bad parser configuration for %s", manifestFile.getFullPath());
} catch (SAXException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"Parser exception for %s", manifestFile.getFullPath());
} catch (IOException e) {
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
"I/O error for %s", manifestFile.getFullPath());
}
return null;
| public static com.android.ide.eclipse.common.project.AndroidManifestParser | parseForData(org.eclipse.core.resources.IFile manifestFile)Parses the manifest file, and collects data.
return parse(null /* javaProject */, manifestFile, null /* errorListener */,
true /* gatherData */, false /* markErrors */);
| public static com.android.ide.eclipse.common.project.AndroidManifestParser | parseForData(java.lang.String osManifestFilePath)Parses the manifest file, and collects data.
try {
return parse(new File(osManifestFilePath));
} catch (CoreException e) {
// Ignore workspace errors (unlikely to happen since this parses an actual file,
// not a workspace resource).
return null;
}
| public static com.android.ide.eclipse.common.project.AndroidManifestParser | parseForError(org.eclipse.jdt.core.IJavaProject javaProject, org.eclipse.core.resources.IFile manifestFile, com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener errorListener)Parses the manifest file, collects data, and checks for errors.
return parse(javaProject, manifestFile, errorListener, true, true);
|
|