Improve the error message when additional build-info prop has null value
Closes gh-6724
This commit is contained in:
parent
f41e629760
commit
742657983b
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
|
@ -119,9 +120,21 @@ public final class BuildPropertiesWriter {
|
|||
this.artifact = artifact;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
validateAdditionalProperties(additionalProperties);
|
||||
this.additionalProperties = additionalProperties;
|
||||
}
|
||||
|
||||
private static void validateAdditionalProperties(
|
||||
Map<String, String> additionalProperties) {
|
||||
if (additionalProperties != null) {
|
||||
for (Entry<String, String> property : additionalProperties.entrySet()) {
|
||||
if (property.getValue() == null) {
|
||||
throw new NullAdditionalPropertyValueException(property.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
|
@ -143,4 +156,16 @@ public final class BuildPropertiesWriter {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when an additional property with a null value is encountered.
|
||||
*/
|
||||
public static class NullAdditionalPropertyValueException
|
||||
extends IllegalArgumentException {
|
||||
|
||||
public NullAdditionalPropertyValueException(String name) {
|
||||
super("Additional property '" + name + "' is illegal as its value is null");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.apache.maven.plugins.annotations.Parameter;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import org.springframework.boot.loader.tools.BuildPropertiesWriter;
|
||||
import org.springframework.boot.loader.tools.BuildPropertiesWriter.NullAdditionalPropertyValueException;
|
||||
import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails;
|
||||
|
||||
/**
|
||||
|
|
@ -53,8 +54,8 @@ public class BuildInfoMojo extends AbstractMojo {
|
|||
private File outputFile;
|
||||
|
||||
/**
|
||||
* Additional properties to store in the build-info.properties. Each entry is prefixed by
|
||||
* {@code build.} in the generated build-info.properties.
|
||||
* Additional properties to store in the build-info.properties. Each entry is prefixed
|
||||
* by {@code build.} in the generated build-info.properties.
|
||||
*/
|
||||
@Parameter
|
||||
private Map<String, String> additionalProperties;
|
||||
|
|
@ -67,6 +68,10 @@ public class BuildInfoMojo extends AbstractMojo {
|
|||
this.project.getArtifactId(), this.project.getVersion(),
|
||||
this.project.getName(), this.additionalProperties));
|
||||
}
|
||||
catch (NullAdditionalPropertyValueException ex) {
|
||||
throw new MojoFailureException(
|
||||
"Failed to generated build-info.properties. " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new MojoExecutionException(ex.getMessage(), ex);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue