@Test(expected = BundleException.class) public void updateBundleWithInvalidManifest() throws BundleException, InvalidSyntaxException { Actors actors = stageActors(true, this::updateBundleWithInvalidManifest_mockBundleProvider); actors.getBundleHelper().doInstallBundleInRepository(new File("."), "any"); }
Bundle doInstallBundleInRepository(File tempFile, String fileName) throws BundleException { File jarToInstall = tempFile; installResults.clear(); try { BundleIdentifier identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { jarToInstall = wrapPlainJar(tempFile, fileName); identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { throw new BundleException("Could not generate Bundle filename. Make sure the content is an OSGi bundle."); } String symbolicName = identifier.getSymbolicName(); logger.info("Wrapped plain jar as a OSGi bundle: {}.", symbolicName); } fileName = identifier.toJarFilename(); String location = generateRepositoryLocation(fileName); Bundle bundle = bundleContext.getBundle(location); boolean classpathBundle = false; if (bundle == null) { bundle = findBundleBySymbolicName(identifier); if (bundle != null) { NodeRef deletedNode = uninstallAndDeleteBundle(bundle); if (deletedNode != null) { logger.warn("Deleted existing repository bundle {} with an identical Symbolic name: {}.", deletedNode, identifier.getSymbolicName()); bundle = null; } else { classpathBundle = true; } } } InputStream inputStream = createStreamForFile(jarToInstall); if (bundle != null) { bundle.stop(); bundle.update(inputStream); FrameworkWiring wiring = getFrameworkWiring(); HashSet<Bundle> bundleSet = new HashSet<Bundle>(); bundleSet.add(bundle); wiring.resolveBundles(bundleSet); if (!isFragmentBundle(bundle)) { bundlesToStart.offer(bundle); Bundle[] dependantBundles = wiring.getDependencyClosure(bundleSet) .stream() .filter(bndl -> bndl.getState() == Bundle.ACTIVE) .toArray(Bundle[]::new); ArrayList<Bundle> dependantBundlesList = new ArrayList<Bundle>(Arrays.asList(dependantBundles)); List<Bundle> dependantBundlesSorted = BundleDependencies.sortByDependencies(dependantBundlesList); dependantBundlesSorted.sort(Collections.reverseOrder()); for (Bundle dependant : dependantBundlesSorted) { dependant.stop(); } for (Bundle dependant : dependantBundlesSorted) { bundlesToStart.offer(dependant); } wiring.refreshBundles(bundleSet, this); } else { return bundle; } } else { bundle = bundleContext.installBundle(location, inputStream); if (!isFragmentBundle(bundle)) { bundle.start(); installResults.add(new InstallResult(null)); } } if (bundle != null) { if (!classpathBundle) { BundleManifest manifest = createBundleManifest(bundle); saveBundleInRepository(jarToInstall, fileName, manifest); } else { logger.warn("Temporarily updated classpath bundle: {}, update will be reverted after restart.", bundle.getSymbolicName()); } try { BundleHelperCompanion.evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES)); } catch (InterruptedException tx) { logger.warn("Timed out waiting for an installation result", tx); } resetWebScriptsCache(); } return bundle; } catch (IOException e) { e.printStackTrace(); return null; } finally { } }
BundleHelper implements EventListener<SpringContextException>, FrameworkListener { Bundle doInstallBundleInRepository(File tempFile, String fileName) throws BundleException { File jarToInstall = tempFile; installResults.clear(); try { BundleIdentifier identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { jarToInstall = wrapPlainJar(tempFile, fileName); identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { throw new BundleException("Could not generate Bundle filename. Make sure the content is an OSGi bundle."); } String symbolicName = identifier.getSymbolicName(); logger.info("Wrapped plain jar as a OSGi bundle: {}.", symbolicName); } fileName = identifier.toJarFilename(); String location = generateRepositoryLocation(fileName); Bundle bundle = bundleContext.getBundle(location); boolean classpathBundle = false; if (bundle == null) { bundle = findBundleBySymbolicName(identifier); if (bundle != null) { NodeRef deletedNode = uninstallAndDeleteBundle(bundle); if (deletedNode != null) { logger.warn("Deleted existing repository bundle {} with an identical Symbolic name: {}.", deletedNode, identifier.getSymbolicName()); bundle = null; } else { classpathBundle = true; } } } InputStream inputStream = createStreamForFile(jarToInstall); if (bundle != null) { bundle.stop(); bundle.update(inputStream); FrameworkWiring wiring = getFrameworkWiring(); HashSet<Bundle> bundleSet = new HashSet<Bundle>(); bundleSet.add(bundle); wiring.resolveBundles(bundleSet); if (!isFragmentBundle(bundle)) { bundlesToStart.offer(bundle); Bundle[] dependantBundles = wiring.getDependencyClosure(bundleSet) .stream() .filter(bndl -> bndl.getState() == Bundle.ACTIVE) .toArray(Bundle[]::new); ArrayList<Bundle> dependantBundlesList = new ArrayList<Bundle>(Arrays.asList(dependantBundles)); List<Bundle> dependantBundlesSorted = BundleDependencies.sortByDependencies(dependantBundlesList); dependantBundlesSorted.sort(Collections.reverseOrder()); for (Bundle dependant : dependantBundlesSorted) { dependant.stop(); } for (Bundle dependant : dependantBundlesSorted) { bundlesToStart.offer(dependant); } wiring.refreshBundles(bundleSet, this); } else { return bundle; } } else { bundle = bundleContext.installBundle(location, inputStream); if (!isFragmentBundle(bundle)) { bundle.start(); installResults.add(new InstallResult(null)); } } if (bundle != null) { if (!classpathBundle) { BundleManifest manifest = createBundleManifest(bundle); saveBundleInRepository(jarToInstall, fileName, manifest); } else { logger.warn("Temporarily updated classpath bundle: {}, update will be reverted after restart.", bundle.getSymbolicName()); } try { BundleHelperCompanion.evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES)); } catch (InterruptedException tx) { logger.warn("Timed out waiting for an installation result", tx); } resetWebScriptsCache(); } return bundle; } catch (IOException e) { e.printStackTrace(); return null; } finally { } } }
BundleHelper implements EventListener<SpringContextException>, FrameworkListener { Bundle doInstallBundleInRepository(File tempFile, String fileName) throws BundleException { File jarToInstall = tempFile; installResults.clear(); try { BundleIdentifier identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { jarToInstall = wrapPlainJar(tempFile, fileName); identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { throw new BundleException("Could not generate Bundle filename. Make sure the content is an OSGi bundle."); } String symbolicName = identifier.getSymbolicName(); logger.info("Wrapped plain jar as a OSGi bundle: {}.", symbolicName); } fileName = identifier.toJarFilename(); String location = generateRepositoryLocation(fileName); Bundle bundle = bundleContext.getBundle(location); boolean classpathBundle = false; if (bundle == null) { bundle = findBundleBySymbolicName(identifier); if (bundle != null) { NodeRef deletedNode = uninstallAndDeleteBundle(bundle); if (deletedNode != null) { logger.warn("Deleted existing repository bundle {} with an identical Symbolic name: {}.", deletedNode, identifier.getSymbolicName()); bundle = null; } else { classpathBundle = true; } } } InputStream inputStream = createStreamForFile(jarToInstall); if (bundle != null) { bundle.stop(); bundle.update(inputStream); FrameworkWiring wiring = getFrameworkWiring(); HashSet<Bundle> bundleSet = new HashSet<Bundle>(); bundleSet.add(bundle); wiring.resolveBundles(bundleSet); if (!isFragmentBundle(bundle)) { bundlesToStart.offer(bundle); Bundle[] dependantBundles = wiring.getDependencyClosure(bundleSet) .stream() .filter(bndl -> bndl.getState() == Bundle.ACTIVE) .toArray(Bundle[]::new); ArrayList<Bundle> dependantBundlesList = new ArrayList<Bundle>(Arrays.asList(dependantBundles)); List<Bundle> dependantBundlesSorted = BundleDependencies.sortByDependencies(dependantBundlesList); dependantBundlesSorted.sort(Collections.reverseOrder()); for (Bundle dependant : dependantBundlesSorted) { dependant.stop(); } for (Bundle dependant : dependantBundlesSorted) { bundlesToStart.offer(dependant); } wiring.refreshBundles(bundleSet, this); } else { return bundle; } } else { bundle = bundleContext.installBundle(location, inputStream); if (!isFragmentBundle(bundle)) { bundle.start(); installResults.add(new InstallResult(null)); } } if (bundle != null) { if (!classpathBundle) { BundleManifest manifest = createBundleManifest(bundle); saveBundleInRepository(jarToInstall, fileName, manifest); } else { logger.warn("Temporarily updated classpath bundle: {}, update will be reverted after restart.", bundle.getSymbolicName()); } try { BundleHelperCompanion.evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES)); } catch (InterruptedException tx) { logger.warn("Timed out waiting for an installation result", tx); } resetWebScriptsCache(); } return bundle; } catch (IOException e) { e.printStackTrace(); return null; } finally { } } BundleHelper();  BundleHelper(BundleContext bundleContext,
            RepositoryStoreService repositoryStoreService,
            FileFolderService fileFolderService,
            ContentService contentService,
            NodeService nodeService,
            Container webScriptsContainer); }
