From 52918da57143079749dcc5746e622fec4ec2610f Mon Sep 17 00:00:00 2001
From: Ricky Ng-Adam <>
Date: Tue, 24 Mar 2009 20:14:26 -0700
Subject: [PATCH] Automated import from //branches/master/...@141414,141414
---
.../common/project/AndroidManifestParser.java | 36 ++++++++---
.../com/android/ide/eclipse/tests/AdtTestData.java | 29 ++++++++-
.../common/project/AndroidManifestParserTest.java | 75 +++++++++-------------
.../data/AndroidManifest-instrumentation.xml | 18 ++++++
.../unittests/data/AndroidManifest-testapp.xml | 17 +++++
5 files changed, 119 insertions(+), 56 deletions(-)
create mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-instrumentation.xml
create mode 100644 eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-testapp.xml
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/project/AndroidManifestParser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/project/AndroidManifestParser.java
index fe11e694c..fa7e9b9f4 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/project/AndroidManifestParser.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/common/project/AndroidManifestParser.java
@@ -16,6 +16,7 @@
package com.android.ide.eclipse.common.project;
+import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.common.AndroidConstants;
import com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener;
import com.android.sdklib.SdkConstants;
@@ -579,7 +580,6 @@ public class AndroidManifestParser {
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
errorListener, gatherData, javaProject, markErrors);
-
parser.parse(new InputSource(manifestFile.getContents()), manifestHandler);
// get the result from the handler
@@ -590,10 +590,15 @@ public class AndroidManifestParser {
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) {
- } finally {
- }
+ AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
+ "I/O error for %s", manifestFile.getFullPath());
+ }
return null;
}
@@ -633,11 +638,15 @@ public class AndroidManifestParser {
manifestHandler.getApiLevelRequirement(), manifestHandler.getInstrumentations(),
manifestHandler.getUsesLibraries());
} catch (ParserConfigurationException e) {
+ AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
+ "Bad parser configuration for %s", manifestFile.getAbsolutePath());
} catch (SAXException e) {
+ AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
+ "Parser exception for %s", manifestFile.getAbsolutePath());
} catch (IOException e) {
- } finally {
- }
-
+ AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
+ "I/O error for %s", manifestFile.getAbsolutePath());
+ }
return null;
}
@@ -660,10 +669,12 @@ public class AndroidManifestParser {
boolean gatherData,
boolean markErrors)
throws CoreException {
+
+ IFile manifestFile = getManifest(javaProject.getProject());
+
try {
SAXParser parser = sParserFactory.newSAXParser();
-
- IFile manifestFile = getManifest(javaProject.getProject());
+
if (manifestFile != null) {
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
errorListener, gatherData, javaProject, markErrors);
@@ -678,10 +689,15 @@ public class AndroidManifestParser {
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) {
- } finally {
- }
+ AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
+ "I/O error for %s", manifestFile.getFullPath());
+ }
return null;
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/AdtTestData.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/AdtTestData.java
index 262ef65a1..d86d585a3 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/AdtTestData.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/AdtTestData.java
@@ -15,7 +15,13 @@
*/
package com.android.ide.eclipse.tests;
+import com.android.ide.eclipse.common.AndroidConstants;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+
import java.io.File;
+import java.io.IOException;
import java.net.URL;
import java.util.logging.Logger;
@@ -45,12 +51,29 @@ public class AdtTestData {
// accessed normally
mOsRootDataPath = System.getProperty("test_data");
if (mOsRootDataPath == null) {
- sLogger.info("Cannot find test_data directory, init to class loader");
+ sLogger.info("Cannot find test_data environment variable, init to class loader");
URL url = this.getClass().getClassLoader().getResource("data"); //$NON-NLS-1$
- mOsRootDataPath = url.getFile();
+
+ if (Platform.isRunning()) {
+ sLogger.info("Running as an Eclipse Plug-in JUnit test, using FileLocator");
+ try {
+ mOsRootDataPath = FileLocator.resolve(url).getFile();
+ } catch (IOException e) {
+ sLogger.warning("IOException while using FileLocator, reverting to url");
+ mOsRootDataPath = url.getFile();
+ }
+ } else {
+ sLogger.info("Running as an plain JUnit test, using url as-is");
+ mOsRootDataPath = url.getFile();
+ }
+ }
+
+ if (mOsRootDataPath.equals(AndroidConstants.WS_SEP + "data")) {
+ sLogger.warning("Resource data not found using class loader!, Defaulting to no path");
}
+
if (!mOsRootDataPath.endsWith(File.separator)) {
- sLogger.info("Fixing test_data env variable does not end with path separator");
+ sLogger.info("Fixing test_data env variable (does not end with path separator)");
mOsRootDataPath = mOsRootDataPath.concat(File.separator);
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/common/project/AndroidManifestParserTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/common/project/AndroidManifestParserTest.java
index 516e448e6..7e8b0af10 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/common/project/AndroidManifestParserTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/common/project/AndroidManifestParserTest.java
@@ -16,17 +16,20 @@
package com.android.ide.eclipse.common.project;
-import junit.framework.TestCase;
+import com.android.ide.eclipse.tests.AdtTestData;
-import com.android.ide.eclipse.mock.FileMock;
+import junit.framework.TestCase;
/**
* Tests for {@link AndroidManifestParser}
*/
public class AndroidManifestParserTest extends TestCase {
- private AndroidManifestParser mManifest;
+ private AndroidManifestParser mManifestTestApp;
+ private AndroidManifestParser mManifestInstrumentation;
- private static final String PACKAGE_NAME = "com.android.testapp"; //$NON-NLS-1$
+ private static final String INSTRUMENTATION_XML = "AndroidManifest-instrumentation.xml"; //$NON-NLS-1$
+ private static final String TESTAPP_XML = "AndroidManifest-testapp.xml"; //$NON-NLS-1$
+ private static final String PACKAGE_NAME = "com.android.testapp"; //$NON-NLS-1$
private static final String ACTIVITY_NAME = "com.android.testapp.MainActivity"; //$NON-NLS-1$
private static final String LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
private static final String INSTRUMENTATION_NAME = "android.test.InstrumentationTestRunner"; //$NON-NLS-1$
@@ -35,60 +38,46 @@ public class AndroidManifestParserTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- // create the test data
- StringBuilder sb = new StringBuilder();
- sb.append("\n"); //$NON-NLS-1$
- sb.append("\n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \"\n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" \n"); //$NON-NLS-1$
- sb.append(" "); //$NON-NLS-1$
- sb.append(" \n");
- sb.append("\n"); //$NON-NLS-1$
-
- FileMock mockFile = new FileMock("AndroidManifest.xml", sb.toString().getBytes());
+ String testFilePath = AdtTestData.getInstance().getTestFilePath(
+ TESTAPP_XML);
+ mManifestTestApp = AndroidManifestParser.parseForData(testFilePath);
+ assertNotNull(mManifestTestApp);
- mManifest = AndroidManifestParser.parseForData(mockFile);
- assertNotNull(mManifest);
+ testFilePath = AdtTestData.getInstance().getTestFilePath(
+ INSTRUMENTATION_XML);
+ mManifestInstrumentation = AndroidManifestParser.parseForData(testFilePath);
+ assertNotNull(mManifestInstrumentation);
}
+ public void testGetInstrumentationInformation() {
+ assertEquals(1, mManifestInstrumentation.getInstrumentations().length);
+ assertEquals(INSTRUMENTATION_NAME, mManifestTestApp.getInstrumentations()[0]);
+ }
+
public void testGetPackage() {
- assertEquals("com.android.testapp", mManifest.getPackage());
+ assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
}
public void testGetActivities() {
- assertEquals(1, mManifest.getActivities().length);
- assertEquals(ACTIVITY_NAME, mManifest.getActivities()[0]);
+ assertEquals(1, mManifestTestApp.getActivities().length);
+ assertEquals(ACTIVITY_NAME, mManifestTestApp.getActivities()[0]);
}
public void testGetLauncherActivity() {
- assertEquals(ACTIVITY_NAME, mManifest.getLauncherActivity());
+ assertEquals(ACTIVITY_NAME, mManifestTestApp.getLauncherActivity());
}
public void testGetUsesLibraries() {
- assertEquals(1, mManifest.getUsesLibraries().length);
- assertEquals(LIBRARY_NAME, mManifest.getUsesLibraries()[0]);
+ assertEquals(1, mManifestTestApp.getUsesLibraries().length);
+ assertEquals(LIBRARY_NAME, mManifestTestApp.getUsesLibraries()[0]);
}
public void testGetInstrumentations() {
- assertEquals(1, mManifest.getInstrumentations().length);
- assertEquals(INSTRUMENTATION_NAME, mManifest.getInstrumentations()[0]);
+ assertEquals(1, mManifestTestApp.getInstrumentations().length);
+ assertEquals(INSTRUMENTATION_NAME, mManifestTestApp.getInstrumentations()[0]);
+ }
+
+ public void testGetPackageName() {
+ assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-instrumentation.xml b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-instrumentation.xml
new file mode 100644
index 000000000..b380f967e
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-instrumentation.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-testapp.xml b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-testapp.xml
new file mode 100644
index 000000000..8ae70121c
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/data/AndroidManifest-testapp.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ "
+
+
+
+
+ "
+
+
\ No newline at end of file
--
2.11.0