public ChildFirstClassLoaderBuilder addMavenResourceURL(String artifactGav) throws IOException, ClassNotFoundException { final String name = "maven-" + escape(artifactGav); final Path file = new File(cache, name).toPath(); if (Files.exists(file)) { log.trace("Using cached maven url for " + artifactGav + " from " + file.toAbsolutePath().toString()); try (final ObjectInputStream in = new ObjectInputStream(Files.newInputStream(file))){ classloaderURLs.add((URL)in.readObject()); } catch (Exception e) { log.warn("Error loading cached maven url for " + artifactGav + " from " + file.toAbsolutePath().toString()); throw e; } } else { log.trace("No cached maven url for " + artifactGav + " found. " + file.toAbsolutePath().toString() + " does not exist."); final URL url = mavenUtil.createMavenGavURL(artifactGav); classloaderURLs.add(url); try (final ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(Files.newOutputStream(file)))){ out.writeObject(url); } catch (Exception e) { log.warn("Error writing cached maven url for " + artifactGav + " to " + file.toAbsolutePath().toString()); throw e; } } return this; }
public ChildFirstClassLoaderBuilder addRecursiveMavenResourceURL(String artifactGav, String... excludes) throws DependencyCollectionException, DependencyResolutionException, IOException, ClassNotFoundException { final String name = "maven-recursive-" + escape(artifactGav); final Path file = new File(cache, name).toPath(); if (Files.exists(file)) { log.trace("Using cached recursive maven urls for " + artifactGav + " from " + file.toAbsolutePath().toString()); try (final ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(Files.newInputStream(file)))){ classloaderURLs.addAll((List<URL>)in.readObject()); } catch (Exception e) { log.warn("Error loading cached recursive maven urls for " + artifactGav + " from " + file.toAbsolutePath().toString()); throw e; } } else { log.trace("No cached recursive maven urls for " + artifactGav + " found. " + file.toAbsolutePath().toString() + " does not exist."); final List<URL> urls = mavenUtil.createMavenGavRecursiveURLs(artifactGav, excludes); classloaderURLs.addAll(urls); try (final ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(Files.newOutputStream(file)))){ out.writeObject(urls); } catch (Exception e) { log.warn("Error writing cached recursive maven urls for " + artifactGav + " to " + file.toAbsolutePath().toString()); throw e; } } return this; }