blob: ba2a8af4dff076b889fa01b2f8ca4d34a065ae8f [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 Boyar24bec1c2015-07-09 10:51:54 -070046 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 }
172
Yigit Boyard437f7e2015-10-30 16:28:34 -0700173 if (!dataBindingConfig.runProguard || !dataBindingConfig.inReleaseBuild) {
George Mount69cbd9e2015-08-26 10:46:58 -0700174 return
175 }
176 def jarName = project.uploadArchives.repositories.mavenDeployer.pom.artifactId
177 def workingDir = "${project.buildDir}/intermediates/fullJar"
178 def fatJar = "${workingDir}/${jarName}-fat.jar"
179 def proguardJar = "${workingDir}/${jarName}-proguard.jar"
180 def jarJar = project.jar.archivePath
181
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 }
211 project.tasks.create(name: 'proguard', type: proguard.gradle.ProGuardTask) {
212 dependsOn 'fatJar'
213
214 injars fatJar
215 outjars proguardJar
216
217 configuration '../proguard.cfg'
218 }
219
220 project.tasks.create(name: 'jarJarFile') {
221 dependsOn 'proguard'
222 dependsOn project.jar
223 def inputLibrary = proguardJar
224 def outputLibrary = jarJar
225 inputs.file(inputLibrary)
226 outputs.file(outputLibrary)
227
228 doLast {
Yigit Boyar9784c9a2015-10-12 18:59:27 -0700229 def jarJarLibrary = new File(dataBindingConfig.externalPrebuiltsBase,
George Mount69cbd9e2015-08-26 10:46:58 -0700230 'tools/common/m2/repository/com/googlecode/jarjar/jarjar/1.3/jarjar-1.3.jar').
231 getCanonicalPath()
232 // in Ant
233 ant.taskdef(name: "jarjarIt",
234 classname: 'com.tonicsystems.jarjar.JarJarTask',
235 classpath: jarJarLibrary)
236 // start jarjar task
237 ant.jarjarIt(jarfile: outputLibrary) {
238 // input is our inputLibrary
239 zipfileset(src: inputLibrary)
240 // rule to repackage antlr to new package
241 rule pattern: 'org.antlr.**', result: 'com.google.repacked.antlr.@1'
242 rule pattern: 'com.tunnelvisionlabs.**', result: 'com.google.repacked.tunnelvision.@1'
Yigit Boyar499caca2015-10-30 17:09:12 +0000243 rule pattern: 'org.abego.treelayout.**', result: 'com.google.repacked.treelayout.@1'
George Mount69cbd9e2015-08-26 10:46:58 -0700244 // rule to repackage commons
245 rule pattern: 'org.apache.**', result: 'com.google.repacked.apache.@1'
246 rule pattern: 'kotlin.**', result: 'com.google.repacked.kotlin.@1'
247 }
248 }
249 }
250
251 project.uploadArchives {
252 dependsOn 'jarJarFile'
253 repositories {
254 mavenDeployer {
255 pom.whenConfigured { pom ->
256 pom.dependencies.removeAll { dep ->
257 def isBaseLibrary = dep.groupId == 'com.android.databinding' &&
258 dep.artifactId == 'baseLibrary'
259 def isGradle = dep.groupId == 'com.android.tools.build' &&
260 dep.artifactId == 'gradle'
Yigit Boyar499caca2015-10-30 17:09:12 +0000261 def isChardet = dep.groupId == 'com.googlecode.juniversalchardet' &&
262 dep.artifactId == 'juniversalchardet'
263 return !isBaseLibrary && !isGradle && !isChardet
George Mount69cbd9e2015-08-26 10:46:58 -0700264 }
265 }
266 }
267 }
Yigit Boyard437f7e2015-10-30 16:28:34 -0700268 outputs.upToDateWhen { false } // force it to re-run all the time.
269 }
270 project.bintrayUpload.dependsOn 'jarJarFile'
271 project.publishing.publications.mavenJava(MavenPublication) {
272 pom.withXml {
273 def deps = findChildByTag(asNode(), "dependencies")
274 if (deps == null) {
275 throw new IllegalArgumentException("cannot find dependencies in pom file")
276 }
277 def unwanted = deps.children().findAll {
278 def groupId = findChildByTag(it, "groupId").localText()[0]
279 def artifactId = findChildByTag(it, "artifactId").localText()[0]
280 def isBaseLibrary = groupId == 'com.android.databinding' &&
281 artifactId == 'baseLibrary'
282 def isGradle = groupId == 'com.android.tools.build' && artifactId == 'gradle'
283 def isChardet = groupId == 'com.googlecode.juniversalchardet' &&
284 artifactId == 'juniversalchardet'
285 return !isBaseLibrary && !isGradle && !isChardet
286 }
287 unwanted.each {
288 deps.remove(it)
289 }
290 }
George Mount69cbd9e2015-08-26 10:46:58 -0700291 }
292}