private static ClassLoader resolveClassLoader( Map<String, ClassLoader> classLoaders, List<String> seen, Map<String, Classpath> classpaths, String id) throws MalformedURLException { if (classLoaders.containsKey(id)) { return classLoaders.get(id); } if (seen.contains(id)) { throw new ConfigurationException(MessageNames.CIRCULAR_CLASSPATH, id); } // Add the id to the list of classloaders we have attempted to build. seen.add(id); Classpath classpath = classpaths.get(id); if (classpath == null) { throw new ConfigurationException(MessageNames.CLASSPATH_UNDEFINED, id); } String parentClasspathId = classpath.getParent(); ClassLoader parentClassLoader = null; if (parentClasspathId != null && !Strings.EMPTY.equals(parentClasspathId)) { parentClassLoader = resolveClassLoader(classLoaders, seen, classpaths, parentClasspathId); } else { /* Should be the 'extension' classloader. */ parentClassLoader = Bootstrap.class.getClassLoader().getParent(); } URL[] classpathUrls; classpathUrls = findClasspathURLS(classpath.getValue()); SettableCodebaseClassLoader classLoader = new SettableCodebaseClassLoader(classpathUrls, parentClassLoader); classLoaders.put(id, classLoader); log.log( Level.FINE, MessageNames.CONFIGURED_CLASSPATH, new Object[] {id, Utils.format(classpathUrls)}); seen.remove(id); return classLoader; }
private static Map<String, ClassLoader> createClassLoaders(ContainerConfig config) throws MalformedURLException { Map<String, ClassLoader> classLoaders = new HashMap<String, ClassLoader>(); classLoaders.put(Strings.BOOTSTRAP_CLASS_LOADER, Bootstrap.class.getClassLoader()); /* Setup the classloaders according to the config file. */ List<String> seen = new LinkedList<String>(); Map<String, Classpath> classpaths = new HashMap<String, Classpath>(); for (Classpath classpath : config.getClasspath()) { if (classpaths.containsKey(classpath.getId())) { throw new ConfigurationException(MessageNames.DUPLICATE_CLASSPATH, classpath.getId()); } classpaths.put(classpath.getId(), classpath); } for (String id : classpaths.keySet()) { resolveClassLoader(classLoaders, seen, classpaths, id); } return classLoaders; }
private Classpath createClasspathWithTwoElements() { return Classpath.emptyClasspath() .addClassPathElementUrl(FIRST_ELEMENT) .addClassPathElementUrl(SECOND_ELEMENT); }
public void testReadFromPropertiesWithEmptyProperties() throws Exception { Classpath recreatedClasspath = readClasspathFromProperties(); assertTrue(recreatedClasspath.getClassPath().isEmpty()); }