use of org.osgi.framework.Version in project aries by apache.
the class Main method extendImportPackage.
private static void extendImportPackage(Manifest manifest) throws IOException {
String utilPkgVersion = getPackageVersion(Util.class);
Version osgiVersion = Version.parseVersion(utilPkgVersion);
Version minVersion = new Version(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro());
Version maxVersion = new Version(osgiVersion.getMajor(), osgiVersion.getMinor() + 1, 0);
String ip = manifest.getMainAttributes().getValue(IMPORT_PACKAGE);
if (ip == null)
ip = "";
StringBuilder sb = new StringBuilder(ip);
if (ip.length() > 0)
sb.append(",");
sb.append(Util.class.getPackage().getName());
sb.append(";version=\"[");
sb.append(minVersion);
sb.append(",");
sb.append(maxVersion);
sb.append(")\"");
manifest.getMainAttributes().putValue(IMPORT_PACKAGE, sb.toString());
}
use of org.osgi.framework.Version in project aries by apache.
the class RepositoryGenerator method find.
/**
* the format of resource is like bundlesymbolicname;version=1.0.0, for example com.ibm.ws.eba.example.blog.api;version=1.0.0,
*/
@SuppressWarnings({ "rawtypes", "unused" })
public Resource find(String resource) throws SubsystemException {
generateOBR();
Content content = new ContentImpl(resource);
String symbolicName = content.getContentName();
// this version could possibly be a range
String version = content.getVersion().toString();
StringBuilder filterString = new StringBuilder();
filterString.append("(&(name" + "=" + symbolicName + "))");
filterString.append("(version" + "=" + version + "))");
//org.apache.felix.bundlerepository.Resource[] res = this.repositoryAdmin.discoverResources(filterString.toString());
Repository[] repos = this.repositoryAdmin.listRepositories();
org.apache.felix.bundlerepository.Resource res = null;
for (Repository repo : repos) {
org.apache.felix.bundlerepository.Resource[] resources = repo.getResources();
for (int i = 0; i < resources.length; i++) {
if (resources[i].getSymbolicName().equals(symbolicName)) {
if (resources[i].getVersion().compareTo(new Version(version)) == 0) {
res = resources[i];
break;
}
}
}
}
if (res == null) {
// throw new SubsystemException("unable to find the resource " + resource);
return null;
}
Map props = res.getProperties();
Object type = props.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
return new FelixResourceAdapter(res);
}
use of org.osgi.framework.Version in project aries by apache.
the class OBRAriesResolver method resolve.
@Deprecated
@Override
public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
log.trace("resolving {}", app);
ApplicationMetadata appMeta = app.getApplicationMetadata();
String appName = appMeta.getApplicationSymbolicName();
Version appVersion = appMeta.getApplicationVersion();
List<Content> appContent = appMeta.getApplicationContents();
Collection<Content> useBundleContent = appMeta.getUseBundles();
List<Content> contents = new ArrayList<Content>();
contents.addAll(appContent);
contents.addAll(useBundleContent);
if ((constraints != null) && (constraints.length > 0)) {
for (ResolveConstraint con : constraints) {
contents.add(ContentFactory.parseContent(con.getBundleName(), con.getVersionRange().toString()));
}
}
Resolver obrResolver = getConfiguredObrResolver(appName, appVersion.toString(), toModelledResource(app.getBundleInfo()), false);
// add a resource describing the requirements of the application metadata.
obrResolver.add(createApplicationResource(appName, appVersion, contents));
if (obrResolver.resolve()) {
Set<BundleInfo> result = new HashSet<BundleInfo>();
List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
for (Resource resource : requiredResources) {
BundleInfo bundleInfo = toBundleInfo(resource, false);
result.add(bundleInfo);
}
if (returnOptionalResources) {
for (Resource resource : obrResolver.getOptionalResources()) {
BundleInfo bundleInfo = toBundleInfo(resource, true);
result.add(bundleInfo);
}
}
return result;
} else {
Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
//refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied packages or other bundles
Map<String, Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver, reasons);
StringBuffer reqList = new StringBuffer();
Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
for (String reason : unsatisfiedRequirements.keySet()) {
reqList.append('\n');
reqList.append(reason);
}
ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE", new Object[] { app.getApplicationMetadata().getApplicationName(), reqList }));
re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
log.debug(LOG_EXIT, "resolve", re);
throw re;
}
}
use of org.osgi.framework.Version in project aries by apache.
the class BundleRepositoryManagerImpl method getBundleSuggestions.
public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
Iterator<DeploymentContent> it = content.iterator();
while (it.hasNext()) {
DeploymentContent bundleToFind = it.next();
Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
for (BundleRepository obj : providers) {
BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
if (suggestion != null) {
List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
if (suggestions == null) {
suggestions = new ArrayList<BundleSuggestion>();
bundlesuggestions.put(suggestion.getVersion(), suggestions);
}
suggestions.add(suggestion);
}
}
BundleSuggestion suggestion = null;
if (!!!bundlesuggestions.isEmpty()) {
List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
if (thoughts != null) {
Collections.sort(thoughts, new Comparator<BundleSuggestion>() {
public int compare(BundleSuggestion o1, BundleSuggestion o2) {
return o1.getCost() - o2.getCost();
}
});
suggestion = thoughts.get(0);
}
}
// add the suggestion to the list
if (suggestion != null) {
urlToBeInstalled.put(bundleToFind, suggestion);
} else {
throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
}
}
LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
return urlToBeInstalled;
}
use of org.osgi.framework.Version in project aries by apache.
the class EquinoxFrameworkUtils method existInExports.
/**
* check if the value in nvm already exist in the exports
* @param key
* @param nvm
* @param exports
* @return boolean whether the value in nvm already exist in the exports
*/
private static boolean existInExports(String key, Map<String, String> nvm, final Collection<Content> exports) {
boolean value = false;
for (Content nvp : exports) {
if (nvp.getContentName().trim().equals(key.trim())) {
// ok key equal. let's check the version
// if version is higher, we still want to import, for example javax.transaction;version=1.1
String vi = nvm.get(Constants.VERSION_ATTRIBUTE);
String ve = nvp.getNameValueMap().get(Constants.VERSION_ATTRIBUTE);
if (vi == null || vi.length() == 0) {
vi = "0.0.0";
}
if (ve == null || ve.length() == 0) {
ve = "0.0.0";
}
if (vi.indexOf(",") == -1) {
if (new Version(vi).compareTo(new Version(ve)) <= 0) {
// we got it covered in our exports
value = true;
}
} else {
// parse vi into version range.
VersionRange vri = ManifestHeaderProcessor.parseVersionRange(vi);
Version minV = vri.getMinimumVersion();
Version maxV = vri.getMaximumVersion();
if (minV.compareTo(new Version(ve)) < 0 && maxV.compareTo(new Version(ve)) > 0) {
value = true;
} else if (minV.compareTo(new Version(ve)) == 0 && !!!vri.isMinimumExclusive()) {
value = true;
} else if (maxV.compareTo(new Version(ve)) == 0 && !!!vri.isMaximumExclusive()) {
value = true;
}
}
}
}
return value;
}
Aggregations