From eb33432ceaa134530fb2cbe86efb0afb5eb6b383 Mon Sep 17 00:00:00 2001 From: forax Date: Sat, 13 Oct 2018 12:45:46 +0200 Subject: [PATCH] the resolver should also check artifact jars if there are merged --- .../pro/plugin/resolver/ResolverPlugin.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com.github.forax.pro.plugin.resolver/com/github/forax/pro/plugin/resolver/ResolverPlugin.java b/src/main/java/com.github.forax.pro.plugin.resolver/com/github/forax/pro/plugin/resolver/ResolverPlugin.java index fa9cf91..62434c9 100644 --- a/src/main/java/com.github.forax.pro.plugin.resolver/com/github/forax/pro/plugin/resolver/ResolverPlugin.java +++ b/src/main/java/com.github.forax.pro.plugin.resolver/com/github/forax/pro/plugin/resolver/ResolverPlugin.java @@ -3,6 +3,7 @@ import static com.github.forax.pro.api.MutableConfig.derive; import static com.github.forax.pro.helper.util.Lazy.lazy; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; import java.io.IOException; import java.io.UncheckedIOException; @@ -254,12 +255,14 @@ public int execute(Config config) throws IOException { switch(resolvedArtifactList.size()) { case 1: { var resolvedArtifact = resolvedArtifactList.get(0); - checkArtifactModuleName(log, moduleName, resolvedArtifact); + var moduleReferenceOpt = validateModuleReferenceFromArtifact(log, resolvedArtifact); + moduleReferenceOpt.ifPresent(ref -> checkArtifactModuleName(log, moduleName, ref, resolvedArtifact)); Files.copy(resolvedArtifact.getPath(), jarPath); break; } default: - mergeInOneJar(resolvedArtifactList.stream().map(ArtifactDescriptor::getPath).collect(Collectors.toList()), jarPath, log); + resolvedArtifactList.forEach(artifact -> validateModuleReferenceFromArtifact(log, artifact)); + mergeInOneJar(resolvedArtifactList.stream().map(ArtifactDescriptor::getPath).collect(toList()), jarPath, log); } } @@ -278,21 +281,25 @@ private static void verifyDeclaration(String kind, Set unresolvedModules } } - private static void checkArtifactModuleName(Log log, String moduleName, ArtifactDescriptor resolvedArtifact) { + private static Optional validateModuleReferenceFromArtifact(Log log, ArtifactDescriptor resolvedArtifact) { var finder = ModuleFinder.of(resolvedArtifact.getPath()); Set moduleReferences; try { moduleReferences = finder.findAll(); } catch (FindException e) { log.info(null, __ -> "WARNING! finding " + resolvedArtifact + " failed: " + e); - return; + return Optional.empty(); } var referenceOpt = moduleReferences.stream().findFirst(); if (!referenceOpt.isPresent()) { log.info(null, __ -> "WARNING! artifact " + resolvedArtifact + " is not a valid jar"); - return; + return Optional.empty(); } - var descriptor = referenceOpt.get().descriptor(); + return referenceOpt; + } + + private static void checkArtifactModuleName(Log log, String moduleName, ModuleReference moduleReference, ArtifactDescriptor resolvedArtifact) { + var descriptor = moduleReference.descriptor(); if (descriptor.isAutomatic()) { return; }