Skip to content

Commit

Permalink
Fix jarJar edge case with available-at variants (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Jul 24, 2024
1 parent ed5a151 commit d722afb
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -141,6 +142,8 @@ private static List<ResolvedJarJarArtifact> getIncludedJars(DependencyFilter fil

if (version != null && versionRange != null) {
data.add(new ResolvedJarJarArtifact(result.getFile(), version, versionRange, jarIdentifier.group(), jarIdentifier.artifact()));
} else {
throw new IllegalStateException("Could not determine version or version range for " + jarIdentifier.group()+":"+jarIdentifier.artifact());
}
}
return data.stream()
Expand All @@ -150,18 +153,22 @@ private static List<ResolvedJarJarArtifact> getIncludedJars(DependencyFilter fil

private static void collectFromComponent(ResolvedComponentResult rootComponent, Set<ContainedJarIdentifier> knownIdentifiers, Map<ContainedJarIdentifier, String> versions, Map<ContainedJarIdentifier, String> versionRanges) {
for (DependencyResult result : rootComponent.getDependencies()) {
if (!(result instanceof ResolvedDependencyResult)) {
if (!(result instanceof ResolvedDependencyResult resolvedResult)) {
continue;
}
ResolvedDependencyResult resolvedResult = (ResolvedDependencyResult) result;
ComponentSelector requested = resolvedResult.getRequested();
ResolvedVariantResult variant = resolvedResult.getResolvedVariant();

ResolvedVariantResult originalVariant = resolvedResult.getResolvedVariant();
ResolvedVariantResult variant = originalVariant;
// We do this to account for any available-at usage in module metadata -- the actual artifact will only have
// the module ID of the final target of available-at, but the resolved dependency lets us get the whole
// hierarchy.
while (variant.getExternalVariant().isPresent()) {
variant = variant.getExternalVariant().get();
}
DependencyManagementObject.ArtifactIdentifier artifactIdentifier = capabilityOrModule(variant);
if (artifactIdentifier == null) {
continue;
}

ContainedJarIdentifier jarIdentifier = new ContainedJarIdentifier(artifactIdentifier.getGroup(), artifactIdentifier.getName());
knownIdentifiers.add(jarIdentifier);

Expand All @@ -183,6 +190,13 @@ private static void collectFromComponent(ResolvedComponentResult rootComponent,
}

String version = getVersionFrom(variant);
String originalVersion = getVersionFrom(originalVariant);

if (!Objects.equals(version, originalVersion)) {
throw new IllegalStateException("Version mismatch for " + originalVariant.getOwner() + ": available-at directs to " +
version + " but original is " + originalVersion + " which jarJar cannot handle well; consider depending on the available-at target directly"
);
}

if (version != null) {
versions.put(jarIdentifier, version);
Expand Down

0 comments on commit d722afb

Please sign in to comment.