Skip to content

Commit

Permalink
[TIMOB-10752] Final touches on the module create command.
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Apr 17, 2014
1 parent 131d7d8 commit 200b966
Show file tree
Hide file tree
Showing 25 changed files with 271 additions and 138 deletions.
107 changes: 107 additions & 0 deletions android/templates/module/default/hooks/android-module.js
@@ -0,0 +1,107 @@
/**
* @overview
* Hook that performa Android specific functions when creating an Android module.
*
* @copyright
* Copyright (c) 2014 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

var fs = require('fs'),
path = require('path'),
wrench = require('wrench');

exports.cliVersion = '>=3.2';

exports.init = function (logger, config, cli, appc) {
var __ = appc.i18n(__dirname).__;

cli.on('create.copyFiles.platform.android', {
pre: function (data, callback) {
// create the build/.apt_generated directory
var aptgenDir = path.join(this.projectDir, 'android', 'build', '.apt_generated');
fs.existsSync(aptgenDir) || wrench.mkdirSyncRecursive(aptgenDir);

// determine the minimum supported Android SDK version
var packageJsonFile = (function scan(dir) {
var file = path.join(dir, 'package.json');
if (fs.existsSync(file)) {
return file;
}
dir = path.dirname(dir);
return dir != '/' && scan(dir);
}(__dirname)),
packageJson = require(packageJsonFile),
minAndroidAPILevel = parseInt(appc.version.parseMin(packageJson.vendorDependencies['android sdk']));

var android = require('titanium-sdk/lib/android');
logger.debug(__('Detecting Android environment...'));
android.detect(this.config, null, function (results) {
// find all targets that satisify the minimum supported Android SDK, prefer versions with Google APIs
var apis = {};
Object.keys(results.targets).forEach(function (idx) {
var target = results.targets[idx],
apiLevel = target['based-on'] && target['based-on']['api-level'] ? ~~target['based-on']['api-level'] : ~~target['api-level'],
gapi = target.type == 'add-on' && /google/i.test(target.name);

if (apiLevel >= minAndroidAPILevel && (target.type == 'platform' || gapi)) {
apis[apiLevel] || (apis[apiLevel] = {});
if (typeof apis[apiLevel].idx == 'undefined' || gapi) {
apis[apiLevel].idx = idx;
}

if (gapi) {
apis[apiLevel].googleAPIPath = target.path;
} else {
apis[apiLevel].platformPath = target.path;
}
}
});

var libs = [],
targetAPILevel = Object.keys(apis).sort().shift(),
api = targetAPILevel && apis[targetAPILevel],
target = api && results.targets[api.idx];

// add the android.jar
if (target && target.androidJar) {
libs.push(target.androidJar);
}

// add the maps.jar if we have Google APIs
if (target && target.libraries && target.libraries['com.google.android.maps']) {
libs.push(path.join(target.path, 'libs', target.libraries['com.google.android.maps'].jar));
}

// add the Titanium specific jars
libs.push(
path.join(this.sdk.path, 'android', 'titanium.jar'),
path.join(this.sdk.path, 'android', 'kroll-common.jar'),
path.join(this.sdk.path, 'android', 'kroll-apt.jar')
);

// update the variables
var variables = data.args[0];

// build the classpath
variables.classpath = libs.map(function (lib) {
return '<classpathentry kind="lib" path="' + lib + '"/>';
}).join('\n\t');

// set the Android platform path
variables.androidPlatformPath = api && api.platformPath || '';

// set the Google APIs path
variables.googleAPIPath = api && api.googleAPIPath || '';

// set the Titanium Android platform path
variables.tisdkAndroidPath = path.join(data.args[0].tisdkPath, 'android');

callback();
}.bind(this));
}
});
};
28 changes: 0 additions & 28 deletions android/templates/module/default/hooks/create.js

This file was deleted.

Expand Up @@ -3,6 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="build/.apt_generated"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
___CLASSPATH_ENTRIES___
<%- classpath %>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>___PROJECTNAME___</name>
<name><%- moduleName %></name>
<comment></comment>
<projects>
</projects>
Expand Down
@@ -0,0 +1,7 @@
#Thu Sep 02 15:18:34 CDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=.apt_generated
org.eclipse.jdt.apt.reconcileEnabled=true

org.eclipse.jdt.apt.processorOptions/kroll.jsonFile=<%- moduleName %>.json
@@ -0,0 +1,3 @@
#Thu Sep 02 15:18:34 CDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.processAnnotations=enabled
@@ -1,3 +1,3 @@
titanium.platform=__SDK_ANDROID__
android.platform=___ANDROID_PLATFORM___
google.apis=___GOOGLE_APIS___
titanium.platform=<%- tisdkAndroidPath %>
android.platform=<%- androidPlatformPath %>
google.apis=<%- googleAPIPath %>
32 changes: 30 additions & 2 deletions android/templates/module/default/template/android/build.xml.ejs
@@ -1,10 +1,38 @@
<project name="__PROJECT_SHORT_NAME_LOWER__" default="dist">
<project name="<%- moduleName.toLowerCase() %>" default="dist">
<description>
Ant build script for Titanium Android module __PROJECT_SHORT_NAME__
Ant build script for Titanium Android module <%- moduleName %>
</description>

<property name="ti.module.root" location="${basedir}"/>
<property file="build.properties" />

<!-- Copy documentation subdirectories -->
<mkdir dir="${basedir}/documentation"/>
<copy todir="${basedir}/documentation">
<fileset dir="${basedir}/../documentation"/>
</copy>

<!-- Copy example subdirectories -->
<mkdir dir="${basedir}/example"/>
<copy todir="${basedir}/example">
<fileset dir="${basedir}/../example"/>
</copy>

<!-- Copy assets subdirectories -->
<mkdir dir="${basedir}/assets"/>
<copy todir="${basedir}/assets">
<fileset dir="${basedir}/../assets"/>
</copy>

<!-- Copy license -->
<copy todir="${basedir}" file="${basedir}/../LICENSE"/>

<target name="cleancopy" description="Delete old copies">
<delete dir="${basedir}/documentation"/>
<delete dir="${basedir}/example"/>
<delete dir="${basedir}/assets"/>
<delete file="${basedir}/LICENSE"/>
</target>

<import file="${titanium.platform}/../module/android/build.xml"/>
</project>
Expand Up @@ -6,7 +6,7 @@
* Please see the LICENSE included with this distribution for details.
*
*/
package __MODULE_ID__;
package <%- moduleId %>;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
Expand All @@ -23,8 +23,8 @@ import org.appcelerator.titanium.view.TiUIView;
import android.app.Activity;


