Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/snapshot version #53

Merged
merged 4 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/it/test14-forcerelease/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dentrassi.maven.rpm.test</groupId>
<artifactId>test14-forcerelease</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>rpm</packaging>

<name>Test Package #14</name>
<description>
Test snapshotVersion parameter with foreceRelease
</description>

<url>http://dentrassi.de</url>

<organization>
<name>Jens Reimann</name>
<url>http://dentrassi.de</url>
</organization>

<licenses>
<license>
<name>Eclipse Public License - v 1.0</name>
<distribution>repo</distribution>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<skipSigning>true</skipSigning>
<rpm.skipSigning>true</rpm.skipSigning>
</properties>

<build>

<plugins>
<plugin>
<groupId>de.dentrassi.maven</groupId>
<artifactId>rpm</artifactId>
<extensions>true</extensions>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<group>Application/Misc</group>

<forceRelease>true</forceRelease>
<snapshotVersion>1.2.3</snapshotVersion>
<version>4.5.6</version>

<signature>
<keyId>${keyId}</keyId>
<keyringFile>${user.home}/.gnupg/secring.gpg</keyringFile>
<passphrase>${passphrase}</passphrase>
<hashAlgorithm>SHA1</hashAlgorithm>
<skip>${skipSigning}</skip>
</signature>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>sign</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<skipSigning>false</skipSigning>
</properties>
</profile>
</profiles>

</project>
8 changes: 8 additions & 0 deletions src/it/test14-forcerelease/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
myfile=null
basedir.eachDirRecurse{dir ->
dir.eachFileMatch(~/.*test14-forcerelease-4.5.6-1.noarch.rpm.*/) { file ->
myfile=file
}
}

myfile != null
5 changes: 4 additions & 1 deletion src/it/test14-primaryname/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>rpm</goal>
</goals>
<configuration>
<group>Application/Misc</group>

<forceRelease>false</forceRelease>
<version>1.0.0</version>
<version>1.2.3</version>

<signature>
<keyId>${keyId}</keyId>
Expand Down
84 changes: 84 additions & 0 deletions src/it/test14-snapshotname/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.dentrassi.maven.rpm.test</groupId>
<artifactId>test14-snapshotname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>rpm</packaging>

<name>Test Package #14</name>
<description>
Test snapshotVersion parameter
</description>

<url>http://dentrassi.de</url>

<organization>
<name>Jens Reimann</name>
<url>http://dentrassi.de</url>
</organization>

<licenses>
<license>
<name>Eclipse Public License - v 1.0</name>
<distribution>repo</distribution>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<skipSigning>true</skipSigning>
<rpm.skipSigning>true</rpm.skipSigning>
</properties>

<build>

<plugins>
<plugin>
<groupId>de.dentrassi.maven</groupId>
<artifactId>rpm</artifactId>
<extensions>true</extensions>
<version>@project.version@</version>
<executions>
<execution>
<goals><goal>rpm</goal></goals>
<id>xxx</id>
<configuration>
<group>Application/Misc</group>

<forceRelease>false</forceRelease>
<snapshotVersion>1.2.3</snapshotVersion>
<version>4.5.6</version>

<signature>
<keyId>${keyId}</keyId>
<keyringFile>${user.home}/.gnupg/secring.gpg</keyringFile>
<passphrase>${passphrase}</passphrase>
<hashAlgorithm>SHA1</hashAlgorithm>
<skip>${skipSigning}</skip>
</signature>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>sign</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<skipSigning>false</skipSigning>
</properties>
</profile>
</profiles>

</project>
10 changes: 10 additions & 0 deletions src/it/test14-snapshotname/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.io.File

myfile=null
basedir.eachDirRecurse{dir ->
dir.eachFileMatch(~/.*test14-snapshotname-1.2.3-0.\d+.noarch.rpm.*/) { file ->
myfile=file
}
}

myfile != null
48 changes: 37 additions & 11 deletions src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,26 @@ public class RpmMojo extends AbstractMojo
private MavenProjectHelper projectHelper;

/**
* The version string to process
* Keeps the version information after the initial calculation.
*/
private RpmVersion rpmVersion;

/**
* The version string to be processed in case of a release build
*
* @see #snapshotVersion
*/
@Parameter ( defaultValue = "${project.version}" )
private String version;

/**
* The version string to be processed in case of a SNAPSHOT build
*
* @see #version
*/
@Parameter ( property = "rpm.snapshotVersion" )
private String snapshotVersion;

/**
* The RPM package name
*/
Expand Down Expand Up @@ -532,7 +547,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
* </p>
*/
@Parameter
private final List<SimpleDependency> enhances = new LinkedList<> ();;
private final List<SimpleDependency> enhances = new LinkedList<> ();

/**
* Weak backward dependency.
Expand All @@ -543,7 +558,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
* </p>
*/
@Parameter
private final List<SimpleDependency> supplements = new LinkedList<> ();;
private final List<SimpleDependency> supplements = new LinkedList<> ();

