You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2016/05/16 18:55:32 UTC

git commit: [flex-asjs] [refs/heads/develop] - Updated cordova-build.xml ANT script.

Repository: flex-asjs
Updated Branches:
  refs/heads/develop 35b543ef0 -> f56c612dc


Updated cordova-build.xml ANT script.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f56c612d
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f56c612d
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f56c612d

Branch: refs/heads/develop
Commit: f56c612dc88f2247781ee4318ec9e6d90a706703
Parents: 35b543e
Author: Peter Ent <pe...@apache.org>
Authored: Mon May 16 14:55:29 2016 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Mon May 16 14:55:29 2016 -0400

----------------------------------------------------------------------
 cordova-build.xml | 149 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 97 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f56c612d/cordova-build.xml
----------------------------------------------------------------------
diff --git a/cordova-build.xml b/cordova-build.xml
index 1e209b8..d7fb343 100644
--- a/cordova-build.xml
+++ b/cordova-build.xml
@@ -18,80 +18,125 @@
 
 -->
 
-<project name="createproject" default="main" basedir=".">
+<project name="createproject" default="main">
 
-    <condition property="project.name.specified" value="true">
-            <isset property="PROJECT_NAME" />
+	<!-- this ANT script assumes you are in the following directory structure:
+	
+	     .    /* run ANT here */
+	     ./src/<APP>.mxml   /* The main application MXML tag */
+	     ./bin/js-debug     /* The result of building APP.mxml via mxmlc
+	     ./app/<APP>        /* The Cordova application directory
+	     
+	     1. This ANT script will build the template Cordova app/APP if it does not
+	     already exist. 
+	     
+	     2. This ANT script will compile the APP.mxml into bin/js-debug
+	     
+	     3. This ANT script will remove ./app/<APP>/www contents are replace it with
+	     the contents of bin/js-debug.
+	     
+	     Optionally, you can run the Cordova application using ant run <platform>
+	     
+	-->
+	
+	<target name="main" depends="create, compilejs, copyfiles" description="Creates the Cordova app if needed, compiles the FlexJS app, copies the results to Cordova app">
+		<echo message="Building app ${appname} for platform ${platform}" />
+	</target>
+	
+	<!-- Set up properties and conditions -->
+	
+	<condition property="platform" value="android">
+	<!-- override with -Dplatform=other-platform-name -->
+		<not>
+			<isset property="platform" />
+		</not>
     </condition>
-    <fail message="PROJECT_NAME not specified. Should specify desired name of cordova project" unless="project.name.specified"/>
-
-    <condition property="target.dir.specified" value="true">
-        <isset property="TARGET_DIR" />
-    </condition>
-    <fail message="TARGET_DIR not specified. Should specify folder to contain cordova project folder" unless="target.dir.specified"/>
-
-    <condition property="project.dir.specified" value="true">
-        <isset property="PROJECT_DIR" />
-    </condition>
-    <fail message="PROJECT_DIR not specified. Should specify folder that contains the bin/js-debug output of a FlexJS project" unless="project.dir.specified"/>
-
-    <property name="target.dir" value="${TARGET_DIR}" />
-    <property name="project.name" value="${PROJECT_NAME}" />
-    <property name="project.dir" value="${PROJECT_DIR}" />
-
-    <property name="app.dir" value="${target.dir}/${project.name}" />
-    <available file="${app.dir}" type="dir" property="app.dir.exists"/>
-
-    <available file="${target.dir}" type="dir" property="target.dir.exists"/>
-    <fail message="${target.dir} does not exist" unless="target.dir.exists"/>
-    <available file="${project.dir}/bin/js-debug" type="dir" property="project.dir.exists"/>
-    <fail message="${project.dir}/bin/js-debug does not exist" unless="project.dir.exists"/>
     
-    <target name="create" unless="app.dir.exists">
+    
+	<basename property="directory.name" file="${user.dir}" />
+	<!-- override with -Dappname=other-app-name -->
+    <condition property="appname" value="${directory.name}">
+    	<not>
+    		<isset property="appname" />
+    	</not>
+    </condition>
+	
+	<property name="cordova.target.dir" value="${user.dir}/app/${appname}" />
+    <available file="${cordova.target.dir}" type="dir" property="app.dir.exists"/>
+	
+	<!-- Step 1: create the Cordova template project unless it already exists -->
+	
+	<target name="makedir" unless="app.dir.exists">
+		<mkdir dir="${user.dir}/app" />
+	</target>
+	
+	<target name="create" unless="app.dir.exists" depends="makedir" description="Creates the Cordova application template">
     	<!-- create the project -->
-		<exec executable="cordova" dir="${target.dir}">
+		<exec executable="cordova" dir="${user.dir}/app">
 			<arg value="create" />
-			<arg value="${project.name}" />
-			<arg value="org.apache.flex.mobile" />
-			<arg value="${project.name}" />
+			<arg value="${appname}" />
 		</exec>
+		
+		<echo>Adding in platform(s). This may take awhile.</echo>
 
 		<!-- add in the platforms -->
-		<exec executable="cordova" dir="${app.dir}">
+		<exec executable="cordova" dir="${cordova.target.dir}">
 			<arg value="platform" />
 			<arg value="add" />
-			<arg value="android" />
+			<arg value="${platform}" />
 		</exec>
     </target>
     
-    <target name="copyfiles" depends="create">
-    	<echo message="Removing www directory contents" />
+    <!-- Step 2: Compile the FlexJS application -->
+    
+    <target name="compilejs" description="Compiles the FlexJS app into JavaScript">
+    	<echo message="Compiling FlexJS app" />
+    	<exec executable="mxmlc" dir="${user.dir}/src">
+    		<arg value="${appname}.mxml" />
+    	</exec>
+    </target>
+    
+    <!-- Step 3: Clean www directory -->
+    
+    <target name="purge">
     	<delete includeEmptyDirs="true">
-    		<fileset dir="${app.dir}/www" includes="**/*" />
+    		<fileset dir="${cordova.target.dir}/www" includes="**/*" />
     	</delete>
