/** * Creates a Closeable object that can be used to to switch to current class * loader to the framework class loader and will automatically set the * ClassLoader back to the previous class loader when closed * * @return a NarCloseable */ public static NarCloseable withFrameworkNar() { final ClassLoader frameworkClassLoader; try { frameworkClassLoader = NarClassLoadersHolder.getInstance().getFrameworkBundle().getClassLoader(); } catch (final Exception e) { // This should never happen in a running instance, but it will occur in unit tests logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders."); if (logger.isDebugEnabled()) { logger.error("", e); } return new NarCloseable(null); } final ClassLoader current = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(frameworkClassLoader); return new NarCloseable(current); }
final List<BundleDetails> additionalBundleDetails = loadBundleDetails(additionalUnpackedNars); for (final Bundle bundle : getBundles()) { final BundleDetails bundleDetail = bundle.getBundleDetails(); final String bundleId = bundleDetail.getCoordinate().getId(); try { final ClassLoader bundleClassLoader = createBundleClassLoader(bundleDetail, bundleIdToCoordinatesLookup); if (bundleClassLoader != null) { final Bundle bundle = new Bundle(bundleDetail, bundleClassLoader);
/** * Initializes and loads the NarClassLoaders. This method must be called * before the rest of the methods to access the classloaders are called and * it can be safely called any number of times provided the same framework * and extension working dirs are used. * * @param frameworkWorkingDir where to find framework artifacts * @param extensionsWorkingDir where to find extension artifacts * @throws java.io.IOException if any issue occurs while exploding nar working directories. * @throws java.lang.ClassNotFoundException if unable to load class definition * @throws IllegalStateException already initialized with a given pair of * directories cannot reinitialize or use a different pair of directories. */ public void init(File frameworkWorkingDir, File extensionsWorkingDir) throws IOException, ClassNotFoundException { init(ClassLoader.getSystemClassLoader(), frameworkWorkingDir, extensionsWorkingDir); }
private List<BundleDetails> loadBundleDetails(List<File> unpackedNars) { final List<BundleDetails> narDetails = new ArrayList<>(); for (final File unpackedNar : unpackedNars) { try { final BundleDetails narDetail = getNarDetails(unpackedNar); final BundleCoordinate unpackedNarCoordinate = narDetail.getCoordinate(); // Skip this NAR if there is another NAR with the same group, id, and version final Optional<Bundle> existingBundle = getBundle(unpackedNarCoordinate); if (existingBundle.isPresent()) { final BundleDetails existingBundleDetails = existingBundle.get().getBundleDetails(); final String existingNarWorkingDir = existingBundleDetails.getWorkingDirectory().getCanonicalPath(); final String unpackedNarWorkingDir = narDetail.getWorkingDirectory().getCanonicalPath(); logger.error("Unable to load NAR with coordinates {} and working directory {} " + "because another NAR with the same coordinates already exists at {}", new Object[]{unpackedNarCoordinate, unpackedNarWorkingDir, existingNarWorkingDir}); } else { narDetails.add(narDetail); } } catch (Exception e) { logger.error("Unable to load NAR {} due to {}, skipping...", new Object[]{unpackedNar.getAbsolutePath(), e.getMessage()}); } } return narDetails; }
final ClassLoader jettyClassLoader = getJettyBundle().getClassLoader(); bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), jettyClassLoader); } else { final Optional<Bundle> dependencyBundle = getBundle(bundleDependencyCoordinate); bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), narDependencyClassLoader); } else { final Optional<Bundle> matchingDependencyIdBundle = getBundle(coordinate); if (matchingDependencyIdBundle.isPresent()) { final String dependencyCoordinateStr = bundleDependencyCoordinate.getCoordinate(); bundleClassLoader = createNarClassLoader(bundleDetail.getWorkingDirectory(), narDependencyClassLoader);
NarClassLoaders.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory()); final ClassLoader frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader(); if (frameworkClassLoader == null) { throw new IllegalStateException("Unable to find the framework NAR ClassLoader."); final Set<Bundle> narBundles = NarClassLoaders.getInstance().getBundles();
narClassLoaders.init(rootClassLoader, properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory()); final ClassLoader frameworkClassLoader = narClassLoaders.getFrameworkBundle().getClassLoader(); if (frameworkClassLoader == null) { throw new IllegalStateException("Unable to find the framework NAR ClassLoader."); final Set<Bundle> narBundles = narClassLoaders.getBundles();
/** * Creates a Closeable object that can be used to to switch to current class * loader to the framework class loader and will automatically set the * ClassLoader back to the previous class loader when closed * * @return a NarCloseable */ public static NarCloseable withFrameworkNar() { final ClassLoader frameworkClassLoader; try { frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader(); } catch (final Exception e) { // This should never happen in a running instance, but it will occur in unit tests logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders."); if (logger.isDebugEnabled()) { logger.error("", e); } return new NarCloseable(null); } final ClassLoader current = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(frameworkClassLoader); return new NarCloseable(current); }
BundleDetails narDetail = null; try { narDetail = getNarDetails(unpackedNar); } catch (IllegalStateException e) { logger.warn("Unable to load NAR {} due to {}, skipping...", jettyClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), rootClassloader); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), jettyClassLoader); } else { final String dependencyCoordinateStr = narDependencyCoordinate.getCoordinate(); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader); } else { narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader);
/** * @return The singleton instance of the NarClassLoaders */ public static NarClassLoaders getInstance() { if (INSTANCE == null) { synchronized (NarClassLoadersHolder.class) { if (INSTANCE == null) { INSTANCE = new NarClassLoaders(); } } } return INSTANCE; }
ic = initContext; if (ic == null) { initContext = ic = load(rootClassloader, frameworkWorkingDir, extensionsWorkingDir);
NarClassLoaders.getInstance().init(properties.getFrameworkWorkingDirectory(), properties.getExtensionsWorkingDirectory()); final ClassLoader frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader(); if (frameworkClassLoader == null) { throw new IllegalStateException("Unable to find the framework NAR ClassLoader."); final Set<Bundle> narBundles = NarClassLoaders.getInstance().getBundles();
/** * Creates a Closeable object that can be used to to switch to current class * loader to the framework class loader and will automatically set the * ClassLoader back to the previous class loader when closed * * @return a NarCloseable */ public static NarCloseable withFrameworkNar() { final ClassLoader frameworkClassLoader; try { frameworkClassLoader = NarClassLoaders.getInstance().getFrameworkBundle().getClassLoader(); } catch (final Exception e) { // This should never happen in a running instance, but it will occur in unit tests logger.error("Unable to access Framework ClassLoader due to " + e + ". Will continue without changing ClassLoaders."); if (logger.isDebugEnabled()) { logger.error("", e); } return new NarCloseable(null); } final ClassLoader current = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(frameworkClassLoader); return new NarCloseable(current); }
BundleDetails narDetail = null; try { narDetail = getNarDetails(unpackedNar); } catch (IllegalStateException e) { logger.warn("Unable to load NAR {} due to {}, skipping...", narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), currentContextClassLoader); } else { final String dependencyCoordinateStr = narDependencyCoordinate.getCoordinate(); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader); } else { narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader);
/** * @return The singleton instance of the NarClassLoaders */ public static NarClassLoaders getInstance() { NarClassLoaders result = ncl; if (result == null) { synchronized (NarClassLoaders.class) { result = ncl; if (result == null) { ncl = result = new NarClassLoaders(); } } } return result; }
ic = initContext; if (ic == null) { initContext = ic = load(frameworkWorkingDir, extensionsWorkingDir);
ClassLoader currentCl = null; final Bundle frameworkBundle = NarClassLoadersHolder.getInstance().getFrameworkBundle(); if (frameworkBundle != null) { currentCl = Thread.currentThread().getContextClassLoader();
BundleDetails narDetail = null; try { narDetail = getNarDetails(unpackedNar); } catch (IllegalStateException e) { logger.warn("Unable to load NAR {} due to {}, skipping...", narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), currentContextClassLoader); } else { final String dependencyCoordinateStr = narDependencyCoordinate.getCoordinate(); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader); } else { narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader);
/** * @return The singleton instance of the NarClassLoaders */ public static NarClassLoaders getInstance() { NarClassLoaders result = ncl; if (result == null) { synchronized (NarClassLoaders.class) { result = ncl; if (result == null) { ncl = result = new NarClassLoaders(); } } } return result; }
ic = initContext; if (ic == null) { initContext = ic = load(frameworkWorkingDir, extensionsWorkingDir);