1 | import java.util.regex.Pattern
|
---|
2 |
|
---|
3 | plugins {
|
---|
4 | id "java"
|
---|
5 | id "eclipse"
|
---|
6 | id "pmd"
|
---|
7 | id "com.github.ben-manes.versions" version "0.17.0"
|
---|
8 | id "com.github.spotbugs" version "1.6.1"
|
---|
9 | id "net.ltgt.errorprone" version "0.0.13"
|
---|
10 | id "org.openstreetmap.josm" version "0.4.0"
|
---|
11 | }
|
---|
12 | def versions = [
|
---|
13 | errorprone: "2.3.1",
|
---|
14 | junit: "5.1.1",
|
---|
15 | pmd: "6.2.0",
|
---|
16 | spotbugs: "3.1.3"
|
---|
17 | ]
|
---|
18 |
|
---|
19 | // Set up ErrorProne
|
---|
20 | dependencies.errorprone "com.google.errorprone:error_prone_core:${versions.errorprone}"
|
---|
21 | tasks.withType(JavaCompile) {
|
---|
22 | options.compilerArgs += [
|
---|
23 | '-Xep:DefaultCharset:ERROR',
|
---|
24 | '-Xep:ClassCanBeStatic:ERROR',
|
---|
25 | '-Xep:StringEquality:ERROR',
|
---|
26 | '-Xep:WildcardImport:WARN',
|
---|
27 | '-Xep:MethodCanBeStatic:WARN',
|
---|
28 | '-Xep:RemoveUnusedImports:WARN',
|
---|
29 | '-Xep:PrivateConstructorForUtilityClass:WARN',
|
---|
30 | '-Xep:LambdaFunctionalInterface:WARN',
|
---|
31 | '-Xep:ConstantField:WARN'
|
---|
32 | ]
|
---|
33 | }
|
---|
34 |
|
---|
35 | pmd {
|
---|
36 | toolVersion = versions.pmd
|
---|
37 | ignoreFailures true
|
---|
38 | ruleSets = []
|
---|
39 | ruleSetConfig = resources.text.fromFile("$projectDir/config/pmd/ruleset.xml")
|
---|
40 | sourceSets = [sourceSets.main]
|
---|
41 | }
|
---|
42 |
|
---|
43 | spotbugs {
|
---|
44 | toolVersion = versions.spotbugs
|
---|
45 | ignoreFailures = true
|
---|
46 | sourceSets = [sourceSets.main]
|
---|
47 | }
|
---|
48 | tasks.withType(com.github.spotbugs.SpotBugsTask) {
|
---|
49 | reports {
|
---|
50 | xml.enabled = false
|
---|
51 | html.enabled = true
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | sourceSets {
|
---|
56 | main {
|
---|
57 | java {
|
---|
58 | srcDirs = ["src"]
|
---|
59 | }
|
---|
60 | lang {
|
---|
61 | srcDirs = ["data"]
|
---|
62 | }
|
---|
63 | resources {
|
---|
64 | srcDirs = ["$projectDir"]
|
---|
65 | include "images/**"
|
---|
66 | include "GPL-v2.0.txt"
|
---|
67 | include "README"
|
---|
68 | }
|
---|
69 | }
|
---|
70 | test {
|
---|
71 | java {
|
---|
72 | srcDirs = ["test/unit"]
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | repositories {
|
---|
78 | jcenter()
|
---|
79 | }
|
---|
80 | dependencies {
|
---|
81 | testImplementation "org.junit.jupiter:junit-jupiter-api:${versions.junit}"
|
---|
82 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${versions.junit}"
|
---|
83 | testImplementation "org.junit.vintage:junit-vintage-engine:${versions.junit}"
|
---|
84 | testImplementation "com.github.spotbugs:spotbugs-annotations:${versions.spotbugs}"
|
---|
85 | testImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
|
---|
86 | }
|
---|
87 |
|
---|
88 | version = getVersion()
|
---|
89 | josm {
|
---|
90 | josmCompileVersion = "13600"
|
---|
91 | manifest {
|
---|
92 | // Description is duplicated in build.xml, because only there it is synced to Launchpad for translation
|
---|
93 | description = "Simplifies linking OSM objects to Wikipedia articles and Wikidata items"
|
---|
94 | oldVersionDownloadLink 12900, "34109", new URL("https://svn.openstreetmap.org/applications/editors/josm/dist/wikipedia.jar?p=34113")
|
---|
95 | oldVersionDownloadLink 12878, "33635", new URL("https://svn.openstreetmap.org/applications/editors/josm/dist/wikipedia.jar?p=33636")
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * @return the current version of the repo as determined by the first of these commands that returns a valid result:
|
---|
101 | * <ul>
|
---|
102 | * <li>`git log` Search for a line with a git-svn-id in the current commit (append "-dirty" if working tree differs)</li>
|
---|
103 | * <li>`git describe` Let git describe the current commit, should only fail, if this is not a git repo</li>
|
---|
104 | * <li>`svn info` take the revision number from the SVN info command</li>
|
---|
105 | * </ul>
|
---|
106 | */
|
---|
107 | def getVersion() {
|
---|
108 | // First attempt: Check if the commit has a git-svn-id, return SVN revision
|
---|
109 | def result = getVersion("git-svn-id: .*@([1-9][0-9]*) .*", "git", "log", "-1", "--format=%b")
|
---|
110 | if (result == null) {
|
---|
111 | // Second attempt: Check if the commit can be git-described, return the description by git
|
---|
112 | result = getVersion("(.+)", "git", "describe", "--always", "--long", "--dirty")
|
---|
113 | if (result == null) {
|
---|
114 | // Third attempt: Check if we are in an SVN repo, return revision number
|
---|
115 | result = getVersion("Revision: ([1-9][0-9]*)", "svn", "info")
|
---|
116 | if (result == null) {
|
---|
117 | result = "UNKNOWN"
|
---|
118 | } else {
|
---|
119 | result = "r$result"
|
---|
120 | }
|
---|
121 | }
|
---|
122 | } else {
|
---|
123 | result = "r$result"
|
---|
124 | def dirtyProcess = new ProcessBuilder("git", "diff-index", "--quiet", "HEAD").start()
|
---|
125 | if (dirtyProcess.waitFor() != 0) {
|
---|
126 | result += "-dirty"
|
---|
127 | }
|
---|
128 | }
|
---|
129 | return result
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Runs the specified command, matches the lines of the output with the given linePattern.
|
---|
134 | * @param linePattern the linePattern to match the lines against
|
---|
135 | * @param command the command to execute
|
---|
136 | * @return if a line matches, return the first RegEx group, else return null
|
---|
137 | */
|
---|
138 | def getVersion(String linePattern, String... command) {
|
---|
139 | def process = new ProcessBuilder(command).directory(project.projectDir).start()
|
---|
140 | if (process.waitFor() != 0) {
|
---|
141 | return null
|
---|
142 | }
|
---|
143 | def pattern = Pattern.compile(linePattern)
|
---|
144 | return Arrays.stream(process.inputStream.text.split("\n"))
|
---|
145 | .map { pattern.matcher(it)}
|
---|
146 | .filter { it.matches() }
|
---|
147 | .map { it.group(1).trim() }
|
---|
148 | .findFirst()
|
---|
149 | .orElse(null)
|
---|
150 | }
|
---|