-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
203 lines (179 loc) · 6.14 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import java.util.regex.Pattern
plugins {
id 'java'
id 'com.gradle.build-scan' version '1.15.2'
id 'maven-publish'
}
group 'com.gauck.sam'
version '1.7.1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}
publishing {
repositories {
maven {
name = "GitHub"
url = uri("https://maven.pkg.github.com/Samasaur1/Utilities")
credentials {
username = findProperty("USERNAME") ?: System.getenv("GITHUB_ACTOR")
password = findProperty("GITHUB_API_TOKEN") ?: System.getenv("GITHUB_TOKEN")
}
}
}
publications {
maven(MavenPublication) {
groupId = group
artifactId = "utilities"
from components.java
}
}
}
def incrementPatchVersion() {
println(":incrementVersion - Incrementing Patch Version...")
incrementVersion(false, false, true)
}
def incrementMinorVersion() {
println(":incrementVersion - Incrementing Minor Version...")
incrementVersion(false, true, false)
}
def incrementMajorVersion() {
println(":incrementVersion - Incrementing Major Version...")
incrementVersion(true, false, false)
}
def incrementVersion(boolean major, boolean minor, boolean patch) {
println()
if (major) {
println(":incrementVersion - Incrementing Major Version...")
} else if (minor) {
println(":incrementVersion - Incrementing Minor Version...")
} else if (patch) {
println(":incrementVersion - Incrementing Patch Version...")
}
println()
def file = file("build.gradle")
def patternVersionNumber = Pattern.compile("(?<=\\n)version '(\\d+)\\.(\\d+)\\.(\\d+)'")
def text = file.getText()
def matcherVersionNumber = patternVersionNumber.matcher(text)
matcherVersionNumber.find()
def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
def patchVersion = Integer.parseInt(matcherVersionNumber.group(3))
def newMajor = majorVersion + (major ? 1 : 0)
def newMinor = newMajor == majorVersion ? minorVersion + (minor ? 1 : 0) : 0
def newPatch = (newMajor == majorVersion && newMinor == minorVersion) ? patchVersion + (patch ? 1 : 0) : 0
def newVersion = newMajor + "." + newMinor + "." + newPatch
println(":incrementVersion - Old version: " + majorVersion + "." + minorVersion + "." + patchVersion)
println(":incrementVersion - New version: " + newVersion)
println()
def content = matcherVersionNumber.replaceAll("version '" + newVersion + "'")
file.write(content)
}
def setVersion(int major, int minor, int patch) {
println()
print(":setVersion - Setting version to ")
def file = file("build.gradle")
def patternVersionNumber = Pattern.compile("(?<=\\n)version '(\\d+)\\.(\\d+)\\.(\\d+)'")
def text = file.getText()
def matcherVersionNumber = patternVersionNumber.matcher(text)
matcherVersionNumber.find()
def majorVersion = Integer.parseInt(matcherVersionNumber.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber.group(2))
def patchVersion = Integer.parseInt(matcherVersionNumber.group(3))
def newVersion = major + "." + minor + "." + patch
println(newVersion)//see line 2 of this method
println()
println(":setVersion - Old version: " + majorVersion + "." + minorVersion + "." + patchVersion)
println(":setVersion - New version: " + newVersion)
println()
def content = matcherVersionNumber.replaceAll("version '" + newVersion + "'")
file.write(content)
}
def setVersion(String version, boolean dummy) {
println()
println(":setVersion - Setting version to " + version)
println()
def file1 = file("build.gradle")
def patternVersionNumber1 = Pattern.compile("(?<=\\n)version '(\\d+)\\.(\\d+)\\.(\\d+)'")
def text1 = file1.getText()
def matcherVersionNumber1 = patternVersionNumber1.matcher(text1)
matcherVersionNumber1.find()
def majorVersion = Integer.parseInt(matcherVersionNumber1.group(1))
def minorVersion = Integer.parseInt(matcherVersionNumber1.group(2))
def patchVersion = Integer.parseInt(matcherVersionNumber1.group(3))
def content1 = matcherVersionNumber1.replaceAll("version '" + version + "'")
file1.write(content1)
}
//noinspection GroovyAssignabilityCheck
task updateMajor() {
doFirst {
incrementMajorVersion()
}
}
//noinspection GroovyAssignabilityCheck
task updateMinor() {
doFirst {
incrementMinorVersion()
}
}
//noinspection GroovyAssignabilityCheck
task updatePatch() {
doFirst {
incrementPatchVersion()
}
}
//noinspection GroovyAssignabilityCheck
task update(dependsOn: ':version') {
doFirst {
println(":update - What type of update would you like? (major, minor, patch)")
println(":update - Enter a number 1-3 that corresponds to the above")
println(":update - Anything that is not 1-3 will not update anything")
def type = System.in.newReader().readLine()
switch (type) {
case "1":
incrementMajorVersion()
break
case "2":
incrementMinorVersion()
break
case "3":
incrementPatchVersion()
break
default:
println("Not doing anything")
}
}
}
//noinspection GroovyAssignabilityCheck
task version {
doFirst {
println(version)
}
}
//noinspection GroovyAssignabilityCheck
task testing {
doFirst {
//Whatever
}
}
//noinspection GroovyAssignabilityCheck
task resetVersion(dependsOn: ':version') {
doFirst {
println("What version would you like to reset to?")
println("Please be very careful that this is the correct format.")
println("It should be: \${MAJOR}.\${MINOR}.\${PATCH}")
setVersion(System.in.newReader().readLine(), true)
}
}
test {
testLogging {
events "passed", "skipped", "failed"
}
}