@Test void nestedDependency(@TempDir final File temporaryFolder) throws IOException { final File file = new File(temporaryFolder, UUID.randomUUID().toString() + ".jar"); file.getParentFile().mkdirs(); try (final JarOutputStream enclosing = new JarOutputStream(new FileOutputStream(file))) { enclosing.putNextEntry(new ZipEntry("MAVEN-INF/repository/foo/bar/dummy/1.0.0/dummy-1.0.0.jar")); try (final JarOutputStream nested = new JarOutputStream(enclosing)) { nested.putNextEntry(new ZipEntry("TALEND-INF/dependencies.txt")); nested .write(new DependenciesTxtBuilder() .withDependency("org.apache.tomee:ziplock:jar:7.0.5:runtime") .withDependency("org.apache.tomee:javaee-api:jar:7.0-1:compile") .build() .getBytes(StandardCharsets.UTF_8)); } } try (final URLClassLoader tempLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, getSystemClassLoader())) { final List<String> toResolve = new MvnDependencyListLocalRepositoryResolver("TALEND-INF/dependencies.txt", d -> null) .resolve(tempLoader, "foo/bar/dummy/1.0.0/dummy-1.0.0.jar") .map(Artifact::toPath) .collect(toList()); assertEquals(asList("org/apache/tomee/ziplock/7.0.5/ziplock-7.0.5.jar", "org/apache/tomee/javaee-api/7.0-1/javaee-api-7.0-1.jar"), toResolve); } }
@Override public Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact) { return Stream .of(readDependencies(ofNullable(getJar(artifact)) .filter(Files::exists) .map(this::findDependenciesFile) .orElseGet(() -> { final boolean isNested; try (final InputStream stream = rootLoader .getResourceAsStream(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + artifact)) { isNested = stream != null; } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } if (isNested) { try (final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], rootLoader, name -> true, name -> true, new String[] { artifact }, new String[0])) { try (final InputStream deps = configurableClassLoader.getResourceAsStream(dependenciesListFile)) { return ofNullable(deps).map(s -> { try { return slurp(s); } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } }).orElse(""); } } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } } return ""; }))); }
MvnDependencyListLocalRepositoryResolver implements Resolver { @Override public Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact) { return Stream .of(readDependencies(ofNullable(getJar(artifact)) .filter(Files::exists) .map(this::findDependenciesFile) .orElseGet(() -> { final boolean isNested; try (final InputStream stream = rootLoader .getResourceAsStream(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + artifact)) { isNested = stream != null; } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } if (isNested) { try (final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], rootLoader, name -> true, name -> true, new String[] { artifact }, new String[0])) { try (final InputStream deps = configurableClassLoader.getResourceAsStream(dependenciesListFile)) { return ofNullable(deps).map(s -> { try { return slurp(s); } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } }).orElse(""); } } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } } return ""; }))); } }
MvnDependencyListLocalRepositoryResolver implements Resolver { @Override public Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact) { return Stream .of(readDependencies(ofNullable(getJar(artifact)) .filter(Files::exists) .map(this::findDependenciesFile) .orElseGet(() -> { final boolean isNested; try (final InputStream stream = rootLoader .getResourceAsStream(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + artifact)) { isNested = stream != null; } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } if (isNested) { try (final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], rootLoader, name -> true, name -> true, new String[] { artifact }, new String[0])) { try (final InputStream deps = configurableClassLoader.getResourceAsStream(dependenciesListFile)) { return ofNullable(deps).map(s -> { try { return slurp(s); } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } }).orElse(""); } } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } } return ""; }))); }  }
MvnDependencyListLocalRepositoryResolver implements Resolver { @Override public Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact) { return Stream .of(readDependencies(ofNullable(getJar(artifact)) .filter(Files::exists) .map(this::findDependenciesFile) .orElseGet(() -> { final boolean isNested; try (final InputStream stream = rootLoader .getResourceAsStream(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + artifact)) { isNested = stream != null; } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } if (isNested) { try (final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], rootLoader, name -> true, name -> true, new String[] { artifact }, new String[0])) { try (final InputStream deps = configurableClassLoader.getResourceAsStream(dependenciesListFile)) { return ofNullable(deps).map(s -> { try { return slurp(s); } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } }).orElse(""); } } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } } return ""; }))); }  @Override Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact); Stream<Artifact> resolveFromDescriptor(final InputStream descriptor); }
MvnDependencyListLocalRepositoryResolver implements Resolver { @Override public Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact) { return Stream .of(readDependencies(ofNullable(getJar(artifact)) .filter(Files::exists) .map(this::findDependenciesFile) .orElseGet(() -> { final boolean isNested; try (final InputStream stream = rootLoader .getResourceAsStream(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + artifact)) { isNested = stream != null; } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } if (isNested) { try (final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], rootLoader, name -> true, name -> true, new String[] { artifact }, new String[0])) { try (final InputStream deps = configurableClassLoader.getResourceAsStream(dependenciesListFile)) { return ofNullable(deps).map(s -> { try { return slurp(s); } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } }).orElse(""); } } catch (final IOException e) { log.debug(e.getMessage(), e); return ""; } } return ""; }))); }  @Override Stream<Artifact> resolve(final ClassLoader rootLoader, final String artifact); Stream<Artifact> resolveFromDescriptor(final InputStream descriptor);  }