+    </target>
+    
+    <!-- Step 4: Copy files from step 2 -->
+    
+    <target name="copyfiles" depends="purge">
     	<echo message="Copying files from project" />
-    	<copy todir="${app.dir}/www">
-    		<fileset dir="${project.dir}/bin/js-debug" />
+    	<copy todir="${cordova.target.dir}/www">
+    		<fileset dir="${user.dir}/bin/js-debug" />
     	</copy>
     </target>
     
-    <target name="build" depends="copyfiles">
-		<!-- build the app -->
-		<exec executable="cordova" dir="${app.dir}">
-			<arg value="build" />
-			<arg value="android" />
-		</exec>
-    </target>
+    <!--
+    	Running the app on the platform
+    -->
     
-    <target name="main" depends="build">
-    	<echo message="App = ${app.dir} and basedir = ${basedir}" />
+    <target name="run" description="Runs the Cordova application on the specified platform">
+    	<echo message="Launching ${appname} on platform ${platform}" />
+    	<exec executable="cordova" dir="${cordova.target.dir}">
+    		<arg value="run" />
+    		<arg value="${platform}" />
+    	</exec>
     </target>
     
-    <target name="help">
-    	<echo message="ant -f cordova-build.xml -DPROJECT_NAME=name -DPROJECT_DIR=FlexJSProjectDirectory -DTARGET_DIR=PhoneGapProjectDirectory" />
-    	<echo message="PhoneGap project is created inside of PhoneGapProjectDirectory with the PROJECT name and all files are copied" />
-    	<echo message="from FlexJSProjectDirectory/bin/js-debug into the PhoneGap project." />
+    <!--
+    	Cleaning Tasks
+    -->
+    
+    <target name="clean" depends="purge" description="Removes files created during the build and copy">
+    	<delete dir="${user.dir}/bin-debug" failonerror="false" />
+    	<delete dir="${user.dir}/bin-release" failonerror="false" />
     </target>
     
-</project>
+    <target name="super-clean" depends="clean" description="Removes all files and directories except src and its contents">
+    	<delete dir="${user.dir}/bin" />
+    	<delete dir="${user.dir}/app" />
+    </target>
 
+</project>
\ No newline at end of file