OSDN Git Service

Refactor the manifest parser test in the correct package.
authorXavier Ducrohet <xav@android.com>
Mon, 17 May 2010 21:35:48 +0000 (14:35 -0700)
committerXavier Ducrohet <xav@android.com>
Mon, 17 May 2010 22:09:13 +0000 (15:09 -0700)
And don't make it use the Parser Helper that's eclipse specific.

Also fixed the versionCode parsing (bug introduced in previous CL)

Change-Id: Ie472d7d6c4847e3fae660873cca7d71e801a2a34

sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java
sdkmanager/libs/sdklib/tests/com/android/sdklib/testdata/AndroidManifest-instrumentation.xml [moved from eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/AndroidManifest-instrumentation.xml with 100% similarity]
sdkmanager/libs/sdklib/tests/com/android/sdklib/testdata/AndroidManifest-testapp.xml [moved from eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/testdata/AndroidManifest-testapp.xml with 100% similarity]
sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java [moved from eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/project/AndroidManifestParserTest.java with 83% similarity]

index 2330020..3b9cd0b 100644 (file)
@@ -35,6 +35,7 @@ import org.xml.sax.helpers.DefaultHandler;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
@@ -142,7 +143,7 @@ public class AndroidManifestParser {
                                         AndroidManifest.ATTRIBUTE_VERSIONCODE, true);
                                 if (tmp != null) {
                                     try {
-                                        mManifestData.mVersionCode = Integer.getInteger(tmp);
+                                        mManifestData.mVersionCode = Integer.valueOf(tmp);
                                     } catch (NumberFormatException e) {
                                         // keep null in the field.
                                     }
@@ -427,7 +428,6 @@ public class AndroidManifestParser {
                             AndroidManifest.ATTRIBUTE_LARGESCREENS, true /*hasNamespace*/));
         }
 
-
         /**
          * Searches through the attributes list for a particular one and returns its value.
          * @param attributes the attribute list to search through
@@ -525,6 +525,33 @@ public class AndroidManifestParser {
     }
 
     /**
+     * Parses the Android Manifest from an {@link InputStream}, and returns a {@link ManifestData}
+     * object containing the result of the parsing.
+     *
+     * @param manifestFileStream the {@link InputStream} representing the manifest file.
+     * @return
+     * @throws StreamException
+     * @throws IOException
+     * @throws SAXException
+     * @throws ParserConfigurationException
+     */
+    public static ManifestData parse(InputStream manifestFileStream)
+            throws SAXException, IOException, StreamException, ParserConfigurationException {
+        if (manifestFileStream != null) {
+            SAXParser parser = sParserFactory.newSAXParser();
+
+            ManifestData data = new ManifestData();
+
+            ManifestHandler manifestHandler = new ManifestHandler(null, data, null);
+            parser.parse(new InputSource(manifestFileStream), manifestHandler);
+
+            return data;
+        }
+
+        return null;
+    }
+
+    /**
      * Returns an {@link IAbstractFile} object representing the manifest for the given project.
      *
      * @param project The project containing the manifest file.
@@ -1,11 +1,11 @@
 /*
  * Copyright (C) 2007 The Android Open Source Project
  *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *      http://www.eclipse.org/org/documents/epl-v10.php
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  */
 
-package com.android.ide.eclipse.adt.internal.project;
+package com.android.sdklib.xml;
 
-import com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper;
-import com.android.ide.eclipse.tests.AdtTestData;
-import com.android.sdklib.xml.ManifestData;
+import java.io.InputStream;
 
 import junit.framework.TestCase;
 
 /**
- * Tests for {@link AndroidManifestHelper}
+ * Tests for {@link AndroidManifestParser}
  */
 public class AndroidManifestParserTest extends TestCase {
     private ManifestData mManifestTestApp;
     private ManifestData mManifestInstrumentation;
 
     private static final String TESTDATA_PATH =
-        "com/android/ide/eclipse/testdata/";  //$NON-NLS-1$
+        "/com/android/sdklib/testdata/";  //$NON-NLS-1$
     private static final String INSTRUMENTATION_XML = TESTDATA_PATH +
         "AndroidManifest-instrumentation.xml";  //$NON-NLS-1$
     private static final String TESTAPP_XML = TESTDATA_PATH +
@@ -46,12 +44,13 @@ public class AndroidManifestParserTest extends TestCase {
     protected void setUp() throws Exception {
         super.setUp();
 
-        String testFilePath = AdtTestData.getInstance().getTestFilePath(TESTAPP_XML);
-        mManifestTestApp = AndroidManifestHelper.parseForData(testFilePath);
+        InputStream manifestStream = this.getClass().getResourceAsStream(TESTAPP_XML);
+
+        mManifestTestApp = AndroidManifestParser.parse(manifestStream);
         assertNotNull(mManifestTestApp);
 
-        testFilePath = AdtTestData.getInstance().getTestFilePath(INSTRUMENTATION_XML);
-        mManifestInstrumentation = AndroidManifestHelper.parseForData(testFilePath);
+        manifestStream = this.getClass().getResourceAsStream(INSTRUMENTATION_XML);
+        mManifestInstrumentation = AndroidManifestParser.parse(manifestStream);
         assertNotNull(mManifestInstrumentation);
     }