1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-11 03:55:04 -05:00

summary: updated build.xml and tests/build.xml.

build.xml and tests/build.xml:
  updated general format to match what is generated in a new project.
  moved targets common to both to build_common.xml.
  replaced some exec calls (perl, mv) and inline javascript with ant tasks (including extensions from Android and ant-contrib).

build.xml:
  fixed indentation.
  privatized targets that don't need to be called directly from command-line.
  renamed some properties.

tests/build.xml:
  renamed test project from K9 to K9Tests.

tools/ant-contrib.jar:
  new!

.gitignore:
  added note about local per-repo rules.
This commit is contained in:
ashley willis 2012-06-01 15:41:14 -05:00
parent 67caa357fd
commit cb715387b5
5 changed files with 247 additions and 240 deletions

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
# Local per-repo rules can be added to the .git/info/exclude file in your
# repo. These rules are not committed with the repo so they are not shared
# with others. This method can be used for locally-generated files that you
# dont expect other users to generate, like files created by your editor.
.settings
bin
coverage

234
build.xml
View File

@ -4,7 +4,7 @@
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
@ -41,25 +41,23 @@
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
@ -80,6 +78,7 @@
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: custom -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<!-- K9 CUSTOM STUFF -->
@ -87,50 +86,83 @@
<property name="rclib" value="${out.dir}/K9RemoteControl.jar" />
<property name="rcdir" value="com/fsck/k9/remotecontrol/**" />
<!-- A bloody hack, but a useful and quick one -->
<target name="get-version">
<exec executable="perl" failonerror="true" outputproperty="version-name" errorproperty="version-error">
<!-- yes, ant needs &quot; for " in doublequoted strings. -->
<arg line="-ne'/android:versionName.*?=.*?&quot;(.*?)&quot;/ ? print $1 : undef ' AndroidManifest.xml" />
</exec>
<echo>Building version number ${version-name}</echo>
<target name="-get-version" depends="-get-version-name">
<echo>Building version number ${current-version-name}</echo>
</target>
<target name="get-version-from-git">
<exec executable="git" failonerror="true" outputproperty="version-name" errorproperty="version-error">
<arg line="describe --tags"/>
</exec>
<echo>Building version number ${version-name}</echo>
<target name="-get-version-name">
<xpath input="AndroidManifest.xml" expression="/manifest/@android:versionName" output="current-version-name" />
</target>
<target name="set-version">
<target name="-get-version-code">
<xpath input="AndroidManifest.xml" expression="/manifest/@android:versionCode" output="current-version-code" />
</target>
<target name="-get-version-from-git">
<exec executable="git" failonerror="true" outputproperty="current-version-name" errorproperty="current-version-error">
<arg line="describe --tags" />
</exec>
<echo>Building version number ${current-version-name}</echo>
</target>
<target name="-auto-incr-version">
<regex property="major" input="${current-version-name}" regexp="(\d+)\.\d+" select="\1" />
<regex property="minor" input="${current-version-name}" regexp="\d+\.(\d+)" select="\1" />
<math result="minor" operand1="${minor}" operation="+" operand2="1" datatype="int"/>
<if.contrib>
<length string="${minor}" when="eq" length="1" />
<then>
<var name="minor" value="00${minor}" />
</then>
<elseif>
<length string="${minor}" when="eq" length="2" />
<then>
<var name="minor" value="0${minor}" />
</then>
</elseif>
</if.contrib>
<regex property="version-name" input="${major}." regexp="(\d+.)" replace="\1${minor}" />
</target>
<target name="-set-version" depends="-get-version-name,-get-version-code">
<!-- pass -Dversion-name=4.200 to define the version instead of auto-incrementing it -->
<if.contrib>
<isset property="version-name" />
<else>
<runtarget target="-auto-incr-version" />
</else>
</if.contrib>
<echo>Setting version to ${version-name}</echo>
<fail unless="version-name">You can't set the version without passing -Dversion-name=1.234</fail>
<exec executable="perl" failonerror="true">
<arg line="-p -i.bak -e's/(?&lt;=android:versionName=&quot;)(.*?)(?=&quot;)/${version-name}/' AndroidManifest.xml"/>
</exec>
<exec executable="perl" failonerror="true">
<arg line="-p -i.bak -e's/(?&lt;=android:versionCode=&quot;)(\d+)(?=&quot;)/$1+1/e' AndroidManifest.xml" />
</exec>
<replace file="AndroidManifest.xml"
token="android:versionName=&quot;${current-version-name}&quot;"
value="android:versionName=&quot;${version-name}&quot;" summary="true"
/>
<math result="new-version-code" operand1="${current-version-code}" operation="+" operand2="1" datatype="int"/>
<replace file="AndroidManifest.xml"
token="android:versionCode=&quot;${current-version-code}&quot;"
value="android:versionCode=&quot;${new-version-code}&quot;" summary="true"
/>
</target>
<!-- rules -->
<target name="bump-version" depends="set-version,commit-version">
<echo>Bumping K-9 to ${version-name}</echo>
<target name="bump-version" depends="-set-version,-commit-version">
<echo>Bumped K-9 to ${version-name}</echo>
</target>
<target name="commit-version">
<target name="-commit-version">
<exec executable="git" failonerror="true">
<arg line="commit -m'Bumped manifest to ${version-name}' AndroidManifest.xml"/>
<arg line="commit -m'Bumped manifest to ${version-name}' AndroidManifest.xml" />
</exec>
<exec executable="git" failonerror="true">
<arg line="tag ${version-name}"/>
<arg line="tag ${version-name}" />
</exec>
<exec executable="git" failonerror="true">
<arg line="push"/>
<arg line="push" />
</exec>
<exec executable="git" failonerror="true">
<arg line="push origin tag ${version-name}"/>
<arg line="push origin tag ${version-name}" />
</exec>
</target>
@ -139,30 +171,29 @@
<echo>Creating library ${rclib} for remote control applications</echo>
<jar destfile="${rclib}" basedir="${out.classes.dir}" includes="${rcdir}" />
</target>
<target name="upload" depends="clean,get-version,release">
<target name="upload" depends="clean,-get-version,release">
<echo>Uploading to Google Code using Google::Code::Upload</echo>
<exec executable="mv" failonerror="true">
<arg value="${out.final.file}" />
<arg value="bin/k9-${version-name}-release.apk" />
</exec>
<move file="${out.final.file}" tofile="bin/k9-${current-version-name}-release.apk" />
<property name="gcode-project" value="k9mail" />
<exec executable="googlecode_upload.pl" failonerror="true">
<arg value="--summary" />
<arg value="${ant.project.name} ${version-name}"/>
<arg value="${ant.project.name} ${current-version-name}" />
<arg value="--project" />
<arg value="k9mail"/>
<arg value="--user"/>
<arg value="${gcode-project}" />
<arg value="--user" />
<arg value="${gcode-user}" />
<arg value="--pass"/>
<arg value="--pass" />
<arg value="${gcode-pass}" />
<arg value="--labels"/>
<arg value="Type-Installer"/>
<arg value="bin/k9-${version-name}-release.apk" />
<arg value="--labels" />
<arg value="Type-Installer" />
<arg value="bin/k9-${current-version-name}-release.apk" />
</exec>
</target>
<target name="astyle">
<exec executable="astyle" failonerror="true">
<arg line="--style=java --indent=spaces=4 --indent-switches --max-instatement-indent=4 --brackets=attach --add-brackets --convert-tabs --unpad-paren --pad-header --pad-oper --suffix=none --recursive 'src/com/fsck/k9/*.java' 'tests/src/com/fsck/k9/*.java'"/>
<arg line="--style=java --indent=spaces=4 --indent-switches --max-instatement-indent=4 --brackets=attach --add-brackets --convert-tabs --unpad-paren --pad-header --pad-oper --suffix=none --recursive 'src/com/fsck/k9/*.java' 'tests/src/com/fsck/k9/*.java'" />
</exec>
</target>
@ -172,6 +203,7 @@
<echo>Additional targets:</echo>
<!--echo> bump-version: ant -Dversion-name=3.123</echo>
<echo> Bumps the project version to 3.123,tags and commits it.</echo>
<echo> If version-name is not given, it will auto-increment.</echo>
<echo> upload: Uploads a new release to google code.</echo-->
<echo> rclib: Creates library for remote control applications.</echo>
<echo> astyle: Make K-9's source look like it's supposed to.</echo>
@ -187,55 +219,14 @@
<target name="eclipse" description="Apply template Eclipse settings">
<copy todir=".settings">
<fileset dir="tools/eclipse-settings"/>
<fileset dir="tools/eclipse-settings" />
</copy>
</target>
<property environment="env" />
<property name="javadoc-dir" location="javadoc" />
<target name="javadoc" description="build javadoc">
<mkdir dir="${javadoc-dir}"/>
<javadoc
destdir="${javadoc-dir}"
doctitle="K-9 Mail"
verbose="on"
use="true"
classpath="${env.ANDROID_HOME}/platforms/${target}/android.jar"
sourcepath="gen;src"
linkoffline="http://d.android.com/reference ${env.ANDROID_HOME}/docs/reference/"
/>
</target>
<target name="lint-xml">
<exec executable="lint" failonerror="true">
<arg value="--xml" />
<arg value="lint-results.xml" />
<arg path="." />
</exec>
</target>
<target name="lint-html">
<exec executable="lint" failonerror="true">
<arg value="--html" />
<arg value="lint-results.html" />
<arg path="." />
</exec>
</target>
<target name="monkey">
<xpath input="AndroidManifest.xml" expression="/manifest/@package" output="manifest.package" />
<if condition="monkey.count">
<else>
<property name="monkey.count" value="200" />
</else>
</if>
<if condition="monkey.seed">
<else>
<property name="monkey.seed" value="0" />
</else>
</if>
<property name="monkey.seed" value="0" /><!-- largest == 9223372036854775807 == 2**63 - 1 -->
<exec executable="${adb}" output="monkey.txt" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="-e" />
@ -244,46 +235,29 @@
<arg value="-p" />
<arg value="${manifest.package}" />
<arg value="-v" />
<arg value="-v" />
<arg value="-s" />
<arg value="${monkey.seed}" />
<arg value="${monkey.count}" />
</exec>
</target>
<scriptdef name="lastindexplus1" language="javascript">
<attribute name="text" />
<attribute name="substring" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var substring = attributes.get("substring");
project.setProperty(attributes.get("property"), text.lastIndexOf(substring) + 1);
]]>
</scriptdef>
<target name="reg" depends="-get-version-code">
<regex property="branch" input="${env.GIT_BRANCH}" regexp="(?:.*/)?(.+)" select="\1" global="true"/>
<regex property="commit" input="${env.GIT_COMMIT}" regexp="([\da-fA-F]{10})" select="\1" global="true"/>
<math result="version-code" operand1="${current-version-code}" operation="+" operand2="1" datatype="int"/>
<echo message="branch = ${branch} ${commit} ${current-version-code} ${version-code}" />
</target>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
<!-- this, and the two scriptdefs above, are for CloudBees. see tests/build.xml -->
<!-- this is for CloudBees. see tests/build.xml -->
<target name="-artifactd" depends="-set-debug-files, -artifact" />
<target name="-artifacti" depends="-set-instrumented-mode, -artifact" />
<target name="-artifact">
<lastindexplus1 text="${env.GIT_BRANCH}" substring="/" property="lastindexof" />
<substring text="${env.GIT_BRANCH}" start="${lastindexof}" property="branch" />
<substring text="${env.GIT_COMMIT}" start="0" end="10" property="commit" />
<regex property="branch" input="${env.GIT_BRANCH}" regexp="(?:.*/)?(.+)" select="\1" global="true" />
<regex property="commit" input="${env.GIT_COMMIT}" regexp="([\da-fA-F]{10})" select="\1" />
<copy file="${out.final.file}"
tofile="${out.dir}/K9-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}.apk"
tofile="${out.dir}/${ant.project.name}-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}.apk"
verbose="on"
/>
</target>
@ -296,7 +270,9 @@
<delete dir="${javadoc-dir}" verbose="${verbose}" />
</target>
<!-- END K-9 STUFF-->
<import file="${sdk.dir}/tools/ant/build.xml" />
<!-- common to both build.xml and tests/build.xml -->
<import file="build_common.xml" />
<!-- END K-9 CUSTOM STUFF -->
</project>

