Skip to content

Commit

Permalink
Allow version part substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
reda-alaoui authored and ctron committed Jan 14, 2025
1 parent 733484a commit c7f1f20
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/de/dentrassi/maven/osgi/dp/AbstractDpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -125,6 +128,9 @@ public abstract class AbstractDpMojo extends AbstractMojo {
@Parameter(property = "version")
private String version;

@Parameter(property = "versionPartsSubstitutions")
private Properties versionPartsSubstitutions;

public AbstractDpMojo() {
super();
}
Expand Down Expand Up @@ -316,7 +322,16 @@ private Version makeQualifiedVersion() {
getLog().debug("Failed to get qualified tycho version", e);
}

String version = this.project.getVersion();

String version = Optional.ofNullable(versionPartsSubstitutions)
.orElseGet(Properties::new)
.entrySet()
.stream()
.reduce(
this.project.getVersion(),
(aVersion, substitution) -> aVersion.replaceAll(Pattern.quote(String.valueOf(substitution.getKey())), String.valueOf(substitution.getValue())),
(v1, v2) -> v2);

if (version.endsWith("-SNAPSHOT")) {
version = version.replaceAll("-SNAPSHOT$", "." + this.session.getStartTime().toInstant().getEpochSecond());
}
Expand Down

0 comments on commit c7f1f20

Please sign in to comment.