blob: 2aa4ea4b2056e59bd23b02294c7d413d1a11503e [file] [log] [blame]
Yigit Boyard437f7e2015-10-30 16:28:34 -07001import groovy.xml.QName
Yigit Boyarb1356332015-05-21 15:49:58 -07002
Yigit Boyar24bec1c2015-07-09 10:51:54 -07003buildscript {
Yigit Boyar9784c9a2015-10-12 18:59:27 -07004 ext.dataBindingRootFolder = project.projectDir
Yigit Boyar24bec1c2015-07-09 10:51:54 -07005 apply from: 'propLoader.gradle'
6 ext.addRepos(repositories)
Yigit Boyar9784c9a2015-10-12 18:59:27 -07007 if (ext.dataBindingConfig.addRemoteRepos) {
Yigit Boyar24bec1c2015-07-09 10:51:54 -07008 dependencies {
Yigit Boyar9784c9a2015-10-12 18:59:27 -07009 classpath "com.android.databinding:localizemaven:${dataBindingConfig.extraPluginsVersion}"
Yigit Boyar24bec1c2015-07-09 10:51:54 -070010 }
11 }
George Mount69cbd9e2015-08-26 10:46:58 -070012 dependencies {
13 classpath 'net.sf.proguard:proguard-gradle:5.2.1'
14 }
Yigit Boyar24bec1c2015-07-09 10:51:54 -070015}
Yigit Boyard437f7e2015-10-30 16:28:34 -070016
Yigit Boyar840f0ce2014-12-12 16:45:00 -080017subprojects {
Yigit Boyard437f7e2015-10-30 16:28:34 -070018 if (dataBindingConfig.isIndependent) {
19 apply plugin: 'maven'
20 if (dataBindingConfig.addRemoteRepos && !dataBindingConfig.forGradlePlugin) {
21 apply plugin: 'com.android.databinding.localizemaven'
22 }
23 } else {
24 apply from: "${project.projectDir}/../../buildSrc/base/baseJava.gradle"
Yigit Boyar63d47892015-07-10 09:03:05 -070025 }
26
Yigit Boyar9784c9a2015-10-12 18:59:27 -070027 if (it.name != "compilationTests") {
28 group = dataBindingConfig.group
29 version = dataBindingConfig.version
Yigit Boyar9784c9a2015-10-12 18:59:27 -070030 uploadArchives {
31 repositories {
32 mavenDeployer {
Yigit Boyard437f7e2015-10-30 16:28:34 -070033 repository(url: "file://${dataBindingConfig.mavenRepoDir}")
Yigit Boyar9784c9a2015-10-12 18:59:27 -070034 }
Yigit Boyarf9e51c02015-03-12 14:30:29 -070035 }
36 }
37 }
Yigit Boyar9784c9a2015-10-12 18:59:27 -070038
Yigit Boyar24bec1c2015-07-09 10:51:54 -070039 buildscript {
40 addRepos(repositories)
Yigit Boyar24bec1c2015-07-09 10:51:54 -070041 }
Yigit Boyard437f7e2015-10-30 16:28:34 -070042
Yigit Boyar24bec1c2015-07-09 10:51:54 -070043}
44
Yigit Boyar9784c9a2015-10-12 18:59:27 -070045if (dataBindingConfig.addRemoteRepos && !dataBindingConfig.forGradlePlugin) {
Yigit Boyar59229482015-10-29 17:17:48 -070046 rootProject.localizeMaven {
Yigit Boyar9784c9a2015-10-12 18:59:27 -070047 localRepoDir = file(dataBindingConfig.megaRepoDir)
48 otherRepoDirs = dataBindingConfig.localRepositories
Yigit Boyar24bec1c2015-07-09 10:51:54 -070049 }
Yigit Boyarf9e51c02015-03-12 14:30:29 -070050}
51
52task deleteRepo(type: Delete) {
Yigit Boyar9784c9a2015-10-12 18:59:27 -070053 delete "${dataBindingConfig.mavenRepoDir}/${dataBindingConfig.group.replace('.', '/')}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070054}
55
Yigit Boyaree758672015-04-16 15:12:02 -070056task deletePrebuildFolder(type: Delete) {
Yigit Boyar9784c9a2015-10-12 18:59:27 -070057 delete "${dataBindingConfig.prebuildFolder}"
Yigit Boyaree758672015-04-16 15:12:02 -070058}
59
Yigit Boyarc64ae352015-04-21 14:05:41 -070060task deleteEap(type: Delete) {
Yigit Boyar9784c9a2015-10-12 18:59:27 -070061 delete "${dataBindingConfig.eapOutDir}"
Yigit Boyarc64ae352015-04-21 14:05:41 -070062}
63
64
Yigit Boyara6e45832015-03-13 15:58:53 -070065def buildExtensionsTask = project.tasks.create "buildExtensionsTask", Exec
66buildExtensionsTask.workingDir file('extensions').getAbsolutePath()
Yigit Boyara6e45832015-03-13 15:58:53 -070067buildExtensionsTask.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070068buildExtensionsTask.args 'clean', 'uploadArchives', '--info', '--stacktrace',
Yigit Boyar9784c9a2015-10-12 18:59:27 -070069 "-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
70 "-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
71 "-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
Yigit Boyara6e45832015-03-13 15:58:53 -070072buildExtensionsTask.dependsOn subprojects.uploadArchives
73
Yigit Boyaree758672015-04-16 15:12:02 -070074def prepareExtensionPrebuilds = project.tasks.create "prepareExtensionPrebuilds", Exec
75prepareExtensionPrebuilds.workingDir file('extensions').getAbsolutePath()
76prepareExtensionPrebuilds.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070077prepareExtensionPrebuilds.args 'clean', 'preparePrebuilds', '--info', '--stacktrace',
Yigit Boyar9784c9a2015-10-12 18:59:27 -070078 "-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
79 "-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
80 "-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
Yigit Boyaree758672015-04-16 15:12:02 -070081prepareExtensionPrebuilds.dependsOn subprojects.uploadArchives
82
Yigit Boyarf9e51c02015-03-12 14:30:29 -070083file('integration-tests').listFiles().findAll { it.isDirectory() }.each {
Yigit Boyara6e45832015-03-13 15:58:53 -070084 println("Creating run test task for ${it.getAbsolutePath()}.")
Yigit Boyarf9e51c02015-03-12 14:30:29 -070085 def testTask = project.tasks.create "runTestsOf${it.getName().capitalize()}", Exec
Yigit Boyara6e45832015-03-13 15:58:53 -070086 testTask.workingDir it.getAbsolutePath()
Yigit Boyarf9e51c02015-03-12 14:30:29 -070087 //on linux
88 testTask.commandLine './gradlew'
Yigit Boyarb90752c2015-09-28 16:42:16 -070089 testTask.args 'clean', 'connectedCheck', '--info', '--stacktrace',
Yigit Boyar9784c9a2015-10-12 18:59:27 -070090 "-PuseReleaseVersion=${dataBindingConfig.inReleaseBuild ? 'true' : 'false'}",
91 "-PaddRemoteRepos=${dataBindingConfig.addRemoteRepos ? 'true' : 'false'}",
92 "-PforGradlePlugin=${dataBindingConfig.forGradlePlugin ? 'true' : 'false'}"
Yigit Boyarf9e51c02015-03-12 14:30:29 -070093 testTask.dependsOn subprojects.uploadArchives
94}
95
96task runIntegrationTests {
97 dependsOn tasks.findAll { task -> task.name.startsWith('runTestsOf') }
98}
99
100task runAllTests {
101 dependsOn runIntegrationTests
102}
103
Yigit Boyaree758672015-04-16 15:12:02 -0700104task preparePrebuilds() {
105 dependsOn deletePrebuildFolder
106 dependsOn prepareExtensionPrebuilds
107}
108
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700109allprojects {
110 afterEvaluate { project ->
111 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('test')}
Yigit Boyara6e45832015-03-13 15:58:53 -0700112 runAllTests.dependsOn project.tasks.findAll {task -> task.name.equals('connectedCheck')}
Yigit Boyaree758672015-04-16 15:12:02 -0700113 preparePrebuilds.dependsOn project.tasks.findAll {task -> task.name.startsWith('prebuild')}
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700114 }
115}
116
Yigit Boyara6e45832015-03-13 15:58:53 -0700117subprojects.uploadArchives.each { it.shouldRunAfter deleteRepo }
Yigit Boyarae161282015-04-21 11:02:58 -0700118subprojects.uploadArchives.each { it.shouldRunAfter deletePrebuildFolder }
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700119
Yigit Boyara6e45832015-03-13 15:58:53 -0700120buildExtensionsTask.shouldRunAfter deleteRepo
Yigit Boyar99a3d312015-03-25 12:46:05 -0700121tasks['runTestsOfMultiModuleTestApp'].dependsOn tasks['runTestsOfIndependentLibrary']
Yigit Boyara6e45832015-03-13 15:58:53 -0700122
Yigit Boyarf9e51c02015-03-12 14:30:29 -0700123
124task rebuildRepo() {
125 dependsOn deleteRepo
126 dependsOn subprojects.uploadArchives
Yigit Boyaree758672015-04-16 15:12:02 -0700127}
128
Yigit Boyarc64ae352015-04-21 14:05:41 -0700129task copySamplesToEap(type : Copy) {
130 mustRunAfter deleteEap
131 from ("$projectDir/samples") {
132 exclude "**/build"
Yigit Boyar2939c3b2015-04-23 15:03:56 -0700133 exclude "**/local.properties"
Yigit Boyarc64ae352015-04-21 14:05:41 -0700134 }
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700135 into "${dataBindingConfig.eapOutDir}/samples"
Yigit Boyarc64ae352015-04-21 14:05:41 -0700136}
137
138
139task copyMavenRepoToEap(type : Copy) {
140 mustRunAfter deleteEap
141 dependsOn rebuildRepo
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700142 from(dataBindingConfig.mavenRepoDir)
143 into "${dataBindingConfig.eapOutDir}/${dataBindingConfig.mavenRepoName}"
Yigit Boyarc64ae352015-04-21 14:05:41 -0700144}
145
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700146tasks.create(name : 'createEapdataBindingConfigFile') << {
147 def propsFile = new File("${dataBindingConfig.eapOutDir}/databinding.properties")
Yigit Boyarc64ae352015-04-21 14:05:41 -0700148 Properties props = new Properties()
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700149 props.setProperty('version', dataBindingConfig.version)
150 props.setProperty('mavenRepoName', dataBindingConfig.mavenRepoName)
Yigit Boyarc64ae352015-04-21 14:05:41 -0700151 props.store(propsFile.newWriter(), null)
152}
153
Yigit Boyarc64ae352015-04-21 14:05:41 -0700154task batchEAP() {
155 dependsOn deleteEap
156 dependsOn copyMavenRepoToEap
157 dependsOn copySamplesToEap
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700158 dependsOn createEapdataBindingConfigFile
Yigit Boyar24bec1c2015-07-09 10:51:54 -0700159}
George Mount69cbd9e2015-08-26 10:46:58 -0700160
Yigit Boyard437f7e2015-10-30 16:28:34 -0700161def findChildByTag(node, tag) {
162 return node.children().find {
163 it.name().getLocalPart().equals(tag)
164 }
165}
166
George Mount69cbd9e2015-08-26 10:46:58 -0700167def fullJar(project) {
168 def localizeTask = project.parent.tasks.findByName('localizeDependencies')
169 if (localizeTask != null) {
170 localizeTask.dependsOn project.tasks.findByName('buildLicenseNotice')
171 }
Yigit Boyar04ea1582016-03-28 15:58:45 -0700172 if (!dataBindingConfig.inReleaseBuild) {
George Mount69cbd9e2015-08-26 10:46:58 -0700173 return
174 }
175 def jarName = project.uploadArchives.repositories.mavenDeployer.pom.artifactId
176 def workingDir = "${project.buildDir}/intermediates/fullJar"
177 def fatJar = "${workingDir}/${jarName}-fat.jar"
178 def proguardJar = "${workingDir}/${jarName}-proguard.jar"
179 def jarJar = project.jar.archivePath
Yigit Boyar04ea1582016-03-28 15:58:45 -0700180 def runProguard = dataBindingConfig.runProguard
George Mount69cbd9e2015-08-26 10:46:58 -0700181
182 project.configurations {
183 jarJarArchives
184 }
185
186 project.tasks.create(name: 'fatJar', type: Jar) {
187 baseName = jarName + '-fat'
188 doFirst {
189 file(workingDir).mkdirs()
190 }
191 def deps = new HashSet<ResolvedDependency>()
192 project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
193 if (!it.moduleGroup.startsWith('com.android.tools')) {
194 deps.addAll(it.allModuleArtifacts)
195 }
196 }
Yigit Boyar499caca2015-10-30 17:09:12 +0000197 from { deps.findAll { !it.name.contains('baseLibrary') && !it.name.contains("juniversalchardet")}.collect {
George Mount69cbd9e2015-08-26 10:46:58 -0700198 it.file.isDirectory() ? it.file : project.zipTree(it.file)
199 } } {
200 exclude "META-INF/maven/**"
201 exclude "META-INF/MANIFEST.MF"
202 exclude "META-INF/LICENSE.txt"
203 exclude "META-INF/NOTICE.txt"
204 exclude "META-INF/services/javax.annotation.processing.Processor"
205 exclude "**/*.stg"
206 }
207 archiveName "${baseName}.jar"
208 destinationDir = new File(workingDir)
209 with project.jar
210 }
Yigit Boyar04ea1582016-03-28 15:58:45 -0700211 /**
212 * not used unless jarJarFile is changed to use proguarded version instead.
213 */
George Mount69cbd9e2015-08-26 10:46:58 -0700214 project.tasks.create(name: 'proguard', type: proguard.gradle.ProGuardTask) {
215 dependsOn 'fatJar'
216
217 injars fatJar
218 outjars proguardJar
219
220 configuration '../proguard.cfg'
221 }
222
223 project.tasks.create(name: 'jarJarFile') {
Yigit Boyar04ea1582016-03-28 15:58:45 -0700224 dependsOn runProguard ? 'proguard' : 'fatJar'
George Mount69cbd9e2015-08-26 10:46:58 -0700225 dependsOn project.jar
Yigit Boyar04ea1582016-03-28 15:58:45 -0700226 def inputLibrary = runProguard ? proguardJar : fatJar
George Mount69cbd9e2015-08-26 10:46:58 -0700227 def outputLibrary = jarJar
228 inputs.file(inputLibrary)
229 outputs.file(outputLibrary)
230
231 doLast {
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700232 def jarJarLibrary = new File(dataBindingConfig.externalPrebuiltsBase,
George Mount195a49a2016-04-26 16:47:27 -0700233 'tools/common/m2/repository/com/googlecode/jarjar/jarjar/1.4/jarjar-1.4.jar').
George Mount69cbd9e2015-08-26 10:46:58 -0700234 getCanonicalPath()
235 // in Ant
236 ant.taskdef(name: "jarjarIt",
237 classname: 'com.tonicsystems.jarjar.JarJarTask',
238 classpath: jarJarLibrary)
239 // start jarjar task
240 ant.jarjarIt(jarfile: outputLibrary) {
241 // input is our inputLibrary
242 zipfileset(src: inputLibrary)
243 // rule to repackage antlr to new package
Yigit Boyar15b66822016-04-07 15:16:07 -0700244 rule pattern: 'org.antlr.**', result: 'com.google.repacked.org.antlr.@1'
Yigit Boyar499caca2015-10-30 17:09:12 +0000245 rule pattern: 'org.abego.treelayout.**', result: 'com.google.repacked.treelayout.@1'
George Mount69cbd9e2015-08-26 10:46:58 -0700246 // rule to repackage commons
247 rule pattern: 'org.apache.**', result: 'com.google.repacked.apache.@1'
248 rule pattern: 'kotlin.**', result: 'com.google.repacked.kotlin.@1'
249 }
250 }
251 }
252
Yigit Boyar04ea1582016-03-28 15:58:45 -0700253 def setupUpload = { uploadTask ->
254 uploadTask.dependsOn 'jarJarFile'
255 uploadTask.repositories {
256 mavenDeployer {
257 pom.whenConfigured { pom ->
258 pom.dependencies.removeAll { dep ->
259 def isBaseLibrary = dep.groupId == 'com.android.databinding' &&
260 dep.artifactId == 'baseLibrary'
261 def isGradle = dep.groupId == 'com.android.tools.build' &&
262 dep.artifactId == 'gradle'
263 def isChardet = dep.groupId == 'com.googlecode.juniversalchardet' &&
264 dep.artifactId == 'juniversalchardet'
265 return !isBaseLibrary && !isGradle && !isChardet
266 }
George Mount69cbd9e2015-08-26 10:46:58 -0700267 }
268 }
269 }
Yigit Boyar04ea1582016-03-28 15:58:45 -0700270 uploadTask.outputs.upToDateWhen { false } // force it to re-run all the time.
Yigit Boyard437f7e2015-10-30 16:28:34 -0700271 }
Yigit Boyar04ea1582016-03-28 15:58:45 -0700272
273 if (project.publishLocal != null) {
274 setupUpload(project.publishLocal)
275 }
276 if (project.uploadArchives != null) {
277 setupUpload(project.uploadArchives)
278 }
279
Yigit Boyard437f7e2015-10-30 16:28:34 -0700280 project.bintrayUpload.dependsOn 'jarJarFile'
281 project.publishing.publications.mavenJava(MavenPublication) {
282 pom.withXml {
283 def deps = findChildByTag(asNode(), "dependencies")
284 if (deps == null) {
285 throw new IllegalArgumentException("cannot find dependencies in pom file")
286 }
287 def unwanted = deps.children().findAll {
288 def groupId = findChildByTag(it, "groupId").localText()[0]
289 def artifactId = findChildByTag(it, "artifactId").localText()[0]
290 def isBaseLibrary = groupId == 'com.android.databinding' &&
291 artifactId == 'baseLibrary'
292 def isGradle = groupId == 'com.android.tools.build' && artifactId == 'gradle'
293 def isChardet = groupId == 'com.googlecode.juniversalchardet' &&
294 artifactId == 'juniversalchardet'
295 return !isBaseLibrary && !isGradle && !isChardet
296 }
297 unwanted.each {
298 deps.remove(it)
299 }
300 }
George Mount69cbd9e2015-08-26 10:46:58 -0700301 }
302}