Changeset 34176 in osm
- Timestamp:
- 2018-04-28T22:27:20+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/build.gradle
r34174 r34176 1 import java.util.regex.Pattern 2 1 3 plugins { 2 4 id "java" … … 84 86 } 85 87 86 version = "34161"88 version = getVersion() 87 89 josm { 88 90 josmCompileVersion = "13600" … … 94 96 } 95 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 }
Note:
See TracChangeset
for help on using the changeset viewer.