1import org.apache.tools.ant.filters.ReplaceTokens
2import com.google.cloud.tools.gradle.appengine.core.DeployTask
3
4buildscript {
5    ext {
6        springBootVersion = '1.5.13.RELEASE'
7        objectifyVersion = '6.0'
8        jacksonVersion = '2.9.7'
9        googleCloudVersion = '0.47.0-alpha'
10        googleJavaFormatVersion = '0.7.1'
11        googleHttpClientVersion = '1.25.0'
12        lombokVersion = '1.18.4'
13        appGradlePluginVersion = '2.0.0-rc3'
14        protobufGradlePlugin = '0.8.7'
15        googleSheetsAPI = 'v4-rev548-1.25.0'
16    }
17    repositories {
18        jcenter()
19        mavenCentral()
20        maven {
21            url "https://plugins.gradle.org/m2/"
22        }
23        maven {
24            url 'https://oss.sonatype.org/content/repositories/snapshots/'
25        }
26    }
27    dependencies {
28        classpath "com.google.cloud.tools:appengine-gradle-plugin:${appGradlePluginVersion}"    // latest App Engine Gradle tasks
29        classpath "com.google.protobuf:protobuf-gradle-plugin:${protobufGradlePlugin}"
30        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
31    }
32}
33
34plugins {
35    id 'war'        // standard Web Archive plugin
36    id "com.github.sherter.google-java-format" version "0.7.1"
37}
38
39apply plugin: 'com.google.protobuf'
40apply plugin: 'com.google.cloud.tools.appengine-standard'  // App Engine tasks
41
42apply from: rootProject.file('gradle/profiles.gradle')
43
44group = 'com.android.vts'
45version = '4'
46description = "Google Android VTS dashboard"
47
48sourceCompatibility = 1.8
49targetCompatibility = 1.8
50
51
52repositories {
53    maven {
54        url 'https://oss.sonatype.org/content/repositories/snapshots' // SNAPSHOT repository (if needed)
55    }
56    mavenCentral()
57    jcenter()
58}
59
60dependencies {
61    compile 'com.google.appengine:appengine-api-1.0-sdk:+'  // Latest App Engine Api's
62    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
63
64    compile 'jstl:jstl:1.2'
65
66    compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7'
67    compile group: 'org.apache.commons', name: 'commons-math3', version:'3.6.1'
68    compile group: 'commons-codec', name: 'commons-codec', version:'1.9'
69    compile group: 'com.google.cloud', name: 'google-cloud', version: "${googleCloudVersion}"
70    compile group: 'com.google.code.gson', name: 'gson', version:'2.7'
71    compile group: 'com.googlecode.objectify', name: 'objectify', version: "${objectifyVersion}"
72    compile group: 'org.json', name: 'json', version:'20180130'
73    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}"
74    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}"
75    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "${jacksonVersion}"
76
77    compile group: 'com.google.apis', name: 'google-api-services-oauth2', version:'v1-rev136-1.23.0'
78    compile group: 'com.google.http-client', name: 'google-http-client', version: "${googleHttpClientVersion}"
79    compile group: 'com.google.http-client', name: 'google-http-client-protobuf', version: "${googleHttpClientVersion}"
80    compile group: 'com.google.visualization', name: 'visualization-datasource', version:'1.1.1'
81
82    compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.1'
83
84    compile(group: 'com.google.api-client', name: 'google-api-client', version: "${googleHttpClientVersion}") {
85        exclude(module: 'guava-jdk5')
86    }
87    compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: "${googleHttpClientVersion}"
88    compile group: 'com.google.apis', name: 'google-api-services-sheets', version: "${googleSheetsAPI}"
89
90    testCompile group: 'junit', name: 'junit', version: '4.12'
91    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0'
92    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version:'5.0.3'
93
94    testCompile 'com.google.appengine:appengine-testing:+'
95    testCompile 'com.google.appengine:appengine-api-stubs:+'
96    testCompile 'com.google.appengine:appengine-tools-sdk:+'
97
98    compile group: 'org.projectlombok', name: 'lombok', version: "${lombokVersion}"
99    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: "${lombokVersion}"
100}
101
102// Always run unit tests
103appengineDeploy.dependsOn test
104appengineStage.dependsOn test
105
106googleJavaFormat {
107    toolVersion = '1.6'
108    options style: 'AOSP'
109    source = sourceSets*.allJava
110    include '**/*.java'
111    exclude '**/*Template.java'
112    exclude 'src/test/template_*'
113}
114
115sourceSets {
116    main {
117        proto {
118            srcDir '../test_serving/proto'
119            include 'TestScheduleConfigMessage.proto'
120        }
121        java {
122            srcDir 'src/main/java'
123        }
124    }
125}
126
127protobuf {
128    generateProtoTasks {
129        ofSourceSet('main').each { task ->
130            task.builtins {
131                python {
132                    outputSubDir = 'python'
133                }
134                java {
135                    outputSubDir = 'java'
136                }
137            }
138        }
139    }
140}
141
142appengine {  // App Engine tasks configuration
143    tools {
144        // configure the Cloud Sdk tooling
145    }
146
147    run {
148        environment = [
149                GOOGLE_CLOUD_PROJECT: "android-vts-staging",
150                // DATASTORE_USE_PROJECT_ID_AS_APP_ID: "true",
151        ]
152        port = 8080
153        jvmFlags = [
154                "-Xdebug",
155                "-Dappengine.fullscan.seconds=5"
156        ]
157    }
158    stage {
159        // configure staging for deployment
160    }
161    deploy {   // deploy configuration
162        version = project.property("appEngineVersion")
163        projectId = project.property("projectIdList")
164
165    }
166}
167
168test {
169    useJUnit()
170    testLogging.showStandardStreams = true
171    beforeTest { descriptor ->
172        logger.lifecycle("test: " + descriptor + "  Running")
173    }
174
175    onOutput { descriptor, event ->
176        logger.lifecycle("test: " + descriptor + ": " + event.message )
177    }
178    afterTest { descriptor, result ->
179        logger.lifecycle("test: " + descriptor + ": " + result )
180    }
181}
182
183tasks.whenTaskAdded { task ->
184    if (task.name =~ /generate.*Proto/) {
185        task.finalizedBy(copyGeneratedProtoFiles)
186    }
187}
188
189task copyGeneratedProtoFiles(type: Copy) {
190    into(projectDir)
191
192    from("build/generated/source/proto/main/java") {
193        into "src/main/java"
194    }
195    from("build/generated/source/proto/main/python") {
196        into "python"
197    }
198}
199
200
201tasks.addRule("Pattern: vtsGaeDeploy<ID>") { String taskName ->
202    if (taskName.startsWith("vtsGaeDeploy-")) {
203
204        def projectId = taskName.replace("vtsGaeDeploy-", "")
205        def version = project.property("appEngineVersion")
206
207        def appengineWebCopy = tasks.create(name: "appengineWebCopy-${projectId}", type: Copy) {
208            from "${webAppDirName}/WEB-INF/appengine-web.xml"
209            into "${appengine.stage.sourceDirectory}/WEB-INF"
210            filter(ReplaceTokens, tokens: [PROJECT_ID: projectId])
211        }
212        appengineWebCopy.dependsOn appengineStage
213        appengineWebCopy.mustRunAfter appengineStage
214
215        def gcsConfigCopy = task("gcsConfigCopy-${projectId}") {
216            doFirst {
217                println "============ resource folder processing ============"
218
219                if (project.loadConfigFromGcs.toBoolean()) {
220                    exec {
221                        println "The resources folder will be copied from GCS!"
222                        commandLine "gsutil",
223                                    "cp",
224                                    "-R",
225                                    "${project.gcsConfigPath}${project.mode}/dashboard/${projectId}/resources/*",
226                                    "$appengine.stage.stagingDirectory/WEB-INF/classes"
227                    }
228                } else {
229                    println "The local resource folder will be used!"
230                }
231            }
232
233            doLast {
234
235            }
236        }
237        gcsConfigCopy.dependsOn appengineWebCopy
238        gcsConfigCopy.mustRunAfter appengineWebCopy
239
240        def deployTaskList = [appengineDeploy]
241
242        def vtsGaeDeployTask = task(taskName) {
243
244            doFirst {
245                println "--------------> setup deploying tasks <-------------"
246            }
247
248            doLast {
249                def commandKeyList = [
250                        'enableAppengineDeployCron': appengineDeployCron,
251                        'enableAppengineDeployDispatch': appengineDeployDispatch,
252                        'enableAppengineDeployDos': appengineDeployDos,
253                        'enableAppengineDeployIndex': appengineDeployIndex,
254                        'enableAppengineDeployQueue': appengineDeployQueue
255                ]
256
257                commandKeyList.each { key, value ->
258                    if (project.hasProperty(key) && project.getProperty(key).toBoolean()) {
259                        deployTaskList.push(value)
260                    }
261                }
262            }
263        }
264
265        vtsGaeDeployTask.dependsOn gcsConfigCopy
266        vtsGaeDeployTask.mustRunAfter gcsConfigCopy
267        vtsGaeDeployTask.finalizedBy deployTaskList
268    }
269}
270
271task vtsGaeMultiDeploy {
272    dependsOn {
273        def taskList = []
274        def projectIdList = project.property("projectIdList")
275        projectIdList.split(",").each { projectId ->
276            taskList.push(tasks.findByName("vtsGaeDeploy-${projectId.trim()}".toString()))
277        }
278        return taskList
279    }
280}
281