diff options
author | Ian Ni-Lewis <ilewis@google.com> | 2013-09-26 09:04:22 -0700 |
---|---|---|
committer | Ian Ni-Lewis <ilewis@google.com> | 2013-09-26 09:04:22 -0700 |
commit | 7516e7567809cb14a0cc4e68047aa004afb623d9 (patch) | |
tree | d153f4e94094ac720e120488e1069e6a5973d77a | |
parent | afc5bda968044835f25162908c411c1f1211a9b9 (diff) | |
download | build-7516e7567809cb14a0cc4e68047aa004afb623d9.tar.gz |
Add support for emitting Ant projects
Added an "emitAnt" task that copies the sample code into a more
traditional Android Ant file structure.
Change-Id: I04500c885b5fcfbe017b49f4b41b920a795c74b5
6 files changed, 72 insertions, 13 deletions
diff --git a/build.gradle b/build.gradle index 3d4a020a..61eb6a73 100644 --- a/build.gradle +++ b/build.gradle @@ -28,3 +28,27 @@ task wrapper(type: Wrapper) { gradleVersion = '1.6' } +task emitAnt(type:Copy) { + def outputPath = "build/ant" + def inputPath = "${project.projectDir}/${samplegen.targetSampleModule()}" + mkdir outputPath + into outputPath + includeEmptyDirs + ["main", "common", "template"].each { input -> + [[ "java", "src"], ["res", "res"]].each { filetype -> + def srcPath = "${inputPath}/src/${input}/${filetype[0]}" + into("${filetype[1]}") { + from(srcPath) + } + } + } + from("${inputPath}/src/main") { include "AndroidManifest.xml" } + from("${inputPath}/src/template") { include "project.properties" } +} + +task emitBrowsable(type:Copy) { + def output = "build/browsable" + mkdir output + into output + +} diff --git a/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenPlugin.groovy b/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenPlugin.groovy index 8bd9d39b..faa29737 100644 --- a/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenPlugin.groovy +++ b/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenPlugin.groovy @@ -51,7 +51,6 @@ class SampleGenPlugin implements Plugin { void apply(project) { project.extensions.create("samplegen", SampleGenProperties) project.samplegen.project = project - project.afterEvaluate({ SampleGenProperties samplegen = project.samplegen project.task('create') { if (project.gradle.startParameter.taskNames.contains('create')) { @@ -64,6 +63,7 @@ class SampleGenPlugin implements Plugin { samplegen.getRefreshProperties() } + project.afterEvaluate({ createTask(project, 'processTemplates', samplegen, @@ -91,6 +91,7 @@ class SampleGenPlugin implements Plugin { // People get nervous when they see a task with no actions, so... project.create << {println "Project creation finished."} project.refresh << {println "Project refresh finished."} + }) } diff --git a/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenProperties.groovy b/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenProperties.groovy index ebd40d5d..5a811081 100644 --- a/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenProperties.groovy +++ b/buildSrc/src/main/groovy/com/example/android/samples/build/SampleGenProperties.groovy @@ -106,11 +106,21 @@ class SampleGenProperties { } /** - * Returns the sample's fully qualified Java package as an OS dependent - * path fragment + * Transforms a package name into a java-style OS dependent path + * @param pkg cccc + * @return The java-style path to the package's code */ - String targetSamplePackageAsPath() { - return targetSamplePackage.replaceAll(/\./, File.separator) + String packageAsPath(String pkg) { + return pkg.replaceAll(/\./, File.separator) + } + + /** + * Transforms a path into a java-style package name + * @param path The java-style path to the package's code + * @return Name of the package to transform + */ + String pathAsPackage(String path) { + return path.replaceAll(File.separator, /\./) } /** @@ -147,7 +157,7 @@ class SampleGenProperties { String outputPath = relativeInputPath outputPath = outputPath.replaceAll('_PROJECT_', targetSampleName()) outputPath = outputPath.replaceAll('_MODULE_', targetSampleModule()) - outputPath = outputPath.replaceAll('_PACKAGE_', targetSamplePackageAsPath()) + outputPath = outputPath.replaceAll('_PACKAGE_', packageAsPath(targetSampleModule())) // This is kind of a hack; IntelliJ picks up any and all subdirectories named .idea, so // named them ._IDE_ instead. TODO: remove when generating .idea projects is no longer necessary. diff --git a/templates/base/_MODULE_/build.gradle.ftl b/templates/base/_MODULE_/build.gradle.ftl index aa5617bc..7d6da5f4 100644 --- a/templates/base/_MODULE_/build.gradle.ftl +++ b/templates/base/_MODULE_/build.gradle.ftl @@ -48,13 +48,7 @@ List<String> dirs = [ android { <#-- Note that target SDK is hardcoded in this template. We expect all samples to always use the most current SDK as their target. --> -<#if (sample.compileSdkVersion)?is_number > - compileSdkVersion ${sample.compileSdkVersion} -<#elseif (sample.compileSdkVersion)?is_string> - compileSdkVersion "${sample.compileSdkVersion}" -<#else> - compileSdkVersion 18 -</#if> + compileSdkVersion ${compile_sdk} buildToolsVersion "18.0.1" sourceSets { diff --git a/templates/base/_MODULE_/src/template/project.properties.ftl b/templates/base/_MODULE_/src/template/project.properties.ftl new file mode 100644 index 00000000..81066779 --- /dev/null +++ b/templates/base/_MODULE_/src/template/project.properties.ftl @@ -0,0 +1,18 @@ +<#ftl> +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, +user.home): +<#noparse> +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt +</#noparse> + +# Project target. +target=android-${compile_sdk} diff --git a/templates/include/common.ftl b/templates/include/common.ftl index a0a8c45b..0a199737 100644 --- a/templates/include/common.ftl +++ b/templates/include/common.ftl @@ -20,3 +20,15 @@ <#elseif meta.outputFile?ends_with("xml")> <#include "xml-style-copyright.ftl"> </#if> + +<#-- Set the compile SDK version. This is more complicated than it should be, because + the version can be either a number or a string (e.g. KeyLimePie) so we need to test + both to see if the variable is empty. +--> +<#if (sample.compileSdkVersion)?is_number > + <#assign compile_sdk = sample.compileSdkVersion> +<#elseif (sample.compileSdkVersion)?is_string> + <#assign compile_sdk = "sample.compileSdkVersion"> +<#else> + <#assign compile_sdk = 18> +</#if> |