// This proxy can be created by calling ___MODULE_NAME_CAMEL___.createExample({message: "hello world"})
@Kroll.proxy(creatableInModule=___MODULE_NAME_CAMEL___Module.class)
// This proxy can be created by calling <%- moduleNameCamel %>.createExample({message: "hello world"})
@Kroll.proxy(creatableInModule=<%- moduleNameCamel %>Module.class)
public class ExampleProxy extends TiViewProxy
{
// Standard Debugging variables
Expand Down Expand Up @@ -76,12 +76,12 @@ public class ExampleProxy extends TiViewProxy
public void handleCreationDict(KrollDict options)
{
super.handleCreationDict(options);

if (options.containsKey("message")) {
Log.d(LCAT, "example created with message: " + options.get("message"));
}
}

// Methods
@Kroll.method
public void printMessage(String message)
Expand Down
Expand Up @@ -6,7 +6,7 @@
* Please see the LICENSE included with this distribution for details.
*
*/
package __MODULE_ID__;
package <%- moduleId %>;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
Expand All @@ -16,18 +16,18 @@ import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;


@Kroll.module(name="___MODULE_NAME_CAMEL___", id="__MODULE_ID__")
public class ___MODULE_NAME_CAMEL___Module extends KrollModule
@Kroll.module(name="<%- moduleNameCamel %>", id="<%- moduleId %>")
public class <%- moduleNameCamel %>Module extends KrollModule
{

// Standard Debugging variables
private static final String LCAT = "___MODULE_NAME_CAMEL___Module";
private static final String LCAT = "<%- moduleNameCamel %>Module";
private static final boolean DBG = TiConfig.LOGD;

// You can define constants with @Kroll.constant, for example:
// @Kroll.constant public static final String EXTERNAL_NAME = value;
public ___MODULE_NAME_CAMEL___Module()

public <%- moduleNameCamel %>Module()
{
super();
}
Expand All @@ -46,16 +46,16 @@ public class ___MODULE_NAME_CAMEL___Module extends KrollModule
Log.d(LCAT, "example called");
return "hello world";
}

// Properties
@Kroll.getProperty
public String getExampleProp()
{
Log.d(LCAT, "get example property");
return "hello world";
}


@Kroll.setProperty
public void setExampleProp(String value) {
Log.d(LCAT, "set example property: " + value);
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/create.js
Expand Up @@ -392,7 +392,7 @@ CreateCommand.prototype.run = function run(logger, config, cli, finished) {
// load the project type lib
creator = new this.types[type](logger, config, cli);
logger.info(__('Creating %s project', type));
dump(cli.argv.platforms);

appc.async.series(this, [
function (next) {
cli.emit([
Expand Down
6 changes: 2 additions & 4 deletions cli/lib/creators/app.js
Expand Up @@ -170,23 +170,21 @@ AppCreator.prototype.run = function run(callback) {

tasks.push(function (next) {
// send the analytics
/*
this.cli.addAnalyticsEvent('project.create.mobile', {
dir: this.projectDir,
name: this.projectName,
publisher: this.projectConfig.publisher,
url: this.projectConfig.url,
image: this.projectConfig.image,
appid: this.id,
description: this.projectConfig.description,
description: '',
type: 'mobile',
guid: this.projectConfig.guid,
version: this.projectConfig.version,
copyright: this.projectConfig.copyright,
runtime: '1.0',
runtime: '1.0.0',
date: (new Date()).toDateString()
});
*/
next();
});

Expand Down

0 comments on commit 200b966

Please sign in to comment.