You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

701 lines
20KB

  1. buildscript {
  2. repositories {
  3. jcenter()
  4. maven { url 'https://plugins.gradle.org/m2/' }
  5. maven { url 'https://dl.bintray.com/content/aalmiray/kordamp' }
  6. }
  7. dependencies {
  8. classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
  9. classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2'
  10. classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
  11. }
  12. }
  13. plugins {
  14. id 'ru.vyarus.animalsniffer' version '1.5.0'
  15. id 'net.ltgt.errorprone' version '0.8.1'
  16. }
  17. apply plugin: 'org.kordamp.gradle.markdown'
  18. apply from: 'version.gradle'
  19. allprojects {
  20. apply plugin: 'java'
  21. apply plugin: 'java-library'
  22. apply plugin: 'eclipse'
  23. apply plugin: 'idea'
  24. apply plugin: 'jacoco'
  25. apply plugin: 'net.ltgt.errorprone'
  26. ext {
  27. gitCommit = getGitCommit()
  28. javadocAllDir = new File(buildDir, 'javadoc')
  29. documentationDir = new File(buildDir, 'documentation')
  30. releasedocsDir = new File(buildDir, 'releasedocs')
  31. rootConfigDir = new File(rootDir, 'config')
  32. sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
  33. isReleaseVersion = !isSnapshot
  34. isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI'))
  35. signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment)
  36. sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
  37. sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
  38. // Returns only the date in yyyy-MM-dd format, as otherwise, with
  39. // hh:mm:ss information, the manifest files would change with every
  40. // build, causing unnecessary rebuilds.
  41. builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date())
  42. oneLineDesc = 'An Open Source XMPP (Jabber) client library'
  43. integrationTestProjects = [
  44. ':smack-integration-test',
  45. ':smack-omemo-signal-integration-test',
  46. ].collect{ project(it) }
  47. javadocAllProjects = subprojects - integrationTestProjects
  48. // A dirty hack used for Gradle's jacoco plugin, since is not
  49. // hable to handle the case when a (sub)project has no unit
  50. // tests. :-(
  51. projectsWithoutUnitTests = [
  52. ':smack-android',
  53. ':smack-android-extensions',
  54. ':smack-bosh',
  55. ':smack-compression-jzlib',
  56. ':smack-debug',
  57. ':smack-debug-slf4j',
  58. ':smack-java7',
  59. ':smack-jingle-old',
  60. ':smack-resolver-dnsjava',
  61. ':smack-resolver-javax',
  62. ':smack-resolver-minidns',
  63. ':smack-omemo-signal-integration-test',
  64. ].collect{ project(it) }
  65. projectsWithUnitTests = subprojects - projectsWithoutUnitTests
  66. androidProjects = [
  67. ':smack-tcp',
  68. ':smack-bosh',
  69. ':smack-core',
  70. ':smack-im',
  71. ':smack-resolver-minidns',
  72. ':smack-sasl-provided',
  73. ':smack-extensions',
  74. ':smack-experimental',
  75. ':smack-omemo',
  76. ':smack-omemo-signal',
  77. ':smack-openpgp',
  78. ':smack-xmlparser',
  79. ':smack-xmlparser-xpp3',
  80. ].collect{ project(it) }
  81. androidBootClasspathProjects = [
  82. ':smack-android',
  83. ':smack-android-extensions',
  84. ].collect{ project(it) }
  85. androidOptionalProjects = [
  86. ':smack-tcp',
  87. ':smack-extensions',
  88. ':smack-experimental',
  89. ':smack-bosh',
  90. ':smack-omemo',
  91. ':smack-omemo-signal',
  92. ].collect{ project(it) }
  93. gplLicensedProjects = [
  94. ':smack-omemo-signal',
  95. ':smack-omemo-signal-integration-test',
  96. ':smack-repl'
  97. ].collect{ project(it) }
  98. // When this list is empty, then move the according javadoc
  99. // tool Werror option into the global configure section.
  100. nonStrictJavadocProjects = [
  101. ':smack-bosh',
  102. ':smack-core',
  103. ':smack-experimental',
  104. ':smack-extensions',
  105. ':smack-im',
  106. ':smack-integration-test',
  107. ':smack-jingle-old',
  108. ':smack-legacy',
  109. ':smack-omemo',
  110. ':smack-tcp',
  111. ].collect{ project(it) }
  112. // Lazily evaluate the Android bootClasspath and offline
  113. // Javadoc using a closure, so that targets which do not
  114. // require it are still able to succeed without an Android
  115. // SDK.
  116. androidBootClasspath = { getAndroidRuntimeJar() }
  117. androidJavadocOffline = { getAndroidJavadocOffline() }
  118. junit4Projects = [
  119. ':smack-core',
  120. ':smack-extensions',
  121. ':smack-im',
  122. ':smack-integration-test',
  123. ':smack-omemo',
  124. ':smack-omemo-signal',
  125. ':smack-openpgp',
  126. ].collect { project(it) }
  127. junitVersion = '5.4.2'
  128. powerMockVersion = '2.0.2'
  129. commonsIoVersion = '2.6'
  130. }
  131. group = 'org.igniterealtime.smack'
  132. sourceCompatibility = JavaVersion.VERSION_1_8
  133. targetCompatibility = sourceCompatibility
  134. version = shortVersion
  135. if (isSnapshot) {
  136. version += '-SNAPSHOT'
  137. }
  138. test {
  139. useJUnitPlatform()
  140. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  141. // Enable full stacktraces of failed tests. Especially handy
  142. // for environments like Travis.
  143. testLogging {
  144. events "failed"
  145. exceptionFormat "full"
  146. }
  147. }
  148. ext.sharedManifest = manifest {
  149. attributes('Implementation-Version': version,
  150. 'Implementation-GitRevision': ext.gitCommit,
  151. // According to OSGi core 5.0 section 3.2.5 the qualifier (the fourth
  152. // version element) must begin with a dot. So we replace only the
  153. // first occurence of an dash with a dot.
  154. // For example 4.0.0-rc1 becomes 4.0.0.rc1, but
  155. // 4.0.0-SNAPSHOT-2014-05-01 becomes 4.0.0.SNAPSHOT-2014-05-01
  156. 'Bundle-Version': version.replaceFirst("-", "."),
  157. 'Built-Date': ext.builtDate,
  158. 'Built-JDK': System.getProperty('java.version'),
  159. 'Built-Gradle': gradle.gradleVersion,
  160. 'Built-By': System.getProperty('user.name')
  161. )
  162. }
  163. eclipse {
  164. classpath {
  165. downloadJavadoc = true
  166. }
  167. }
  168. repositories {
  169. mavenLocal()
  170. mavenCentral()
  171. // Add OSS Sonatype Snapshot repository
  172. maven {
  173. url 'https://oss.sonatype.org/content/repositories/snapshots'
  174. }
  175. }
  176. tasks.withType(JavaCompile) {
  177. // Some systems may not have set their platform default
  178. // converter to 'utf8', but we use unicode in our source
  179. // files. Therefore ensure that javac uses unicode
  180. options.encoding = 'UTF-8'
  181. options.compilerArgs = [
  182. '-Xlint:all',
  183. // Set '-options' because a non-java7 javac will emit a
  184. // warning if source/traget is set to 1.7 and
  185. // bootclasspath is *not* set.
  186. // TODO implement a sound heuristic to determine a java7
  187. // rt.jar on the build host. And if none is found,
  188. // fallback to using a environment variable,
  189. // e.g. JAVA7_HOME. See SMACK-651.
  190. '-Xlint:-options',
  191. '-Werror',
  192. ]
  193. options.errorprone {
  194. error(
  195. "UnusedVariable",
  196. "UnusedMethod",
  197. "MethodCanBeStatic",
  198. )
  199. errorproneArgs = [
  200. // Disable errorprone checks
  201. '-Xep:TypeParameterUnusedInFormals:OFF',
  202. // Disable errorpone StringSplitter check, as it
  203. // recommends using Splitter from Guava, which we don't
  204. // have (nor want to use in Smack).
  205. '-Xep:StringSplitter:OFF',
  206. '-Xep:JdkObsolete:OFF',
  207. // Disabled because sinttest re-uses BeforeClass from junit.
  208. // TODO: change sinttest so that it has it's own
  209. // BeforeClass and re-enable this check.
  210. '-Xep:JUnit4ClassAnnotationNonStatic:OFF',
  211. // Disabled but should be re-enabled at some point
  212. //'-Xep:InconsistentCapitalization:OFF',
  213. '-Xep:MixedMutabilityReturnType:OFF',
  214. ]
  215. }
  216. }
  217. tasks.withType(ScalaCompile) {
  218. scalaCompileOptions.additionalParameters = [
  219. '-Xfatal-warnings',
  220. '-feature',
  221. ]
  222. }
  223. jacoco {
  224. toolVersion = "0.8.3"
  225. }
  226. jacocoTestReport {
  227. dependsOn test
  228. getSourceDirectories().setFrom(project.files(sourceSets.main.allSource.srcDirs))
  229. getClassDirectories().setFrom(project.files(sourceSets.main.output))
  230. reports {
  231. xml.enabled true
  232. }
  233. }
  234. if (JavaVersion.current().isJava8Compatible()) {
  235. tasks.withType(Javadoc) {
  236. // The '-quiet' as second argument is actually a hack,
  237. // since the one paramater addStringOption doesn't seem to
  238. // work, we extra add '-quiet', which is added anyway by
  239. // gradle.
  240. options.addStringOption('Xdoclint:all', '-quiet')
  241. // Treat warnings as errors.
  242. // See also https://bugs.openjdk.java.net/browse/JDK-8200363
  243. options.addStringOption('Xwerror', '-quiet')
  244. }
  245. }
  246. tasks.withType(Javadoc) {
  247. options.charSet = "UTF-8"
  248. options.encoding = 'UTF-8'
  249. }
  250. dependencies {
  251. testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
  252. testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
  253. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
  254. errorprone 'com.google.errorprone:error_prone_core:2.3.3'
  255. errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
  256. }
  257. // Make all project's 'test' target depend on javadoc, so that
  258. // javadoc is also linted.
  259. test { dependsOn javadoc }
  260. }
  261. configure (junit4Projects) {
  262. dependencies {
  263. testImplementation "org.junit.vintage:junit-vintage-engine:$junitVersion"
  264. testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion"
  265. testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
  266. testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion"
  267. }
  268. }
  269. task copyAllJavadocDocFiles(type: Copy) {
  270. from javadocAllProjects.collect { project ->
  271. "${project.projectDir}/src/javadoc" }
  272. into javadocAllDir
  273. include '**/doc-files/*.*'
  274. }
  275. task javadocAll(type: Javadoc, dependsOn: copyAllJavadocDocFiles) {
  276. source javadocAllProjects.collect {project ->
  277. project.sourceSets.main.allJava.findAll {
  278. // Filter out symbolic links to avoid
  279. // "warning: a package-info.java file has already been seen for package"
  280. // javadoc warnings.
  281. !java.nio.file.Files.isSymbolicLink(it.toPath())
  282. }
  283. }
  284. destinationDir = javadocAllDir
  285. // Might need a classpath
  286. classpath = files(subprojects.collect {project ->
  287. project.sourceSets.main.compileClasspath})
  288. classpath += files(androidBootClasspath)
  289. options {
  290. // Add source compatiblitiy statement to work around bug in JDK 11
  291. // See
  292. // - https://bugs.openjdk.java.net/browse/JDK-8217177
  293. // - http://hg.openjdk.java.net/jdk/jdk/rev/8ce4083fc831
  294. // - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920020
  295. source = sourceCompatibility
  296. linkSource = true
  297. use = true
  298. links = [
  299. "https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/",
  300. "https://jxmpp.org/releases/$jxmppVersion/javadoc/",
  301. "https://minidns.org/releases/$miniDnsVersion/javadoc/",
  302. ] as String[]
  303. overview = "$projectDir/resources/javadoc-overview.html"
  304. }
  305. }
  306. import org.apache.tools.ant.filters.ReplaceTokens
  307. task prepareReleasedocs(type: Copy) {
  308. from 'resources/releasedocs'
  309. into releasedocsDir
  310. filter(ReplaceTokens, tokens: [version: version, releasedate: builtDate, targetCompatibility: targetCompatibility.toString()])
  311. }
  312. markdownToHtml {
  313. sourceDir = new File(projectDir, "/documentation")
  314. outputDir documentationDir
  315. configuration = [tables: true, fencedCodeBlocks: true]
  316. }
  317. task distributionZip(type: Zip, dependsOn: [javadocAll, prepareReleasedocs, markdownToHtml]) {
  318. classifier builtDate
  319. into ('javadoc') {
  320. from(javadocAllDir)
  321. }
  322. into ('releasedocs') {
  323. from(releasedocsDir)
  324. }
  325. into ('releasedocs/documentation') {
  326. from(documentationDir)
  327. }
  328. }
  329. task maybeCheckForSnapshotDependencies {
  330. // Don't check for Snapshot dependencies if this is a snapshot.
  331. onlyIf { isReleaseVersion }
  332. // Run in the execution phase, not in configuration phase, as the
  333. // 'each' forces the runtime configuration to be resovled, which
  334. // causes "Cannot change dependencies of configuration after it
  335. // has been included in dependency resolution." errors.
  336. // See https://discuss.gradle.org/t/23153
  337. doLast {
  338. allprojects { project ->
  339. project.configurations.runtime.each {
  340. if (it.toString().contains("-SNAPSHOT"))
  341. throw new Exception("Release build contains snapshot dependencies: " + it)
  342. }
  343. }
  344. }
  345. }
  346. test { dependsOn maybeCheckForSnapshotDependencies }
  347. jar {
  348. // Root project should not create empty jar artifact
  349. enabled = false
  350. }
  351. // Disable upload archives for the root project
  352. uploadArchives.enabled = false
  353. description = """\
  354. Smack ${version}
  355. ${oneLineDesc}."""
  356. evaluationDependsOnChildren()
  357. subprojects {
  358. apply plugin: 'maven-publish'
  359. apply plugin: 'signing'
  360. apply plugin: 'checkstyle'
  361. apply plugin: 'org.kordamp.gradle.clirr'
  362. checkstyle {
  363. toolVersion = '8.22'
  364. }
  365. task sourcesJar(type: Jar, dependsOn: classes) {
  366. classifier = 'sources'
  367. from sourceSets.main.allSource
  368. }
  369. task javadocJar(type: Jar, dependsOn: javadoc) {
  370. classifier = 'javadoc'
  371. from javadoc.destinationDir
  372. }
  373. task testsJar(type: Jar, dependsOn: testClasses) {
  374. classifier = 'tests'
  375. from sourceSets.test.output
  376. }
  377. artifacts {
  378. // See http://stackoverflow.com/a/21946676/194894
  379. testRuntime testsJar
  380. }
  381. publishing {
  382. publications {
  383. mavenJava(MavenPublication) {
  384. from components.java
  385. artifact sourcesJar
  386. artifact javadocJar
  387. artifact testsJar
  388. pom {
  389. name = 'Smack'
  390. packaging = 'jar'
  391. inceptionYear = '2003'
  392. url = 'http://www.igniterealtime.org/projects/smack/'
  393. description project.description
  394. issueManagement {
  395. system = 'JIRA'
  396. url = 'https://igniterealtime.org/issues/browse/SMACK'
  397. }
  398. scm {
  399. url = 'https://github.com/igniterealtime/Smack'
  400. connection = 'scm:git:https://github.com/igniterealtime/Smack.git'
  401. developerConnection = 'scm:git:https://github.com/igniterealtime/Smack.git'
  402. }
  403. developers {
  404. developer {
  405. id = 'flow'
  406. name = 'Florian Schmaus'
  407. email = 'flow@igniterealtime.org'
  408. }
  409. }
  410. }
  411. }
  412. }
  413. repositories {
  414. maven {
  415. url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl
  416. if (sonatypeCredentialsAvailable) {
  417. credentials {
  418. username = sonatypeUsername
  419. password = sonatypePassword
  420. }
  421. }
  422. }
  423. }
  424. }
  425. rootProject.distributionZip {
  426. dependsOn build
  427. from(buildDir) {
  428. include "$libsDirName/*${version}.jar"
  429. include "$libsDirName/*${version}-javadoc.jar"
  430. include "$libsDirName/*${version}-sources.jar"
  431. }
  432. }
  433. // Workaround for gpg signatory not supporting the 'required' option
  434. // See https://github.com/gradle/gradle/issues/5064#issuecomment-381924984
  435. // Note what we use 'signing.gnupg.keyName' instead of 'signing.keyId'.
  436. tasks.withType(Sign) {
  437. onlyIf {
  438. project.hasProperty('signing.gnupg.keyName')
  439. }
  440. }
  441. signing {
  442. useGpgCmd()
  443. required { signingRequired }
  444. sign publishing.publications.mavenJava
  445. }
  446. clirr {
  447. // 2018-08-14: Disabled Clirr because
  448. // - It reports an breaking change in android.jar (seems right, but there is nothing we can do about it)
  449. // - Only the first smack-* projects are correctly checked,
  450. // the other ones have the output of a clirr report from a previous project
  451. // (Look at the clirr reports).
  452. enabled false
  453. semver false
  454. }
  455. // Work around https://github.com/gradle/gradle/issues/4046
  456. javadoc.dependsOn('copyJavadocDocFiles')
  457. task copyJavadocDocFiles(type: Copy) {
  458. from('src/javadoc')
  459. into 'build/docs/javadoc'
  460. include '**/doc-files/*.*'
  461. }
  462. // If this subproject has a Makefile then make copyJavadocDocFiles
  463. // and the root project's javadocAll task dependend on
  464. // generateFiles.
  465. if (file("$projectDir/Makefile").exists()) {
  466. copyJavadocDocFiles.dependsOn('generateFiles')
  467. rootProject.copyAllJavadocDocFiles.dependsOn("${project.name}:generateFiles")
  468. task generateFiles(type: Exec) {
  469. workingDir projectDir
  470. commandLine 'make'
  471. }
  472. clean.dependsOn('cleanGeneratedFiles')
  473. rootProject.clean.dependsOn("${project.name}:cleanGeneratedFiles")
  474. task cleanGeneratedFiles(type: Exec) {
  475. workingDir projectDir
  476. commandLine 'make', 'clean'
  477. }
  478. }
  479. }
  480. configure (androidProjects + androidBootClasspathProjects) {
  481. apply plugin: 'ru.vyarus.animalsniffer'
  482. dependencies {
  483. signature "net.sf.androidscents.signature:android-api-level-${smackMinAndroidSdk}:4.4.2_r4@signature"
  484. }
  485. animalsniffer {
  486. sourceSets = [sourceSets.main]
  487. }
  488. }
  489. // There is no need to ever clirr integration test projects and the
  490. // smack-repl project.
  491. configure(integrationTestProjects + project(':smack-repl')) {
  492. clirr {
  493. enabled false
  494. }
  495. }
  496. // Disable clirr on omemo modules
  497. project(':smack-omemo').clirr.enabled = false
  498. project(':smack-omemo-signal').clirr.enabled = false
  499. subprojects*.jar {
  500. manifest {
  501. from sharedManifest
  502. }
  503. }
  504. configure(subprojects - nonStrictJavadocProjects) {
  505. tasks.withType(Javadoc) {
  506. // Abort on javadoc warnings.
  507. // See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363)
  508. // for information about the -Xwerror option.
  509. options.addStringOption('Xwerror', '-quiet')
  510. }
  511. }
  512. configure(subprojects - gplLicensedProjects) {
  513. checkstyle {
  514. configProperties.checkstyleLicenseHeader = "header"
  515. }
  516. publishing {
  517. publications {
  518. mavenJava(MavenPublication) {
  519. pom {
  520. licenses {
  521. license {
  522. name = 'The Apache Software License, Version 2.0'
  523. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  524. distribution = 'repo'
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. configure(gplLicensedProjects) {
  533. checkstyle {
  534. configProperties.checkstyleLicenseHeader = "${project.name}-gplv3-license-header"
  535. }
  536. publishing {
  537. publications {
  538. mavenJava(MavenPublication) {
  539. pom {
  540. licenses {
  541. license {
  542. name = 'GNU General Public License, version 3 or any later version'
  543. url = 'https://www.gnu.org/licenses/gpl.txt'
  544. distribution = 'repo'
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552. configure(androidBootClasspathProjects) {
  553. compileJava {
  554. options.bootstrapClasspath = files(androidBootClasspath)
  555. }
  556. javadoc {
  557. classpath += files(androidBootClasspath)
  558. }
  559. }
  560. apply plugin: "com.github.kt3k.coveralls"
  561. coveralls {
  562. sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
  563. }
  564. task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
  565. dependsOn = projectsWithUnitTests.jacocoTestReport
  566. getSourceDirectories().setFrom(files(projectsWithUnitTests.sourceSets.main.allSource.srcDirs))
  567. getClassDirectories().setFrom(files(projectsWithUnitTests.sourceSets.main.output))
  568. getExecutionData().setFrom(files(projectsWithUnitTests.jacocoTestReport.executionData))
  569. reports {
  570. xml.enabled true
  571. xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
  572. }
  573. // We could remove the following setOnlyIf line, but then
  574. // jacocoRootReport would silently be SKIPPED if something with
  575. // the projectsWithUnitTests is wrong (e.g. a project is missing
  576. // in there).
  577. setOnlyIf { true }
  578. }
  579. // Important to specify this task after the subprojects block
  580. task clirrRootReport(type: org.kordamp.gradle.clirr.ClirrReportTask) {
  581. dependsOn = subprojects.tasks.clirr
  582. reports = files((subprojects.findAll { it.clirr.enabled == true }).tasks.clirr.xmlReport)
  583. }
  584. task integrationTest {
  585. description 'Verify correct functionality of Smack by running some integration tests.'
  586. dependsOn project(':smack-integration-test').tasks.run
  587. }
  588. task omemoSignalIntTest {
  589. description 'Run integration tests of the smack-omemo module in combination with smack-omemo-signal.'
  590. dependsOn project(':smack-omemo-signal-integration-test').tasks.run
  591. }
  592. def getGitCommit() {
  593. def dotGit = new File("$projectDir/.git")
  594. if (!dotGit.isDirectory()) return 'non-git build'
  595. def projectDir = dotGit.getParentFile()
  596. def cmd = 'git describe --always --tags --dirty=+'
  597. def proc = cmd.execute(null, projectDir)
  598. proc.waitForOrKill(10 * 1000)
  599. def gitCommit = proc.text.trim()
  600. assert !gitCommit.isEmpty()
  601. def srCmd = 'git symbolic-ref --short HEAD'
  602. def srProc = srCmd.execute(null, projectDir)
  603. srProc.waitForOrKill(10 * 1000)
  604. if (srProc.exitValue() == 0) {
  605. // Only add the information if the git command was
  606. // successful. There may be no symbolic reference for HEAD if
  607. // e.g. in detached mode.
  608. def symbolicReference = srProc.text.trim()
  609. assert !symbolicReference.isEmpty()
  610. gitCommit += "-$symbolicReference"
  611. }
  612. gitCommit
  613. }
  614. def getAndroidRuntimeJar() {
  615. def androidApiLevel = ext.smackMinAndroidSdk
  616. def androidHome = getAndroidHome()
  617. def androidJar = new File("$androidHome/platforms/android-${androidApiLevel}/android.jar")
  618. if (androidJar.isFile()) {
  619. return androidJar
  620. } else {
  621. throw new Exception("Can't find android.jar for $androidApiLevel API. Please install corresponding SDK platform package")
  622. }
  623. }
  624. def getAndroidJavadocOffline() {
  625. def androidHome = getAndroidHome()
  626. return androidHome.toString() + "/docs/reference"
  627. }
  628. def getAndroidHome() {
  629. def androidHomeEnv = System.getenv("ANDROID_HOME")
  630. if (androidHomeEnv == null) {
  631. throw new Exception("ANDROID_HOME environment variable is not set")
  632. }
  633. def androidHome = new File(androidHomeEnv)
  634. if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
  635. return androidHome
  636. }