BundleHelper implements EventListener<SpringContextException>, FrameworkListener { Bundle doInstallBundleInRepository(File tempFile, String fileName) throws BundleException { File jarToInstall = tempFile; installResults.clear(); try { BundleIdentifier identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { jarToInstall = wrapPlainJar(tempFile, fileName); identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { throw new BundleException("Could not generate Bundle filename. Make sure the content is an OSGi bundle."); } String symbolicName = identifier.getSymbolicName(); logger.info("Wrapped plain jar as a OSGi bundle: {}.", symbolicName); } fileName = identifier.toJarFilename(); String location = generateRepositoryLocation(fileName); Bundle bundle = bundleContext.getBundle(location); boolean classpathBundle = false; if (bundle == null) { bundle = findBundleBySymbolicName(identifier); if (bundle != null) { NodeRef deletedNode = uninstallAndDeleteBundle(bundle); if (deletedNode != null) { logger.warn("Deleted existing repository bundle {} with an identical Symbolic name: {}.", deletedNode, identifier.getSymbolicName()); bundle = null; } else { classpathBundle = true; } } } InputStream inputStream = createStreamForFile(jarToInstall); if (bundle != null) { bundle.stop(); bundle.update(inputStream); FrameworkWiring wiring = getFrameworkWiring(); HashSet<Bundle> bundleSet = new HashSet<Bundle>(); bundleSet.add(bundle); wiring.resolveBundles(bundleSet); if (!isFragmentBundle(bundle)) { bundlesToStart.offer(bundle); Bundle[] dependantBundles = wiring.getDependencyClosure(bundleSet) .stream() .filter(bndl -> bndl.getState() == Bundle.ACTIVE) .toArray(Bundle[]::new); ArrayList<Bundle> dependantBundlesList = new ArrayList<Bundle>(Arrays.asList(dependantBundles)); List<Bundle> dependantBundlesSorted = BundleDependencies.sortByDependencies(dependantBundlesList); dependantBundlesSorted.sort(Collections.reverseOrder()); for (Bundle dependant : dependantBundlesSorted) { dependant.stop(); } for (Bundle dependant : dependantBundlesSorted) { bundlesToStart.offer(dependant); } wiring.refreshBundles(bundleSet, this); } else { return bundle; } } else { bundle = bundleContext.installBundle(location, inputStream); if (!isFragmentBundle(bundle)) { bundle.start(); installResults.add(new InstallResult(null)); } } if (bundle != null) { if (!classpathBundle) { BundleManifest manifest = createBundleManifest(bundle); saveBundleInRepository(jarToInstall, fileName, manifest); } else { logger.warn("Temporarily updated classpath bundle: {}, update will be reverted after restart.", bundle.getSymbolicName()); } try { BundleHelperCompanion.evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES)); } catch (InterruptedException tx) { logger.warn("Timed out waiting for an installation result", tx); } resetWebScriptsCache(); } return bundle; } catch (IOException e) { e.printStackTrace(); return null; } finally { } } BundleHelper();  BundleHelper(BundleContext bundleContext,
            RepositoryStoreService repositoryStoreService,
            FileFolderService fileFolderService,
            ContentService contentService,
            NodeService nodeService,
            Container webScriptsContainer); BundleContext getBundleContext(); String getBundleRepositoryLocation(); @PostConstruct ServiceRegistration registerEventListeners(); List<Bundle> getFrameworkBundles(); List<Bundle> getExtensionBundles(); Bundle getBundle(Long id); Bundle installBundleInRepository(FormField file); Bundle installBundleInRepository(Content content); NodeRef uninstallAndDeleteBundle(Bundle bundle); ServiceReference<?>[] getAllServices(); @Override void onEvent(SpringContextException event); @Override Class<?>[] supportedEventTypes(); @Override void frameworkEvent(FrameworkEvent event); }
