Skip to content

Commit

Permalink
Add better support for includeBuild when creating Minecraft artifacts (
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Jul 1, 2024
1 parent 9eec30e commit c8ebfb7
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -830,24 +830,35 @@ static String guessMavenGav(ResolvedArtifactResult result) {
String artifactId;
String ext = "";
String classifier = null;

var filename = result.getFile().getName();
var startOfExt = filename.lastIndexOf('.');
if (startOfExt != -1) {
ext = filename.substring(startOfExt + 1);
filename = filename.substring(0, startOfExt);
}

if (result.getId() instanceof ModuleComponentArtifactIdentifier moduleId) {
var artifact = moduleId.getComponentIdentifier().getModule();
var version = moduleId.getComponentIdentifier().getVersion();
var expectedBasename = artifact + "-" + version;
var filename = result.getFile().getName();
var startOfExt = filename.lastIndexOf('.');
if (startOfExt != -1) {
ext = filename.substring(startOfExt + 1);
filename = filename.substring(0, startOfExt);
}

if (filename.startsWith(expectedBasename + "-")) {
classifier = filename.substring((expectedBasename + "-").length());
}
artifactId = moduleId.getComponentIdentifier().getGroup() + ":" + artifact + ":" + version;
} else {
ext = "jar";
artifactId = result.getId().getComponentIdentifier().toString();
// When we encounter a project reference, the component identifier does not expose the group or module name.
// But we can access the list of capabilities associated with the published variant the artifact originates from.
// If the capability was not overridden, this will be the project GAV. If it is *not* the project GAV,
// it will be at least in valid GAV format, not crashing NFRT when it parses the manifest. It will just be ignored.
var capabilities = result.getVariant().getCapabilities();
if (capabilities.size() == 1) {
var capability = capabilities.get(0);
artifactId = capability.getGroup() + ":" + capability.getName() + ":" + capability.getVersion();
} else {
artifactId = result.getId().getComponentIdentifier().toString();
}
}
String gav = artifactId;
if (classifier != null) {
Expand Down

0 comments on commit c8ebfb7

Please sign in to comment.