Skip to content

Commit

Permalink
feat: Add Maven CI Friendly Version Goal
Browse files Browse the repository at this point in the history
  • Loading branch information
lfvjimisola authored and jimisola committed May 28, 2024
1 parent 9b03590 commit aeae472
Show file tree
Hide file tree
Showing 43 changed files with 871 additions and 0 deletions.
8 changes: 8 additions & 0 deletions versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@
<artifactId>commons-lang3</artifactId>
</dependency>

<!-- other -->

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.13.3.202401111512-r</version>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag
invoker.buildResult = failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-0-commits-0-tags</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /Caused by: org.apache.maven.plugin.MojoExecutionException: SCM repo has no head\/commits\./
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "SCM repo should have no head/commits"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-1-commit-0-tags</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Setting property 'revision' to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '0.0.1-1-SNAPSHOT'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-X ${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-4-commits-1-vtag</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')
exec('git tag 1.1.1')
exec('git tag')

testFile << 'content2'
exec('git add test.txt')
exec('git commit -m commit_no2')

testFile << 'content3'
exec('git add test.txt')
exec('git commit -m commit_no3')

testFile << 'content4'
exec('git add test.txt')
exec('git commit -m commit_no4')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Setting property 'revision' to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '1.1.2-4-SNAPSHOT'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag -DuseVersion=9.9.9-9
invoker.environmentVariables.VERSIONS_MAVEN_PLUGIN_SCM_USE_VERSION = 5.5.5-5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-env-use-version</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}


def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Setting property 'revision' to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '5.5.5-5'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-latest-commit</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')
exec('git tag v1.1.1')
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// check that property was set

def mavenLogFile = new File(basedir, 'build.log')
assert mavenLogFile.exists() : "Maven log file does not exist"

// Read the log file
def logContent = mavenLogFile.text

// Define a pattern to match the version output
def versionPattern = /\[INFO\] Setting property 'revision' to: (.+)/
def matcher = (logContent =~ versionPattern)
assert matcher.find() : "Version information not found in log file"

// Extract the version from the matched group
def actualVersion = matcher[0][1]

def expectedVersion = '1.1.1'

assert actualVersion == expectedVersion : "Expected version '${expectedVersion}', but found '${actualVersion}'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set-version-from-scm-tag -DappendSnapshot=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-ci-friendly-versions-param-append-snapshot</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>ranges-update-report</name>
<url>http://localhost/</url>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
// smoke test if we have a needed tools
def gitVersion = "git --version".execute()
gitVersion.consumeProcessOutput(System.out, System.out)
gitVersion.waitFor()
return gitVersion.exitValue() == 0
} catch (Exception e) {
// some error occurs - we skip a test
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void exec(String command) {
def proc = command.execute(null, basedir)
proc.consumeProcessOutput(System.out, System.out)
proc.waitFor()
assert proc.exitValue() == 0 : "Command '${command}' returned status: ${proc.exitValue()}"
}

def testFile = new File(basedir, 'test.txt')
testFile << 'content'

exec('git init')
exec('git add test.txt')
exec('git commit -m initial-commit')
Loading

0 comments on commit aeae472

Please sign in to comment.