Skip to content

Commit

Permalink
Use force context qualifier set to none for release build
Browse files Browse the repository at this point in the history
  • Loading branch information
jstroleny committed May 31, 2024
1 parent 8198db7 commit 8c5a976
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 8c5a976

Please sign in to comment.