Skip to content

Commit

Permalink
Migrate from equinox.resolver.VersionRange to osgi.VersionRange
Browse files Browse the repository at this point in the history
Part of #1069
  • Loading branch information
HannesWell committed Jul 21, 2024
1 parent 195449a commit 129a107
Show file tree
Hide file tree
Showing 33 changed files with 213 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -70,12 +69,12 @@ public void setUp() throws Exception {
fBaseline = TestSuiteHelper.createTestingBaseline(TEST_PLUGINS);
assertNotNull("the testing baseline should exist", fBaseline); //$NON-NLS-1$
List<IRequiredComponentDescription> reqs = new ArrayList<>();
reqs.add(new RequiredComponentDescription("org.eclipse.core.runtime", new BundleVersionRange(Util.EMPTY_STRING))); //$NON-NLS-1$
reqs.add(new RequiredComponentDescription("org.eclipse.core.runtime", new BundleVersionRange("0.0.0"))); //$NON-NLS-1$ //$NON-NLS-2$
validateComponent(fBaseline, COMPONENT_A, "A Plug-in", _1_0_0, "J2SE-1.5", reqs); //$NON-NLS-1$ //$NON-NLS-2$

reqs = new ArrayList<>();
reqs.add(new RequiredComponentDescription("org.eclipse.core.runtime", new BundleVersionRange(Util.EMPTY_STRING))); //$NON-NLS-1$
reqs.add(new RequiredComponentDescription(COMPONENT_A, new BundleVersionRange(Util.EMPTY_STRING)));
reqs.add(new RequiredComponentDescription("org.eclipse.core.runtime", new BundleVersionRange("0.0.0"))); //$NON-NLS-1$ //$NON-NLS-2$
reqs.add(new RequiredComponentDescription(COMPONENT_A, new BundleVersionRange("0.0.0"))); //$NON-NLS-1$
validateComponent(fBaseline, COMPONENT_B, "B Plug-in", _1_0_0, "J2SE-1.4", reqs); //$NON-NLS-1$ //$NON-NLS-2$
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*******************************************************************************/
package org.eclipse.pde.api.tools.internal;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.api.tools.internal.provisional.IVersionRange;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

/**
* Implementation of a required component description based on OSGi bundles.
Expand Down Expand Up @@ -48,22 +48,23 @@ public BundleVersionRange(VersionRange range) {

@Override
public String getMaximumVersion() {
return fRange.getMaximum().toString();
Version right = fRange.getRight();
return right != null ? right.toString() : null;
}

@Override
public String getMinimumVersion() {
return fRange.getMinimum().toString();
return fRange.getLeft().toString();
}

@Override
public boolean isIncludeMaximum() {
return fRange.getIncludeMaximum();
return fRange.getRightType() == VersionRange.RIGHT_CLOSED;
}

@Override
public boolean isIncludeMinimum() {
return fRange.getIncludeMinimum();
return fRange.getLeftType() == VersionRange.LEFT_CLOSED;
}

@Override
Expand All @@ -86,7 +87,7 @@ public String toString() {

@Override
public boolean isIncluded(String version) {
return fRange.isIncluded(new Version(version));
return fRange.includes(new Version(version));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.api.tools.internal.ApiBaselineManager;
import org.eclipse.pde.api.tools.internal.ApiFilterStore;
Expand Down Expand Up @@ -116,6 +115,7 @@
import org.eclipse.pde.api.tools.internal.util.Util;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

/**
* Base implementation of the analyzer used in the {@link ApiAnalysisBuilder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface IVersionRange {
/**
* Returns the maximum version in this range.
*
* @return maximum version
* @return maximum version, {@code null} if no explicit upper bound is exists.
*/
public String getMaximumVersion();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.internal.p2.publisher.eclipse.Messages;
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.build.internal.tests.ant.AntUtils;
import org.eclipse.pde.build.tests.BuildConfiguration;
import org.eclipse.pde.build.tests.PDETestCase;
Expand All @@ -76,6 +75,7 @@
import org.junit.Ignore;
import org.junit.Test;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

public class ScriptGenerationTests extends PDETestCase {

Expand Down Expand Up @@ -704,45 +704,45 @@ public void testBug247091() throws Exception {
@Test
public void testBug247091_2() throws Exception {
VersionRange range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0");
assertTrue(range.getIncludeMinimum());
assertTrue(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_CLOSED, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0"));
assertEquals(range.getRight(), new Version("1.0.0"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.qualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0"));
assertEquals(range.getRight(), new Version("1.0.1"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.zqualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0.z"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0.z"));
assertEquals(range.getRight(), new Version("1.0.1"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.abcqualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0.abc"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0.abc"));
assertEquals(range.getRight(), new Version("1.0.0.abd"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.abzqualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0.abz"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0.abz"));
assertEquals(range.getRight(), new Version("1.0.0.ac"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.abzzqualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0.abzz"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0.abzz"));
assertEquals(range.getRight(), new Version("1.0.0.ac"));

range = org.eclipse.pde.internal.build.Utils.createVersionRange("1.0.0.abzz_qualifier");
assertTrue(range.getIncludeMinimum());
assertFalse(range.getIncludeMaximum());
assertEquals(range.getMinimum(), new Version("1.0.0.abzz_"));
assertEquals(VersionRange.LEFT_CLOSED, range.getLeftType());
assertEquals(VersionRange.RIGHT_OPEN, range.getRightType());
assertEquals(range.getLeft(), new Version("1.0.0.abzz_"));
assertEquals(range.getRight(), new Version("1.0.0.abzza"));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.internal.build.ant.FileSet;
import org.eclipse.pde.internal.build.builder.BuildDirector;
import org.eclipse.pde.internal.build.builder.ModelBuildScriptGenerator;
import org.eclipse.pde.internal.build.site.BuildTimeFeature;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

public class P2ConfigScriptGenerator extends AssembleConfigScriptGenerator {
private static final VersionRange OLD_EXECUTABLE_RANGE = new VersionRange(Version.emptyVersion, true, new Version(3, 3, 200, "v20090306-1900"), false); //$NON-NLS-1$
private static final VersionRange OLD_EXECUTABLE_RANGE = new VersionRange(VersionRange.LEFT_CLOSED, Version.emptyVersion, new Version(3, 3, 200, "v20090306-1900"), VersionRange.RIGHT_OPEN); //$NON-NLS-1$
private AssemblyInformation assemblyInformation = null;
private boolean assembling = false;
private boolean versionsList = false;
Expand Down Expand Up @@ -505,9 +505,9 @@ private boolean isOldExecutableFeature(BuildTimeFeature feature) {
if (!feature.getId().equals(FEATURE_EQUINOX_EXECUTABLE))
return false;

if (feature.isBinary() || !OLD_EXECUTABLE_RANGE.isIncluded(new Version(feature.getVersion())))
if (feature.isBinary() || !OLD_EXECUTABLE_RANGE.includes(new Version(feature.getVersion()))) {
return false;

}
Properties properties = getFeatureBuildProperties(feature);
return properties != null && Boolean.valueOf((String) properties.get(PROPERTY_CUSTOM)).booleanValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
******************************************************************************/
package org.eclipse.pde.internal.build;

import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

public class P2InfUtils {
public static final int INSTRUCTION_INSTALL = 0;
Expand All @@ -33,7 +33,7 @@ public static void printBundleCU(StringBuffer buffer, int i, String name, Versio
}

public static void printBundleCU(StringBuffer buffer, int i, String name, String cuVersion, Version hostVersion, String filter, String[] instructions) {
VersionRange hostRange = new VersionRange(hostVersion, true, hostVersion, true);
VersionRange hostRange = Utils.createExactVersionRange(hostVersion);
//cuVersion may not be a proper OSGi version at this point (ie 1.0.0.$qualifier$)
String cuRange = "[" + cuVersion + "," + cuVersion + "]"; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
String prefix = "units." + i + '.'; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;
import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.pde.internal.build.site.BuildTimeFeature;
import org.eclipse.pde.internal.build.site.P2Utils;
import org.eclipse.pde.internal.build.site.PDEState;
import org.osgi.framework.Filter;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

public class ProductGenerator extends AbstractScriptGenerator {
private static final String SIMPLE_CONFIGURATOR_CONFIG_URL = "org.eclipse.equinox.simpleconfigurator.configUrl"; //$NON-NLS-1$
Expand Down Expand Up @@ -219,7 +219,7 @@ private void generateP2InfCUs(StringBuffer buffer, int startIndex, boolean cus,
productVersionString = productVersion.getMajor() + "." + productVersion.getMinor() + "." + productVersion.getMicro() + ".$qualifier$"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
productRangeString = "[" + productVersionString + "," + productVersionString + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
productRangeString = new VersionRange(new Version(productVersionString), true, new Version(productVersionString), true).toString();
productRangeString = Utils.createExactVersionRange(new Version(productVersionString)).toString();
}

if (cus) {
Expand Down Expand Up @@ -251,7 +251,7 @@ private void generateP2InfCUs(StringBuffer buffer, int startIndex, boolean cus,

BundleDescription launcher = assembly.getPlugin(BUNDLE_EQUINOX_LAUNCHER, null);
if (launcher != null && launchers) {
VersionRange launcherRange = new VersionRange(launcher.getVersion(), true, launcher.getVersion(), true);
VersionRange launcherRange = Utils.createExactVersionRange(launcher.getVersion());

// include the launcher jar
P2InfUtils.printRequires(buffer, null, index++, P2InfUtils.NAMESPACE_IU, BUNDLE_EQUINOX_LAUNCHER, launcherRange, launcher.getPlatformFilter(), true);
Expand All @@ -272,7 +272,7 @@ private void generateP2InfCUs(StringBuffer buffer, int startIndex, boolean cus,
//in case of no version on the product, the branding defaults to the version of the launcher provider
if (executableFeature != null && productVersionString.equals(Version.emptyVersion.toString())) {
String brandedVersion = executableFeature.getVersion();
brandedRange = new VersionRange(new Version(brandedVersion), true, new Version(brandedVersion), true).toString();
brandedRange = Utils.createExactVersionRange(new Version(brandedVersion)).toString();
}

List<Config> configs = getConfigInfos();
Expand All @@ -284,7 +284,7 @@ private void generateP2InfCUs(StringBuffer buffer, int startIndex, boolean cus,
fragmentName += '.' + config.getArch();
BundleDescription fragment = assembly.getPlugin(fragmentName, null);
if (fragment != null) {
VersionRange fragmentRange = new VersionRange(fragment.getVersion(), true, fragment.getVersion(), true);
VersionRange fragmentRange = Utils.createExactVersionRange(fragment.getVersion());
//include the launcher fragment
P2InfUtils.printRequires(buffer, null, index++, P2InfUtils.NAMESPACE_IU, fragmentName, fragmentRange, fragment.getPlatformFilter(), true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.internal.build.ant.AntScript;
import org.eclipse.pde.internal.build.site.BuildTimeFeature;
import org.eclipse.pde.internal.build.site.BuildTimeSite;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

/**
* General utility class.
Expand Down Expand Up @@ -110,60 +110,77 @@ public static char base64Character(int number) {
return BASE_64_ENCODING.charAt(number);
}

public static final VersionRange EMPTY_RANGE = new VersionRange("0.0.0"); //$NON-NLS-1$

public static VersionRange createVersionRange(String versionId) {
VersionRange range = null;
if (versionId == null || versionId.length() == 0 || GENERIC_VERSION_NUMBER.equals(versionId))
range = VersionRange.emptyRange;
range = EMPTY_RANGE;
else {
int qualifierIdx = versionId.indexOf(IBuildPropertiesConstants.PROPERTY_QUALIFIER);
if (qualifierIdx != -1) {
String newVersion = versionId.substring(0, qualifierIdx);
if (newVersion.endsWith(".")) //$NON-NLS-1$
if (newVersion.endsWith(".")) { //$NON-NLS-1$
newVersion = newVersion.substring(0, newVersion.length() - 1);

}
Version lower = new Version(newVersion);
Version upper = null;
String newQualifier = incrementQualifier(lower.getQualifier());
if (newQualifier == null)
if (newQualifier == null) {
upper = new Version(lower.getMajor(), lower.getMinor(), lower.getMicro() + 1);
else
} else {
upper = new Version(lower.getMajor(), lower.getMinor(), lower.getMicro(), newQualifier);
range = new VersionRange(lower, true, upper, false);
}
range = new VersionRange(VersionRange.LEFT_CLOSED, lower, upper, VersionRange.RIGHT_OPEN);
} else {
range = new VersionRange(new Version(versionId), true, new Version(versionId), true);
range = new VersionRange(VersionRange.LEFT_CLOSED, new Version(versionId), new Version(versionId), VersionRange.RIGHT_CLOSED);
}
}
return range;
}

public static VersionRange createVersionRange(String lowerBound, boolean includeLowerBound, String upperBound, boolean includeUpperBound) {
char leftType = includeLowerBound ? VersionRange.LEFT_CLOSED : VersionRange.LEFT_OPEN;
char rightType = includeUpperBound ? VersionRange.RIGHT_CLOSED : VersionRange.RIGHT_OPEN;
return new VersionRange(leftType, Version.parseVersion(lowerBound), Version.parseVersion(upperBound), rightType);
}

public static VersionRange createExactVersionRange(Version version) {
return new VersionRange(VersionRange.LEFT_CLOSED, version, version, VersionRange.RIGHT_CLOSED);
}

public static VersionRange parseVersionRange(String version) {
return version != null && !version.isEmpty() ? new VersionRange(version) : EMPTY_RANGE;
}

public static VersionRange createVersionRange(FeatureEntry entry) {
String versionSpec = entry.getVersion();
if (versionSpec == null)
return VersionRange.emptyRange;

if (versionSpec == null) {
return EMPTY_RANGE;
}
Version version = new Version(versionSpec);
if (version.equals(Version.emptyVersion))
return VersionRange.emptyRange;

if (version.equals(Version.emptyVersion)) {
return EMPTY_RANGE;
}
String match = entry.getMatch();
if (!entry.isRequires() || match == null) {
return createVersionRange(versionSpec);
}

if (match.equals("perfect")) //$NON-NLS-1$
return new VersionRange(version, true, version, true);
return new VersionRange(VersionRange.LEFT_CLOSED, version, version, VersionRange.RIGHT_CLOSED);
if (match.equals("equivalent")) { //$NON-NLS-1$
Version upper = new Version(version.getMajor(), version.getMinor() + 1, 0);
return new VersionRange(version, true, upper, false);
return new VersionRange(VersionRange.LEFT_CLOSED, version, upper, VersionRange.RIGHT_OPEN);
}
if (match.equals("compatible")) { //$NON-NLS-1$
Version upper = new Version(version.getMajor() + 1, 0, 0);
return new VersionRange(version, true, upper, false);
return new VersionRange(VersionRange.LEFT_CLOSED, version, upper, VersionRange.RIGHT_OPEN);
}
if (match.equals("greaterOrEqual")) //$NON-NLS-1$
return new VersionRange(version, true, new VersionRange(null).getMaximum(), true);
return new VersionRange(VersionRange.LEFT_CLOSED, version, null, VersionRange.RIGHT_CLOSED);

return VersionRange.emptyRange;
return EMPTY_RANGE;
}

private static String incrementQualifier(String qualifier) {
Expand Down
Loading

0 comments on commit 129a107

Please sign in to comment.