Search in sources :

Example 6 with IDirectory

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");
    }
}
Also used : IDirectory(org.apache.aries.util.filesystem.IDirectory) File(java.io.File) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 7 with IDirectory

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;
}
Also used : IFile(org.apache.aries.util.filesystem.IFile) HashMap(java.util.HashMap) IDirectory(org.apache.aries.util.filesystem.IDirectory) ManifestHeaderProcessor(org.apache.aries.util.manifest.ManifestHeaderProcessor) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File)

Example 8 with IDirectory

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");
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URLConnection(java.net.URLConnection) TransformerException(javax.xml.transform.TransformerException) URISyntaxException(java.net.URISyntaxException) ResolverException(org.apache.aries.application.management.ResolverException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ModelledResource(org.apache.aries.application.modelling.ModelledResource) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashSet(java.util.HashSet)

Example 9 with IDirectory

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;
}
Also used : IDirectory(org.apache.aries.util.filesystem.IDirectory)

Example 10 with IDirectory

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;
}
Also used : IFile(org.apache.aries.util.filesystem.IFile) IDirectory(org.apache.aries.util.filesystem.IDirectory) ArrayList(java.util.ArrayList) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File)

Aggregations

IDirectory (org.apache.aries.util.filesystem.IDirectory)14 File (java.io.File)11 IFile (org.apache.aries.util.filesystem.IFile)7 FileOutputStream (java.io.FileOutputStream)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 AriesApplication (org.apache.aries.application.management.AriesApplication)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 RepositoryGenerator (org.apache.aries.application.management.spi.repository.RepositoryGenerator)2 ModelledResourceManager (org.apache.aries.application.modelling.ModelledResourceManager)2 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1