BundleHelper implements EventListener<SpringContextException>, FrameworkListener { Bundle doInstallBundleInRepository(File tempFile, String fileName) throws BundleException { File jarToInstall = tempFile; installResults.clear(); try { BundleIdentifier identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { jarToInstall = wrapPlainJar(tempFile, fileName); identifier = getBundleIdentifier(jarToInstall); if (identifier == null) { throw new BundleException("Could not generate Bundle filename. Make sure the content is an OSGi bundle."); } String symbolicName = identifier.getSymbolicName(); logger.info("Wrapped plain jar as a OSGi bundle: {}.", symbolicName); } fileName = identifier.toJarFilename(); String location = generateRepositoryLocation(fileName); Bundle bundle = bundleContext.getBundle(location); boolean classpathBundle = false; if (bundle == null) { bundle = findBundleBySymbolicName(identifier); if (bundle != null) { NodeRef deletedNode = uninstallAndDeleteBundle(bundle); if (deletedNode != null) { logger.warn("Deleted existing repository bundle {} with an identical Symbolic name: {}.", deletedNode, identifier.getSymbolicName()); bundle = null; } else { classpathBundle = true; } } } InputStream inputStream = createStreamForFile(jarToInstall); if (bundle != null) { bundle.stop(); bundle.update(inputStream); FrameworkWiring wiring = getFrameworkWiring(); HashSet<Bundle> bundleSet = new HashSet<Bundle>(); bundleSet.add(bundle); wiring.resolveBundles(bundleSet); if (!isFragmentBundle(bundle)) { bundlesToStart.offer(bundle); Bundle[] dependantBundles = wiring.getDependencyClosure(bundleSet) .stream() .filter(bndl -> bndl.getState() == Bundle.ACTIVE) .toArray(Bundle[]::new); ArrayList<Bundle> dependantBundlesList = new ArrayList<Bundle>(Arrays.asList(dependantBundles)); List<Bundle> dependantBundlesSorted = BundleDependencies.sortByDependencies(dependantBundlesList); dependantBundlesSorted.sort(Collections.reverseOrder()); for (Bundle dependant : dependantBundlesSorted) { dependant.stop(); } for (Bundle dependant : dependantBundlesSorted) { bundlesToStart.offer(dependant); } wiring.refreshBundles(bundleSet, this); } else { return bundle; } } else { bundle = bundleContext.installBundle(location, inputStream); if (!isFragmentBundle(bundle)) { bundle.start(); installResults.add(new InstallResult(null)); } } if (bundle != null) { if (!classpathBundle) { BundleManifest manifest = createBundleManifest(bundle); saveBundleInRepository(jarToInstall, fileName, manifest); } else { logger.warn("Temporarily updated classpath bundle: {}, update will be reverted after restart.", bundle.getSymbolicName()); } try { BundleHelperCompanion.evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES)); } catch (InterruptedException tx) { logger.warn("Timed out waiting for an installation result", tx); } resetWebScriptsCache(); } return bundle; } catch (IOException e) { e.printStackTrace(); return null; } finally { } } BundleHelper();  BundleHelper(BundleContext bundleContext,
            RepositoryStoreService repositoryStoreService,
            FileFolderService fileFolderService,
            ContentService contentService,
            NodeService nodeService,
            Container webScriptsContainer); BundleContext getBundleContext(); String getBundleRepositoryLocation(); @PostConstruct ServiceRegistration registerEventListeners(); List<Bundle> getFrameworkBundles(); List<Bundle> getExtensionBundles(); Bundle getBundle(Long id); Bundle installBundleInRepository(FormField file); Bundle installBundleInRepository(Content content); NodeRef uninstallAndDeleteBundle(Bundle bundle); ServiceReference<?>[] getAllServices(); @Override void onEvent(SpringContextException event); @Override Class<?>[] supportedEventTypes(); @Override void frameworkEvent(FrameworkEvent event);  }