use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentGeneratorTest method checkBundleInAppContentAndUseContent.
@Test
public void checkBundleInAppContentAndUseContent() throws Exception {
List<ModelledResource> cmr = new ArrayList<ModelledResource>();
cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
// The second time DeploymentGenerator calls the Resolver, it will provide just
// test.shared. The resolver will return test.shared _plus_ test.isolated.
_resolver.addResult(cmr);
Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "1.0.0")));
Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(mockContent("test.api", "1.0.0")));
app = Skeleton.newMock(AriesApplication.class);
Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
mf.write(System.out);
assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.api;deployed-version=1.1.0"));
assertTrue(mf.getMainAttributes().getValue("Deployed-Use-Bundle").contains("test.api;deployed-version=1.0.0"));
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentGeneratorTest method checkBundleInAppContentAndProvisionContent.
@Test
public void checkBundleInAppContentAndProvisionContent() throws Exception {
List<ModelledResource> cmr = new ArrayList<ModelledResource>();
cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
// The second time DeploymentGenerator calls the Resolver, it will provide just
// test.shared. The resolver will return test.shared _plus_ test.isolated.
_resolver.addResult(cmr);
Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "1.0.0")));
app = Skeleton.newMock(AriesApplication.class);
Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
try {
DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
fail("Expected exception because we can't provision an isolated bundle twice");
} catch (ResolverException rx) {
}
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentManifestManagerImpl method pruneFakeBundlesFromResults.
private void pruneFakeBundlesFromResults(Collection<ModelledResource> results, Collection<ModelledResource> fakeResources) {
_logger.debug(LOG_ENTRY, "pruneFakeBundleFromResults", new Object[] { results });
List<String> fakeBundles = new ArrayList<String>();
fakeBundles.add(FAKE_BUNDLE_NAME);
for (ModelledResource resource : fakeResources) {
fakeBundles.add(resource.getSymbolicName());
}
Iterator<ModelledResource> it = results.iterator();
while (it.hasNext()) {
ModelledResource mr = it.next();
if (fakeBundles.contains(mr.getSymbolicName())) {
it.remove();
}
}
_logger.debug(LOG_EXIT, "pruneFakeBundleFromResults");
}
use of org.apache.aries.application.modelling.ModelledResource 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.modelling.ModelledResource in project aries by apache.
the class OBRResolverAdvancedTest method generateOBRRepoXML.
private void generateOBRRepoXML(boolean nullURI, String... bundleFiles) throws Exception {
Set<ModelledResource> mrs = new HashSet<ModelledResource>();
FileOutputStream fout = new FileOutputStream("repository.xml");
RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
for (String fileName : bundleFiles) {
File bundleFile = new File(fileName);
IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
String uri = "";
if (!!!nullURI) {
uri = bundleFile.toURI().toString();
}
if ("delete.jar".equals(fileName)) {
jarDir = null;
}
mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
}
repositoryGenerator.generateRepository("Test repo description", mrs, fout);
fout.close();
}
Aggregations