private void copyBundles()

in src/main/java/org/apache/sling/launchpad/base/impl/BootstrapInstaller.java [293:341]


    private void copyBundles(File slingStartupDir, String parent, int startLevel) {

        // set default start level
        if (startLevel < 0) {
            startLevel = 0;
        }
        // this will be set and created on demand
        File startUpLevelDir = null;

        Iterator<String> res = resourceProvider.getChildren(parent);
        while (res.hasNext()) {
            // path to the next resource
            String path = res.next();

            if (DirectoryUtil.isBundle(path)) {
                // try to access the bundle file, ignore if not possible
                InputStream ins = resourceProvider.getResourceAsStream(path);
                if (ins == null) {
                    continue;
                }

                try {
                    // ensure we have a directory for the startlevel only when
                    // needed
                    if (startUpLevelDir == null) {
                        startUpLevelDir = getOrCreateDirectory(slingStartupDir,
                            String.valueOf(startLevel));
                    }

                    // copy over the bundle based on the startlevel
                    String bundleFileName = extractFileName(path);
                    File bundleFile = new File(startUpLevelDir, bundleFileName);
                    try {
                        copyStreamToFile(ins, bundleFile);
                    } catch (IOException e) {
                        // should this fail here or just log a warning?
                        throw new RuntimeException("Failure copying file from "
                            + path + " to startup dir (" + startUpLevelDir
                            + ") and name (" + bundleFileName + "): " + e, e);
                    }
                } finally {
                    try {
                        ins.close();
                    } catch (IOException ignore) {
                    }
                }
            }
        }
    }