/**
* Weak forward dependency.
Expand All @@ -554,7 +569,7 @@ public void setGenerateDefaultSourcePackage ( final boolean generateDefaultSourc
* </p>
*/
@Parameter
private final List<SimpleDependency> recommends = new LinkedList<> ();;
private final List<SimpleDependency> recommends = new LinkedList<> ();

/**
* An optional signature descriptor for GPG signing the final RPM
Expand Down Expand Up @@ -847,7 +862,7 @@ private String makeTargetFilename ()
private Path makeTargetFile ( final Path targetDir )
{
final String outputFileName = makeTargetFilename ();
final Path targetFile = targetDir.resolve ( outputFileName );;
final Path targetFile = targetDir.resolve ( outputFileName );
this.logger.debug ( "Resolved output file name - fileName: %s, fullName: %s", this.outputFileName, targetFile );
return targetFile;
}
Expand Down Expand Up @@ -903,7 +918,7 @@ private SignatureProcessor makeRsaSigner ( final Signature signature ) throws Mo
@FunctionalInterface
private interface DependencyAdder
{
public void add ( String name, String version, RpmDependencyFlags[] flags );
void add ( String name, String version, RpmDependencyFlags[] flags );
}

private void fillDependencies ( final RpmBuilder builder )
Expand Down Expand Up @@ -1147,7 +1162,7 @@ private void fillFromEntryCollect ( final BuilderContext ctx, final PackageEntry

RpmMojo.this.logger.debug ( "%s%s (dir)", padding, dir );
final Path relative = from.relativize ( dir );
final String targetName = makeUnix ( targetPrefix + relative.toString () );
final String targetName = makeUnix ( targetPrefix + relative );
RpmMojo.this.logger.debug ( "%s - target: %s", padding, targetName );
ctx.addDirectory ( targetName, provider );
}
Expand Down Expand Up @@ -1231,11 +1246,21 @@ private String makePackageName ()

private RpmVersion makeVersion ()
{
if ( rpmVersion != null )
{
return rpmVersion;
}

if ( !this.forceRelease && isSnapshotVersion () )
{
this.logger.info ( "Building with SNAPSHOT version" );
final String baseVersion = this.project.getVersion ().substring ( 0, this.project.getVersion ().length () - SNAPSHOT_SUFFIX.length () );
return new RpmVersion ( this.epoch, baseVersion, makeSnapshotReleaseString () );
if (this.snapshotVersion != null && !this.snapshotVersion.isEmpty()) {
this.logger.info("Building with SNAPSHOT version from <snapshotVersion> parameter: %s", this.snapshotVersion);
return new RpmVersion(this.epoch, this.snapshotVersion, makeSnapshotReleaseString());
}

final String baseVersion = this.project.getVersion().substring(0, this.project.getVersion().length() - SNAPSHOT_SUFFIX.length());
this.logger.info("Building with SNAPSHOT version from project: %s", baseVersion);
return new RpmVersion(this.epoch, baseVersion, makeSnapshotReleaseString());
}
return new RpmVersion ( this.epoch, this.version, this.release );
}
Expand Down Expand Up @@ -1344,6 +1369,7 @@ private String makeHostname ()
}
catch ( final IOException e )
{
// ignore and try one of the following ways to detect the hostname
}

hostname = System.getenv ( "COMPUTERNAME" );
Expand Down Expand Up @@ -1373,7 +1399,7 @@ private String makeHostname ()
}
}

private static interface StringSupplier extends Supplier<String>
private interface StringSupplier extends Supplier<String>
{
}

Expand Down
20 changes: 11 additions & 9 deletions src/site/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ platform running at least Java 8.
## Versioning

The default way this plugin creates an RPM version from a Maven versions is as follows:
* Non-SNAPSHOT versions are taken as is an get the release `1` assigned.

* Non-SNAPSHOT versions are taken as is and get the release `1` assigned.

* The Non-SNAPSHOT release value can be overridden using the parameter `release`.

* SNAPSHOT versions will get the `-SNAPSHOT` removed and get a generated release identifier assigned.


* The version string used can be overridden by the `version` and `snapshVersion` parameters.

* The release identifier is a combination of the parameter `snapshotReleasePrefix` (defaults to `0.`)
and the value of the parameter `snapshotBuildId` (defaults to the current timestamp in the format `yyyyMMddHHmm`).

* The parameter "release" has no effect for "-SNAPSHOT" versions. Unless the
parameter `forceRelease` is set to `true`, in which case the build will always fall back to
the Non-SNAPSHOT behavior and use the `release` field as it is.

For example will the RPM version for the Maven version `1.0.0` be `1.0.0-1`. And the Maven version
of `1.0.0-SNAPSHOT` will result in `1.0.0-0.201604250101` (depending on the actual date and time).

The result of these rules are SNAPSHOT releases which is always lower than the final release.
Unless you override using `forceRelease` and and `snapshotBuildId`.
The result of these rules are SNAPSHOT releases which is always lower than the final release.
Unless you override using `forceRelease` or `snapshotBuildId`.

## Contributing

Expand Down