Skip to content

Commit 4d5bb0c

Browse files
authored
add parameter snapshotVersion to set the version string for snapshots (#53)
- add new parameter - adapt documentation - add integration test cases test14-snapshotname and test14-forcerelease - fix missing <goal>-tag in test14-primaryname - cache RPM version information once calculated (primarily avoids duplicate logging) - some code cleanups
1 parent 68412c9 commit 4d5bb0c

File tree

7 files changed

+239
-21
lines changed

7 files changed

+239
-21
lines changed

src/it/test14-forcerelease/pom.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>de.dentrassi.maven.rpm.test</groupId>
7+
<artifactId>test14-forcerelease</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<packaging>rpm</packaging>
10+
11+
<name>Test Package #14</name>
12+
<description>
13+
Test snapshotVersion parameter with foreceRelease
14+
</description>
15+
16+
<url>http://dentrassi.de</url>
17+
18+
<organization>
19+
<name>Jens Reimann</name>
20+
<url>http://dentrassi.de</url>
21+
</organization>
22+
23+
<licenses>
24+
<license>
25+
<name>Eclipse Public License - v 1.0</name>
26+
<distribution>repo</distribution>
27+
<url>https://www.eclipse.org/legal/epl-v10.html</url>
28+
</license>
29+
</licenses>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
34+
<skipSigning>true</skipSigning>
35+
<rpm.skipSigning>true</rpm.skipSigning>
36+
</properties>
37+
38+
<build>
39+
40+
<plugins>
41+
<plugin>
42+
<groupId>de.dentrassi.maven</groupId>
43+
<artifactId>rpm</artifactId>
44+
<extensions>true</extensions>
45+
<version>@project.version@</version>
46+
<executions>
47+
<execution>
48+
<goals>
49+
<goal>rpm</goal>
50+
</goals>
51+
<configuration>
52+
<group>Application/Misc</group>
53+
54+
<forceRelease>true</forceRelease>
55+
<snapshotVersion>1.2.3</snapshotVersion>
56+
<version>4.5.6</version>
57+
58+
<signature>
59+
<keyId>${keyId}</keyId>
60+
<keyringFile>${user.home}/.gnupg/secring.gpg</keyringFile>
61+
<passphrase>${passphrase}</passphrase>
62+
<hashAlgorithm>SHA1</hashAlgorithm>
63+
<skip>${skipSigning}</skip>
64+
</signature>
65+
66+
</configuration>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
<profiles>
74+
<profile>
75+
<id>sign</id>
76+
<activation>
77+
<activeByDefault>false</activeByDefault>
78+
</activation>
79+
<properties>
80+
<skipSigning>false</skipSigning>
81+
</properties>
82+
</profile>
83+
</profiles>
84+
85+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
myfile=null
2+
basedir.eachDirRecurse{dir ->
3+
dir.eachFileMatch(~/.*test14-forcerelease-4.5.6-1.noarch.rpm.*/) { file ->
4+
myfile=file
5+
}
6+
}
7+
8+
myfile != null

src/it/test14-primaryname/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@
4545
<version>@project.version@</version>
4646
<executions>
4747
<execution>
48+
<goals>
49+
<goal>rpm</goal>
50+
</goals>
4851
<configuration>
4952
<group>Application/Misc</group>
5053

5154
<forceRelease>false</forceRelease>
52-
<version>1.0.0</version>
55+
<version>1.2.3</version>
5356

5457
<signature>
5558
<keyId>${keyId}</keyId>

src/it/test14-snapshotname/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>de.dentrassi.maven.rpm.test</groupId>
7+
<artifactId>test14-snapshotname</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<packaging>rpm</packaging>
10+
11+
<name>Test Package #14</name>
12+
<description>
13+
Test snapshotVersion parameter
14+
</description>
15+
16+
<url>http://dentrassi.de</url>
17+
18+
<organization>
19+
<name>Jens Reimann</name>
20+
<url>http://dentrassi.de</url>
21+
</organization>
22+
23+
<licenses>
24+
<license>
25+
<name>Eclipse Public License - v 1.0</name>
26+
<distribution>repo</distribution>
27+
<url>https://www.eclipse.org/legal/epl-v10.html</url>
28+
</license>
29+
</licenses>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
34+
<skipSigning>true</skipSigning>
35+
<rpm.skipSigning>true</rpm.skipSigning>
36+
</properties>
37+
38+
<build>
39+
40+
<plugins>
41+
<plugin>
42+
<groupId>de.dentrassi.maven</groupId>
43+
<artifactId>rpm</artifactId>
44+
<extensions>true</extensions>
45+
<version>@project.version@</version>
46+
<executions>
47+
<execution>
48+
<goals><goal>rpm</goal></goals>
49+
<id>xxx</id>
50+
<configuration>
51+
<group>Application/Misc</group>
52+
53+
<forceRelease>false</forceRelease>
54+
<snapshotVersion>1.2.3</snapshotVersion>
55+
<version>4.5.6</version>
56+
57+
<signature>
58+
<keyId>${keyId}</keyId>
59+
<keyringFile>${user.home}/.gnupg/secring.gpg</keyringFile>
60+
<passphrase>${passphrase}</passphrase>
61+
<hashAlgorithm>SHA1</hashAlgorithm>
62+
<skip>${skipSigning}</skip>
63+
</signature>
64+
65+
</configuration>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
72+
<profiles>
73+
<profile>
74+
<id>sign</id>
75+
<activation>
76+
<activeByDefault>false</activeByDefault>
77+
</activation>
78+
<properties>
79+
<skipSigning>false</skipSigning>
80+
</properties>
81+
</profile>
82+
</profiles>
83+
84+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.io.File
2+
3+
myfile=null
4+
basedir.eachDirRecurse{dir ->
5+
dir.eachFileMatch(~/.*test14-snapshotname-1.2.3-0.\d+.noarch.rpm.*/) { file ->
6+
myfile=file
7+
}
8+
}
9+
10+
myfile != null

src/main/java/de/dentrassi/rpm/builder/RpmMojo.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,26 @@ public class RpmMojo extends AbstractMojo
9393
private MavenProjectHelper projectHelper;
9494

9595
/**
96-
* The version string to process
96+
* Keeps the version information after the initial calculation.
97+
*/
98+
private RpmVersion rpmVersion;
99+
100+
/**
101+
* The version string to be processed in case of a release build
102+
*
103+
* @see #snapshotVersion
97104
*/
98105
@Parameter ( defaultValue = "${project.version}" )
99106
private String version;
100107

108+
/**
109+
* The version string to be processed in case of a SNAPSHOT build
110+
*
111+
* @see #version
112+
*/
113+
@Parameter ( property = "rpm.snapshotVersion" )
114+
private String snapshotVersion;
115+
101116
/**
102117
* The RPM package name
103118
*/
@@ -532,7 +547,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
532547
* </p>
533548
*/
534549
@Parameter
535-
private final List<SimpleDependency> enhances = new LinkedList<> ();;
550+
private final List<SimpleDependency> enhances = new LinkedList<> ();
536551

537552
/**
538553
* Weak backward dependency.
@@ -543,7 +558,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
543558
* </p>
544559
*/
545560
@Parameter
546-
private final List<SimpleDependency> supplements = new LinkedList<> ();;
561+
private final List<SimpleDependency> supplements = new LinkedList<> ();
547562

548563
/**
549564
* Weak forward dependency.
@@ -554,7 +569,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
554569
* </p>
555570
*/
556571
@Parameter
557-
private final List<SimpleDependency> recommends = new LinkedList<> ();;
572+
private final List<SimpleDependency> recommends = new LinkedList<> ();
558573

559574
/**
560575
* An optional signature descriptor for GPG signing the final RPM
@@ -847,7 +862,7 @@ private String makeTargetFilename ()
847862
private Path makeTargetFile ( final Path targetDir )
848863
{
849864
final String outputFileName = makeTargetFilename ();
850-
final Path targetFile = targetDir.resolve ( outputFileName );;
865+
final Path targetFile = targetDir.resolve ( outputFileName );
851866
this.logger.debug ( "Resolved output file name - fileName: %s, fullName: %s", this.outputFileName, targetFile );
852867
return targetFile;
853868
}
@@ -903,7 +918,7 @@ private SignatureProcessor makeRsaSigner ( final Signature signature ) throws Mo
903918
@FunctionalInterface
904919
private interface DependencyAdder
905920
{
906-
public void add ( String name, String version, RpmDependencyFlags[] flags );
921+
void add ( String name, String version, RpmDependencyFlags[] flags );
907922
}
908923

909924
private void fillDependencies ( final RpmBuilder builder )
@@ -1147,7 +1162,7 @@ private void fillFromEntryCollect ( final BuilderContext ctx, final PackageEntry
11471162

11481163
RpmMojo.this.logger.debug ( "%s%s (dir)", padding, dir );
11491164
final Path relative = from.relativize ( dir );
1150-
final String targetName = makeUnix ( targetPrefix + relative.toString () );
1165+
final String targetName = makeUnix ( targetPrefix + relative );
11511166
RpmMojo.this.logger.debug ( "%s - target: %s", padding, targetName );
11521167
ctx.addDirectory ( targetName, provider );
11531168
}
@@ -1231,11 +1246,21 @@ private String makePackageName ()
12311246

12321247
private RpmVersion makeVersion ()
12331248
{
1249+
if ( rpmVersion != null )
1250+
{
1251+
return rpmVersion;
1252+
}
1253+
12341254
if ( !this.forceRelease && isSnapshotVersion () )
12351255
{
1236-
this.logger.info ( "Building with SNAPSHOT version" );
1237-
final String baseVersion = this.project.getVersion ().substring ( 0, this.project.getVersion ().length () - SNAPSHOT_SUFFIX.length () );
1238-
return new RpmVersion ( this.epoch, baseVersion, makeSnapshotReleaseString () );
1256+
if (this.snapshotVersion != null && !this.snapshotVersion.isEmpty()) {
1257+
this.logger.info("Building with SNAPSHOT version from <snapshotVersion> parameter: %s", this.snapshotVersion);
1258+
return new RpmVersion(this.epoch, this.snapshotVersion, makeSnapshotReleaseString());
1259+
}
1260+
1261+
final String baseVersion = this.project.getVersion().substring(0, this.project.getVersion().length() - SNAPSHOT_SUFFIX.length());
1262+
this.logger.info("Building with SNAPSHOT version from project: %s", baseVersion);
1263+
return new RpmVersion(this.epoch, baseVersion, makeSnapshotReleaseString());
12391264
}
12401265
return new RpmVersion ( this.epoch, this.version, this.release );
12411266
}
@@ -1344,6 +1369,7 @@ private String makeHostname ()
13441369
}
13451370
catch ( final IOException e )
13461371
{
1372+
// ignore and try one of the following ways to detect the hostname
13471373
}
13481374

13491375
hostname = System.getenv ( "COMPUTERNAME" );
@@ -1373,7 +1399,7 @@ private String makeHostname ()
13731399
}
13741400
}
13751401

1376-
private static interface StringSupplier extends Supplier<String>
1402+
private interface StringSupplier extends Supplier<String>
13771403
{
13781404
}
13791405

src/site/markdown/index.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ platform running at least Java 8.
1616
## Versioning
1717

1818
The default way this plugin creates an RPM version from a Maven versions is as follows:
19-
20-
* Non-SNAPSHOT versions are taken as is an get the release `1` assigned.
21-
19+
20+
* Non-SNAPSHOT versions are taken as is and get the release `1` assigned.
21+
2222
* The Non-SNAPSHOT release value can be overridden using the parameter `release`.
23-
23+
2424
* SNAPSHOT versions will get the `-SNAPSHOT` removed and get a generated release identifier assigned.
25-
25+
26+
* The version string used can be overridden by the `version` and `snapshVersion` parameters.
27+
2628
* The release identifier is a combination of the parameter `snapshotReleasePrefix` (defaults to `0.`)
2729
and the value of the parameter `snapshotBuildId` (defaults to the current timestamp in the format `yyyyMMddHHmm`).
28-
30+
2931
* The parameter "release" has no effect for "-SNAPSHOT" versions. Unless the
3032
parameter `forceRelease` is set to `true`, in which case the build will always fall back to
3133
the Non-SNAPSHOT behavior and use the `release` field as it is.
32-
34+
3335
For example will the RPM version for the Maven version `1.0.0` be `1.0.0-1`. And the Maven version
3436
of `1.0.0-SNAPSHOT` will result in `1.0.0-0.201604250101` (depending on the actual date and time).
3537

36-
The result of these rules are SNAPSHOT releases which is always lower than the final release.
37-
Unless you override using `forceRelease` and and `snapshotBuildId`.
38+
The result of these rules are SNAPSHOT releases which is always lower than the final release.
39+
Unless you override using `forceRelease` or `snapshotBuildId`.
3840

3941
## Contributing
4042

0 commit comments

Comments
 (0)