Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Retain .qualifier/-SNAPSHOT on version bump

fix eclipse-tycho#2877
  • Loading branch information
mlehmannm authored Oct 28, 2023
1 parent 9fbe413 commit 3b42036
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
5 changes: 5 additions & 0 deletions tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -72,7 +74,7 @@ public void replaceQualifierInCapabilities(List<Element> 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 {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 3b42036

Please sign in to comment.