Skip to content

Commit

Permalink
the resolver should also check artifact jars if there are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
forax committed Oct 13, 2018
1 parent eac9f06 commit eb33432
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -278,21 +281,25 @@ private static void verifyDeclaration(String kind, Set<String> unresolvedModules
}
}

private static void checkArtifactModuleName(Log log, String moduleName, ArtifactDescriptor resolvedArtifact) {
private static Optional<ModuleReference> validateModuleReferenceFromArtifact(Log log, ArtifactDescriptor resolvedArtifact) {
var finder = ModuleFinder.of(resolvedArtifact.getPath());
Set<ModuleReference> 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;
}
Expand Down

0 comments on commit eb33432

Please sign in to comment.