use of org.apache.aries.application.Content in project aries by apache.
the class DeploymentMetadataImpl method getContentsAsString.
private String getContentsAsString(Collection<Content> contents) {
StringBuilder builder = new StringBuilder();
boolean beginning = true;
for (Content c : contents) {
if (!!!beginning) {
builder.append(",");
}
builder.append(c);
beginning = false;
}
return builder.toString();
}
use of org.apache.aries.application.Content in project aries by apache.
the class IsolationTestUtils method prepareSampleBundleV2.
/**
* Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle,
* which returns the message "hello brave new world" rather than "hello world"
*
* This means setting up a global bundle repository as well as a global OBR repository
*/
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
BundleRepository repo = new BundleRepository() {
public int getCost() {
return 1;
}
public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
return new BundleSuggestion() {
public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
File f = new File("sample_2.0.0.jar");
try {
return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
public Version getVersion() {
return new Version("2.0.0");
}
public Set<Content> getImportPackage() {
return Collections.emptySet();
}
public Set<Content> getExportPackage() {
return Collections.emptySet();
}
public int getCost() {
return 1;
}
};
} else {
return null;
}
}
};
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
Attributes attrs = new Attributes();
attrs.putValue("Bundle-ManifestVersion", "2");
attrs.putValue("Bundle-Version", "2.0.0");
attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
attrs.putValue("Manifest-Version", "1");
ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
use of org.apache.aries.application.Content in project aries by apache.
the class AriesApplicationManagerImplTest method testCreateAndConversion.
@Test
public void testCreateAndConversion() throws Exception {
AriesApplication app = createApplication(CONVERSION_EBA);
ApplicationMetadata appMeta = app.getApplicationMetadata();
assertEquals(appMeta.getApplicationName(), "conversion.eba");
assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
List<Content> appContent = appMeta.getApplicationContents();
assertEquals(2, appContent.size());
Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
assertTrue(appContent.contains(fbw));
assertTrue(appContent.contains(mbl));
DeploymentMetadata dm = app.getDeploymentMetadata();
List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
assertEquals(2, dcList.size());
DeploymentContent dc1 = new DeploymentContentImpl("hello.world.jar;deployed-version=1.1.0");
DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.0");
DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
assertTrue(dcList.contains(dc1));
assertTrue(dcList.contains(dc2));
dcList = dm.getApplicationProvisionBundles();
assertEquals(1, dcList.size());
assertTrue(dcList.contains(dc3));
assertEquals(2, app.getBundleInfo().size());
BundleInfo info;
info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
assertNotNull(info);
assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
assertNotNull(info);
assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
use of org.apache.aries.application.Content in project aries by apache.
the class OBRAriesResolver method toImportedBundle.
private Collection<ImportedBundle> toImportedBundle(Collection<Content> content) throws ResolverException {
log.debug(LOG_ENTRY, "toImportedBundle", content);
List<ImportedBundle> result = new ArrayList<ImportedBundle>();
for (Content c : content) {
try {
result.add(modellingManager.getImportedBundle(c.getContentName(), c.getVersion().toString()));
} catch (InvalidAttributeException iae) {
throw new ResolverException(iae);
}
}
log.debug(LOG_EXIT, "toImportedBundle", result);
return result;
}
use of org.apache.aries.application.Content in project aries by apache.
the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.
public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx, AriesApplication app) {
BundleFrameworkConfiguration config = null;
DeploymentMetadata metadata = app.getDeploymentMetadata();
/**
* Set up framework config properties
*/
Properties frameworkConfig = new Properties();
// Problems occur if the parent framework has osgi.console set because the child framework
// will also attempt to listen on the same port which will cause port clashs. Setting this
// to null essentially turns the console off.
frameworkConfig.put("osgi.console", "none");
String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
/**
* Set up BundleManifest for the framework bundle
*/
Properties frameworkBundleManifest = new Properties();
frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata.getApplicationSymbolicName());
frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion().toString());
/**
* Set up Import-Package header for framework manifest
*/
// Extract the import packages and remove anything we already have available in the current framework
Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata.getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
if (imports != null && !imports.isEmpty()) {
StringBuffer buffer = new StringBuffer();
for (Content i : imports) buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length() - 1));
}
/**
* Set up CompositeServiceFilter-Import header for framework manifest
*/
StringBuilder serviceImportFilter = new StringBuilder();
String txRegsitryImport = "(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")";
Collection<Filter> deployedServiceImports = metadata.getDeployedServiceImport();
//if there are more services than the txRegistry import a OR group is required for the Filter
if (deployedServiceImports.size() > 0) {
serviceImportFilter.append("(|");
}
for (Filter importFilter : metadata.getDeployedServiceImport()) {
serviceImportFilter.append(importFilter.toString());
}
serviceImportFilter.append(txRegsitryImport);
//close the OR group if needed
if (deployedServiceImports.size() > 0) {
serviceImportFilter.append(")");
}
frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
return config;
}
Aggregations