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.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,9 +120,21 @@ public final class BuildPropertiesWriter {
|
||||||
this.artifact = artifact;
|
this.artifact = artifact;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
validateAdditionalProperties(additionalProperties);
|
||||||
this.additionalProperties = 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() {
|
public String getGroup() {
|
||||||
return this.group;
|
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.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
import org.springframework.boot.loader.tools.BuildPropertiesWriter;
|
import org.springframework.boot.loader.tools.BuildPropertiesWriter;
|
||||||
|
import org.springframework.boot.loader.tools.BuildPropertiesWriter.NullAdditionalPropertyValueException;
|
||||||
import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails;
|
import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,8 +54,8 @@ public class BuildInfoMojo extends AbstractMojo {
|
||||||
private File outputFile;
|
private File outputFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional properties to store in the build-info.properties. Each entry is prefixed by
|
* Additional properties to store in the build-info.properties. Each entry is prefixed
|
||||||
* {@code build.} in the generated build-info.properties.
|
* by {@code build.} in the generated build-info.properties.
|
||||||
*/
|
*/
|
||||||
@Parameter
|
@Parameter
|
||||||
private Map<String, String> additionalProperties;
|
private Map<String, String> additionalProperties;
|
||||||
|
|
@ -67,6 +68,10 @@ public class BuildInfoMojo extends AbstractMojo {
|
||||||
this.project.getArtifactId(), this.project.getVersion(),
|
this.project.getArtifactId(), this.project.getVersion(),
|
||||||
this.project.getName(), this.additionalProperties));
|
this.project.getName(), this.additionalProperties));
|
||||||
}
|
}
|
||||||
|
catch (NullAdditionalPropertyValueException ex) {
|
||||||
|
throw new MojoFailureException(
|
||||||
|
"Failed to generated build-info.properties. " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new MojoExecutionException(ex.getMessage(), ex);
|
throw new MojoExecutionException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue