Ian Ni-Lewis | eb640c0 | 2013-09-09 17:01:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // The SampleGenPlugin source is in the buildSrc directory. |
| 18 | import com.example.android.samples.build.SampleGenPlugin |
| 19 | apply plugin: SampleGenPlugin |
| 20 | |
| 21 | // Add a preflight task that depends on the "refresh" task that gets |
| 22 | // added by the SampleGenPlugin. |
| 23 | task preflight { |
| 24 | project.afterEvaluate({preflight.dependsOn(project.refresh)}) |
| 25 | } |
| 26 | |
| 27 | task wrapper(type: Wrapper) { |
| 28 | gradleVersion = '1.6' |
Ian Ni-Lewis | afc5bda | 2013-09-24 13:16:50 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 31 | task emitAnt(type:Copy) { |
Ian Ni-Lewis | 8e1b2ff | 2013-09-30 14:20:39 -0700 | [diff] [blame] | 32 | def outputPath = "${samplegen.pathToBuild}/ant" |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 33 | def inputPath = "${project.projectDir}/${samplegen.targetSampleModule()}" |
| 34 | mkdir outputPath |
| 35 | into outputPath |
| 36 | includeEmptyDirs |
| 37 | ["main", "common", "template"].each { input -> |
| 38 | [[ "java", "src"], ["res", "res"]].each { filetype -> |
| 39 | def srcPath = "${inputPath}/src/${input}/${filetype[0]}" |
| 40 | into("${filetype[1]}") { |
| 41 | from(srcPath) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | from("${inputPath}/src/main") { include "AndroidManifest.xml" } |
| 46 | from("${inputPath}/src/template") { include "project.properties" } |
| 47 | } |
| 48 | |
Ian Ni-Lewis | 8e1b2ff | 2013-09-30 14:20:39 -0700 | [diff] [blame] | 49 | task emitBrowseable(type:Copy) { |
| 50 | def outputPath = "${samplegen.pathToBuild}/browsable" |
Ian Ni-Lewis | 8da8625 | 2013-09-26 16:05:05 -0700 | [diff] [blame] | 51 | def inputPath = "${project.projectDir}/${samplegen.targetSampleModule()}" |
| 52 | mkdir outputPath |
| 53 | into outputPath |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 54 | |
Ian Ni-Lewis | 8da8625 | 2013-09-26 16:05:05 -0700 | [diff] [blame] | 55 | ["main", "common", "template"].each { input -> |
| 56 | def srcPath = "${inputPath}/src/${input}" |
| 57 | into("src") { |
| 58 | from("${srcPath}/java") |
| 59 | eachFile { FileCopyDetails fcd -> |
| 60 | def file = fcd.name |
| 61 | def parent = fcd.relativePath.parent |
| 62 | def newPath = parent.pathString.replaceAll ('(?<=/)([^/]+)/(?!java)', {a,b -> "$b."}) |
| 63 | newPath = "${newPath}/${file}" |
| 64 | fcd.path = newPath |
| 65 | println fcd.path |
| 66 | } |
| 67 | } |
| 68 | into("res") { |
| 69 | from("${srcPath}/res") |
| 70 | } |
| 71 | } |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 72 | } |