1 11 package org.eclipse.core.internal.plugins; 12 13 import org.eclipse.core.runtime.IPluginPrerequisite; 14 import org.eclipse.core.runtime.PluginVersionIdentifier; 15 import org.eclipse.osgi.service.resolver.BundleSpecification; 16 import org.eclipse.osgi.service.resolver.VersionRange; 17 import org.osgi.framework.Version; 18 19 20 23 public class PluginPrerequisite implements IPluginPrerequisite { 24 private static final Version maxVersion = new Version(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); 25 private BundleSpecification prereq = null; 26 27 public PluginPrerequisite(BundleSpecification b) { 28 prereq = b; 29 } 30 31 public PluginVersionIdentifier getResolvedVersionIdentifier() { 32 Version actualVersion = prereq.getSupplier().getVersion(); 33 if (actualVersion == null) 34 return null; 35 return new PluginVersionIdentifier(actualVersion.toString()); 36 } 37 38 public String getUniqueIdentifier() { 39 return prereq.getName(); 40 } 41 42 public PluginVersionIdentifier getVersionIdentifier() { 43 Version specifiedVersion = prereq.getVersionRange() == null ? null : prereq.getVersionRange().getMinimum(); 44 if (specifiedVersion == null) 45 return null; 46 return new PluginVersionIdentifier(specifiedVersion.toString()); 47 } 48 49 public boolean isExported() { 50 return prereq.isExported(); 51 } 52 53 public boolean isMatchedAsGreaterOrEqual() { 54 return isMatchedAsGreaterOrEqual(prereq.getVersionRange()); 55 } 56 57 public boolean isMatchedAsCompatible() { 58 return isMatchedAsCompatible(prereq.getVersionRange()); 59 } 60 61 public boolean isMatchedAsEquivalent() { 62 return isMatchedAsEquivalent(prereq.getVersionRange()); 63 } 64 65 public boolean isMatchedAsPerfect() { 66 return isMatchedAsPerfect(prereq.getVersionRange()); 67 } 68 69 public boolean isMatchedAsExact() { 70 return isMatchedAsEquivalent(); 71 } 72 73 public boolean isOptional() { 74 return prereq.isOptional(); 75 } 76 77 private static boolean isMatchedAsGreaterOrEqual(VersionRange versionRange) { 78 if (versionRange == null || versionRange.getMinimum() == null) 79 return false; 80 Version maximum = versionRange.getMaximum(); 81 if (maximum == null || maximum.compareTo(maxVersion) >= 0) 82 return true; 83 return false; 84 } 85 86 private static boolean isMatchedAsPerfect(VersionRange versionRange) { 87 if (versionRange == null || versionRange.getMinimum() == null) 88 return false; 89 Version minimum = versionRange.getMinimum(); 90 Version maximum = versionRange.getMaximum() == null ? maxVersion : versionRange.getMaximum(); 91 if (minimum.equals(maximum)) 92 return true; 93 return false; 94 } 95 96 private static boolean isMatchedAsEquivalent(VersionRange versionRange) { 97 if (versionRange == null || versionRange.getMinimum() == null) 98 return false; 99 Version minimum = versionRange.getMinimum(); 100 Version maximum = versionRange.getMaximum() == null ? maxVersion : versionRange.getMaximum(); 101 if (!versionRange.getIncludeMinimum() || versionRange.getIncludeMaximum()) 102 return false; 103 else if (minimum.getMajor() == maximum.getMajor() - 1) 104 return false; 105 else if (minimum.getMajor() != maximum.getMajor()) 106 return false; 107 else if (minimum.getMinor() == maximum.getMinor() - 1) 108 return true; 109 return false; 110 } 111 112 private static boolean isMatchedAsCompatible(VersionRange versionRange) { 113 if (versionRange == null || versionRange.getMinimum() == null) 114 return false; 115 Version minimum = versionRange.getMinimum(); 116 Version maximum = versionRange.getMaximum() == null ? maxVersion : versionRange.getMaximum(); 117 if (!versionRange.getIncludeMinimum() || versionRange.getIncludeMaximum()) 118 return false; 119 else if (minimum.getMajor() == maximum.getMajor() - 1) 120 return true; 121 return false; 122 } 123 } 124 | Popular Tags |