forked from hortonworks/cloudbreak
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
269 lines (230 loc) · 9 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import com.github.zafarkhaja.semver.Version
import org.ajoberstar.gradle.git.release.opinion.Strategies
import org.ajoberstar.gradle.git.release.opinion.Strategies.BuildMetadata
import org.ajoberstar.gradle.git.release.opinion.Strategies.PreRelease
import org.ajoberstar.gradle.git.release.semver.ChangeScope
import org.ajoberstar.gradle.git.release.semver.PartialSemVerStrategy
import org.ajoberstar.gradle.git.release.semver.SemVerStrategy
import org.ajoberstar.gradle.git.release.semver.SemVerStrategyState
import org.ajoberstar.gradle.git.release.semver.TagUtil
import org.ajoberstar.grgit.Grgit
import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.all
import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.closure
import static org.ajoberstar.gradle.git.release.semver.StrategyUtil.parseIntOrZero
final class VersionUtils {
final static Version getNearestPreReleaseVersion(Grgit grgit, SemVerStrategyState state, String label) {
List versionTags = grgit.tag.list().inject([]) { list, tag ->
Version version = TagUtil.parseAsVersion(tag)
if (version) {
if (grgit.isAncestorOf(tag, state.currentHead)) {
def reachableCommitLog = grgit.log {
range tag.commit.id, state.currentHead.id
}
def distance = reachableCommitLog.size()
def data = [version: version, distance: distance]
list << data
}
}
list
}
Map preRelease = versionTags.findAll { versionTag ->
versionTag.version.preReleaseVersion.contains(label)
}.min { a, b ->
a.distance <=> b.distance ?: (a.version <=> b.version) * -1
}
return preRelease.version
}
}
final class VersionStrategies {
private Grgit grgit
public VersionStrategies(Grgit grgit) {
this.grgit = grgit
}
final class Normal {
private Grgit grgit
public Normal(Grgit grgit) {
this.grgit = grgit
}
final PartialSemVerStrategy INCREMENT_FROM_PRE_RELEASE = closure { state ->
def nearestAny = state.nearestVersion.any
if ("dev".equals(state.stageFromProp) && ("".equals(nearestAny.preReleaseVersion) || nearestAny.preReleaseVersion.contains("rc"))) {
switch (state.scopeFromProp) {
case ChangeScope.MAJOR:
return state.copyWith(inferredNormal: nearestAny.incrementMajorVersion())
case ChangeScope.MINOR:
return state.copyWith(inferredNormal: nearestAny.incrementMinorVersion())
case ChangeScope.PATCH:
return state.copyWith(inferredNormal: nearestAny.incrementPatchVersion())
default:
return state
}
} else if ("rc".equals(state.stageFromProp)) {
if ("".equals(nearestAny.preReleaseVersion)) {
return state.copyWith(inferredNormal: nearestAny.incrementPatchVersion())
} else if (state.scopeFromProp == ChangeScope.PATCH) {
def rcVersion = VersionUtils.getNearestPreReleaseVersion(grgit, state, "rc")
return state.copyWith(inferredNormal: rcVersion.normalVersion)
} else {
return state.copyWith(inferredNormal: nearestAny.normalVersion)
}
} else {
return state.copyWith(inferredNormal: nearestAny.normalVersion)
}
}
}
final class PreRelStrategies {
private Grgit grgit
private String preReleaseLabel
public PreRelStrategies(Grgit grgit, String preReleaseLabel) {
this.grgit = grgit
this.preReleaseLabel = preReleaseLabel
}
final PartialSemVerStrategy COUNT_INCREMENTED = closure { state ->
def nearest = state.nearestVersion
def nearestPreRelease
def nearestRc = VersionUtils.getNearestPreReleaseVersion(grgit, state, "rc")
def currentPreIdents = state.inferredPreRelease ? state.inferredPreRelease.split('\\.') as List : []
if (preReleaseLabel.equals("rc") || (preReleaseLabel.equals("dev") && nearestRc.preReleaseVersion.equals("rc.1") && nearest.any.normalVersion != state.inferredNormal)){
nearestPreRelease = nearestRc
} else {
nearestPreRelease = VersionUtils.getNearestPreReleaseVersion(grgit, state, "dev")
}
if (nearestPreRelease == nearest.normal || nearestPreRelease.normalVersion != state.inferredNormal) {
currentPreIdents << '1'
} else {
def nearestPreIdents = nearestPreRelease.preReleaseVersion.split('\\.')
if (nearestPreIdents.size() <= currentPreIdents.size()) {
currentPreIdents << '1'
} else if (currentPreIdents == nearestPreIdents[0..(currentPreIdents.size() - 1)]) {
def count = parseIntOrZero(nearestPreIdents[currentPreIdents.size()])
currentPreIdents << Integer.toString(count + 1)
} else {
currentPreIdents << '1'
}
}
return state.copyWith(inferredPreRelease: currentPreIdents.join('.'))
}
}
final SemVerStrategy FEATURE_BRANCH = Strategies.DEFAULT.copyWith(
name: 'feature-branch',
stages: ['fb'] as SortedSet,
allowDirtyRepo: true,
preReleaseStrategy: all(PreRelease.STAGE_FLOAT, PreRelease.COUNT_COMMITS_SINCE_ANY, PreRelease.SHOW_UNCOMMITTED),
buildMetadataStrategy: BuildMetadata.COMMIT_ABBREVIATED_ID,
createTag: false
)
final SemVerStrategy DEV = Strategies.DEFAULT.copyWith(
name: 'development',
stages: ['dev'] as SortedSet,
allowDirtyRepo: true,
normalStrategy: new Normal(grgit).INCREMENT_FROM_PRE_RELEASE,
preReleaseStrategy: all(PreRelease.STAGE_FIXED, new PreRelStrategies(grgit, "dev").COUNT_INCREMENTED)
)
final SemVerStrategy RC = Strategies.DEFAULT.copyWith(
name: 'pre-release',
stages: ['rc'] as SortedSet,
allowDirtyRepo: true,
normalStrategy: new Normal(grgit).INCREMENT_FROM_PRE_RELEASE,
preReleaseStrategy: all(PreRelease.STAGE_FIXED, new PreRelStrategies(grgit, "rc").COUNT_INCREMENTED),
enforcePrecedence: false
)
final SemVerStrategy FINAL = Strategies.DEFAULT.copyWith(
name: 'release',
stages: ['final'] as SortedSet,
allowDirtyRepo: true,
enforcePrecedence: false
)
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.2.0"
classpath "com.smokejumperit.gradle.license:Gradle-License-Report:0.0.2"
}
}
if (project.hasProperty("release.stage")) {
apply plugin: 'org.ajoberstar.release-opinion'
release {
grgit = Grgit.open(project.file('.'))
VersionStrategies versionStrategies = new VersionStrategies(grgit)
versionStrategy versionStrategies.FINAL
versionStrategy versionStrategies.RC
versionStrategy versionStrategies.FEATURE_BRANCH
versionStrategy versionStrategies.DEV
defaultVersionStrategy = versionStrategies.FEATURE_BRANCH
tagStrategy {
prefixNameWithV = false
}
}
}
def env = project.hasProperty('env') ? project.getProperty('env') : 'local'
ext.config = new ConfigSlurper(env).parse(file("$rootDir/gradle/config/buildConfig.groovy").toURL())
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'com.sequenceiq'
configurations {
testRuntime {
exclude group: "org.springframework.cloud"
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'checkstyle'
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
deployerJars
all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
all*.exclude group: 'com.google.guava', module: 'guava-jdk5'
}
dependencies {
deployerJars("org.springframework.build.aws:org.springframework.build.aws.maven:3.0.0.RELEASE")
}
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: "s3://maven.sequenceiq.com/releases") {
authentication(userName: "$System.env.AWS_ACCESS_KEY", passphrase: "$System.env.AWS_SECRET_ACCESS_KEY")
}
snapshotRepository(url: "s3://maven.sequenceiq.com/snapshots") {
authentication(userName: "$System.env.AWS_ACCESS_KEY", passphrase: "$System.env.AWS_SECRET_ACCESS_KEY")
}
}
}
}
checkstyle {
toolVersion = "7.6"
}
checkstyleMain {
ignoreFailures = false
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
configProperties = ['config_loc': "$rootDir/config/checkstyle"]
}
checkstyleTest {
ignoreFailures = false
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
configProperties = ['config_loc': "$rootDir/config/checkstyle"]
}
dependencies {
checkstyle('com.puppycrawl.tools:checkstyle:6.11.1') {
exclude group: 'com.google.guava'
}
checkstyle("com.google.guava:guava:21.0") { force = true }
}
task allDeps(type: DependencyReportTask) {}
repositories {
mavenCentral()
maven { url "http://maven.sequenceiq.com/releases" }
maven { url "http://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/release" }
mavenLocal()
}
}