Bundle installBundleFromDirectory()

in src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java [118:153]


    Bundle installBundleFromDirectory(final Path dir, boolean refreshPackages) throws IOException {
        if (Files.isDirectory(dir)) {
            logger.info("Checking dir {} for bundle install", dir);
            final Path manifestFile = dir.resolve(JarFile.MANIFEST_NAME);
            if (Files.exists(dir)) {
                try (InputStream fis = Files.newInputStream(manifestFile)) {
                    final Manifest mf = new Manifest(fis);

                    final String symbolicName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
                    if (symbolicName != null) {
                        // search bundle
                        Bundle found = getBundle(symbolicName);

                        Path tmpJarFile = Files.createTempFile(dir.getFileName().toString(), "bundle");
                        try {
                            createJar(dir, tmpJarFile, mf);
                            try (InputStream in = Files.newInputStream(tmpJarFile)) {
                                String location = dir.toAbsolutePath().toString();
                                return installOrUpdateBundle(found, in, location, refreshPackages);
                            } catch (final BundleException be) {
                                throw new IllegalArgumentException("Unable to install/update bundle from dir " + dir, be);
                            }
                        } finally {
                            Files.delete(tmpJarFile);
                        }
                    } else {
                        throw new IllegalArgumentException("Manifest in " + dir + " does not have a symbolic name");
                    }
                }
            } else {
                throw new IllegalArgumentException("Dir " + dir + " does not have a manifest");
            }
        } else {
            throw new IllegalArgumentException("Dir " + dir + " does not exist");
        }
    }