use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class OBRResolverTest method generateOBRRepoXML.
private void generateOBRRepoXML(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);
mrs.add(modelledResourceManager.getModelledResource(bundleFile.toURI().toString(), jarDir));
}
repositoryGenerator.generateRepository("Test repo description", mrs, fout);
fout.close();
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class AriesApplicationManagerImplTest method testStoreAndReload.
@Test
public void testStoreAndReload() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
File dest = new File("ariesApplicationManagerImplTest/stored.eba");
app.store(dest);
/* Dest should be a zip file with four entries:
* /foo.bar.widgets.jar
* /my.business.logic.jar
* /META-INF/APPLICATION.MF
* /META-INF/DEPLOYMENT.MF
*/
IDirectory storedEba = FileSystem.getFSRoot(dest);
assertNotNull(storedEba);
assertEquals(storedEba.listFiles().size(), 3);
IFile ifile = storedEba.getFile("META-INF/APPLICATION.MF");
assertNotNull(ifile);
ifile = storedEba.getFile("META-INF/DEPLOYMENT.MF");
assertNotNull(ifile);
ifile = storedEba.getFile("foo.bar.widgets.jar");
assertNotNull(ifile);
ifile = storedEba.getFile("my.business.logic.jar");
assertNotNull(ifile);
AriesApplication newApp = _appMgr.createApplication(storedEba);
DeploymentMetadata dm = newApp.getDeploymentMetadata();
assertEquals(2, dm.getApplicationDeploymentContents().size());
assertEquals(1, dm.getApplicationProvisionBundles().size());
assertEquals(dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
assertEquals(dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class AriesApplicationManagerImplTest method createApplication.
private AriesApplication createApplication(String fileName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ManagementException, ResolverException {
// This next block is a very long winded way of constructing a BundleInfoImpl
// against the existing (BundleManifest bm, String location) constructor. If we
// find we need a String-based BundleInfoImpl constructor for other reasons,
// we could change to using it here.
Set<BundleInfo> nextResolverResult = new HashSet<BundleInfo>();
String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
File persistenceLibrary = new File(persistenceLibraryLocation);
BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
BundleInfo resolvedPersistenceLibrary = new SimpleBundleInfo(mf, persistenceLibraryLocation);
Field v = SimpleBundleInfo.class.getDeclaredField("_version");
v.setAccessible(true);
v.set(resolvedPersistenceLibrary, new Version("1.1.0"));
nextResolverResult.add(resolvedPersistenceLibrary);
_resolver.setNextResult(nextResolverResult);
IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
AriesApplication app = _appMgr.createApplication(testEba);
app = _appMgr.resolve(app);
return app;
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class OpenEJBLocator method getClassPathLocations.
/**
* Find the classpath entries for our bundle
*
* @param manifest
* @param bundle
* @return
*/
private List<IDirectory> getClassPathLocations(BundleManifest manifest, IDirectory bundle) {
List<IDirectory> result = new ArrayList<IDirectory>();
String rawCp = manifest.getRawAttributes().getValue(Constants.BUNDLE_CLASSPATH);
logger.debug("Classpath is " + rawCp);
if (rawCp == null || rawCp.trim() == "")
result.add(bundle);
else {
List<NameValuePair> splitCp = ManifestHeaderProcessor.parseExportString(rawCp);
List<IFile> allFiles = null;
for (NameValuePair nvp : splitCp) {
String name = nvp.getName().trim();
if (".".equals(name)) {
result.add(bundle);
} else {
IFile f = bundle.getFile(name);
if (f == null) {
// Zip. Check to make sure
if (allFiles == null)
allFiles = bundle.listAllFiles();
for (IFile file : allFiles) {
if (file.getName().startsWith(name)) {
result.add(new ClasspathIDirectory(bundle, name));
break;
}
}
} else {
IDirectory converted = f.convertNested();
if (converted != null)
result.add(converted);
}
}
}
}
return result;
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class FileSystemImpl method getFSRoot.
public static ICloseableDirectory getFSRoot(InputStream is) {
File tempFile = null;
try {
tempFile = File.createTempFile("inputStreamExtract", ".zip");
} catch (IOException e1) {
throw new IORuntimeException("IOException in IDirectory.getFSRoot", e1);
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tempFile);
IOUtils.copy(is, fos);
} catch (IOException e) {
return null;
} finally {
IOUtils.close(fos);
}
IDirectory dir = getFSRoot(tempFile, null);
if (dir == null)
return null;
else
return new InputStreamClosableDirectory(dir, tempFile);
}
Aggregations