use of org.apache.aries.application.management.BundleInfo in project aries by apache.
the class AriesApplicationImpl method storeInDirectory.
private void storeInDirectory(File dir) throws IOException, MalformedURLException {
OutputStream out = null;
InputStream in = null;
try {
out = IOUtils.getOutputStream(dir, AppConstants.APPLICATION_MF);
_applicationMetadata.store(out);
} finally {
IOUtils.close(out);
}
if (_deploymentMetadata != null) {
try {
out = IOUtils.getOutputStream(dir, AppConstants.DEPLOYMENT_MF);
_deploymentMetadata.store(out);
} finally {
IOUtils.close(out);
}
}
// Write the by-value eba files out
for (BundleInfo bi : _bundleInfo) {
// bi.getLocation() will return a URL to the source bundle. It may be of the form
// file:/path/to/my/file.jar, or
// jar:file:/my/path/to/eba.jar!/myBundle.jar
String bundleLocation = bi.getLocation();
String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
try {
out = IOUtils.getOutputStream(dir, bundleFileName);
URL bundleURL = new URL(bundleLocation);
InputStream is = bundleURL.openStream();
IOUtils.copy(is, out);
} finally {
IOUtils.close(out);
IOUtils.close(in);
}
}
// Write the migrated bundles out
if (_modifiedBundles != null) {
for (Map.Entry<String, BundleConversion> modifiedBundle : _modifiedBundles.entrySet()) {
try {
out = IOUtils.getOutputStream(dir, modifiedBundle.getKey());
IOUtils.copy(modifiedBundle.getValue().getInputStream(), out);
} finally {
IOUtils.close(out);
}
}
}
}
use of org.apache.aries.application.management.BundleInfo 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.management.BundleInfo in project aries by apache.
the class RepositoryGenerator method generateOBR.
public void generateOBR() {
if (generated) {
return;
}
synchronized (this) {
if (obrPath == null) {
// set to a default obr file which is local m2 repo
String file = System.getProperty("user.home") + "/.m2/repository/";
if (new File(file).exists()) {
obrPath = file;
}
}
// if repository.xml already exists, no need to generate it
if (new File(obrPath + REPOSITORY_FILE).exists()) {
registerOBR();
generated = true;
return;
}
File rootFile = new File(obrPath);
if (!rootFile.exists() || !rootFile.isDirectory()) {
throw new IllegalArgumentException("obr path " + obrPath + " is not valid");
}
Manve2Repository repo = new Manve2Repository(rootFile);
SortedSet<String> ss = repo.listFiles();
Set<BundleInfo> infos = new HashSet<BundleInfo>();
for (String s : ss) {
BundleInfo info = new BundleInfoImpl(s);
infos.add(info);
}
Document doc;
try {
doc = RepositoryDescriptorGenerator.generateRepositoryDescriptor("Subsystem Repository description", infos);
FileOutputStream fout = new FileOutputStream(obrPath + REPOSITORY_FILE);
TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(fout));
fout.close();
TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(System.out));
} catch (Exception e) {
LOGGER.error("Exception occurred when generate obr", e);
e.printStackTrace();
}
registerOBR();
generated = true;
}
}
Aggregations