use of org.osgi.framework.Version in project bndtools by bndtools.
the class BundleSorter method compare.
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
Resource r1 = (Resource) e1;
Resource r2 = (Resource) e2;
Capability id1 = ResourceUtils.getIdentityCapability(r1);
Capability id2 = ResourceUtils.getIdentityCapability(r2);
String name1 = ResourceUtils.getIdentity(id1);
if (name1 == null) {
name1 = "";
}
String name2 = ResourceUtils.getIdentity(id2);
if (name2 == null) {
name2 = "";
}
int ret = name1.compareTo(name2);
if (ret != 0) {
return ret;
}
Version ver1 = ResourceUtils.getVersion(id1);
if (ver1 == null) {
ver1 = Version.emptyVersion;
}
Version ver2 = ResourceUtils.getVersion(id2);
if (ver2 == null) {
ver2 = Version.emptyVersion;
}
// This comparison is the reverse of what you would expect
return ver2.compareTo(ver1);
}
use of org.osgi.framework.Version in project bnd by bndtools.
the class BundleAnalyzer method doPlainJarIdentity.
private void doPlainJarIdentity(Resource resource, List<? super Capability> caps) {
String name = (String) resource.getProperties().get(Resource.NAME);
if (name.toLowerCase().endsWith(SUFFIX_JAR))
name = name.substring(0, name.length() - SUFFIX_JAR.length());
Version version = null;
int dashIndex = name.lastIndexOf('-');
if (dashIndex > 0) {
try {
String versionStr = name.substring(dashIndex + 1);
version = new Version(versionStr);
name = name.substring(0, dashIndex);
} catch (Exception e) {
version = null;
}
}
Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, name).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, Namespaces.RESOURCE_TYPE_PLAIN_JAR);
if (version != null)
builder.addAttribute(Namespaces.ATTR_VERSION, version);
caps.add(builder.buildCapability());
}
use of org.osgi.framework.Version in project bnd by bndtools.
the class BundleAnalyzer method doBundleIdentity.
private void doBundleIdentity(Resource resource, MimeType mimeType, List<? super Capability> caps) throws Exception {
Manifest manifest = resource.getManifest();
if (manifest == null)
throw new IllegalArgumentException("Missing bundle manifest.");
String type;
switch(mimeType) {
case Bundle:
type = Namespaces.RESOURCE_TYPE_BUNDLE;
break;
case Fragment:
type = Namespaces.RESOURCE_TYPE_FRAGMENT;
break;
default:
type = Namespaces.RESOURCE_TYPE_PLAIN_JAR;
break;
}
SymbolicName bsn = Util.getSymbolicName(resource);
boolean singleton = Boolean.TRUE.toString().equalsIgnoreCase(bsn.getAttributes().get(Constants.SINGLETON_DIRECTIVE + ":"));
Version version = Util.getVersion(resource);
Builder builder = new Builder().setNamespace(Namespaces.NS_IDENTITY).addAttribute(Namespaces.NS_IDENTITY, bsn.getName()).addAttribute(Namespaces.ATTR_IDENTITY_TYPE, type).addAttribute(Namespaces.ATTR_VERSION, version);
if (singleton)
builder.addDirective(Namespaces.DIRECTIVE_SINGLETON, Boolean.TRUE.toString());
caps.add(builder.buildCapability());
}
use of org.osgi.framework.Version in project sling by apache.
the class OsgiInstallerImpl method getInstallationState.
/**
* @see org.apache.sling.installer.api.info.InfoProvider#getInstallationState()
*/
@Override
public InstallationState getInstallationState() {
synchronized (this.resourcesLock) {
final InstallationState state = new InstallationState() {
private final List<ResourceGroup> activeResources = new ArrayList<>();
private final List<ResourceGroup> installedResources = new ArrayList<>();
private final List<RegisteredResource> untransformedResources = new ArrayList<>();
@Override
public List<ResourceGroup> getActiveResources() {
return activeResources;
}
@Override
public List<ResourceGroup> getInstalledResources() {
return installedResources;
}
@Override
public List<RegisteredResource> getUntransformedResources() {
return untransformedResources;
}
@Override
public String toString() {
return "InstallationState[active resources: " + this.activeResources + ", installed resources: " + this.installedResources + ", untransformed resources: " + this.untransformedResources + "]";
}
};
for (final String entityId : this.persistentList.getEntityIds()) {
if (!this.persistentList.isSpecialEntityId(entityId)) {
final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
final String alias = group.getAlias();
final List<Resource> resources = new ArrayList<>();
boolean first = true;
boolean isActive = false;
for (final TaskResource tr : group.getResources()) {
final ResourceState resourceState = tr.getState();
if (first) {
if (resourceState == ResourceState.INSTALL || resourceState == ResourceState.UNINSTALL) {
isActive = true;
}
first = false;
}
resources.add(new Resource() {
@Override
public String getScheme() {
return tr.getScheme();
}
@Override
public String getURL() {
return tr.getURL();
}
@Override
public String getType() {
return tr.getType();
}
@Override
public InputStream getInputStream() throws IOException {
return tr.getInputStream();
}
@Override
public Dictionary<String, Object> getDictionary() {
return tr.getDictionary();
}
@Override
public String getDigest() {
return tr.getDigest();
}
@Override
public int getPriority() {
return tr.getPriority();
}
@Override
public String getEntityId() {
return tr.getEntityId();
}
@Override
public ResourceState getState() {
return resourceState;
}
@Override
public Version getVersion() {
return tr.getVersion();
}
@Override
public long getLastChange() {
return ((RegisteredResourceImpl) tr).getLastChange();
}
@Override
public Object getAttribute(final String key) {
return tr.getAttribute(key);
}
@Override
@CheckForNull
public String getError() {
return tr.getError();
}
@Override
public String toString() {
return "resource[entityId=" + getEntityId() + ", scheme=" + getScheme() + ", url=" + getURL() + ", type=" + getType() + ", error=" + getError() + ", state=" + getState() + ", version=" + getVersion() + ", lastChange=" + getLastChange() + ", priority=" + getPriority() + ", digest=" + getDigest() + "]";
}
});
}
final ResourceGroup rg = new ResourceGroup() {
@Override
public List<Resource> getResources() {
return resources;
}
@Override
public String getAlias() {
return alias;
}
@Override
public String toString() {
return "group[" + resources + "]";
}
};
if (isActive) {
state.getActiveResources().add(rg);
} else {
state.getInstalledResources().add(rg);
}
}
}
Collections.sort(state.getActiveResources(), COMPARATOR);
Collections.sort(state.getInstalledResources(), COMPARATOR);
state.getUntransformedResources().addAll(this.persistentList.getUntransformedResources());
return state;
}
}
use of org.osgi.framework.Version in project sling by apache.
the class RegisteredResourceImpl method isSameResource.
/**
* Compare two resources where we know that they point to the same entity and have the
* same URL!
*/
public static boolean isSameResource(final RegisteredResourceImpl a, final RegisteredResourceImpl b) {
// check if the artifacts have a version
final Version va = a.getVersion();
final Version vb = b.getVersion();
if (va != null && vb != null) {
// Compare version
if (!vb.equals(va)) {
return false;
}
final boolean isSnapshot = va.toString().contains("SNAPSHOT");
if (!isSnapshot) {
return true;
}
}
// we just compare the digest
return a.getDigest().equals(b.getDigest());
}
Aggregations