Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8180] Handle NPE due non-existent tags #1641

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
// - maven-plugin-api (for model)
// - Plexus Container (for model supporting classes and exceptions)
Xpp3Dom root = Xpp3DomBuilder.build(reader);
String groupId = root.getChild("groupId").getValue();
String artifactId = root.getChild("artifactId").getValue();
String goalPrefix = root.getChild("goalPrefix").getValue();
String name = root.getChild("name").getValue();
String groupId = mayGetChild(root, "groupId");
String artifactId = mayGetChild(root, "artifactId");
String goalPrefix = mayGetChild(root, "goalPrefix");
String name = mayGetChild(root, "name");
// sanity check: plugin descriptor extracted from artifact must have same GA
if (Objects.equals(artifact.getGroupId(), groupId)
&& Objects.equals(artifact.getArtifactId(), artifactId)) {
// here groupId and artifactId cannot be null
return new PluginInfo(groupId, artifactId, goalPrefix, name);
} else {
throw new InvalidArtifactPluginMetadataException(
Expand All @@ -151,16 +152,25 @@ private PluginInfo extractPluginInfo(Artifact artifact) {
}
}
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
if (e instanceof InvalidArtifactPluginMetadataException) {
throw (InvalidArtifactPluginMetadataException) e;
}
// here we can have: IO. ZIP or Plexus Conf Ex: but we should not interfere with user intent
}
}
}
return null;
}

private static String mayGetChild(Xpp3Dom node, String child) {
Xpp3Dom c = node.getChild(child);
if (c != null) {
return c.getValue();
}
return null;
}

public static final class InvalidArtifactPluginMetadataException extends IllegalArgumentException {
InvalidArtifactPluginMetadataException(String s) {
super(s);
Expand Down