private ClassLoader getApplicationClassLoader() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (userClassPath != null) { cl = ClassLoaderFactory.createClassLoader(userClassPath, this.getClass().getClassLoader(), userHome); } return cl; }
public static ClassLoader createClassLoader(String classpath, ClassLoader parent, String userHome) throws Exception { final List<URL> urls = new ArrayList<>(); String[] cps = StringUtils.split(classpath, File.pathSeparatorChar); // PathMatcher is not thread-safe. final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.{zip,jar}"); for (String cp : cps) { if (cp.endsWith("*")) { String substring = cp.substring(0, cp.length() - 1); Files.walkFileTree(makeFile(userHome, substring).toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { urls.add(file.toUri().toURL()); } return super.visitFile(file, attrs); } }); } else { File f = makeFile(userHome, cp); if (!f.exists()) { throw new IOException("File " + f.getPath() + " does not exist"); } urls.add(f.toURI().toURL()); } } URL[] uurl = urls.toArray(new URL[0]); return new URLClassLoader(uurl, parent); }
public void resetOpenL() { userContext = null; OpenL.reset(); OpenLConfiguration.reset(); HashMap<?, ClassLoader> old = ClassLoaderFactory.reset(); JavaOpenClass.resetAllClassloaders(old); }
IConfigurableResourceContext getConfigurationContext(IOpenLConfiguration extendsConfiguration) throws Exception { ClassLoader parentLoader = extendsConfiguration == null ? ClassLoaderFactory.getOpenlCoreLoader(null) : extendsConfiguration.getConfigurationContext().getClassLoader(); ClassLoader myClassLoader = parentLoader; if (classpath != null && classpath.trim().length() != 0) { String baseDir = getProject().getBaseDir().getCanonicalPath(); UserContext ucxt = new UserContext(null, baseDir); myClassLoader = ClassLoaderFactory.createUserClassloader(category, classpath, parentLoader, ucxt); } else { myClassLoader = AntOpenLBuilder.userCxt.top().getUserClassLoader(); } return new ConfigurableResourceContext(myClassLoader, conf); }
public void reset(ReloadType reloadType) throws Exception { switch (reloadType) { case FORCED: OpenL.reset(); OpenLConfiguration.reset(); ClassLoaderFactory.reset(); case RELOAD: modulesCache.reset(); case SINGLE: // Clear the cache of dependency manager, as the project has been modified. studio.getDependencyManager() .reset(new Dependency( DependencyType.MODULE, new IdentifierNode(null, null, moduleInfo.getName(), null))); break; } setModuleInfo(moduleInfo, reloadType); savedSearches = null; projectRoot = null; }
private ClassLoader getApplicationClassLoader() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (userClassPath != null) { cl = ClassLoaderFactory.createClassLoader(userClassPath, this.getClass().getClassLoader(), userHome); } return cl; }
public static ClassLoader createClassLoader(String classpath, ClassLoader parent, String userHome) throws Exception { final List<URL> urls = new ArrayList<>(); String[] cps = StringUtils.split(classpath, File.pathSeparatorChar); // PathMatcher is not thread-safe. final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.{zip,jar}"); for (String cp : cps) { if (cp.endsWith("*")) { String substring = cp.substring(0, cp.length() - 1); Files.walkFileTree(makeFile(userHome, substring).toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { urls.add(file.toUri().toURL()); } return super.visitFile(file, attrs); } }); } else { File f = makeFile(userHome, cp); if (!f.exists()) { throw new IOException("File " + f.getPath() + " does not exist"); } urls.add(f.toURI().toURL()); } } URL[] uurl = urls.toArray(new URL[0]); return new URLClassLoader(uurl, parent); }
private ClassLoader getApplicationClassLoader() throws Exception { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (userClassPath != null) { cl = ClassLoaderFactory.createClassLoader(userClassPath, this.getClass().getClassLoader(), userHome); } return cl; }
private IOpenLBuilder makeBuilder(String openl, IConfigurableResourceContext cxt, IUserContext ucxt) throws Exception { String builderClassPath = cxt.findProperty(openl + BUILDER_CLASS_PATH); if (builderClassPath == null) { builderClassPath = cxt.findProperty(DEFAULT_BUILDER_CLASS_PATH_PROPERTY); } ClassLoader ucl = ucxt.getUserClassLoader(); ClassLoader cl = OpenL.class.getClassLoader(); try { Class<?> c = ucl.loadClass(OpenL.class.getName()); if (c != null) { cl = ucl; } } catch (Exception ignored) { // Ignore } if (builderClassPath != null) { cl = ClassLoaderFactory.createClassLoader(builderClassPath, cl, ucxt.getUserHome()); } String builderClassName = cxt.findProperty(openl + BUILDER_CLASS); if (builderClassName == null) { builderClassName = cxt.findProperty(DEFAULT_BUILDER_CLASS_PROPERTY); } if (builderClassName == null) { builderClassName = openl + "." + OPENL_BUILDER; } return (IOpenLBuilder)ClassFactory.forName(builderClassName, cl).newInstance(); } }
private IOpenLBuilder makeBuilder(String openl, IConfigurableResourceContext cxt, IUserContext ucxt) throws Exception { String builderClassPath = cxt.findProperty(openl + BUILDER_CLASS_PATH); if (builderClassPath == null) { builderClassPath = cxt.findProperty(DEFAULT_BUILDER_CLASS_PATH_PROPERTY); } ClassLoader ucl = ucxt.getUserClassLoader(); ClassLoader cl = OpenL.class.getClassLoader(); try { Class<?> c = ucl.loadClass(OpenL.class.getName()); if (c != null) { cl = ucl; } } catch (Exception ignored) { // Ignore } if (builderClassPath != null) { cl = ClassLoaderFactory.createClassLoader(builderClassPath, cl, ucxt.getUserHome()); } String builderClassName = cxt.findProperty(openl + BUILDER_CLASS); if (builderClassName == null) { builderClassName = cxt.findProperty(DEFAULT_BUILDER_CLASS_PROPERTY); } if (builderClassName == null) { builderClassName = openl + "." + OPENL_BUILDER; } return (IOpenLBuilder)ClassFactory.forName(builderClassName, cl).newInstance(); } }