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) { |
Ian Ni-Lewis | 81ea031 | 2013-10-04 14:13:46 -0700 | [diff] [blame^] | 28 | gradleVersion = '1.8' |
Ian Ni-Lewis | afc5bda | 2013-09-24 13:16:50 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Ian Ni-Lewis | 81ea031 | 2013-10-04 14:13:46 -0700 | [diff] [blame^] | 31 | |
| 32 | String outPath(String buildType) { |
| 33 | def repoInfo = "repo info platform/developers/build".execute().text |
| 34 | def buildPath = (repoInfo =~ /Mount path: (.*)/)[0][1] |
| 35 | return "${buildPath}/out/${buildType}/${samplegen.targetSampleName()}"; |
| 36 | } |
| 37 | |
| 38 | |
| 39 | |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 40 | task emitAnt(type:Copy) { |
Ian Ni-Lewis | 81ea031 | 2013-10-04 14:13:46 -0700 | [diff] [blame^] | 41 | def outputPath = outPath("ant"); |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 42 | def inputPath = "${project.projectDir}/${samplegen.targetSampleModule()}" |
| 43 | mkdir outputPath |
| 44 | into outputPath |
| 45 | includeEmptyDirs |
| 46 | ["main", "common", "template"].each { input -> |
| 47 | [[ "java", "src"], ["res", "res"]].each { filetype -> |
| 48 | def srcPath = "${inputPath}/src/${input}/${filetype[0]}" |
| 49 | into("${filetype[1]}") { |
| 50 | from(srcPath) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | from("${inputPath}/src/main") { include "AndroidManifest.xml" } |
| 55 | from("${inputPath}/src/template") { include "project.properties" } |
| 56 | } |
| 57 | |
Ian Ni-Lewis | 8e1b2ff | 2013-09-30 14:20:39 -0700 | [diff] [blame] | 58 | task emitBrowseable(type:Copy) { |
Ian Ni-Lewis | 81ea031 | 2013-10-04 14:13:46 -0700 | [diff] [blame^] | 59 | def outputPath =outPath("browseable"); |
Ian Ni-Lewis | 8da8625 | 2013-09-26 16:05:05 -0700 | [diff] [blame] | 60 | def inputPath = "${project.projectDir}/${samplegen.targetSampleModule()}" |
| 61 | mkdir outputPath |
| 62 | into outputPath |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 63 | |
Ian Ni-Lewis | 81ea031 | 2013-10-04 14:13:46 -0700 | [diff] [blame^] | 64 | from("${project.projectDir}/_index.jd") |
| 65 | |
Ian Ni-Lewis | 8da8625 | 2013-09-26 16:05:05 -0700 | [diff] [blame] | 66 | ["main", "common", "template"].each { input -> |
| 67 | def srcPath = "${inputPath}/src/${input}" |
| 68 | into("src") { |
| 69 | from("${srcPath}/java") |
| 70 | eachFile { FileCopyDetails fcd -> |
| 71 | def file = fcd.name |
| 72 | def parent = fcd.relativePath.parent |
| 73 | def newPath = parent.pathString.replaceAll ('(?<=/)([^/]+)/(?!java)', {a,b -> "$b."}) |
| 74 | newPath = "${newPath}/${file}" |
| 75 | fcd.path = newPath |
| 76 | println fcd.path |
| 77 | } |
| 78 | } |
| 79 | into("res") { |
| 80 | from("${srcPath}/res") |
| 81 | } |
| 82 | } |
Ian Ni-Lewis | 7516e75 | 2013-09-26 09:04:22 -0700 | [diff] [blame] | 83 | } |