Skip to content

Commit a9a8c84

Browse files
authored
Make empty classifier null (not empty string) (#287)
And be consistent: as some legacy stuff in Maven and around (plugins) perform just nullcheck and not also empty string check, and get confused on empty string classifier. Plugins are (should) not be reused as dependencies, so despite the helper class is `public` I see no harm to alter it. Supersedes #135 Fixes #138
1 parent a8368b0 commit a9a8c84

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/main/java/org/apache/maven/plugins/gpg/FilesCollector.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.codehaus.plexus.util.SelectorUtils;
3434
import org.eclipse.aether.artifact.Artifact;
3535

36+
import static java.util.Objects.requireNonNull;
37+
3638
/**
3739
* Collects project artifact, the POM, and attached artifacts to be signed.
3840
*
@@ -81,7 +83,7 @@ public List<Item> collect() throws MojoExecutionException, MojoFailureException
8183
File file = artifact.getFile();
8284

8385
if (file != null && file.isFile()) {
84-
items.add(new Item(file, artifact.getExtension()));
86+
items.add(new Item(file, null, artifact.getExtension()));
8587
} else if (project.getAttachedArtifacts().isEmpty()) {
8688
throw new MojoFailureException("The project artifact has not been assembled yet. "
8789
+ "Please do not invoke this goal before the lifecycle phase \"package\".");
@@ -103,7 +105,7 @@ public List<Item> collect() throws MojoExecutionException, MojoFailureException
103105
throw new MojoExecutionException("Error copying POM for signing.", e);
104106
}
105107

106-
items.add(new Item(pomToSign, "pom"));
108+
items.add(new Item(pomToSign, null, "pom"));
107109

108110
// ----------------------------------------------------------------------------
109111
// Attached artifacts
@@ -147,29 +149,32 @@ protected boolean isExcluded(Artifact artifact) {
147149

148150
public static class Item {
149151
private final File file;
150-
151152
private final String classifier;
152-
153153
private final String extension;
154154

155155
public Item(File file, String classifier, String extension) {
156-
this.file = file;
157-
this.classifier = classifier;
158-
this.extension = extension;
159-
}
160-
161-
public Item(File file, String extension) {
162-
this(file, null, extension);
156+
this.file = requireNonNull(file);
157+
this.classifier = classifier == null || classifier.trim().isEmpty() ? null : classifier; // nullable
158+
this.extension = requireNonNull(extension);
163159
}
164160

161+
/**
162+
* The artifact backing file, never {@code null}.
163+
*/
165164
public File getFile() {
166165
return file;
167166
}
168167

168+
/**
169+
* The classifier, if present, or {@code null}.
170+
*/
169171
public String getClassifier() {
170172
return classifier;
171173
}
172174

175+
/**
176+
* The file extension (without leading period), never {@code null}.
177+
*/
173178
public String getExtension() {
174179
return extension;
175180
}

0 commit comments

Comments
 (0)