1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*******************************************************************************
* Copyright (c) 2007, 2011 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
* Rob Harrop - SpringSource Inc. (bug 247522)
*******************************************************************************/
package org.eclipse.osgi.internal.resolver;
import java.util.*;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.eclipse.osgi.service.resolver.*;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.*;
public class NativeCodeDescriptionImpl extends BaseDescriptionImpl implements NativeCodeDescription {
private static final VersionRange[] EMPTY_VERSIONRANGES = new VersionRange[0];
private volatile Filter filter;
private String[] languages;
private String[] nativePaths;
private String[] osNames;
private VersionRange[] osVersions;
private String[] processors;
private BundleDescription supplier;
private volatile boolean invalidNativePaths = false;
public Filter getFilter() {
return filter;
}
public String[] getLanguages() {
synchronized (this.monitor) {
if (languages == null)
return BundleDescriptionImpl.EMPTY_STRING;
return languages;
}
}
public String[] getNativePaths() {
synchronized (this.monitor) {
if (nativePaths == null)
return BundleDescriptionImpl.EMPTY_STRING;
return nativePaths;
}
}
public String[] getOSNames() {
synchronized (this.monitor) {
if (osNames == null)
return BundleDescriptionImpl.EMPTY_STRING;
return osNames;
}
}
public VersionRange[] getOSVersions() {
synchronized (this.monitor) {
if (osVersions == null)
return EMPTY_VERSIONRANGES;
return osVersions;
}
}
public String[] getProcessors() {
synchronized (this.monitor) {
if (processors == null)
return BundleDescriptionImpl.EMPTY_STRING;
return processors;
}
}
public BundleDescription getSupplier() {
return supplier;
}
public int compareTo(NativeCodeDescription otherDesc) {
State containingState = getSupplier().getContainingState();
if (containingState == null)
return 0;
Dictionary<Object, Object>[] platformProps = containingState.getPlatformProperties();
Version osversion;
try {
osversion = Version.parseVersion((String) platformProps[0].get(Constants.FRAMEWORK_OS_VERSION));
} catch (Exception e) {
osversion = Version.emptyVersion;
}
VersionRange[] thisRanges = getOSVersions();
VersionRange[] otherRanges = otherDesc.getOSVersions();
Version thisHighest = getHighestVersionMatch(osversion, thisRanges);
Version otherHighest = getHighestVersionMatch(osversion, otherRanges);
if (thisHighest.compareTo(otherHighest) < 0)
return -1;
return (getLanguages().length == 0 ? 0 : 1) - (otherDesc.getLanguages().length == 0 ? 0 : 1);
}
public boolean hasInvalidNativePaths() {
return invalidNativePaths;
}
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 toString() {
StringBuffer sb = new StringBuffer();
String[] paths = getNativePaths();
for (int i = 0; i < paths.length; i++) {
if (i > 0) {
sb.append("; "); //$NON-NLS-1$
}
sb.append(paths[i]);
}
String[] procs = getProcessors();
for (int i = 0; i < procs.length; i++) {
sb.append("; "); //$NON-NLS-1$
sb.append(Constants.BUNDLE_NATIVECODE_PROCESSOR);
sb.append('=');
sb.append(procs[i]);
}
String[] oses = getOSNames();
for (int i = 0; i < oses.length; i++) {
sb.append("; "); //$NON-NLS-1$
sb.append(Constants.BUNDLE_NATIVECODE_OSNAME);
sb.append('=');
sb.append(oses[i]);
}
VersionRange[] osRanges = getOSVersions();
for (int i = 0; i < osRanges.length; i++) {
sb.append("; "); //$NON-NLS-1$
sb.append(Constants.BUNDLE_NATIVECODE_OSVERSION);
sb.append("=\""); //$NON-NLS-1$
sb.append(osRanges[i].toString());
sb.append('"');
}
String[] langs = getLanguages();
for (int i = 0; i < langs.length; i++) {
sb.append("; "); //$NON-NLS-1$
sb.append(Constants.BUNDLE_NATIVECODE_LANGUAGE);
sb.append('=');
sb.append(langs[i]);
}
Filter f = getFilter();
if (f != null) {
sb.append("; "); //$NON-NLS-1$
sb.append(Constants.SELECTION_FILTER_ATTRIBUTE);
sb.append("=\""); //$NON-NLS-1$
sb.append(f.toString());
sb.append('"');
}
return (sb.toString());
}
void setInvalidNativePaths(boolean invalidNativePaths) {
this.invalidNativePaths = invalidNativePaths;
}
void setOSNames(String[] osNames) {
synchronized (this.monitor) {
this.osNames = osNames;
}
}
void setOSVersions(VersionRange[] osVersions) {
synchronized (this.monitor) {
this.osVersions = osVersions;
}
}
void setFilter(String filter) throws InvalidSyntaxException {
this.filter = filter == null ? null : FilterImpl.newInstance(filter);
}
void setLanguages(String[] languages) {
synchronized (this.monitor) {
this.languages = languages;
}
}
void setNativePaths(String[] nativePaths) {
synchronized (this.monitor) {
this.nativePaths = nativePaths;
}
}
void setProcessors(String[] processors) {
synchronized (this.monitor) {
this.processors = processors;
}
}
void setSupplier(BundleDescription supplier) {
this.supplier = supplier;
}
@SuppressWarnings("unchecked")
public Map<String, String> getDeclaredDirectives() {
return Collections.EMPTY_MAP;
}
@SuppressWarnings("unchecked")
public Map<String, Object> getDeclaredAttributes() {
return Collections.EMPTY_MAP;
}
}
|