Automated import from //branches/master/...@141414,141414
This commit is contained in:
committed by
The Android Open Source Project
parent
5445556edf
commit
0a001932dc
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.ide.eclipse.common.project;
|
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.AndroidConstants;
|
||||||
import com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener;
|
import com.android.ide.eclipse.common.project.XmlErrorHandler.XmlErrorListener;
|
||||||
import com.android.sdklib.SdkConstants;
|
import com.android.sdklib.SdkConstants;
|
||||||
@@ -579,7 +580,6 @@ public class AndroidManifestParser {
|
|||||||
|
|
||||||
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
|
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
|
||||||
errorListener, gatherData, javaProject, markErrors);
|
errorListener, gatherData, javaProject, markErrors);
|
||||||
|
|
||||||
parser.parse(new InputSource(manifestFile.getContents()), manifestHandler);
|
parser.parse(new InputSource(manifestFile.getContents()), manifestHandler);
|
||||||
|
|
||||||
// get the result from the handler
|
// get the result from the handler
|
||||||
@@ -590,9 +590,14 @@ public class AndroidManifestParser {
|
|||||||
manifestHandler.getApiLevelRequirement(), manifestHandler.getInstrumentations(),
|
manifestHandler.getApiLevelRequirement(), manifestHandler.getInstrumentations(),
|
||||||
manifestHandler.getUsesLibraries());
|
manifestHandler.getUsesLibraries());
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Bad parser configuration for %s", manifestFile.getFullPath());
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Parser exception for %s", manifestFile.getFullPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} finally {
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"I/O error for %s", manifestFile.getFullPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -633,11 +638,15 @@ public class AndroidManifestParser {
|
|||||||
manifestHandler.getApiLevelRequirement(), manifestHandler.getInstrumentations(),
|
manifestHandler.getApiLevelRequirement(), manifestHandler.getInstrumentations(),
|
||||||
manifestHandler.getUsesLibraries());
|
manifestHandler.getUsesLibraries());
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Bad parser configuration for %s", manifestFile.getAbsolutePath());
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Parser exception for %s", manifestFile.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} finally {
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"I/O error for %s", manifestFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,10 +669,12 @@ public class AndroidManifestParser {
|
|||||||
boolean gatherData,
|
boolean gatherData,
|
||||||
boolean markErrors)
|
boolean markErrors)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
|
|
||||||
|
IFile manifestFile = getManifest(javaProject.getProject());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SAXParser parser = sParserFactory.newSAXParser();
|
SAXParser parser = sParserFactory.newSAXParser();
|
||||||
|
|
||||||
IFile manifestFile = getManifest(javaProject.getProject());
|
|
||||||
if (manifestFile != null) {
|
if (manifestFile != null) {
|
||||||
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
|
ManifestHandler manifestHandler = new ManifestHandler(manifestFile,
|
||||||
errorListener, gatherData, javaProject, markErrors);
|
errorListener, gatherData, javaProject, markErrors);
|
||||||
@@ -678,9 +689,14 @@ public class AndroidManifestParser {
|
|||||||
manifestHandler.getInstrumentations(), manifestHandler.getUsesLibraries());
|
manifestHandler.getInstrumentations(), manifestHandler.getUsesLibraries());
|
||||||
}
|
}
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Bad parser configuration for %s", manifestFile.getFullPath());
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"Parser exception for %s", manifestFile.getFullPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} finally {
|
AdtPlugin.logAndPrintError(e, AndroidManifestParser.class.getCanonicalName(),
|
||||||
|
"I/O error for %s", manifestFile.getFullPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -15,7 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.ide.eclipse.tests;
|
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.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -45,12 +51,29 @@ public class AdtTestData {
|
|||||||
// accessed normally
|
// accessed normally
|
||||||
mOsRootDataPath = System.getProperty("test_data");
|
mOsRootDataPath = System.getProperty("test_data");
|
||||||
if (mOsRootDataPath == null) {
|
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$
|
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)) {
|
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);
|
mOsRootDataPath = mOsRootDataPath.concat(File.separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,20 @@
|
|||||||
|
|
||||||
package com.android.ide.eclipse.common.project;
|
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}
|
* Tests for {@link AndroidManifestParser}
|
||||||
*/
|
*/
|
||||||
public class AndroidManifestParserTest extends TestCase {
|
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 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 LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
|
||||||
private static final String INSTRUMENTATION_NAME = "android.test.InstrumentationTestRunner"; //$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 {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
// create the test data
|
String testFilePath = AdtTestData.getInstance().getTestFilePath(
|
||||||
StringBuilder sb = new StringBuilder();
|
TESTAPP_XML);
|
||||||
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); //$NON-NLS-1$
|
mManifestTestApp = AndroidManifestParser.parseForData(testFilePath);
|
||||||
sb.append("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"); //$NON-NLS-1$
|
assertNotNull(mManifestTestApp);
|
||||||
sb.append(" package=\""); //$NON-NLS-1$
|
|
||||||
sb.append(PACKAGE_NAME);
|
|
||||||
sb.append("\">\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <application android:icon=\"@drawable/icon\">\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <activity android:name=\""); //$NON-NLS-1$
|
|
||||||
sb.append(ACTIVITY_NAME);
|
|
||||||
sb.append("\" android:label=\"@string/app_name\">\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <intent-filter>\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <action android:name=\"android.intent.action.MAIN\" />\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <category android:name=\"android.intent.category.LAUNCHER\" />\"\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <category android:name=\"android.intent.category.DEFAULT\" />\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" </intent-filter>\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" </activity>\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" <uses-library android:name=\""); //$NON-NLS-1$
|
|
||||||
sb.append(LIBRARY_NAME);
|
|
||||||
sb.append("\" />\n"); //$NON-NLS-1$
|
|
||||||
sb.append(" </application>"); //$NON-NLS-1$
|
|
||||||
sb.append(" <instrumentation android:name=\""); //$NON-NLS-1$
|
|
||||||
sb.append(INSTRUMENTATION_NAME);
|
|
||||||
sb.append("\"\n");
|
|
||||||
sb.append(" android:targetPackage=\"com.example.android.apis\"\n");
|
|
||||||
sb.append(" android:label=\"Tests for Api Demos.\"/>\n");
|
|
||||||
sb.append("</manifest>\n"); //$NON-NLS-1$
|
|
||||||
|
|
||||||
FileMock mockFile = new FileMock("AndroidManifest.xml", sb.toString().getBytes());
|
testFilePath = AdtTestData.getInstance().getTestFilePath(
|
||||||
|
INSTRUMENTATION_XML);
|
||||||
|
mManifestInstrumentation = AndroidManifestParser.parseForData(testFilePath);
|
||||||
|
assertNotNull(mManifestInstrumentation);
|
||||||
|
}
|
||||||
|
|
||||||
mManifest = AndroidManifestParser.parseForData(mockFile);
|
public void testGetInstrumentationInformation() {
|
||||||
assertNotNull(mManifest);
|
assertEquals(1, mManifestInstrumentation.getInstrumentations().length);
|
||||||
|
assertEquals(INSTRUMENTATION_NAME, mManifestTestApp.getInstrumentations()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetPackage() {
|
public void testGetPackage() {
|
||||||
assertEquals("com.android.testapp", mManifest.getPackage());
|
assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetActivities() {
|
public void testGetActivities() {
|
||||||
assertEquals(1, mManifest.getActivities().length);
|
assertEquals(1, mManifestTestApp.getActivities().length);
|
||||||
assertEquals(ACTIVITY_NAME, mManifest.getActivities()[0]);
|
assertEquals(ACTIVITY_NAME, mManifestTestApp.getActivities()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetLauncherActivity() {
|
public void testGetLauncherActivity() {
|
||||||
assertEquals(ACTIVITY_NAME, mManifest.getLauncherActivity());
|
assertEquals(ACTIVITY_NAME, mManifestTestApp.getLauncherActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetUsesLibraries() {
|
public void testGetUsesLibraries() {
|
||||||
assertEquals(1, mManifest.getUsesLibraries().length);
|
assertEquals(1, mManifestTestApp.getUsesLibraries().length);
|
||||||
assertEquals(LIBRARY_NAME, mManifest.getUsesLibraries()[0]);
|
assertEquals(LIBRARY_NAME, mManifestTestApp.getUsesLibraries()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetInstrumentations() {
|
public void testGetInstrumentations() {
|
||||||
assertEquals(1, mManifest.getInstrumentations().length);
|
assertEquals(1, mManifestTestApp.getInstrumentations().length);
|
||||||
assertEquals(INSTRUMENTATION_NAME, mManifest.getInstrumentations()[0]);
|
assertEquals(INSTRUMENTATION_NAME, mManifestTestApp.getInstrumentations()[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetPackageName() {
|
||||||
|
assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.android.AndroidProject.tests">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This declares that this app uses the instrumentation test runner targeting
|
||||||
|
the package of com.android.samples. To run the tests use the command:
|
||||||
|
"adb shell am instrument -w com.android.samples.tests/android.test.InstrumentationTestRunner"
|
||||||
|
-->
|
||||||
|
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||||
|
android:targetPackage="com.android.AndroidProject"
|
||||||
|
android:label="Sample test for deployment."/>
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<uses-library android:name="android.test.runner" />
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.testapp">
|
||||||
|
<application android:icon="@drawable/icon">
|
||||||
|
<activity android:name="com.android.testapp.MainActivity"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />"
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<uses-library android:name="android.test.runner"/>
|
||||||
|
</application>"
|
||||||
|
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||||
|
android:targetPackage="com.example.android.apis"
|
||||||
|
android:label="Tests for Api Demos."/>
|
||||||
|
</manifest>
|
||||||
Reference in New Issue
Block a user