84
build_common.xml Normal file
View File

@ -0,0 +1,84 @@
<project name="common">
<!-- This file contains scriptdefs, properties, targets, etc that are common
to both build.xml and tests/build.xml. It also loads ant-contrib, where
each desired task needs to be defined below as both ant-contrib and
Android's anttasks.jar define different 'if' tasks. -->
<!-- ANT-CONTRIB -->
<!-- jar file from where the tasks are loaded -->
<path id="antcontrib">
<pathelement path="tools/ant-contrib.jar" />
</path>
<!-- ant-contrib tasks -->
<!-- this is normally named propertyregex -->
<taskdef name="regex"
classname="net.sf.antcontrib.property.RegexTask"
classpathref="antcontrib" />
<taskdef name="math"
classname="net.sf.antcontrib.math.MathTask"
classpathref="antcontrib" />
<taskdef name="runtarget"
classname="net.sf.antcontrib.logic.RunTargetTask"
classpathref="antcontrib" />
<taskdef name="var"
classname="net.sf.antcontrib.property.Variable"
classpathref="antcontrib" />
<!-- renamed to not conflict with android -->
<taskdef name="if.contrib"
classname="net.sf.antcontrib.logic.IfTask"
classpathref="antcontrib" />
<!-- SCRIPTDEFS -->
<!-- PROPERTIES -->
<!-- allow environment variables to be accessable by prepending "env." -->
<property environment="env" />
<!-- javadoc folder relative to ${basedir} -->
<property name="javadoc-dir" location="javadoc" />
<!-- path to lint -->
<property name="lint" location="${android.tools.dir}/lint${bat}" />
<!-- TARGETS -->
<!-- create javadoc in ${javadoc-dir} -->
<target name="javadoc" description="build javadoc">
<mkdir dir="${javadoc-dir}"/>
<javadoc
destdir="${javadoc-dir}"
doctitle="K-9 Mail"
verbose="on"
use="true"
classpath="${env.ANDROID_HOME}/platforms/${target}/android.jar"
sourcepath="gen;src"
linkoffline="http://d.android.com/reference ${env.ANDROID_HOME}/docs/reference/"
/>
</target>
<!-- create lint-results.xml -->
<target name="lint-xml">
<exec executable="${lint}" failonerror="true">
<arg value="--xml" />
<arg value="lint-results.xml" />
<arg path="${basedir}" />
</exec>
</target>
<!-- create lint-results.html and lint-results_files/ -->
<target name="lint-html">
<exec executable="${lint}" failonerror="true">
<arg value="--html" />
<arg value="lint-results.html" />
<arg path="${basedir}" />
</exec>
</target>
</project>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="K9" default="help">
<project name="K9Tests" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
@ -41,25 +41,23 @@
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
@ -80,42 +78,10 @@
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: custom -->
<import file="${sdk.dir}/tools/ant/build.xml" />
<!-- K-9 CUSTOM STUFF -->
<property environment="env" />
<property name="javadoc-dir" location="javadoc" />
<target name="javadoc" description="build javadoc">
<mkdir dir="${javadoc-dir}"/>
<javadoc
destdir="${javadoc-dir}"
doctitle="K-9 Mail"
verbose="on"
use="true"
classpath="${env.ANDROID_HOME}/platforms/${target}/android.jar"
sourcepath="gen;src"
linkoffline="http://d.android.com/reference ${env.ANDROID_HOME}/docs/reference/"
/>
</target>
<target name="lint-xml">
<exec executable="lint" failonerror="true">
<arg value="--xml" />
<arg value="lint-results.xml" />
<arg path="." />
</exec>
</target>
<target name="lint-html">
<exec executable="lint" failonerror="true">
<arg value="--html" />
<arg value="lint-results.html" />
<arg path="." />
</exec>
</target>
<property name="junit-file" location="junit-report.xml" />
<!-- This is overridden because otherwise it deletes coverage.em after extraction, requiring
@ -189,34 +155,14 @@
</exec>
</target>
<scriptdef name="lastindexplus1" language="javascript">
<attribute name="text" />
<attribute name="substring" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var substring = attributes.get("substring");
project.setProperty(attributes.get("property"), text.lastIndexOf(substring) + 1);
]]>
</scriptdef>
<scriptdef name="substring" language="javascript">
<attribute name="text" />
<attribute name="start" />
<attribute name="end" />
<attribute name="property" />
<![CDATA[
var text = attributes.get("text");
var start = attributes.get("start");
var end = attributes.get("end") || text.length();
project.setProperty(attributes.get("property"), text.substring(start, end));
]]>
</scriptdef>
<target name="artifacts" description="Copies the apks as unique CloudBees artifacts">
<lastindexplus1 text="${env.GIT_BRANCH}" substring="/" property="lastindexof" />
<substring text="${env.GIT_BRANCH}" start="${lastindexof}" property="branch" />
<substring text="${env.GIT_COMMIT}" start="0" end="10" property="commit" />
<fail unless="env.GIT_BRANCH" message="The environment variable GIT_BRANCH must exist." />
<fail unless="env.GIT_COMMIT" message="The environment variable GIT_COMMIT must exist." />
<fail unless="env.BUILD_ID" message="The environment variable BUILD_ID must exist." />
<fail unless="env.BUILD_NUMBER" message="The environment variable BUILD_NUMBER must exist." />
<regex property="branch" input="${env.GIT_BRANCH}" regexp="(?:.*/)?(.+)" select="\1" global="true" />
<regex property="commit" input="${env.GIT_COMMIT}" regexp="([\da-fA-F]{10})" select="\1" />
<!-- calls ../build.xml -->
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
@ -227,19 +173,14 @@
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
</subant>
<!-- define out.final.file if not already defined (if calling without debug, for instance) -->
<condition property="out.final.file.isset" value="true" else="false">
<isset property="out.final.file" />
</condition>
<if condition="${out.final.file.isset}">
<if condition="${build.is.mode.set}">
<else>
<property name="out.final.file"
location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
<runtarget target="-set-debug-files" />
</else>
</if>
<copy file="${out.final.file}"
tofile="${out.dir}/K9-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}-tests.apk"
tofile="${out.dir}/${ant.project.name}-${branch}-${env.BUILD_ID}-${commit}-${env.BUILD_NUMBER}.apk"
verbose="on"
/>
</target>
@ -268,7 +209,9 @@
<echo> ant [emma] [debug] artifacts</echo>
</target>
<!-- common to both build.xml and tests/build.xml -->
<import file="../build_common.xml" />
<!-- END K-9 CUSTOM STUFF -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

BIN
tools/ant-contrib.jar Normal file

Binary file not shown.