use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class ModellerTest method testParsingByInputStreamProvider.
@Test
public void testParsingByInputStreamProvider() throws Exception {
final URL pathToTestBundle = getClass().getClassLoader().getResource("test.bundle.jar");
ModelledResource resource = sut.getModelledResource("file:///test.bundle.uri", new ModelledResourceManager.InputStreamProvider() {
public InputStream open() throws IOException {
return pathToTestBundle.openStream();
}
});
checkTestBundleResource(resource);
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class OBRResolverTest method createAndResolveSelfContainedApp.
private Collection<ModelledResource> createAndResolveSelfContainedApp(String extraImport) throws Exception {
FileOutputStream fout = new FileOutputStream(new File("a.bundle.jar"));
ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, "a.bundle").attribute(BUNDLE_VERSION, "1.0.0").attribute(BUNDLE_MANIFESTVERSION, "2").attribute(IMPORT_PACKAGE, "a.pack.age").end().writeOut(fout);
fout.close();
fout = new FileOutputStream(new File("b.bundle.jar"));
ArchiveFixture.newJar().manifest().attribute(BUNDLE_SYMBOLICNAME, "b.bundle").attribute(BUNDLE_VERSION, "1.0.0").attribute(BUNDLE_MANIFESTVERSION, "2").attribute(IMPORT_PACKAGE, extraImport).attribute(EXPORT_PACKAGE, "a.pack.age").end().writeOut(fout);
fout.close();
ModelledResourceManager mrm = context().getService(ModelledResourceManager.class);
ModelledResource aBundle = mrm.getModelledResource(FileSystem.getFSRoot(new File("a.bundle.jar")));
ModelledResource bBundle = mrm.getModelledResource(FileSystem.getFSRoot(new File("b.bundle.jar")));
AriesApplicationResolver resolver = context().getService(AriesApplicationResolver.class);
return resolver.resolveInIsolation("test.app", "1.0.0", Arrays.asList(aBundle, bBundle), Arrays.<Content>asList(ContentFactory.parseContent("a.bundle", "1.0.0"), ContentFactory.parseContent("b.bundle", "1.0.0")));
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class ModelledResourceManagerImpl method model.
private ModelledResource model(String uri, BundleManifest bm, ParsedServiceElements pse) throws ModellerException {
Attributes attributes = bm.getRawAttributes();
ModelledResource mbi = null;
try {
mbi = _modellingManager.getModelledResource(uri, attributes, pse.getReferences(), pse.getServices());
} catch (InvalidAttributeException iae) {
ModellerException me = new ModellerException(iae);
_logger.debug(LOG_EXIT, "getModelledResource", me);
throw me;
}
_logger.debug(LOG_EXIT, "getModelledResource", mbi);
return mbi;
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class RepositoryGeneratorImpl method generateRepository.
public void generateRepository(String[] source, OutputStream fout) throws IOException {
logger.debug(LOG_ENTRY, "generateRepository", new Object[] { source, fout });
List<URI> jarFiles = new ArrayList<URI>();
InputStream in = null;
OutputStream out = null;
File wstemp = null;
Set<ModelledResource> mrs = new HashSet<ModelledResource>();
if (source != null) {
try {
for (String urlString : source) {
// for each entry, we need to find out whether it is in local file system. If yes, we would like to
// scan the bundles recursively under that directory
URI entry;
try {
File f = new File(urlString);
if (f.exists()) {
entry = f.toURI();
} else {
entry = new URI(urlString);
}
if ("file".equals(entry.toURL().getProtocol())) {
jarFiles.addAll(FileUtils.getBundlesRecursive(entry));
} else {
jarFiles.add(entry);
}
} catch (URISyntaxException use) {
throw new IOException(urlString + " is not a valide uri.");
}
}
for (URI jarFileURI : jarFiles) {
String uriString = jarFileURI.toString();
File f = null;
if ("file".equals(jarFileURI.toURL().getProtocol())) {
f = new File(jarFileURI);
} else {
int lastIndexOfSlash = uriString.lastIndexOf("/");
String fileName = uriString.substring(lastIndexOfSlash + 1);
//we need to download this jar/war to wstemp and work on it
URLConnection jarConn = jarFileURI.toURL().openConnection();
in = jarConn.getInputStream();
if (wstemp == null) {
wstemp = new File(tempDir.getTemporaryDirectory(), "generateRepositoryXML_" + System.currentTimeMillis());
boolean created = wstemp.mkdirs();
if (created) {
logger.debug("The temp directory was created successfully.");
} else {
logger.debug("The temp directory was NOT created.");
}
}
//Let's open the stream to download the bundles from remote
f = new File(wstemp, fileName);
out = new FileOutputStream(f);
IOUtils.copy(in, out);
}
IDirectory jarDir = FileSystem.getFSRoot(f);
mrs.add(modelledResourceManager.getModelledResource(uriString, jarDir));
}
generateRepository("Resource Repository", mrs, fout);
} catch (Exception e) {
logger.debug(LOG_EXIT, "generateRepository");
throw new IOException(e);
} finally {
IOUtils.close(in);
IOUtils.close(out);
if (wstemp != null) {
IOUtils.deleteRecursive(wstemp);
}
}
} else {
logger.debug("The URL list is empty");
}
logger.debug(LOG_EXIT, "generateRepository");
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class RepositoryGeneratorImpl method generateRepository.
public static void generateRepository(RepositoryAdmin repositoryAdmin, String repositoryName, Collection<? extends ModelledResource> byValueBundles, OutputStream os) throws ResolverException, IOException {
logger.debug(LOG_ENTRY, "generateRepository", new Object[] { repositoryAdmin, repositoryName, byValueBundles, os });
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException pce) {
throw new ResolverException(pce);
}
Element root = doc.createElement("repository");
root.setAttribute("name", repositoryName);
doc.appendChild(root);
for (ModelledResource mr : byValueBundles) {
BundleResource bundleResource = new BundleResource(mr, repositoryAdmin);
if (bundleResourceTransformers.size() > 0) {
for (BundleResourceTransformer brt : bundleResourceTransformers) {
bundleResource = brt.transform(bundleResource);
}
}
writeResource(bundleResource, mr.getLocation(), doc, root);
}
try {
Transformer trans = TransformerFactory.newInstance().newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.transform(new DOMSource(doc), new StreamResult(os));
} catch (TransformerException te) {
logger.debug(LOG_EXIT, "generateRepository", te);
throw new ResolverException(te);
}
logger.debug(LOG_EXIT, "generateRepository");
}
Aggregations