Skip to content

Commit

Permalink
add option to resolve project.version in depdencendies section
Browse files Browse the repository at this point in the history
This closes #129
  • Loading branch information
michael-wirth authored and McFoggy committed Dec 7, 2020
1 parent 4fb439f commit e0a9acd
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ _[Old](https://jgitver.github.io/maven/configuration/) xml schemas are kept for
- `-Djgitver.skip=true` : skips totally jgitver usage
- `-Djgitver.config=FILE` : overrides default config file and uses FILE instead
- `-Djgitver.use-version=VERSION` : execute jgitver but finally uses VERSION as the project version
- `-Djgitver.jgitver.resolve-project-version=true` : replaces the ${project.version} also in properties, dependencies, dependencyManagement, plugins and pluginManagement sections

#### Working on a detached HEAD

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prebuild.log
build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>

<artifactId>multi-pure-extension-it-module</artifactId>
<packaging>jar</packaging>

<parent>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it</artifactId>
<version>0</version>
</parent>

<description>A simple IT verifying the basic use case.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<finalName>my-module-${project.version}</finalName>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.brouillard.oss.demo;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
82 changes: 82 additions & 0 deletions src/it/multi-pure-extension-resolve-version-variable-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it</artifactId>
<version>0</version>
<packaging>pom</packaging>

<description>Resolve project.version variable in properties, dependencies and plugins.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jgitver.resolve-project-version>true</jgitver.resolve-project-version>
<calculated-project.version>${project.version}</calculated-project.version>
</properties>

<modules>
<module>module</module>
<module>war</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it-module</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it-module</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it-module</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def log = new PrintWriter( new File(basedir, "prebuild.log").newWriter("UTF-8"), true )
log.println( "Prebuild started at: " + new Date() + " in: " + basedir )

[
"git --version",
"git init",
"git config user.name \"nobody\"",
"git config user.email \"nobody@nowhere.com\"",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add .",
"git commit --message=initial_commit",
"git tag -a 1.0.0 --message=release_1.0.0",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add -u",
"git commit --message=added_B_data",
"git log --graph --oneline"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0
}

log.println( "Prebuild completed at: " + new Date() )
log.close()
return true
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def baseDir = new File("$basedir")

File actions = new File(baseDir, "verify-actions.log")
actions.write 'Actions started at: ' + new Date() + '\n'

actions << 'rm -rf .git'.execute(null, baseDir).text

// Check the version was used by the plugin execution
def foundLines = new File("$basedir", "build.log").readLines().findAll { it =~ /fr.brouillard.oss.it.resolve-project-version::multi-pure-extension-it::0 -> 1.0.1-SNAPSHOT/ }
assert 0 < foundLines.size

// And check that the produced artifact was installed with the good version
File installedPomFile = new File("$basedir" + "/../../local-repo/fr/brouillard/oss/it/resolve-project-version/multi-pure-extension-it/1.0.1-SNAPSHOT/", "multi-pure-extension-it-1.0.1-SNAPSHOT.pom")
assert installedPomFile.isFile()
assert 4 == installedPomFile.readLines().findAll { it =~ /<version>1.0.1-SNAPSHOT<\/version>/ }.size()
assert 1 == installedPomFile.readLines().findAll { it =~ /<calculated-project.version>1.0.1-SNAPSHOT<\/calculated-project.version>/ }.size()

File installedJarPomFile = new File("$basedir" + "/../../local-repo/fr/brouillard/oss/it/resolve-project-version/multi-pure-extension-it-module/1.0.1-SNAPSHOT/", "multi-pure-extension-it-module-1.0.1-SNAPSHOT.pom")
assert installedJarPomFile.isFile()
assert 2 == installedJarPomFile.readLines().findAll { it =~ /<version>1.0.1-SNAPSHOT<\/version>/ }.size()

File installedJarFile = new File("$basedir" + "/../../local-repo/fr/brouillard/oss/it/resolve-project-version/multi-pure-extension-it-module/1.0.1-SNAPSHOT/", "multi-pure-extension-it-module-1.0.1-SNAPSHOT.jar")
assert installedJarFile.isFile()

File installedWarPomFile = new File("$basedir" + "/../../local-repo/fr/brouillard/oss/it/resolve-project-version/multi-pure-extension-it-app/1.0.1-SNAPSHOT/", "multi-pure-extension-it-app-1.0.1-SNAPSHOT.pom")
assert installedWarPomFile.isFile()
assert 3 == installedWarPomFile.readLines().findAll { it =~ /<version>1.0.1-SNAPSHOT<\/version>/ }.size()

File installedWarFile = new File("$basedir" + "/../../local-repo/fr/brouillard/oss/it/resolve-project-version/multi-pure-extension-it-app/1.0.1-SNAPSHOT/", "multi-pure-extension-it-app-1.0.1-SNAPSHOT.war")
assert installedWarFile.isFile()
return true
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>

<artifactId>multi-pure-extension-it-app</artifactId>
<packaging>war</packaging>

<parent>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it</artifactId>
<version>0</version>
</parent>

<description>A simple IT verifying the basic use case.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>

<finalName>webapp</finalName>
</build>

<dependencies>
<dependency>
<groupId>fr.brouillard.oss.it.resolve-project-version</groupId>
<artifactId>multi-pure-extension-it-module</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit e0a9acd

Please sign in to comment.