private static VersionRange[] createVersionRanges(String[] ranges) { if (ranges == null) return null; VersionRange[] result = new VersionRange[ranges.length]; for (int i = 0; i < result.length; i++) result[i] = new VersionRange(ranges[i]); return result; }
private boolean matchesVersion(String expectedVersionRangeExpression, Version actualVersion) { if (expectedVersionRangeExpression != null) { try { VersionRange versionRange = new VersionRange(expectedVersionRangeExpression); if (!versionRange.isIncluded(actualVersion)) { return false; } } catch (IllegalArgumentException e) { // ignore } } return true; }
private void writeVersionRange(VersionRange versionRange, DataOutputStream out) throws IOException { if (versionRange == null || versionRange.equals(VersionRange.emptyRange)) { out.writeByte(StateReader.NULL); return; } out.writeByte(StateReader.OBJECT); writeVersion(versionRange.getMinimum(), out); out.writeBoolean(versionRange.getIncludeMinimum()); writeVersion(versionRange.getMaximum(), out); out.writeBoolean(versionRange.getIncludeMaximum()); }
private Version getHighestVersionMatch(Version version, VersionRange[] ranges) { Version highest = Version.emptyVersion; for (int i = 0; i < ranges.length; i++) { if (ranges[i].isIncluded(version) && highest.compareTo(ranges[i].getMinimum()) < 0) highest = ranges[i].getMinimum(); } return highest; }
public String getPluginVersion() { String version = getAttribute(Constants.FRAGMENT_HOST, Constants.BUNDLE_VERSION_ATTRIBUTE); try { VersionRange versionRange = new VersionRange(version); if (versionRange != null) { return versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : version; } } catch (NumberFormatException e) { } return version; }
private static VersionRange fromOSGiVersionRange(org.eclipse.osgi.service.resolver.VersionRange range) { if (range.equals(org.eclipse.osgi.service.resolver.VersionRange.emptyRange)) return VersionRange.emptyRange; return new VersionRange(fromOSGiVersion(range.getMinimum()), range.getIncludeMinimum(), fromOSGiVersion(range.getRight()), range.getIncludeMaximum()); } }
private String getVersionRange(String reqVersion, String matchRule) { if (reqVersion == null) return null; Version minVersion = Version.parseVersion(reqVersion); String versionRange; if (matchRule != null) { if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_PERFECT)) { versionRange = new VersionRange(minVersion, true, minVersion, true).toString(); } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_EQUIVALENT)) { versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor(), minVersion.getMinor() + 1, 0, ""), false).toString(); //$NON-NLS-1$ } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_COMPATIBLE)) { versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$ } else if (matchRule.equalsIgnoreCase(IModel.PLUGIN_REQUIRES_MATCH_GREATER_OR_EQUAL)) { // just return the reqVersion here without any version range versionRange = reqVersion; } else { versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$ } } else { versionRange = new VersionRange(minVersion, true, new Version(minVersion.getMajor() + 1, 0, 0, ""), false).toString(); //$NON-NLS-1$ } StringBuffer result = new StringBuffer(); result.append(';').append(Constants.BUNDLE_VERSION_ATTRIBUTE).append('='); result.append('\"').append(versionRange).append('\"'); return result.toString(); } }
public static VersionRange fromOSGiVersionRange(org.eclipse.osgi.service.resolver.VersionRange range) { if (range.equals(org.eclipse.osgi.service.resolver.VersionRange.emptyRange)) { return VersionRange.emptyRange; } Version min = fromOSGiVersion(range.getLeft()); boolean includeMin = range.getIncludeMinimum(); Version max = fromOSGiVersion(range.getRight()); // TODO The OSGi open ended range does not include the max value, where as the p2 does // Fix the p2 range to not include maximum as well (how will this affect the projector)?. boolean includeMax = Version.MAX_VERSION.equals(max) ? true : range.getIncludeMaximum(); return new VersionRange(min, includeMin, max, includeMax); } }
public void setVersion(String version) { try { if (version != null && !version.equals("")) { //$NON-NLS-1$ fVersionRange = new VersionRange(version); Version max = fVersionRange.getMaximum(); if (max.getMajor() != Integer.MAX_VALUE && fVersionRange.getMinimum().compareTo(fVersionRange.getMaximum()) < 0) fIsRanged = true; } } catch (IllegalArgumentException e) { // illegal version string passed fVersionRange = new VersionRange("[1.0.0,1.0.0]"); //$NON-NLS-1$ } }
@Override public boolean isIncluded(String version) { return fRange.isIncluded(new Version(version)); }
public static int getMatchRule(VersionRange versionRange) { if (versionRange == null || versionRange.getMinimum() == null) return IMatchRules.NONE; Version minimum = versionRange.getLeft(); Version maximum = versionRange.getRight() == null ? maxVersion : versionRange.getRight(); if (maximum.compareTo(maxVersion) >= 0) return IMatchRules.GREATER_OR_EQUAL; else if (minimum.equals(maximum)) return IMatchRules.PERFECT; else if (!versionRange.isIncluded(minimum) || versionRange.isIncluded(maximum)) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMajor() == maximum.getMajor() - 1) return IMatchRules.COMPATIBLE; else if (minimum.getMajor() != maximum.getMajor()) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMinor() == maximum.getMinor() - 1) return IMatchRules.EQUIVALENT; else if (minimum.getMinor() != maximum.getMinor()) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMicro() == maximum.getMicro() - 1) return IMatchRules.PERFECT; // this is as close as we got return IMatchRules.NONE; // no real match rule for this }
public static int getMatchRule(VersionRange versionRange) { if (versionRange == null || versionRange.getMinimum() == null) return IMatchRules.NONE; Version minimum = versionRange.getMinimum(); Version maximum = versionRange.getMaximum() == null ? maxVersion : versionRange.getMaximum(); if (maximum.compareTo(maxVersion) >= 0) return IMatchRules.GREATER_OR_EQUAL; else if (minimum.equals(maximum)) return IMatchRules.PERFECT; else if (!versionRange.isIncluded(minimum) || versionRange.isIncluded(maximum)) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMajor() == maximum.getMajor() - 1) return IMatchRules.COMPATIBLE; else if (minimum.getMajor() != maximum.getMajor()) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMinor() == maximum.getMinor() - 1) return IMatchRules.EQUIVALENT; else if (minimum.getMinor() != maximum.getMinor()) return IMatchRules.NONE; // no real match rule for this else if (minimum.getMicro() == maximum.getMicro() - 1) return IMatchRules.PERFECT; // this is as close as we got return IMatchRules.NONE; // no real match rule for this }
@Override public String toString() { return fRange.toString(); }
public void load(BundleSpecification importModel) { this.fID = importModel.getName(); this.reexported = importModel.isExported(); this.optional = importModel.isOptional(); VersionRange versionRange = importModel.getVersionRange(); if (versionRange == null || VersionRange.emptyRange.equals(versionRange)) { this.version = null; match = IMatchRules.NONE; } else { this.version = versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null; match = PluginBase.getMatchRule(versionRange); } }
Version version = suppliers[i].getVersion(); VersionRange range = host.getVersionRange(); if (!range.isIncluded(version)) { String versionRange = host.getVersionRange().toString(); report(NLS.bind(PDECoreMessages.BundleErrorReporter_BundleRangeInvalidInBundleVersion, versionRange), getLine(header, versionRange),
public boolean equals(Object object) { if (!(object instanceof VersionRange)) return false; VersionRange vr = (VersionRange) object; if (minVersion.equals(vr.getMinimum()) && includeMin == vr.includeMin) if (maxVersion.equals(vr.getMaximum()) && includeMax == vr.includeMax) return true; return false; }
/** * Returns the minimum Version of this VersionRange. * @return the minimum Version of this VersionRange */ public Version getMinimum() { return getLeft(); }
/** * Returns the maximum Version of this VersionRange. * <p> * This method is deprecated. For ranges that have no maximum this method * incorrectly returns a version equal to * <code>Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)</code>. * Use {@link org.osgi.framework.VersionRange#getRight()} instead. * @return the maximum Version of this VersionRange * @deprecated use {@link org.osgi.framework.VersionRange#getRight()} */ public Version getMaximum() { Version right = getRight(); return right == null ? versionMax : right; }
@Override public String getMinimumVersion() { return fRange.getMinimum().toString(); }
@Override public boolean equals(Object obj) { if (obj instanceof BundleVersionRange) { BundleVersionRange range = (BundleVersionRange) obj; return fRange.equals(range.fRange); } return false; }