You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/09/10 22:33:49 UTC
android commit: [CB-4782] Convert ApplicationInfo.java -> appinfo.js
Updated Branches:
refs/heads/master 3df09eacf -> 437daa368
[CB-4782] Convert ApplicationInfo.java -> appinfo.js
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/437daa36
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/437daa36
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/437daa36
Branch: refs/heads/master
Commit: 437daa368ad10d544959ff4a32f12c4f9b10de44
Parents: 3df09ea
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue Sep 10 16:31:42 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Sep 10 16:32:42 2013 -0400
----------------------------------------------------------------------
bin/lib/create.js | 12 +---
.../ApplicationInfo/ApplicationInfo.java | 61 --------------------
bin/templates/cordova/lib/appinfo.js | 41 +++++++++++++
bin/templates/cordova/lib/device.js | 14 ++---
bin/templates/cordova/lib/emulator.js | 13 ++---
bin/update | 8 ---
bin/update.js | 13 -----
7 files changed, 50 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 955de1a..8754f97 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -126,22 +126,11 @@ module.exports.run = function(project_path, package_name, project_name, project_
replaceInFile(manifest_path, /__APILEVEL__/, target_api.split('-')[1]);
var cordova_path = path.join(ROOT, 'bin', 'templates', 'cordova');
- // create app info jar
- if(!fs.existsSync(path.join(cordova_path, 'appinfo.jar'))) {
- console.log('Creating appinfo.jar...');
- var cwd = process.cwd();
- process.chdir(path.join(cordova_path, 'ApplicationInfo'));
- exec('javac ApplicationInfo.java');
- exec('jar -cfe ' + path.join(cordova_path, 'appinfo.jar') + ' ApplicationInfo ApplicationInfo.class');
- process.chdir(cwd);
- }
-
// creating cordova folder and copying run/build/log/launch/check_reqs scripts
var lib_path = path.join(cordova_path, 'lib');
shell.mkdir(path.join(project_path, 'cordova'));
shell.mkdir(path.join(project_path, 'cordova', 'lib'));
- shell.cp(path.join(cordova_path, 'appinfo.jar'), path.join(project_path, 'cordova', 'appinfo.jar'));
shell.cp(path.join(cordova_path, 'build'), path.join(project_path, 'cordova', 'build'));
shell.chmod(755, path.join(project_path, 'cordova', 'build'));
shell.cp(path.join(cordova_path, 'clean'), path.join(project_path, 'cordova', 'clean'));
@@ -155,6 +144,7 @@ module.exports.run = function(project_path, package_name, project_name, project_
shell.cp(path.join(ROOT, 'bin', 'check_reqs'), path.join(project_path, 'cordova', 'check_reqs'));
shell.chmod(755, path.join(project_path, 'cordova', 'check_reqs'));
+ shell.cp(path.join(lib_path, 'appinfo.js'), path.join(project_path, 'cordova', 'lib', 'appinfo.js'));
shell.cp(path.join(lib_path, 'build.js'), path.join(project_path, 'cordova', 'lib', 'build.js'));
shell.cp(path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(project_path, 'cordova', 'lib', 'check_reqs.js'));
shell.cp(path.join(lib_path, 'clean.js'), path.join(project_path, 'cordova', 'lib', 'clean.js'));
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java
deleted file mode 100644
index c344b65..0000000
--- a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you 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.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, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.xml.sax.SAXException;
-import java.io.IOException;
-
-public class ApplicationInfo {
- private static void parseAndroidManifest(String path) {
- // System.out.println(path);
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- Document dom;
- try {
- DocumentBuilder db = dbf.newDocumentBuilder();
- dom = db.parse(path);
-
- // getting package information
- Element manifest = dom.getDocumentElement();
- String pakkage = manifest.getAttribute("package");
-
- // getting activity name
- String activity = ((Element)dom.getElementsByTagName("activity").item(0)).getAttribute("android:name");
- System.out.println(String.format("%s/.%s", pakkage, activity.replace(".", "")));
- } catch(ParserConfigurationException pce) {
- pce.printStackTrace();
- } catch(SAXException se) {
- se.printStackTrace();
- } catch(IOException ioe) {
- ioe.printStackTrace();
- }
-
- }
-
- public static void main(String[] args) {
- String path;
- if(args.length > 0) {
- path = args[0];
- } else {
- path = System.getProperty("user.dir") + "/../AndroidManifest.xml";
- }
- parseAndroidManifest(path);
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/templates/cordova/lib/appinfo.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/appinfo.js b/bin/templates/cordova/lib/appinfo.js
new file mode 100644
index 0000000..1f8ebe2
--- /dev/null
+++ b/bin/templates/cordova/lib/appinfo.js
@@ -0,0 +1,41 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.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, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+var path = require('path');
+var fs = require('fs');
+var cachedAppInfo = null;
+
+function readAppInfoFromManifest() {
+ var manifestPath = path.join(__dirname, '..', '..', 'AndroidManifest.xml');
+ var manifestData = fs.readFileSync(manifestPath, {encoding:'utf8'});
+ var packageName = /\bpackage\s*=\s*"(.+?)"/.exec(manifestData);
+ if (!packageName) throw new Error('Could not find package name within ' + manifestPath);
+ var activityTag = /<activity\b[\s\S]*<\/activity>/.exec(manifestData);
+ if (!activityTag) throw new Error('Could not find <activity> within ' + manifestPath);
+ var activityName = /\bandroid:name\s*=\s*"(.+?)"/.exec(activityTag);
+ if (!activityName) throw new Error('Could not find android:name within ' + manifestPath);
+
+ return packageName[1] + '/.' + activityName[1];
+}
+
+exports.getActivityName = function() {
+ return cachedAppInfo = cachedAppInfo || readAppInfoFromManifest();
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/templates/cordova/lib/device.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js
index 900baf4..46686b6 100644
--- a/bin/templates/cordova/lib/device.js
+++ b/bin/templates/cordova/lib/device.js
@@ -22,6 +22,7 @@
var shell = require('shelljs'),
path = require('path'),
build = require('./build'),
+ appinfo = require('./appinfo'),
exec = require('child_process').exec,
ROOT = path.join(__dirname, '..', '..');
@@ -57,14 +58,7 @@ module.exports.install = function(target) {
target = typeof target !== 'undefined' ? target : device_list[0];
if (device_list.indexOf(target) > -1) {
var apk_path = build.get_apk();
- var cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml');
- var launch_name = shell.exec(cmd, {silent:true, async:false});
- if (launch_name.error) {
- console.log('ERROR : Failed to get application name from appinfo.jar + AndroidManifest : ');
- console.log("Output : " + launch_name.output);
- process.exit(2);
- }
-
+ var launchName = appinfo.getActivityName();
console.log('Installing app on device...');
cmd = 'adb -s ' + target + ' install -r ' + apk_path;
var install = shell.exec(cmd, {silent:false, async:false});
@@ -80,7 +74,7 @@ module.exports.install = function(target) {
// launch the application
console.log('Launching application...');
- cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output.replace('\r', '').replace('\n', '');
+ cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
var launch = shell.exec(cmd, {silent:true, async:false});
if(launch.code > 0) {
console.error('ERROR : Failed to launch application on emulator : ' + launch.error);
@@ -98,4 +92,4 @@ module.exports.install = function(target) {
console.error('ERROR : Failed to deploy to device, no devices found.');
process.exit(2);
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index 579c898..6f8a7dd 100644
--- a/bin/templates/cordova/lib/emulator.js
+++ b/bin/templates/cordova/lib/emulator.js
@@ -21,6 +21,7 @@
var shell = require('shelljs'),
path = require('path'),
+ appinfo = require('./appinfo'),
build = require('./build'),
ROOT = path.join(__dirname, '..', '..'),
new_emulator = 'cordova_emulator';
@@ -317,14 +318,8 @@ module.exports.install = function(target) {
// launch the application
console.log('Launching application...');
- cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml');
- var launch_name = shell.exec(cmd, {silent:true, async:false});
- if (launch_name.error) {
- console.log('ERROR : Failed to get application name from appinfo.jar + AndroidManifest : ');
- console.log("Output : " + launch_name.output);
- process.exit(2);
- }
- cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output.replace('\r', '').replace('\n', '');
+ var launchName = appinfo.getActivityName();
+ cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
console.log(cmd);
var launch = shell.exec(cmd, {silent:false, async:false});
if(launch.code > 0) {
@@ -339,4 +334,4 @@ module.exports.install = function(target) {
console.error('Failed to deploy to emulator.');
process.exit(2);
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/update
----------------------------------------------------------------------
diff --git a/bin/update b/bin/update
index 8e7503d..3fe7f9c 100755
--- a/bin/update
+++ b/bin/update
@@ -51,13 +51,6 @@ function on_exit {
fi
}
-function createAppInfoJar {
- (cd "$BUILD_PATH"/bin/templates/cordova/ApplicationInfo &&
- javac ApplicationInfo.java &&
- jar -cfe ../appinfo.jar ApplicationInfo ApplicationInfo.class
- )
-}
-
function on_error {
echo "An unexpected error occurred: $previous_command exited with $?"
exit 1
@@ -119,7 +112,6 @@ then
mkdir "$PROJECT_PATH"/cordova
mkdir "$PROJECT_PATH"/cordova/lib
fi
-cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar
cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build
cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/437daa36/bin/update.js
----------------------------------------------------------------------
diff --git a/bin/update.js b/bin/update.js
index 8396d6f..e73d2f7 100644
--- a/bin/update.js
+++ b/bin/update.js
@@ -76,17 +76,6 @@ function exec(command) {
}
}
-function createAppInfoJar() {
- if(!fso.FileExists(ROOT+"\\bin\\templates\\cordova\\appinfo.jar")) {
- WScript.Echo("Creating appinfo.jar...");
- var cur = shell.CurrentDirectory;
- shell.CurrentDirectory = ROOT+"\\bin\\templates\\cordova\\ApplicationInfo";
- exec("javac ApplicationInfo.java");
- exec("jar -cfe ..\\appinfo.jar ApplicationInfo ApplicationInfo.class");
- shell.CurrentDirectory = cur;
- }
-}
-
function cleanup() {
if(fso.FileExists(ROOT + '\\framework\\cordova-'+VERSION+'.jar')) {
fso.DeleteFile(ROOT + '\\framework\\cordova-'+VERSION+'.jar');
@@ -138,9 +127,7 @@ if(fso.FolderExists(ROOT + '\\framework')) {
}
// update cordova scripts
-createAppInfoJar();
WScript.Echo("Copying cordova command tools...");
-exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\appinfo.jar ' + PROJECT_PATH + '\\cordova\\appinfo.jar /Y');
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y');
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y');
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\build.bat ' + PROJECT_PATH + '\\cordova\\build.bat /Y');