|
60 | 60 | import org.eclipse.aether.resolution.DependencyRequest; |
61 | 61 | import org.eclipse.aether.resolution.DependencyResolutionException; |
62 | 62 | import org.eclipse.aether.resolution.DependencyResult; |
63 | | -import org.graalvm.buildtools.utils.FileUtils; |
64 | 63 | import org.graalvm.buildtools.utils.JUnitUtils; |
65 | 64 | import org.graalvm.buildtools.utils.NativeImageConfigurationUtils; |
66 | | -import org.w3c.dom.Document; |
67 | | -import org.xml.sax.SAXException; |
68 | 65 |
|
69 | | -import javax.xml.parsers.DocumentBuilder; |
70 | | -import javax.xml.parsers.DocumentBuilderFactory; |
71 | | -import javax.xml.parsers.ParserConfigurationException; |
72 | | -import java.io.File; |
73 | 66 | import java.io.IOException; |
74 | 67 | import java.io.UncheckedIOException; |
75 | 68 | import java.nio.file.Files; |
|
82 | 75 | import java.util.HashSet; |
83 | 76 | import java.util.List; |
84 | 77 | import java.util.Set; |
85 | | -import java.util.regex.Pattern; |
86 | 78 | import java.util.stream.Collectors; |
87 | 79 | import java.util.stream.Stream; |
88 | 80 |
|
@@ -141,8 +133,6 @@ protected void addDependenciesToClasspath() throws MojoExecutionException { |
141 | 133 | .filter(it -> it.getGroupId().startsWith(NativeImageConfigurationUtils.MAVEN_GROUP_ID) || it.getGroupId().startsWith("org.junit")) |
142 | 134 | .map(it -> it.getFile().toPath()) |
143 | 135 | .forEach(imageClasspath::add); |
144 | | - |
145 | | - modules.addAll(collectJUnitModulesAlreadyOnClasspath()); |
146 | 136 | var jars = findJunitPlatformNativeJars(modules); |
147 | 137 | imageClasspath.addAll(jars); |
148 | 138 | } |
@@ -318,51 +308,6 @@ private List<Path> findJunitPlatformNativeJars(Set<Module> modulesAlreadyOnClass |
318 | 308 | .collect(Collectors.toList()); |
319 | 309 | } |
320 | 310 |
|
321 | | - private Set<Module> collectJUnitModulesAlreadyOnClasspath() { |
322 | | - Set<Module> artifacts = new HashSet<>(); |
323 | | - for (Path entry : imageClasspath) { |
324 | | - if (isJUnitArtifact(entry)) { |
325 | | - File pom = getArtifactPOM(entry); |
326 | | - if (pom != null) { |
327 | | - artifacts.add(getModuleFromPOM(pom)); |
328 | | - } |
329 | | - } |
330 | | - } |
331 | | - |
332 | | - return artifacts; |
333 | | - } |
334 | | - |
335 | | - private boolean isJUnitArtifact(Path entry) { |
336 | | - return entry.toString().contains("junit"); |
337 | | - } |
338 | | - |
339 | | - private File getArtifactPOM(Path classpathEntry) { |
340 | | - List<File> artifactContent = getArtifactContent(classpathEntry.getParent()); |
341 | | - List<File> candidates = artifactContent.stream().filter(f -> f.getName().endsWith(".pom")).collect(Collectors.toList()); |
342 | | - return candidates.size() != 1 ? null : candidates.get(0); |
343 | | - } |
344 | | - |
345 | | - private List<File> getArtifactContent(Path path) { |
346 | | - File[] content = path.toFile().listFiles(); |
347 | | - return content == null ? List.of() : List.of(content); |
348 | | - } |
349 | | - |
350 | | - private Module getModuleFromPOM(File pom) { |
351 | | - try { |
352 | | - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
353 | | - factory.setIgnoringElementContentWhitespace(true); |
354 | | - DocumentBuilder builder = factory.newDocumentBuilder(); |
355 | | - Document doc = builder.parse(pom); |
356 | | - |
357 | | - String groupId = doc.getElementsByTagName("groupId").item(0).getFirstChild().getTextContent(); |
358 | | - String artifactId = doc.getElementsByTagName("artifactId").item(0).getFirstChild().getTextContent(); |
359 | | - |
360 | | - return new Module(groupId, artifactId); |
361 | | - } catch (ParserConfigurationException | IOException | SAXException e) { |
362 | | - throw new RuntimeException("Cannot get maven coordinates from " + pom.getPath() + ". Reason: " + e.getMessage()); |
363 | | - } |
364 | | - } |
365 | | - |
366 | 311 | private static final class Module { |
367 | 312 | private final String groupId; |
368 | 313 | private final String artifactId; |
|
0 commit comments