Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2008-12-22 15:30:52 +0000
committerPascal Rapicault2008-12-22 15:30:52 +0000
commit6015a8a074176483727d1ca929eebb590ea26039 (patch)
tree1de3549b65806c93ccb9de4b1df03ff7b5255231 /bundles/org.eclipse.equinox.p2.core
parentdafd36e0149a3be144a51e77ae148beb87224021 (diff)
downloadrt.equinox.p2-6015a8a074176483727d1ca929eebb590ea26039.tar.gz
rt.equinox.p2-6015a8a074176483727d1ca929eebb590ea26039.tar.xz
rt.equinox.p2-6015a8a074176483727d1ca929eebb590ea26039.zip
Bug 233699 - Add support for version types other than OSGipost_version_2008
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.core')
-rw-r--r--bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF7
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/Version.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/VersionRange.java1
6 files changed, 10 insertions, 9 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
index 63753c270..fcbd98419 100644
--- a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
@@ -18,9 +18,7 @@ Import-Package: javax.xml.parsers,
org.osgi.util.tracker;version="1.3.3",
org.xml.sax,
org.xml.sax.helpers
-Export-Package: org.eclipse.equinox.internal.p2.core;
- x-friends:="org.eclipse.equinox.p2.metadata.generator,
- org.eclipse.equinox.p2.publisher",
+Export-Package: org.eclipse.equinox.internal.p2.core;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.publisher",
org.eclipse.equinox.internal.p2.core.helpers;
x-friends:="org.eclipse.equinox.p2.director,
org.eclipse.equinox.p2.artifact.processors,
@@ -73,7 +71,8 @@ Export-Package: org.eclipse.equinox.internal.p2.core;
org.eclipse.equinox.p2.ui.sdk.scheduler,
org.eclipse.equinox.p2.updatechecker,
org.eclipse.equinox.p2.updatesite,
- org.eclipse.pde.ui",
+ org.eclipse.pde.ui,
+ org.eclipse.equinox.p2.metadata",
org.eclipse.equinox.internal.provisional.p2.core.eventbus;
x-friends:="org.eclipse.equinox.p2.metadata,
org.eclipse.equinox.p2.metadata.generator,
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java
index 5be32d53d..a77de48a5 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/CompositeRepositoryIO.java
@@ -23,10 +23,10 @@ import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.core.repository.ICompositeRepository;
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
-import org.eclipse.osgi.service.resolver.VersionRange;
+import org.eclipse.equinox.internal.provisional.p2.core.VersionRange;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
+import org.eclipse.equinox.internal.provisional.p2.core.Version;
import org.xml.sax.*;
/**
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
index c8173754f..94a9e5563 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLParser.java
@@ -19,10 +19,10 @@ import org.eclipse.equinox.internal.p2.core.Activator;
import org.eclipse.equinox.internal.p2.core.StringPool;
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
-import org.eclipse.osgi.service.resolver.VersionRange;
+import org.eclipse.equinox.internal.provisional.p2.core.VersionRange;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
+import org.eclipse.equinox.internal.provisional.p2.core.Version;
import org.osgi.util.tracker.ServiceTracker;
import org.xml.sax.*;
import org.xml.sax.ContentHandler;
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
index 993a32603..05bdc084d 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
@@ -12,7 +12,7 @@ package org.eclipse.equinox.internal.p2.persistence;
import java.io.*;
import java.util.*;
-import org.osgi.framework.Version;
+import org.eclipse.equinox.internal.provisional.p2.core.Version;
public class XMLWriter implements XMLConstants {
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/Version.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/Version.java
new file mode 100644
index 000000000..4e3c6994b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/Version.java
@@ -0,0 +1 @@
+/* * Copyright (c) OSGi Alliance (2004, 2008). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /******************************************************************************* * Copyright (c) 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core; import java.util.NoSuchElementException; import java.util.StringTokenizer; /** * Version identifier for bundles and packages. * * <p> * Version identifiers have four components. * <ol> * <li>Major version. A non-negative integer.</li> * <li>Minor version. A non-negative integer.</li> * <li>Micro version. A non-negative integer.</li> * <li>Qualifier. A text string. See <code>Version(String)</code> for the * format of the qualifier string.</li> * </ol> * * <p> * <code>Version</code> objects are immutable. * * @since 1.3 * @Immutable * @version $Revision: 5962 $ */ public class Version implements Comparable { private final int major; private final int minor; private final int micro; private final String qualifier; private static final String SEPARATOR = "."; //$NON-NLS-1$ /** * The empty version "0.0.0". Equivalent to calling * <code>new Version(0,0,0)</code>. */ public static final Version emptyVersion = new Version(0, 0, 0); /** * Creates a version identifier from the specified numerical components. * * <p> * The qualifier is set to the empty string. * * @param major Major component of the version identifier. * @param minor Minor component of the version identifier. * @param micro Micro component of the version identifier. * @throws IllegalArgumentException If the numerical components are * negative. */ public Version(int major, int minor, int micro) { this(major, minor, micro, null); } /** * Creates a version identifier from the specified components. * * @param major Major component of the version identifier. * @param minor Minor component of the version identifier. * @param micro Micro component of the version identifier. * @param qualifier Qualifier component of the version identifier. If * <code>null</code> is specified, then the qualifier will be set to * the empty string. * @throws IllegalArgumentException If the numerical components are negative * or the qualifier string is invalid. */ public Version(int major, int minor, int micro, String qualifier) { if (qualifier == null) { qualifier = ""; //$NON-NLS-1$ } this.major = major; this.minor = minor; this.micro = micro; this.qualifier = qualifier; validate(); } /** * Created a version identifier from the specified string. * * <p> * Here is the grammar for version strings. * * <pre> * version ::= major('.'minor('.'micro('.'qualifier)?)?)? * major ::= digit+ * minor ::= digit+ * micro ::= digit+ * qualifier ::= (alpha|digit|'_'|'-')+ * digit ::= [0..9] * alpha ::= [a..zA..Z] * </pre> * * There must be no whitespace in version. * * @param version String representation of the version identifier. * @throws IllegalArgumentException If <code>version</code> is improperly * formatted. */ public Version(String version) { int major = 0; int minor = 0; int micro = 0; String qualifier = ""; //$NON-NLS-1$ try { StringTokenizer st = new StringTokenizer(version, SEPARATOR, true); major = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) { st.nextToken(); // consume delimiter minor = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) { st.nextToken(); // consume delimiter micro = Integer.parseInt(st.nextToken()); if (st.hasMoreTokens()) { st.nextToken(); // consume delimiter qualifier = st.nextToken(); if (st.hasMoreTokens()) { throw new IllegalArgumentException("invalid format"); //$NON-NLS-1$ } } } } } catch (NoSuchElementException e) { throw new IllegalArgumentException("invalid format"); //$NON-NLS-1$ } this.major = major; this.minor = minor; this.micro = micro; this.qualifier = qualifier; validate(); } /** * Called by the Version constructors to validate the version components. * * @throws IllegalArgumentException If the numerical components are negative * or the qualifier string is invalid. */ private void validate() { if (major < 0) { throw new IllegalArgumentException("negative major"); //$NON-NLS-1$ } if (minor < 0) { throw new IllegalArgumentException("negative minor"); //$NON-NLS-1$ } if (micro < 0) { throw new IllegalArgumentException("negative micro"); //$NON-NLS-1$ } char[] chars = qualifier.toCharArray(); for (int i = 0, length = chars.length; i < length; i++) { char ch = chars[i]; if (('A' <= ch) && (ch <= 'Z')) { continue; } if (('a' <= ch) && (ch <= 'z')) { continue; } if (('0' <= ch) && (ch <= '9')) { continue; } if ((ch == '_') || (ch == '-')) { continue; } throw new IllegalArgumentException("invalid qualifier: " + qualifier); //$NON-NLS-1$ } } /** * Parses a version identifier from the specified string. * * <p> * See <code>Version(String)</code> for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A <code>Version</code> object representing the version * identifier. If <code>version</code> is <code>null</code> or * the empty string then <code>emptyVersion</code> will be * returned. * @throws IllegalArgumentException If <code>version</code> is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } version = version.trim(); if (version.length() == 0) { return emptyVersion; } return new Version(version); } /** * Returns the major component of this version identifier. * * @return The major component. */ public int getMajor() { return major; } /** * Returns the minor component of this version identifier. * * @return The minor component. */ public int getMinor() { return minor; } /** * Returns the micro component of this version identifier. * * @return The micro component. */ public int getMicro() { return micro; } /** * Returns the qualifier component of this version identifier. * * @return The qualifier component. */ public String getQualifier() { return qualifier; } /** * Returns the string representation of this version identifier. * * <p> * The format of the version string will be <code>major.minor.micro</code> * if qualifier is the empty string or * <code>major.minor.micro.qualifier</code> otherwise. * * @return The string representation of this version identifier. */ public String toString() { int q = qualifier.length(); StringBuffer result = new StringBuffer(20 + q); result.append(major); result.append(SEPARATOR); result.append(minor); result.append(SEPARATOR); result.append(micro); if (q > 0) { result.append(SEPARATOR); result.append(qualifier); } return result.toString(); } /** * Returns a hash code value for the object. * * @return An integer which is a hash code value for this object. */ public int hashCode() { return (major << 24) + (minor << 16) + (micro << 8) + qualifier.hashCode(); } /** * Compares this <code>Version</code> object to another object. * * <p> * A version is considered to be <b>equal to </b> another version if the * major, minor and micro components are equal and the qualifier component * is equal (using <code>String.equals</code>). * * @param object The <code>Version</code> object to be compared. * @return <code>true</code> if <code>object</code> is a * <code>Version</code> and is equal to this object; * <code>false</code> otherwise. */ public boolean equals(Object object) { if (object == this) { // quicktest return true; } if (!(object instanceof Version)) { return false; } Version other = (Version) object; return (major == other.major) && (minor == other.minor) && (micro == other.micro) && qualifier.equals(other.qualifier); } /** * Compares this <code>Version</code> object to another object. * * <p> * A version is considered to be <b>less than </b> another version if its * major component is less than the other version's major component, or the * major components are equal and its minor component is less than the other * version's minor component, or the major and minor components are equal * and its micro component is less than the other version's micro component, * or the major, minor and micro components are equal and it's qualifier * component is less than the other version's qualifier component (using * <code>String.compareTo</code>). * * <p> * A version is considered to be <b>equal to</b> another version if the * major, minor and micro components are equal and the qualifier component * is equal (using <code>String.compareTo</code>). * * @param object The <code>Version</code> object to be compared. * @return A negative integer, zero, or a positive integer if this object is * less than, equal to, or greater than the specified * <code>Version</code> object. * @throws ClassCastException If the specified object is not a * <code>Version</code>. */ public int compareTo(Object object) { if (object == this) { // quicktest return 0; } Version other = (Version) object; int result = major - other.major; if (result != 0) { return result; } result = minor - other.minor; if (result != 0) { return result; } result = micro - other.micro; if (result != 0) { return result; } return qualifier.compareTo(other.qualifier); } public static Version fromOSGiVersion(org.osgi.framework.Version version) { if (version.equals(org.osgi.framework.Version.emptyVersion)) return emptyVersion; return new Version(version.getMajor(), version.getMinor(), version.getMicro(), version.getQualifier()); } public static org.osgi.framework.Version toOSGiVersion(Version version) { if (version.equals(emptyVersion)) return org.osgi.framework.Version.emptyVersion; return new org.osgi.framework.Version(version.getMajor(), version.getMinor(), version.getMicro(), version.getQualifier()); } } \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/VersionRange.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/VersionRange.java
new file mode 100644
index 000000000..769ec07ac
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/provisional/p2/core/VersionRange.java
@@ -0,0 +1 @@
+/******************************************************************************* * Copyright (c) 2003, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.equinox.internal.provisional.p2.core; /** * This class represents a version range. * @since 3.1 * @noextend This class is not intended to be subclassed by clients. */ public class VersionRange { private static final Version versionMax = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); /** * An empty version */ public static final VersionRange emptyRange = new VersionRange(null); private final Version minVersion; private final boolean includeMin; private final Version maxVersion; private final boolean includeMax; /** * Constructs a VersionRange with the specified minVersion and maxVersion. * @param minVersion the minimum version of the range * @param maxVersion the maximum version of the range */ public VersionRange(Version minVersion, boolean includeMin, Version maxVersion, boolean includeMax) { this.minVersion = minVersion; this.includeMin = includeMin; this.maxVersion = maxVersion; this.includeMax = includeMax; } /** * Constructs a VersionRange from the given versionRange String. * @param versionRange a version range String that specifies a range of * versions. */ public VersionRange(String versionRange) { if (versionRange == null || versionRange.length() == 0) { minVersion = Version.emptyVersion; includeMin = true; maxVersion = VersionRange.versionMax; includeMax = true; return; } versionRange = versionRange.trim(); if (versionRange.charAt(0) == '[' || versionRange.charAt(0) == '(') { int comma = versionRange.indexOf(','); if (comma < 0) throw new IllegalArgumentException(); char last = versionRange.charAt(versionRange.length() - 1); if (last != ']' && last != ')') throw new IllegalArgumentException(); minVersion = Version.parseVersion(versionRange.substring(1, comma).trim()); includeMin = versionRange.charAt(0) == '['; maxVersion = Version.parseVersion(versionRange.substring(comma + 1, versionRange.length() - 1).trim()); includeMax = last == ']'; } else { minVersion = Version.parseVersion(versionRange.trim()); includeMin = true; maxVersion = VersionRange.versionMax; includeMax = true; } } /** * Returns the minimum Version of this VersionRange * @return the minimum Version of this VersionRange */ public Version getMinimum() { return minVersion; } /** * Indicates if the minimum version is included in the version range. * @return true if the minimum version is included in the version range; * otherwise false is returned */ public boolean getIncludeMinimum() { return includeMin; } /** * Returns the maximum Version of this VersionRange * @return the maximum Version of this VersionRange */ public Version getMaximum() { return maxVersion; } /** * Indicates if the maximum version is included in the version range. * @return true if the maximum version is included in the version range; * otherwise false is returned */ public boolean getIncludeMaximum() { return includeMax; } /** * Returns whether the given version is included in this VersionRange. * This will depend on the minimum and maximum versions of this VersionRange * and the given version. * * @param version a version to be tested for inclusion in this VersionRange. * (may be <code>null</code>) * @return <code>true</code> if the version is include, * <code>false</code> otherwise */ public boolean isIncluded(Version version) { Version minRequired = getMinimum(); if (minRequired == null) return true; if (version == null) return false; Version maxRequired = getMaximum() == null ? VersionRange.versionMax : getMaximum(); int minCheck = includeMin ? 0 : 1; int maxCheck = includeMax ? 0 : -1; return version.compareTo(minRequired) >= minCheck && version.compareTo(maxRequired) <= maxCheck; } public boolean equals(Object object) { if (!(object instanceof VersionRange)) return false; VersionRange vr = (VersionRange) object; if (minVersion != null && vr.getMinimum() != null) { if (minVersion.equals(vr.getMinimum()) && includeMin == vr.includeMin) if (maxVersion != null && vr.getMaximum() != null) { if (maxVersion.equals(vr.getMaximum()) && includeMax == vr.includeMax) return true; } else return maxVersion == vr.getMaximum(); } else { return minVersion == vr.getMinimum(); } return false; } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (maxVersion != null ? maxVersion.hashCode() : VersionRange.versionMax.hashCode()); result = prime * result + (minVersion != null ? minVersion.hashCode() : Version.emptyVersion.hashCode()); result = prime * result + (includeMax ? 1231 : 1237); result = prime * result + (includeMin ? 1231 : 1237); return result; } public String toString() { if (minVersion == null) return Version.emptyVersion.toString(); if (VersionRange.versionMax.equals(maxVersion)) return minVersion.toString(); StringBuffer result = new StringBuffer(); result.append(includeMin ? '[' : '('); result.append(minVersion); result.append(','); result.append(maxVersion); result.append(includeMax ? ']' : ')'); return result.toString(); } public static org.eclipse.osgi.service.resolver.VersionRange toOSGiVersionRange(VersionRange range) { if (range.equals(emptyRange)) return org.eclipse.osgi.service.resolver.VersionRange.emptyRange; return new org.eclipse.osgi.service.resolver.VersionRange(Version.toOSGiVersion(range.getMinimum()), range.getIncludeMinimum(), Version.toOSGiVersion(range.getMaximum()), range.getIncludeMinimum()); } public static VersionRange fromOSGiVersionRange(org.eclipse.osgi.service.resolver.VersionRange range) { if (range.equals(org.eclipse.osgi.service.resolver.VersionRange.emptyRange)) return emptyRange; return new VersionRange(Version.fromOSGiVersion(range.getMinimum()), range.getIncludeMinimum(), Version.fromOSGiVersion(range.getMaximum()), range.getIncludeMinimum()); } } \ No newline at end of file

Back to the top