Simple to use OpenPGP API based on Bouncycastle https://pgpainless.org
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.
 
 
 

255 lines
8.4 KiB

  1. import java.text.SimpleDateFormat
  2. buildscript {
  3. repositories {
  4. maven {
  5. url "https://plugins.gradle.org/m2/"
  6. }
  7. mavenLocal()
  8. mavenCentral()
  9. }
  10. dependencies {
  11. classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2"
  12. }
  13. }
  14. plugins {
  15. id 'ru.vyarus.animalsniffer' version '1.5.0'
  16. }
  17. apply from: 'version.gradle'
  18. allprojects {
  19. apply plugin: 'java'
  20. apply plugin: 'idea'
  21. apply plugin: 'eclipse'
  22. apply plugin: 'jacoco'
  23. apply plugin: 'checkstyle'
  24. // animalsniffer
  25. apply plugin: 'ru.vyarus.animalsniffer'
  26. dependencies {
  27. signature "net.sf.androidscents.signature:android-api-level-${pgpainlessMinAndroidSdk}:2.3.1_r2@signature"
  28. }
  29. animalsniffer {
  30. sourceSets = [sourceSets.main]
  31. }
  32. // checkstyle
  33. checkstyle {
  34. toolVersion = '8.18'
  35. }
  36. group 'org.pgpainless'
  37. description = "Simple to use OpenPGP API for Java based on Bouncycastle"
  38. version = shortVersion
  39. sourceCompatibility = javaSourceCompatibility
  40. repositories {
  41. mavenCentral()
  42. }
  43. project.ext {
  44. junitVersion = 4.12
  45. androidBootClasspath = getAndroidRuntimeJar(pgpainlessMinAndroidSdk)
  46. rootConfigDir = new File(rootDir, 'config')
  47. gitCommit = getGitCommit()
  48. builtDate = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date())
  49. isContinuousIntegrationEnvironment = Boolean.parseBoolean(System.getenv('CI'))
  50. isReleaseVersion = !isSnapshot
  51. signingRequired = !(isSnapshot || isContinuousIntegrationEnvironment)
  52. sonatypeCredentialsAvailable = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')
  53. sonatypeSnapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
  54. sonatypeStagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
  55. }
  56. if (isSnapshot) {
  57. version = version + '-SNAPSHOT'
  58. }
  59. def projectDirFile = new File("$projectDir")
  60. if (!project.ext.isSnapshot && !'git describe --exact-match HEAD'.execute(null, projectDirFile).text.trim().equals(ext.shortVersion)) {
  61. throw new InvalidUserDataException('Untagged version detected! Please tag every release.')
  62. }
  63. if (!version.endsWith('-SNAPSHOT') && version != 'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim()) {
  64. throw new InvalidUserDataException(
  65. 'Tag mismatch detected, version is ' + version + ' but should be ' +
  66. 'git tag --points-at HEAD'.execute(null, projectDirFile).text.trim())
  67. }
  68. jacoco {
  69. toolVersion = "0.8.5"
  70. }
  71. jacocoTestReport {
  72. dependsOn test
  73. sourceDirectories.setFrom(project.files(sourceSets.main.allSource.srcDirs))
  74. classDirectories.setFrom(project.files(sourceSets.main.output))
  75. reports {
  76. xml.enabled true
  77. }
  78. }
  79. }
  80. subprojects {
  81. apply plugin: 'maven-publish'
  82. apply plugin: 'signing'
  83. task sourcesJar(type: Jar, dependsOn: classes) {
  84. classifier = 'sources'
  85. from sourceSets.main.allSource
  86. }
  87. task javadocJar(type: Jar, dependsOn: javadoc) {
  88. classifier = 'javadoc'
  89. from javadoc.destinationDir
  90. }
  91. task testsJar(type: Jar, dependsOn: testClasses) {
  92. classifier = 'tests'
  93. from sourceSets.test.output
  94. }
  95. publishing {
  96. publications {
  97. mavenJava(MavenPublication) {
  98. from components.java
  99. artifact sourcesJar
  100. artifact javadocJar
  101. artifact testsJar
  102. pom {
  103. name = 'PGPainless'
  104. description = 'Simple to use OpenPGP API for Java based on Bouncycastle'
  105. url = 'https://github.com/pgpainless/pgpainless'
  106. inceptionYear = '2018'
  107. scm {
  108. url = 'https://github.com/pgpainless/pgpainless'
  109. connection = 'scm:https://github.com/pgpainless/pgpainless'
  110. developerConnection = 'scm:git://github.com/pgpainless/pgpainless.git'
  111. }
  112. licenses {
  113. license {
  114. name = 'The Apache Software License, Version 2.0'
  115. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  116. distribution = 'repo'
  117. }
  118. }
  119. developers {
  120. developer {
  121. id = 'vanitasvitae'
  122. name = 'Paul Schaub'
  123. email = 'vanitasvitae@fsfe.org'
  124. }
  125. }
  126. }
  127. }
  128. }
  129. repositories {
  130. if (sonatypeCredentialsAvailable) {
  131. maven {
  132. url isSnapshot ? sonatypeSnapshotUrl : sonatypeStagingUrl
  133. credentials {
  134. username = sonatypeUsername
  135. password = sonatypePassword
  136. }
  137. }
  138. }
  139. }
  140. }
  141. signing {
  142. useGpgCmd()
  143. required { signingRequired }
  144. sign publishing.publications.mavenJava
  145. }
  146. }
  147. def getAndroidRuntimeJar(androidSdkApiLevel) {
  148. def androidHome = getAndroidHome()
  149. def androidJar = new File("$androidHome/platforms/android-$androidSdkApiLevel/android.jar")
  150. if (androidJar.isFile()) {
  151. return androidJar
  152. } else {
  153. throw new Exception("Can't find android.jar for API level $androidSdkApiLevel at $androidHome/platforms/android-$androidSdkApiLevel/android.jar. Please install corresponding SDK platform package")
  154. }
  155. }
  156. def getAndroidHome() {
  157. def androidHomeEnv = System.getenv("ANDROID_HOME")
  158. if (androidHomeEnv == null) {
  159. throw new Exception("ANDROID_HOME environment variable is not set")
  160. }
  161. def androidHome = new File(androidHomeEnv)
  162. if (!androidHome.isDirectory()) throw new Exception("Environment variable ANDROID_HOME is not pointing to a directory")
  163. return androidHome
  164. }
  165. def getGitCommit() {
  166. def projectDirFile = new File("$projectDir")
  167. def dotGit = new File("$projectDir/.git")
  168. if (!dotGit.isDirectory()) return 'non-git build'
  169. def cmd = 'git describe --always --tags --dirty=+'
  170. def proc = cmd.execute(null, projectDirFile)
  171. def gitCommit = proc.text.trim()
  172. assert !gitCommit.isEmpty()
  173. def srCmd = 'git symbolic-ref --short HEAD'
  174. def srProc = srCmd.execute(null, projectDirFile)
  175. srProc.waitForOrKill(10 * 1000)
  176. if (srProc.exitValue() == 0) {
  177. // Only add the information if the git command was
  178. // successful. There may be no symbolic reference for HEAD if
  179. // e.g. in detached mode.
  180. def symbolicReference = srProc.text.trim()
  181. assert !symbolicReference.isEmpty()
  182. gitCommit += "-$symbolicReference"
  183. }
  184. gitCommit
  185. }
  186. apply plugin: "com.github.kt3k.coveralls"
  187. coveralls {
  188. sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
  189. }
  190. task jacocoRootReport(type: JacocoReport) {
  191. dependsOn = subprojects.jacocoTestReport
  192. sourceDirectories.setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
  193. classDirectories.setFrom(files(subprojects.sourceSets.main.output))
  194. executionData.setFrom(files(subprojects.jacocoTestReport.executionData))
  195. reports {
  196. xml.enabled true
  197. xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
  198. }
  199. // We could remove the following setOnlyIf line, but then
  200. // jacocoRootReport would silently be SKIPPED if something with
  201. // the projectsWithUnitTests is wrong (e.g. a project is missing
  202. // in there).
  203. setOnlyIf { true }
  204. }
  205. task javadocAll(type: Javadoc) {
  206. def currentJavaVersion = JavaVersion.current()
  207. if (currentJavaVersion.compareTo(JavaVersion.VERSION_1_9) >= 0) {
  208. options.addStringOption("-release", "8");
  209. }
  210. source subprojects.collect {project ->
  211. project.sourceSets.main.allJava }
  212. destinationDir = new File(buildDir, 'javadoc')
  213. // Might need a classpath
  214. classpath = files(subprojects.collect {project ->
  215. project.sourceSets.main.compileClasspath})
  216. options.linkSource = true
  217. options.use = true
  218. options.links = [
  219. "https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/",
  220. ] as String[]
  221. }