From 3b420369d72e02a61e79b3ceda243853087d51d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Lehmann-M=C3=B6rz?= Date: Sat, 28 Oct 2023 16:08:22 +0200 Subject: [PATCH] fix #2877 (#2878) Retain .qualifier/-SNAPSHOT on version bump fix #2877 --- CONTRIBUTING.md | 2 +- .../org/eclipse/tycho/TychoConstants.java | 5 +++ .../AbstractArtifactBasedProject.java | 6 ++-- ...rcesBundleDependencyMetadataGenerator.java | 12 +++---- .../tycho/packaging/IUXmlTransformer.java | 8 +++-- .../versions/VersionBumpBuildListener.java | 5 +++ .../tycho/versions/engine/Versions.java | 32 +++++++++---------- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e19783466..b272d07866 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ and the minimal reproducer project to Tycho's [issue tracker](https://github.com ### Prerequisites -Java 11 and Maven 3.6.3, or newer. +Java 17 and Maven 3.9.0, or newer. If your Internet connection uses a proxy, make sure that you have the proxy configured in your [Maven settings.xml](https://maven.apache.org/settings.html). 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 0eee2a5b22..76fa56b154 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java @@ -10,6 +10,7 @@ * Contributors: * Sonatype Inc. - initial API and implementation * Christoph Läubrich - Issue #658 - Tycho strips p2 artifact properties (eg PGP, maven info...) + * Marco Lehmann-Mörz - issue #2877 - tycho-versions-plugin:bump-versions does not honor SNAPSHOT suffix *******************************************************************************/ package org.eclipse.tycho; @@ -133,4 +134,8 @@ public interface TychoConstants { public String ROOTFILE_EXTENSION = "zip"; String HEADER_TESTCASES = "Test-Cases"; + + String SUFFIX_QUALIFIER = ".qualifier"; + + String SUFFIX_SNAPSHOT = "-SNAPSHOT"; } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactBasedProject.java b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactBasedProject.java index 9f7ef58478..6a9281b8b7 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactBasedProject.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/AbstractArtifactBasedProject.java @@ -14,11 +14,12 @@ import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.TargetEnvironment; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.core.ArtifactDependencyWalker; public abstract class AbstractArtifactBasedProject extends AbstractTychoProject { // this is stricter than Artifact.SNAPSHOT_VERSION - public static final String SNAPSHOT_VERSION = "-SNAPSHOT"; + public static final String SNAPSHOT_VERSION = TychoConstants.SUFFIX_SNAPSHOT; // requires resolved target platform @Override @@ -36,7 +37,8 @@ protected abstract ArtifactDependencyWalker newDependencyWalker(ReactorProject p protected String getOsgiVersion(ReactorProject project) { String version = project.getVersion(); if (version.endsWith(SNAPSHOT_VERSION)) { - version = version.substring(0, version.length() - SNAPSHOT_VERSION.length()) + ".qualifier"; + version = version.substring(0, version.length() - SNAPSHOT_VERSION.length()) + + TychoConstants.SUFFIX_QUALIFIER; } return version; } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/SourcesBundleDependencyMetadataGenerator.java b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/SourcesBundleDependencyMetadataGenerator.java index d4d48906b9..c4a9defda0 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/SourcesBundleDependencyMetadataGenerator.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2resolver/SourcesBundleDependencyMetadataGenerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 Sonatype Inc. and others. + * Copyright (c) 2008, 2013 Sonatype Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Sonatype Inc. - initial API and implementation + * Marco Lehmann-Mörz - issue #2877 - tycho-versions-plugin:bump-versions does not honor SNAPSHOT suffix *******************************************************************************/ package org.eclipse.tycho.p2resolver; @@ -30,6 +31,7 @@ import org.eclipse.tycho.IArtifactFacade; import org.eclipse.tycho.OptionalResolutionAction; import org.eclipse.tycho.TargetEnvironment; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.core.publisher.TychoMavenPropertiesAdvice; import org.eclipse.tycho.core.shared.MavenContext; import org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator; @@ -42,9 +44,6 @@ @Component(role = DependencyMetadataGenerator.class, hint = DependencyMetadataGenerator.SOURCE_BUNDLE) public class SourcesBundleDependencyMetadataGenerator extends AbstractMetadataGenerator implements DependencyMetadataGenerator { - private static final String SUFFIX_QUALIFIER = ".qualifier"; - - private static final String SUFFIX_SNAPSHOT = "-SNAPSHOT"; @Requirement private MavenContext mavenContext; @@ -110,8 +109,9 @@ private static String toCanonicalVersion(String version) { if (version == null) { return null; } - if (version.endsWith(SUFFIX_SNAPSHOT)) { - return version.substring(0, version.length() - SUFFIX_SNAPSHOT.length()) + SUFFIX_QUALIFIER; + if (version.endsWith(TychoConstants.SUFFIX_SNAPSHOT)) { + return version.substring(0, version.length() - TychoConstants.SUFFIX_SNAPSHOT.length()) + + TychoConstants.SUFFIX_QUALIFIER; } return version; } diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IUXmlTransformer.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IUXmlTransformer.java index 52de8d3c45..46592c190d 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IUXmlTransformer.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/IUXmlTransformer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Rapicorp, Inc. and others. + * Copyright (c) 2015, 2023 Rapicorp, Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * * Contributors: * Rapicorp, Inc. - initial API and implementation + * Marco Lehmann-Mörz - issue #2877 - tycho-versions-plugin:bump-versions does not honor SNAPSHOT suffix *******************************************************************************/ package org.eclipse.tycho.packaging; @@ -23,6 +24,7 @@ import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.IllegalArtifactReferenceException; import org.eclipse.tycho.TargetPlatform; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.model.IU; import de.pdark.decentxml.Element; @@ -72,7 +74,7 @@ public void replaceQualifierInCapabilities(List providedCapabilities, S private boolean hasQualifier(String v) { if (v == null) return false; - return v.endsWith(".qualifier"); + return v.endsWith(TychoConstants.SUFFIX_QUALIFIER); } public void replaceQualifierInRequirements(IU iu, TargetPlatform targetPlatform) throws MojoFailureException { @@ -81,7 +83,7 @@ public void replaceQualifierInRequirements(IU iu, TargetPlatform targetPlatform) return; for (Element req : requirements) { String range = req.getAttributeValue(IU.RANGE); - if (range != null && range.endsWith(".qualifier") + if (range != null && range.endsWith(TychoConstants.SUFFIX_QUALIFIER) && IU.P2_IU_NAMESPACE.equals(req.getAttributeValue(IU.NAMESPACE))) { ArtifactKey artifact = resolveRequirementReference(targetPlatform, req.getAttributeValue(IU.NAME), range, req.toString()); diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/VersionBumpBuildListener.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/VersionBumpBuildListener.java index 01ebfe7baa..54a0d17d57 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/VersionBumpBuildListener.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/VersionBumpBuildListener.java @@ -22,6 +22,7 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.build.BuildListener; import org.eclipse.tycho.core.exceptions.VersionBumpRequiredException; import org.eclipse.tycho.helper.ProjectHelper; @@ -78,6 +79,10 @@ public void buildEnded(MavenSession session) { String newVersion = suggestedVersion.map(String::valueOf) .orElseGet(() -> Versions.incrementVersion(currentVersion, VersionBumpMojo.getIncrement(session, project, projectHelper))); + boolean isSnapshot = currentVersion.endsWith(TychoConstants.SUFFIX_SNAPSHOT); + if (isSnapshot) { + newVersion += TychoConstants.SUFFIX_SNAPSHOT; + } logger.info(project.getId() + " requires a version bump from " + currentVersion + " => " + newVersion); engine.setProjects(metadataReader.getProjects()); diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/Versions.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/Versions.java index 9fd6d01405..3b6077611e 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/Versions.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/engine/Versions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Sonatype Inc. and others. + * Copyright (c) 2011, 2023 Sonatype Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -9,39 +9,38 @@ * * Contributors: * Sonatype Inc. - initial API and implementation + * Marco Lehmann-Mörz - issue #2877 - tycho-versions-plugin:bump-versions does not honor SNAPSHOT suffix *******************************************************************************/ package org.eclipse.tycho.versions.engine; import java.io.File; +import org.eclipse.tycho.TychoConstants; import org.osgi.framework.Version; public class Versions { - private static final String SUFFIX_QUALIFIER = ".qualifier"; - - private static final String SUFFIX_SNAPSHOT = "-SNAPSHOT"; - public static String toCanonicalVersion(String version) { if (version == null) { return null; } - if (version.endsWith(SUFFIX_SNAPSHOT)) { - return version.substring(0, version.length() - SUFFIX_SNAPSHOT.length()) + SUFFIX_QUALIFIER; + if (version.endsWith(TychoConstants.SUFFIX_SNAPSHOT)) { + return version.substring(0, version.length() - TychoConstants.SUFFIX_SNAPSHOT.length()) + + TychoConstants.SUFFIX_QUALIFIER; } return version; } public static String incrementVersion(String version, int increment) { - boolean isSnapshot = version.endsWith(SUFFIX_SNAPSHOT); + boolean isSnapshot = version.endsWith(TychoConstants.SUFFIX_SNAPSHOT); if (isSnapshot) { - version = version.substring(0, version.length() - SUFFIX_SNAPSHOT.length()); + version = version.substring(0, version.length() - TychoConstants.SUFFIX_SNAPSHOT.length()); } Version osgi = new Version(version); String incremented = osgi.getMajor() + "." + osgi.getMinor() + "." + (osgi.getMicro() + increment); if (isSnapshot) { - incremented += SUFFIX_SNAPSHOT; + incremented += TychoConstants.SUFFIX_SNAPSHOT; } return incremented; } @@ -54,11 +53,11 @@ public static String toBaseVersion(String version) { return null; } - if (version.endsWith(SUFFIX_SNAPSHOT)) { - return version.substring(0, version.length() - SUFFIX_SNAPSHOT.length()); + if (version.endsWith(TychoConstants.SUFFIX_SNAPSHOT)) { + return version.substring(0, version.length() - TychoConstants.SUFFIX_SNAPSHOT.length()); } - if (version.endsWith(SUFFIX_QUALIFIER)) { - return version.substring(0, version.length() - SUFFIX_QUALIFIER.length()); + if (version.endsWith(TychoConstants.SUFFIX_QUALIFIER)) { + return version.substring(0, version.length() - TychoConstants.SUFFIX_QUALIFIER.length()); } return version; @@ -74,8 +73,9 @@ public static String toMavenVersion(String version) { return null; } - if (version.endsWith(SUFFIX_QUALIFIER)) { - return version.substring(0, version.length() - SUFFIX_QUALIFIER.length()) + SUFFIX_SNAPSHOT; + if (version.endsWith(TychoConstants.SUFFIX_QUALIFIER)) { + return version.substring(0, version.length() - TychoConstants.SUFFIX_QUALIFIER.length()) + + TychoConstants.SUFFIX_SNAPSHOT; } return version;