use of org.osgi.framework.Version in project bndtools by bndtools.
the class ResolutionWizard method resourceToRunBundle.
private static VersionedClause resourceToRunBundle(Resource resource) {
Capability idCap = ResourceUtils.getIdentityCapability(resource);
String identity = ResourceUtils.getIdentity(idCap);
// Map version range string, using "latest" for any workspace resources
Attrs attribs = new Attrs();
String versionRangeStr;
if (isWorkspace(resource)) {
versionRangeStr = VERSION_SNAPSHOT;
} else {
Version version = ResourceUtils.getVersion(idCap);
VersionRange versionRange = createVersionRange(version);
versionRangeStr = versionRange.toString();
}
attribs.put(Constants.VERSION_ATTRIBUTE, versionRangeStr);
return new VersionedClause(identity, attribs);
}
use of org.osgi.framework.Version in project bndtools by bndtools.
the class ResolutionSuccessPanel method resourceToRequirement.
private static Requirement resourceToRequirement(Resource resource) {
Capability identity = ResourceUtils.getIdentityCapability(resource);
String id = ResourceUtils.getIdentity(identity);
Version version = ResourceUtils.getVersion(identity);
Version dropQualifier = new Version(version.getMajor(), version.getMinor(), version.getMicro());
AndFilter filter = new AndFilter();
filter.addChild(new SimpleFilter(IdentityNamespace.IDENTITY_NAMESPACE, id));
filter.addChild(new LiteralFilter(Filters.fromVersionRange(dropQualifier.toString())));
Requirement req = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter.toString()).buildSyntheticRequirement();
return req;
}
use of org.osgi.framework.Version in project sling by apache.
the class DeployPckTask method execute.
@Override
public void execute(final InstallationContext ctx) {
final TaskResource tr = this.getResource();
// get and check symbolic name
final String symbolicName = (String) tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_SYMBOLICMAME);
if (symbolicName == null) {
logger.error("Resource {} has no symbolic name - ignoring.", tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
return;
}
// get package if available
final DeploymentPackage dp = this.deploymentAdmin.getDeploymentPackage(symbolicName);
if (tr.getState() == ResourceState.INSTALL) {
InputStream is = null;
try {
is = tr.getInputStream();
if (is == null) {
// something went wrong
logger.error("Resource {} does not provide an input stream!", tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} else {
final Version newVersion = new Version((String) tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_VERSION));
// check version
if (dp != null) {
final int compare = dp.getVersion().compareTo(newVersion);
if (compare < 0) {
// installed version is lower -> update
this.deploymentAdmin.installDeploymentPackage(is);
ctx.log("Installed deployment package {} : {}", symbolicName, newVersion);
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
} else if (compare >= 0) {
logger.debug("Deployment package " + symbolicName + " " + newVersion + " is not installed, package with higher or same version is already installed.");
}
} else {
this.deploymentAdmin.installDeploymentPackage(is);
ctx.log("Installed deployment package {} : {}", symbolicName, newVersion);
this.getResourceGroup().setFinishState(ResourceState.INSTALLED);
}
}
} catch (final DeploymentException e) {
logger.error("Unable to install deployment package {} from resource {}", symbolicName, tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} catch (final IOException ioe) {
logger.error("Unable to install deployment package {} from resource {}", symbolicName, tr);
this.getResourceGroup().setFinishState(ResourceState.IGNORED);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignore) {
}
}
}
} else {
// uninstall
if (dp != null) {
try {
dp.uninstall();
} catch (final DeploymentException e) {
logger.error("Unable to uninstall deployment package {} from resource {}", symbolicName, tr);
}
} else {
logger.info("Unable to find deployment package with symbolic name {} for uninstalling.", symbolicName);
}
this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
}
}
use of org.osgi.framework.Version in project sling by apache.
the class DeploymentPackageInstaller method transform.
/**
* @see org.apache.sling.installer.api.tasks.ResourceTransformer#transform(org.apache.sling.installer.api.tasks.RegisteredResource)
*/
public TransformationResult[] transform(final RegisteredResource resource) {
if (resource.getType().equals(InstallableResource.TYPE_FILE)) {
try {
final Manifest m = getManifest(resource.getInputStream());
if (m != null) {
final String sn = m.getMainAttributes().getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME);
if (sn != null) {
final String v = m.getMainAttributes().getValue(DEPLOYMENTPACKAGE_VERSION);
if (v != null) {
final Map<String, Object> attr = new HashMap<String, Object>();
attr.put(DEPLOYMENTPACKAGE_SYMBOLICMAME, sn);
final TransformationResult tr = new TransformationResult();
tr.setId(sn);
tr.setVersion(new Version(v));
tr.setResourceType(TYPE_DP);
tr.setAttributes(attr);
return new TransformationResult[] { tr };
}
}
}
} catch (final IOException ignore) {
// ignore
}
}
return null;
}
use of org.osgi.framework.Version in project sling by apache.
the class ModelTransformer method transform.
@Override
public TransformationResult[] transform(final RegisteredResource resource) {
Model model = null;
File baseDir = null;
if (resource.getType().equals(InstallableResource.TYPE_FILE) && resource.getURL().endsWith(".model")) {
try (final Reader reader = new InputStreamReader(resource.getInputStream(), "UTF-8")) {
model = ModelReader.read(reader, resource.getURL());
} catch (final IOException ioe) {
logger.info("Unable to read model from " + resource.getURL(), ioe);
}
}
if (resource.getType().equals(InstallableResource.TYPE_FILE) && resource.getURL().endsWith(".mar")) {
baseDir = this.bundleContext.getDataFile("");
try (final InputStream is = resource.getInputStream()) {
model = ModelArchiveReader.read(is, new ModelArchiveReader.ArtifactConsumer() {
@Override
public void consume(final Artifact artifact, final InputStream is) throws IOException {
// nothing to do, install task does extraction
}
});
} catch (final IOException ioe) {
logger.info("Unable to read model from " + resource.getURL(), ioe);
}
}
if (model != null) {
Map<Traceable, String> errors = ModelUtility.validate(model);
if (errors == null) {
try {
final Model effectiveModel = ModelUtility.getEffectiveModel(model);
errors = ModelUtility.validateIncludingVersion(effectiveModel);
if (errors == null) {
String modelTxt = null;
try (final StringWriter sw = new StringWriter()) {
ModelWriter.write(sw, effectiveModel);
modelTxt = sw.toString();
} catch (final IOException ioe) {
logger.info("Unable to read model from " + resource.getURL(), ioe);
}
if (modelTxt != null) {
final TransformationResult[] result = new TransformationResult[effectiveModel.getFeatures().size()];
int index = 0;
for (final Feature f : effectiveModel.getFeatures()) {
final TransformationResult tr = new TransformationResult();
tr.setResourceType(TYPE_PROV_MODEL);
tr.setId(f.getName());
tr.setVersion(new Version(f.getVersion()));
final Map<String, Object> attributes = new HashMap<>();
attributes.put(ATTR_MODEL, modelTxt);
attributes.put(ATTR_FEATURE_INDEX, index);
attributes.put(ATTR_FEATURE_NAME, f.getName() + "-" + f.getVersion());
if (baseDir != null) {
final File dir = new File(baseDir, f.getName() + "-" + f.getVersion());
attributes.put(ATTR_BASE_PATH, dir.getAbsolutePath());
}
tr.setAttributes(attributes);
result[index] = tr;
index++;
}
return result;
}
}
} catch (final IllegalArgumentException iae) {
errors = Collections.singletonMap((Traceable) model, iae.getMessage());
}
}
if (errors != null) {
logger.warn("Errors during parsing model at {} : {}", resource.getURL(), errors.values());
}
}
return null;
}
Aggregations