forked from github/cordova-android
[CB-4782] Convert ApplicationInfo.java -> appinfo.js
This commit is contained in:
parent
3df09eacf2
commit
437daa368a
@ -126,22 +126,11 @@ module.exports.run = function(project_path, package_name, project_name, project_
|
|||||||
replaceInFile(manifest_path, /__APILEVEL__/, target_api.split('-')[1]);
|
replaceInFile(manifest_path, /__APILEVEL__/, target_api.split('-')[1]);
|
||||||
|
|
||||||
var cordova_path = path.join(ROOT, 'bin', 'templates', 'cordova');
|
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
|
// creating cordova folder and copying run/build/log/launch/check_reqs scripts
|
||||||
var lib_path = path.join(cordova_path, 'lib');
|
var lib_path = path.join(cordova_path, 'lib');
|
||||||
shell.mkdir(path.join(project_path, 'cordova'));
|
shell.mkdir(path.join(project_path, 'cordova'));
|
||||||
shell.mkdir(path.join(project_path, 'cordova', 'lib'));
|
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.cp(path.join(cordova_path, 'build'), path.join(project_path, 'cordova', 'build'));
|
||||||
shell.chmod(755, 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'));
|
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.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.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(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(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'));
|
shell.cp(path.join(lib_path, 'clean.js'), path.join(project_path, 'cordova', 'lib', 'clean.js'));
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
41
bin/templates/cordova/lib/appinfo.js
vendored
Normal file
41
bin/templates/cordova/lib/appinfo.js
vendored
Normal file
@ -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();
|
||||||
|
};
|
14
bin/templates/cordova/lib/device.js
vendored
14
bin/templates/cordova/lib/device.js
vendored
@ -22,6 +22,7 @@
|
|||||||
var shell = require('shelljs'),
|
var shell = require('shelljs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
build = require('./build'),
|
build = require('./build'),
|
||||||
|
appinfo = require('./appinfo'),
|
||||||
exec = require('child_process').exec,
|
exec = require('child_process').exec,
|
||||||
ROOT = path.join(__dirname, '..', '..');
|
ROOT = path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
@ -57,14 +58,7 @@ module.exports.install = function(target) {
|
|||||||
target = typeof target !== 'undefined' ? target : device_list[0];
|
target = typeof target !== 'undefined' ? target : device_list[0];
|
||||||
if (device_list.indexOf(target) > -1) {
|
if (device_list.indexOf(target) > -1) {
|
||||||
var apk_path = build.get_apk();
|
var apk_path = build.get_apk();
|
||||||
var cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml');
|
var launchName = appinfo.getActivityName();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Installing app on device...');
|
console.log('Installing app on device...');
|
||||||
cmd = 'adb -s ' + target + ' install -r ' + apk_path;
|
cmd = 'adb -s ' + target + ' install -r ' + apk_path;
|
||||||
var install = shell.exec(cmd, {silent:false, async:false});
|
var install = shell.exec(cmd, {silent:false, async:false});
|
||||||
@ -80,7 +74,7 @@ module.exports.install = function(target) {
|
|||||||
|
|
||||||
// launch the application
|
// launch the application
|
||||||
console.log('Launching 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});
|
var launch = shell.exec(cmd, {silent:true, async:false});
|
||||||
if(launch.code > 0) {
|
if(launch.code > 0) {
|
||||||
console.error('ERROR : Failed to launch application on emulator : ' + launch.error);
|
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.');
|
console.error('ERROR : Failed to deploy to device, no devices found.');
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
bin/templates/cordova/lib/emulator.js
vendored
13
bin/templates/cordova/lib/emulator.js
vendored
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
var shell = require('shelljs'),
|
var shell = require('shelljs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
appinfo = require('./appinfo'),
|
||||||
build = require('./build'),
|
build = require('./build'),
|
||||||
ROOT = path.join(__dirname, '..', '..'),
|
ROOT = path.join(__dirname, '..', '..'),
|
||||||
new_emulator = 'cordova_emulator';
|
new_emulator = 'cordova_emulator';
|
||||||
@ -317,14 +318,8 @@ module.exports.install = function(target) {
|
|||||||
|
|
||||||
// launch the application
|
// launch the application
|
||||||
console.log('Launching application...');
|
console.log('Launching application...');
|
||||||
cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml');
|
var launchName = appinfo.getActivityName();
|
||||||
var launch_name = shell.exec(cmd, {silent:true, async:false});
|
cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launchName;
|
||||||
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', '');
|
|
||||||
console.log(cmd);
|
console.log(cmd);
|
||||||
var launch = shell.exec(cmd, {silent:false, async:false});
|
var launch = shell.exec(cmd, {silent:false, async:false});
|
||||||
if(launch.code > 0) {
|
if(launch.code > 0) {
|
||||||
@ -339,4 +334,4 @@ module.exports.install = function(target) {
|
|||||||
console.error('Failed to deploy to emulator.');
|
console.error('Failed to deploy to emulator.');
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,13 +51,6 @@ function on_exit {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAppInfoJar {
|
|
||||||
(cd "$BUILD_PATH"/bin/templates/cordova/ApplicationInfo &&
|
|
||||||
javac ApplicationInfo.java &&
|
|
||||||
jar -cfe ../appinfo.jar ApplicationInfo ApplicationInfo.class
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function on_error {
|
function on_error {
|
||||||
echo "An unexpected error occurred: $previous_command exited with $?"
|
echo "An unexpected error occurred: $previous_command exited with $?"
|
||||||
exit 1
|
exit 1
|
||||||
@ -119,7 +112,6 @@ then
|
|||||||
mkdir "$PROJECT_PATH"/cordova
|
mkdir "$PROJECT_PATH"/cordova
|
||||||
mkdir "$PROJECT_PATH"/cordova/lib
|
mkdir "$PROJECT_PATH"/cordova/lib
|
||||||
fi
|
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/build "$PROJECT_PATH"/cordova/build
|
||||||
cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
|
cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
|
||||||
cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
|
cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
|
||||||
|
@ -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() {
|
function cleanup() {
|
||||||
if(fso.FileExists(ROOT + '\\framework\\cordova-'+VERSION+'.jar')) {
|
if(fso.FileExists(ROOT + '\\framework\\cordova-'+VERSION+'.jar')) {
|
||||||
fso.DeleteFile(ROOT + '\\framework\\cordova-'+VERSION+'.jar');
|
fso.DeleteFile(ROOT + '\\framework\\cordova-'+VERSION+'.jar');
|
||||||
@ -138,9 +127,7 @@ if(fso.FolderExists(ROOT + '\\framework')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update cordova scripts
|
// update cordova scripts
|
||||||
createAppInfoJar();
|
|
||||||
WScript.Echo("Copying cordova command tools...");
|
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\\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\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y');
|
||||||
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\build.bat ' + PROJECT_PATH + '\\cordova\\build.bat /Y');
|
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\build.bat ' + PROJECT_PATH + '\\cordova\\build.bat /Y');
|
||||||
|
Loading…
Reference in New Issue
Block a user