SystemDependencyResolution implements DependencyResolution { @Override public Set<String> resolve(List<String> exclusions) throws IOException { final Set<String> archivesPaths = new HashSet<>(); exclusions.replaceAll(s -> s.replace('.', File.separatorChar)); if (classpath != null) { ApplicationEnvironment env = ApplicationEnvironment.get(); Set<String> classpathElements = new HashSet<>(); Set<String> providedGAVs = new HashSet<>(); List<String> testClasspathElements = testClasspath != null ? testClasspath : Collections.emptyList(); for (final String element : classpath) { if (!element.startsWith(javaHome) && !element.startsWith(pwd + File.separatorChar) && !element.endsWith(".pom")) { if (!excluded(exclusions, element)) { classpathElements.add(element); } } } providedGAVs.addAll( env.getRemovableDependencies() .stream() .map(e -> e.split(":")) .map(e -> e[0] + File.separatorChar + e[1] + File.separatorChar) .map(m -> (useGradleRepo ? m : m.replace('.', File.separatorChar))) .collect(Collectors.toList()) ); for (final String element : classpathElements) { boolean excludedByProvidedGAVs = excluded(providedGAVs, element); boolean excludedByTestClasspath = excluded(testClasspathElements, element); if (!excludedByProvidedGAVs && !excludedByTestClasspath) { archivesPaths.add(element); } } } return archivesPaths; } SystemDependencyResolution(); @Override Set<String> resolve(List<String> exclusions);  }
@Test public void testResolve_withGradle() throws IOException { String group = "org.wildfly.swarm"; String packaging = "jar"; String artifact1 = "test"; String artifact2 = "test2"; String version = "1.0"; String classpathFile1 = buildGradleClassPathEntry(group, artifact1, version, packaging); String classpathFile2 = buildGradleClassPathEntry(group, artifact2, version, packaging); String classpath = classpathFile1 + File.pathSeparator + classpathFile2; System.setProperty("java.class.path", classpath); ApplicationEnvironment env = ApplicationEnvironment.get(); env.getRemovableDependencies().add(group+":"+artifact1+":"+packaging+":"+version); SystemDependencyResolution resolution = new SystemDependencyResolution(); Set<String> result = resolution.resolve(Collections.emptyList()); assertEquals(1,result.size()); assertEquals(classpathFile2, result.iterator().next()); }
@Test public void testResolve_withMaven() throws IOException { String group = "org.wildfly.swarm"; String packaging = "jar"; String artifact1 = "test"; String artifact2 = "test2"; String version = "1.0"; String classpathFile1 = buildMavenClassPathEntry(group, artifact1, version, packaging); String classpathFile2 = buildMavenClassPathEntry(group, artifact2, version, packaging); String classpath = classpathFile1 + File.pathSeparator + classpathFile2; System.setProperty("java.class.path", classpath); ApplicationEnvironment env = ApplicationEnvironment.get(); env.getRemovableDependencies().add(group+":"+artifact1+":"+packaging+":"+version); SystemDependencyResolution resolution = new SystemDependencyResolution(); Set<String> result = resolution.resolve(Collections.emptyList()); assertEquals(1,result.size()); assertEquals(classpathFile2, result.iterator().next()); }