use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class BaseRepository method addResource.
protected void addResource(Resource resource) {
for (Capability cap : resource.getCapabilities(null)) {
String ns = cap.getNamespace();
CapabilitySet set = capSets.get(ns);
if (set == null) {
if ("service-reference".equals(ns) || "osgi.service".equals(ns)) {
set = new CapabilitySet(Collections.singletonList("objectClass"));
} else {
set = new CapabilitySet(Collections.singletonList(ns));
}
capSets.put(ns, set);
}
set.addCapability(cap);
}
resources.add(resource);
}
use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class Overrides method override.
/**
* Compute a list of bundles to install, taking into account overrides.
* <p/>
* The file containing the overrides will be loaded from the given url.
* Blank lines and lines starting with a '#' will be ignored, all other lines
* are considered as urls to override bundles.
* <p/>
* The list of resources to resolve will be scanned and for each bundle,
* if a bundle override matches that resource, it will be used instead.
* <p/>
* Matching is done on bundle symbolic name (they have to be the same)
* and version (the bundle override version needs to be greater than the
* resource to be resolved, and less than the next minor version. A range
* directive can be added to the override url in which case, the matching
* will succeed if the resource to be resolved is within the given range.
*
* @param resources the list of resources to resolve
* @param overrides list of bundle overrides
*/
public static <T extends Resource> void override(Map<String, T> resources, Collection<String> overrides) {
// Do override replacement
for (Clause override : Parser.parseClauses(overrides.toArray(new String[overrides.size()]))) {
String url = override.getName();
String vr = override.getAttribute(OVERRIDE_RANGE);
T over = resources.get(url);
if (over == null) {
// Ignore invalid overrides
continue;
}
for (String uri : new ArrayList<String>(resources.keySet())) {
Resource res = resources.get(uri);
if (getSymbolicName(res).equals(getSymbolicName(over))) {
VersionRange range;
if (vr == null) {
// default to micro version compatibility
Version v1 = getVersion(res);
Version v2 = new Version(v1.getMajor(), v1.getMinor() + 1, 0);
range = new VersionRange(false, v1, v2, true);
} else {
range = VersionRange.parseVersionRange(vr);
}
// if the override is actually a newer version than what we currently have
if (range.contains(getVersion(over)) && getVersion(res).compareTo(getVersion(over)) < 0) {
resources.put(uri, over);
}
}
}
}
}
use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class FabricResource method version.
/**
* Accesses a version resource
*/
@Path("version/{versionId}")
public VersionResource version(@PathParam("versionId") String versionId) {
FabricService fabricService = getFabricService();
if (fabricService != null && Strings.isNotBlank(versionId)) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Version version = profileService.getRequiredVersion(versionId);
if (version != null) {
return new VersionResource(this, version);
} else {
LOG.warn("No version found for: {}", version);
}
}
return null;
}
use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class SupportServiceImpl method collect.
@Override
public File collect() {
String name = String.format("%s-%s", "SUPPORT", DATE_TIME_SUFFIX.format(new Date()));
File result = null;
ZipOutputStream file = null;
try {
result = File.createTempFile(name, ".zip");
LOGGER.info("Collecting information for support in file {}", result.getAbsolutePath());
file = new ZipOutputStream(new FileOutputStream(result));
for (Collector collector : collectors) {
for (Resource resource : collector.collect(resourceFactory)) {
collectFromResource(file, resource);
}
}
} catch (IOException e) {
LOGGER.error("Exception occured while collecting support information - resulting support file may not be usable", e);
} finally {
IOHelpers.close(file);
}
return result;
}
use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.
the class PatchThePatchServiceTest method createdeployment.
@Deployment
public static JavaArchive createdeployment() throws Exception {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
archive.addClass(ServiceLocator.class);
archive.addClass(IOHelpers.class);
archive.addPackage(ServiceTracker.class.getPackage());
archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
archive.addPackage(CommandSupport.class.getPackage());
archive.addClass(VersionCleaner.class);
archive.setManifest(new Asset() {
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleSymbolicName(archive.getName());
builder.addBundleManifestVersion(2);
builder.addImportPackages(Bundle.class, Logger.class);
builder.addImportPackages(AbstractCommand.class, Action.class, Function.class, Validatable.class);
builder.addImportPackages(InvalidComponentException.class);
builder.addImportPackage("org.apache.felix.service.command;status=provisional");
return builder.openStream();
}
});
// add the patch zip files as resource
archive.add(createPatchZipFile(PATCH_ID), "/patches", ZipExporter.class);
return archive;
}
Aggregations