mirror of
https://github.com/SAP/jenkins-library.git
synced 2026-06-19 22:58:55 +02:00
add MTA versioning class
This commit is contained in:
@@ -2,20 +2,20 @@ package com.sap.piper.versioning
|
||||
|
||||
class MtaArtifactVersioning extends ArtifactVersioning {
|
||||
|
||||
private String baseVersion
|
||||
|
||||
protected MtaArtifactVersioning (script, configuration) {
|
||||
super(script, configuration)
|
||||
}
|
||||
|
||||
@Override
|
||||
def getVersion() {
|
||||
baseVersion = script.readYaml(file: configuration.filePath).version
|
||||
return baseVersion
|
||||
def mtaYaml = script.readYaml file: configuration.filePath
|
||||
return mtaYaml.version
|
||||
}
|
||||
|
||||
@Override
|
||||
def setVersion(version) {
|
||||
script.sh "sed -i 's/version: ${baseVersion}/version: ${newVersion}/g' ${configuration.filePath}"
|
||||
def search = "version: ${getVersion()}"
|
||||
def replacement = "version: ${version}"
|
||||
script.sh "sed -i 's/${search}/${replacement}/g' ${configuration.filePath}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.sap.piper.versioning
|
||||
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import util.BasePiperTest
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsShellCallRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
|
||||
class MtaArtifactVersioningTest extends BasePiperTest{
|
||||
|
||||
JenkinsReadYamlRule jryr = new JenkinsReadYamlRule(this, 'test/resources/versioning/MtaArtifactVersioning/')
|
||||
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(jryr)
|
||||
.around(jscr)
|
||||
|
||||
@Test
|
||||
void testVersioning() {
|
||||
MtaArtifactVersioning av = new MtaArtifactVersioning(nullScript, [filePath: 'mta.yaml'])
|
||||
assertEquals('1.2.3', av.getVersion())
|
||||
av.setVersion('1.2.3-20180101')
|
||||
assertEquals("sed -i 's/version: 1.2.3/version: 1.2.3-20180101/g' mta.yaml", jscr.shell[0])
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,12 @@ import org.junit.runners.model.Statement
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
class JenkinsReadYamlRule implements TestRule {
|
||||
|
||||
final BasePipelineTest testInstance
|
||||
final String testRoot
|
||||
|
||||
|
||||
JenkinsReadYamlRule(BasePipelineTest testInstance) {
|
||||
JenkinsReadYamlRule(BasePipelineTest testInstance, testRoot = '') {
|
||||
this.testInstance = testInstance
|
||||
this.testRoot = testRoot
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,7 +29,7 @@ class JenkinsReadYamlRule implements TestRule {
|
||||
if(m.text) {
|
||||
return new Yaml().load(m.text)
|
||||
} else if(m.file) {
|
||||
return new Yaml().load((m.file as File).text)
|
||||
return new Yaml().load(("${this.testRoot}${m.file}" as File).text)
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key 'text' is missing in map ${m}.")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
_schema-version: "2.0"
|
||||
ID: com.sap.samples.anything
|
||||
version: 1.2.3
|
||||
|
||||
modules:
|
||||
- name: any-ui
|
||||
type: html5
|
||||
path: any-ui/
|
||||
|
||||
resources:
|
||||
- name: any-resource
|
||||
Reference in New Issue
Block a user