diff --git a/src/it/test21-modifyversion/pom.xml b/src/it/test21-modifyversion/pom.xml
new file mode 100644
index 0000000..98ab06c
--- /dev/null
+++ b/src/it/test21-modifyversion/pom.xml
@@ -0,0 +1,86 @@
+
+
+ 4.0.0
+
+ de.dentrassi.maven.rpm.test
+ test21-modifyversion
+ 1.0.1.redhat-00001
+ jar
+
+ Test Package #21
+ Test modify version generation
+
+ https://dentrassi.de
+
+
+ Jens Reimann
+ http://dentrassi.de
+
+
+
+
+ Eclipse Public License - v 1.0
+ repo
+ https://www.eclipse.org/legal/epl-v10.html
+
+
+
+
+ UTF-8
+ UTF-8
+ true
+
+
+
+
+
+
+ de.dentrassi.maven
+ rpm
+ @project.version@
+
+
+
+ rpm
+
+
+ false
+ Application/Misc
+
+ true
+
+
+ -
+ _
+
+
+
+
+ ${keyId}
+ ${user.home}/.gnupg/secring.gpg
+ ${passphrase}
+ SHA1
+ ${skipSigning}
+
+
+
+
+
+
+
+
+
+
+
+ sign
+
+ false
+
+
+ false
+
+
+
+
+
\ No newline at end of file
diff --git a/src/it/test21-modifyversion/verify.groovy b/src/it/test21-modifyversion/verify.groovy
new file mode 100644
index 0000000..c8201c6
--- /dev/null
+++ b/src/it/test21-modifyversion/verify.groovy
@@ -0,0 +1,8 @@
+
+def log () {
+ Process proc = ['rpm', '-q', '--queryformat', '[%{VERSION} %{SOURCERPM}]', basedir.toString() + "/target/test21-modifyversion-1.0.1.redhat-00001-1.noarch.rpm"].execute();
+ return proc.in.getText().trim();
+}
+
+String text = log()
+return text.contains("1.0.1.redhat_00001 test21-modifyversion-1.0.1.redhat_00001-1.src.rpm")
diff --git a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
index d01c492..0f5780d 100644
--- a/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
+++ b/src/main/java/de/dentrassi/rpm/builder/RpmMojo.java
@@ -309,7 +309,7 @@ public void setGenerateDefaultSourcePackage(final boolean generateDefaultSourceP
/**
* Whether the plugin should try to evaluate to hostname
*
- * If set to {@code false}, then he build hostname {@code localhost} will be
+ * If set to {@code false}, then the build hostname {@code localhost} will be
* used instead of the actual hostname
*
*/
@@ -793,6 +793,25 @@ public void setSignatureConfiguration(final String signatureConfiguration) {
@Parameter(defaultValue = "SHA-256", property = "rpm.fileDigestAlgorithm")
String fileDigestAlgorithm;
+
+ /**
+ * Whether the plugin should modify internal RPM version for compliance.
+ *
+ * If set to {@code true}, then any replacements specified in the {@code versionReplacements}
+ * property will be applied.
+ */
+ @Parameter(property = "rpm.modifyVersion", defaultValue = "false")
+ boolean modifyVersion = false;
+
+ /**
+ * A list of potential version substitutions to perform on the RPM internal version. This will
+ * not affect the filename; just the version inside the generated RPM. This allows a user
+ * to customise the version if the Maven version does not match RPM requirements e.g. it contains
+ * a '-' (which would need to be replaced by an '_'). The 'search' string is a regex.
+ */
+ @Parameter(property = "rpm.versionReplacements")
+ List versionReplacements = new ArrayList<>();
+
private Instant outputTimestampInstant;
@Component(role = SignatureConfiguration.class)
@@ -845,7 +864,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
this.logger.debug("Default ruleset: %s", this.defaultRuleset);
final String packageName = makePackageName();
- final RpmVersion version = makeVersion();
+ final RpmVersion version = makeVersion(modifyVersion);
this.logger.info("RPM base information - name: %s, version: %s, arch: %s", packageName, version, this.architecture);
@@ -951,9 +970,9 @@ private String makeTargetFilename() {
if (outputFileName == null || outputFileName.isEmpty()) {
if (this.naming.getDefaultFormat() == Naming.DefaultFormat.LEGACY) {
- outputFileName = RpmFileNameProvider.LEGACY_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(), this.architecture);
+ outputFileName = RpmFileNameProvider.LEGACY_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(false), this.architecture);
} else {
- outputFileName = RpmFileNameProvider.DEFAULT_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(), this.architecture);
+ outputFileName = RpmFileNameProvider.DEFAULT_FILENAME_PROVIDER.getRpmFileName(makePackageName(), makeVersion(false), this.architecture);
}
this.logger.debug("Using generated file name - %s", outputFileName, outputFileName);
}
@@ -1312,7 +1331,7 @@ private String makePackageName() {
}
}
- private RpmVersion makeVersion() {
+ private RpmVersion makeVersion(boolean modifyVersion) {
if (!this.forceRelease && isSnapshotVersion()) {
if (this.snapshotVersion != null && !this.snapshotVersion.isEmpty()) {
this.logger.info("Building with SNAPSHOT version from parameter: %s", this.snapshotVersion);
@@ -1323,7 +1342,14 @@ private RpmVersion makeVersion() {
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);
+ String version = this.version;
+ if (modifyVersion) {
+ for (VersionSubstitution versionSubstitution : versionReplacements) {
+ logger.info("For version %s looking for %s to replace with %s", version, versionSubstitution.search, versionSubstitution.replace);
+ version = version.replaceAll(versionSubstitution.search, versionSubstitution.replace);
+ }
+ }
+ return new RpmVersion(this.epoch, version, this.release);
}
private boolean isSnapshotVersion() {
@@ -1369,7 +1395,7 @@ protected void fillPackageInformation(final RpmBuilder builder) {
}
private String generateDefaultSourcePackageName() {
- return RpmLead.toLeadName(makePackageName(), makeVersion()) + ".src.rpm";
+ return RpmLead.toLeadName(makePackageName(), makeVersion(modifyVersion)) + ".src.rpm";
}
private String makeVendor() {
@@ -1452,13 +1478,16 @@ private static void ifSet(final Consumer setter, final String value, fin
}
}
-
public static class Changelog extends RpmInformation.Changelog {
-
private String date;
public String getDate() {
return date;
}
}
+
+ public static class VersionSubstitution {
+ private String search;
+ private String replace;
+ }
}
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index cd8002d..60d7521 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -38,6 +38,22 @@ of `1.0.0-SNAPSHOT` will result in `1.0.0-0.201604250101` (depending on the actu
The result of these rules are SNAPSHOT releases which is always lower than the final release.
Unless you override using `forceRelease` or `snapshotBuildId`.
+### Version Modification
+
+Beyond the above version specification, there is a facility to modify the version _within_ the RPM. This does not affect the file name of the produced RPM. This is useful if the Maven version is non-compliant with RPM versioning. For example if the Maven version is 1.1.rebuild-00001, the `-` could be replaced by `_` (See https://fedoraproject.org/wiki/PackagingDrafts/TildeVersioning#Basic_versioning_rules)
+
+~~~xml
+ true
+
+
+ -
+ _
+
+
+~~~
+
+Multiple version replacements may be specified and they will be applied in sequence.
+
## Contributing
All contributions are welcome!