Skip to content

Commit

Permalink
fix: Finally
Browse files Browse the repository at this point in the history
  • Loading branch information
jimisola committed May 28, 2024
1 parent 90ac453 commit be1810a
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ assert mavenLogFile.exists() : "Maven log file does not exist"
def logContent = mavenLogFile.text

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

Expand Down
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 -DpropertyName=version_from_scm
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-dynamic-versioning-scm-tag-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,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\] Property 'version_from_scm' set 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
Expand Up @@ -58,6 +58,11 @@ public class DynamicVersioningSCMPlugin extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The name of the property that will contain the resolved version.
*/
@Parameter(property = "propertyName", defaultValue = "revision")
protected String propertyName;
/**
* Whether the SNAPSHOT qualifier shall be apppended or not.
*/
Expand Down Expand Up @@ -101,9 +106,9 @@ public void execute() throws MojoExecutionException {
vi = getVersionFromSCM();
}

String version = vi.toString();
project.setVersion(version);
getLog().info("<project.version> set to: " + project.getVersion());
project.getProperties().setProperty(propertyName, vi.toString());
getLog().info("Property '" + propertyName + "' set to: "
+ project.getProperties().getProperty(propertyName));
}

/**
Expand Down

0 comments on commit be1810a

Please sign in to comment.