-
Notifications
You must be signed in to change notification settings - Fork 43
/
maven.groovy
202 lines (171 loc) · 7.6 KB
/
maven.groovy
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
import java.util.Properties
import org.kie.jenkins.MavenCommand
def runMaven(String goals, List options = [], Properties properties = null, String logFileName = null) {
new MavenCommand(this)
.withOptions(options)
.withProperties(properties)
.withLogFileName(logFileName)
.run(goals)
}
def runMaven(String goals, boolean skipTests, List options = [], String logFileName = null) {
new MavenCommand(this)
.withOptions(options)
.skipTests(skipTests)
.withLogFileName(logFileName)
.run(goals)
}
def runMavenWithSettings(String settingsXmlId, String goals, Properties properties, String logFileName = null) {
new MavenCommand(this, ['-fae'])
.withSettingsXmlId(settingsXmlId)
.withProperties(properties)
.withLogFileName(logFileName)
.run(goals)
}
def runMavenWithSettings(String settingsXmlId, String goals, boolean skipTests, String logFileName = null) {
new MavenCommand(this, ['-fae'])
.withSettingsXmlId(settingsXmlId)
.skipTests(skipTests)
.withLogFileName(logFileName)
.run(goals)
}
def runMavenWithSubmarineSettings(String goals, boolean skipTests, String logFileName = null) {
runMavenWithSettings(getSubmarineSettingsXmlId(), goals, skipTests, logFileName)
}
def runMavenWithSubmarineSettings(String goals, Properties properties, String logFileName = null) {
runMavenWithSettings(getSubmarineSettingsXmlId(), goals, properties, logFileName)
}
String getSubmarineSettingsXmlId() {
return '9239af2e-46e3-4ba3-8dd6-1a814fc8a56d'
}
/**
*
* @param settingsXmlId settings.xml file
* @param goals maven gals
* @param sonarCloudId Jenkins token for SonarCloud*
*/
def runMavenWithSettingsSonar(String settingsXmlId, String goals, String sonarCloudId, String logFileName = null) {
withCredentials([string(credentialsId: sonarCloudId, variable: 'TOKEN')]) {
new MavenCommand(this)
.withSettingsXmlId(settingsXmlId)
.withProperty('sonar.token', "${TOKEN}")
.withLogFileName(logFileName)
.run(goals)
}
}
def mvnVersionsSet(String newVersion, boolean allowSnapshots = false) {
mvnVersionsSet(new MavenCommand(this), newVersion, allowSnapshots)
}
def mvnVersionsSet(MavenCommand mvnCmd, String newVersion, boolean allowSnapshots = false) {
mvnCmd.clone()
.withOptions(['-N', '-e'])
.withProperty('full')
.withProperty('newVersion', newVersion)
.withProperty('allowSnapshots', allowSnapshots)
.withProperty('generateBackupPoms', false)
.run('versions:set')
}
def mvnVersionsUpdateParent(String newVersion, boolean allowSnapshots = false) {
mvnVersionsUpdateParent(new MavenCommand(this), newVersion, allowSnapshots)
}
def mvnVersionsUpdateParent(MavenCommand mvnCmd, String newVersion, boolean allowSnapshots = false) {
mvnCmd.clone()
.withOptions(['-N', '-e'])
.withProperty('full')
.withProperty('parentVersion', "[${newVersion}]")
.withProperty('allowSnapshots', allowSnapshots)
.withProperty('generateBackupPoms', false)
.run('versions:update-parent')
}
def mvnVersionsUpdateChildModules(boolean allowSnapshots = false) {
mvnVersionsUpdateChildModules(new MavenCommand(this), allowSnapshots)
}
def mvnVersionsUpdateChildModules(MavenCommand mvnCmd, boolean allowSnapshots = false) {
mvnCmd.clone()
.withOptions(['-N', '-e'])
.withProperty('full')
.withProperty('allowSnapshots', allowSnapshots)
.withProperty('generateBackupPoms', false)
.run('versions:update-child-modules')
}
def mvnVersionsUpdateParentAndChildModules(String newVersion, boolean allowSnapshots = false) {
mvnVersionsUpdateParentAndChildModules(new MavenCommand(this), newVersion, allowSnapshots)
}
def mvnVersionsUpdateParentAndChildModules(MavenCommand mvnCmd, String newVersion, boolean allowSnapshots = false) {
mvnVersionsUpdateParent(mvnCmd, newVersion, allowSnapshots)
mvnVersionsUpdateChildModules(mvnCmd, allowSnapshots)
}
def mvnGetVersionProperty(String property, String pomFile = 'pom.xml') {
mvnGetVersionProperty(new MavenCommand(this), property, pomFile)
}
def mvnGetVersionProperty(MavenCommand mvnCmd, String property, String pomFile = 'pom.xml') {
mvnCmd.clone()
.withOptions(['-q', '-f', "${pomFile}"])
.withProperty('expression', property)
.withProperty('forceStdout')
.returnOutput()
.run('help:evaluate')
.trim()
}
def mvnSetVersionProperty(String property, String newVersion) {
mvnSetVersionProperty(new MavenCommand(this), property, newVersion)
}
def mvnSetVersionProperty(MavenCommand mvnCmd, String property, String newVersion) {
mvnCmd.clone()
.withOptions(['-e'])
.withProperty('property', property)
.withProperty('newVersion', newVersion)
.withProperty('allowSnapshots', true)
.withProperty('generateBackupPoms', false)
.run('versions:set-property')
}
def mvnCompareDependencies(String remotePom, String project = '', boolean updateDependencies = false, boolean updatePropertyVersions = false) {
mvnCompareDependencies(new MavenCommand(this), remotePom, project, updateDependencies, updatePropertyVersions)
}
def mvnCompareDependencies(MavenCommand mvnCmd, String remotePom, String project = '', boolean updateDependencies = false, boolean updatePropertyVersions=false) {
def newMvnCmd = mvnCmd.clone()
.withProperty('remotePom', remotePom)
.withProperty('updatePropertyVersions', updatePropertyVersions)
.withProperty('updateDependencies', updateDependencies)
.withProperty('generateBackupPoms', false)
if(project) {
newMvnCmd.withOptions(["-pl ${project}"])
}
newMvnCmd.run('versions:compare-dependencies')
}
def uploadLocalArtifacts(String mvnUploadCredsId, String artifactDir, String repoUrl) {
def zipFileName = 'artifacts'
withCredentials([usernameColonPassword(credentialsId: mvnUploadCredsId, variable: 'kieUnpack')]) {
dir(artifactDir) {
sh "zip -r ${zipFileName} ."
sh "curl --silent --upload-file ${zipFileName}.zip -u ${kieUnpack} -v ${repoUrl}"
}
}
}
def getLatestArtifactVersionFromRepository(String repositoryUrl, String groupId, String artifactId) {
return getMavenMetadata(repositoryUrl, groupId, artifactId).versioning?.latest?.text()
}
def getLatestArtifactVersionPrefixFromRepository(String repositoryUrl, String groupId, String artifactId, String versionPrefix) {
return getMavenMetadata(repositoryUrl, groupId, artifactId).versioning?.versions?.childNodes().collect{ it.text() }.findAll{ it.startsWith(versionPrefix) }.max()
}
def getMavenMetadata(String repositoryUrl, String groupId, String artifactId) {
def groupIdArtifactId = "${groupId.replaceAll("\\.", "/")}/${artifactId}"
return new XmlSlurper().parse("${repositoryUrl}/${groupIdArtifactId}/maven-metadata.xml")
}
String getProjectPomFromBuildCmd(String buildCmd) {
def pom = "pom.xml"
def fileOption = "-f"
def projectPom = "pom.xml"
regexF = "-f[ =]"
regexFile = "--file[ =]"
if (buildCmd =~ regexF || buildCmd =~ regexFile) {
projectPom = buildCmd.substring(buildCmd.indexOf(fileOption), buildCmd.indexOf(pom) + pom.length())
projectPom = projectPom.split("=| ")[1]
}
return projectPom;
}
/*
* Clean Maven repository on the node
*/
void cleanRepository() {
sh 'rm -rf $HOME/.m2/repository'
}