use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class AriesSubsystemTest method testInstallIDirectory.
@Test
public void testInstallIDirectory() {
File file = new File(COMPOSITE_A);
IDirectory directory = FileSystem.getFSRoot(file);
try {
AriesSubsystem compositeA = getRootAriesSubsystem().install(COMPOSITE_A, directory);
uninstallSubsystemSilently(compositeA);
} catch (Exception e) {
fail("Installation from IDirectory should have succeeded");
}
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class BundleCompatibility method getAllExportedPkgContents.
private Map<String, PackageContent> getAllExportedPkgContents(BundleInfo currentBundle) {
String packageExports = currentBundle.getBundleManifest().getRawAttributes().getValue(Constants.EXPORT_PACKAGE);
List<ManifestHeaderProcessor.NameValuePair> exportPackageLists = ManifestHeaderProcessor.parseExportString(packageExports);
// only perform validation if there are some packages exported. Otherwise, not interested.
Map<String, PackageContent> exportedPackages = new HashMap<String, PackageContent>();
if (!!!exportPackageLists.isEmpty()) {
File bundleFile = currentBundle.getBundle();
IDirectory bundleDir = FileSystem.getFSRoot(bundleFile);
for (ManifestHeaderProcessor.NameValuePair exportedPackage : exportPackageLists) {
String packageName = exportedPackage.getName();
String packageVersion = exportedPackage.getAttributes().get(Constants.VERSION_ATTRIBUTE);
// need to go through each package and scan every class
exportedPackages.put(packageName, new PackageContent(packageName, packageVersion));
}
// scan the jar and list all the files under each package
List<IFile> allFiles = bundleDir.listAllFiles();
for (IFile file : allFiles) {
String directoryFullPath = file.getName();
String directoryName = null;
String fileName = null;
if (file.isFile() && ((file.getName().endsWith(SemanticVersioningUtils.classExt) || (file.getName().endsWith(SemanticVersioningUtils.schemaExt))))) {
if (directoryFullPath.lastIndexOf("/") != -1) {
directoryName = directoryFullPath.substring(0, directoryFullPath.lastIndexOf("/"));
fileName = directoryFullPath.substring(directoryFullPath.lastIndexOf("/") + 1);
}
}
if (directoryName != null) {
String pkgName = directoryName.replaceAll("/", ".");
PackageContent pkgContent = exportedPackages.get(pkgName);
if (pkgContent != null) {
if (file.getName().endsWith(SemanticVersioningUtils.classExt)) {
pkgContent.addClass(fileName, file);
} else {
pkgContent.addXsd(fileName, file);
}
exportedPackages.put(pkgName, pkgContent);
}
}
}
}
return exportedPackages;
}
use of org.apache.aries.util.filesystem.IDirectory 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.util.filesystem.IDirectory in project aries by apache.
the class ManifestDefaultsInjector method updateManifest.
/**
* Quick adapter to update a Manifest, using content of a Zip File.
* <p>
* This is really a wrapper of updateManifest(Manifest,String,IDirectory), with the
* IDirectory being being created from the Zip File. This method avoids other Bundles
* requiring IDirectory solely for calling updateManifest.
* <p>
* @param mf Manifest to be updated
* @param appName The name to use for this app, if the name contains
* a '_' char then the portion after the '_' is used, if possible, as
* the application version.
* @param zip Content to use for application.
* @return true if manifest modified, false otherwise.
*/
public static boolean updateManifest(Manifest mf, String appName, File zip) {
IDirectory appPathIDir = FileSystem.getFSRoot(zip);
boolean result = updateManifest(mf, appName, appPathIDir);
return result;
}
use of org.apache.aries.util.filesystem.IDirectory in project aries by apache.
the class DirectoryImpl method listAllFiles.
public List<IFile> listAllFiles() {
List<IFile> files = new ArrayList<IFile>();
File[] filesInDir = file.listFiles();
if (filesInDir != null) {
for (File f : filesInDir) {
if (f.isFile()) {
files.add(new FileImpl(f, rootDirFile));
} else if (f.isDirectory()) {
IDirectory subdir = new DirectoryImpl(f, rootDirFile);
files.add(subdir);
files.addAll(subdir.listAllFiles());
}
}
}
return files;
}
Aggregations