@Override public synchronized ClassLoader createClassLoader(PluginsSource source) throws Exception { // NOSONAR final String id = id(source); clearClassLoader(id); if (StringUtils.isEmpty(source.getArtifact())) { return Thread.currentThread().getContextClassLoader(); } URL[] urls = aether.resolve(source.getArtifact()).getAsUrls(); List<URL> tempUrls = new ArrayList<>(); File tempDir = FileUtil.createTempDirectory(); for (URL url : urls) { File origin = new File(url.toURI()); File temp = createTempFile(origin.getName(), ".jar", tempDir); copyFile(origin, temp); tempUrls.add(temp.toURI().toURL()); } final CamelotUrlClassloader classLoader = new CamelotUrlClassloader( tempUrls.toArray(new URL[tempUrls.size()]), Thread.currentThread().getContextClassLoader()); classLoadersCache.put(id, new Entry(classLoader, tempDir)); return classLoader; }
/** Generate the id for the loader */ private String id(PluginsSource source) { return source.getArtifact() + "-" + identityHashCode(source); }