From 8c5a9764e54ec6aaa116cb776e013428d880bdb8 Mon Sep 17 00:00:00 2001 From: Jakub Stroleny Date: Fri, 31 May 2024 14:22:09 +0200 Subject: [PATCH] Use force context qualifier set to none for release build --- .../org/eclipse/tycho/TychoConstants.java | 1 + .../tycho/build/TychoCiFriendlyVersions.java | 3 ++- .../CiFriendlyVersionsTest.java | 7 +++-- .../buildversion/BuildQualifierMojo.java | 27 +++++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java index a5e8dbe122..efaeb3d104 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java @@ -27,6 +27,7 @@ public interface TychoConstants { public static final String NAME_JUSTJ_JRE = "jre"; static final String ANY_QUALIFIER = "qualifier"; + static final String QUALIFIER_NONE = "none"; static final boolean USE_SMART_BUILDER = Boolean .parseBoolean(System.getProperty("tycho.build.smartbuilder", "true")); diff --git a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoCiFriendlyVersions.java b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoCiFriendlyVersions.java index c23dbaf4e7..dbb5b2581e 100644 --- a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoCiFriendlyVersions.java +++ b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoCiFriendlyVersions.java @@ -47,6 +47,7 @@ import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.eclipse.tycho.TychoConstants; @Priority(100) @Component(role = ModelVersionProcessor.class) @@ -95,7 +96,7 @@ public void overwriteModelProperties(Properties modelProperties, ModelBuildingRe } else { String forceContextQualifier = request.getSystemProperties().getProperty(PROPERTY_FORCE_QUALIFIER); if (forceContextQualifier != null) { - modelProperties.put(BUILD_QUALIFIER, "." + forceContextQualifier); + modelProperties.put(BUILD_QUALIFIER, TychoConstants.QUALIFIER_NONE.equals(forceContextQualifier) ? "" : "." + forceContextQualifier); } else { String formatString = request.getSystemProperties().getProperty(PROPERTY_BUILDQUALIFIER_FORMAT); if (formatString != null) { diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/CiFriendlyVersionsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/CiFriendlyVersionsTest.java index 056e917c40..48e306d374 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/CiFriendlyVersionsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/buildextension/CiFriendlyVersionsTest.java @@ -100,11 +100,10 @@ public void testMilestoneBuildQualifier() throws Exception { } @Test - public void testReleaseBuildQualifier() throws Exception { + public void testReleaseBuildWithForcedContextQualifier() throws Exception { Verifier verifier = getVerifier("ci-friendly/buildqualifier", false, true); - // this uses an empty/release qualifier - verifier.addCliOption("-Dqualifier="); - verifier.addCliOption("-Dtycho.buildqualifier.format="); + // this uses force context qualifier set to none + verifier.addCliOption("-DforceContextQualifier=none"); verifier.executeGoals(List.of("clean", "package")); verifier.verifyErrorFreeLog(); File file = new File(verifier.getBasedir(), "bundle/target/bundle-1.0.0.jar"); diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java index 88593fedc4..40fb0c66bb 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java @@ -173,11 +173,11 @@ private TychoProjectVersion calculateQualifiedVersion(Date timestamp) return new TychoProjectVersion(unqualifiedVersion, osgiVersion.getQualifier()); } } - String qualifier = getDesiredQualifier(timestamp); - if (!"".equals(qualifier)) { - validateQualifier(qualifier); - } + String forceContextQualifier = getForceContextQualifier(); + String qualifier = getDesiredQualifier(forceContextQualifier, timestamp); + + validateQualifier(forceContextQualifier, qualifier); String pomOSGiVersion = getUnqualifiedVersion(); String suffix = "." + qualifier; @@ -188,15 +188,23 @@ private TychoProjectVersion calculateQualifiedVersion(Date timestamp) return new TychoProjectVersion(pomOSGiVersion, qualifier); } - protected String getDesiredQualifier(Date timestamp) throws MojoExecutionException { + protected String getDesiredQualifier(String forceContextQualifier, Date timestamp) throws MojoExecutionException { String qualifier = forceContextQualifier; + if (TychoConstants.QUALIFIER_NONE.equals(qualifier)) { + qualifier = ""; + } if (qualifier == null) { - qualifier = buildPropertiesParser.parse(DefaultReactorProject.adapt(project)).getForceContextQualifier(); + qualifier = getQualifier(timestamp); } + return qualifier; + } + + private String getForceContextQualifier() { + String qualifier = forceContextQualifier; if (qualifier == null) { - qualifier = getQualifier(timestamp); + qualifier = buildPropertiesParser.parse(DefaultReactorProject.adapt(project)).getForceContextQualifier(); } return qualifier; } @@ -214,7 +222,10 @@ private Version getParsedOSGiVersion() throws MojoFailureException { } } - void validateQualifier(String qualifier) throws MojoFailureException { + void validateQualifier(String forceContextQualifier, String qualifier) throws MojoFailureException { + if (TychoConstants.QUALIFIER_NONE.equals(forceContextQualifier)) { + return; + } // parse a valid version with the given qualifier to check if the qualifier is valid try { Version.parseVersion("1.0.0." + qualifier);