Skip to content

Commit

Permalink
Merge pull request #19864 from dreis2211
Browse files Browse the repository at this point in the history
* pr/19864:
  Use Supplier variants of Assert

Closes gh-19864
  • Loading branch information
snicoll committed Jan 28, 2020
2 parents 9fbaf76 + d8e2349 commit e92e818
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -124,7 +124,7 @@ public void addSourceFolders(Iterable<File> folders) {
*/
public void addSourceFolder(File folder) {
Assert.notNull(folder, "Folder must not be null");
Assert.isTrue(!folder.isFile(), "Folder '" + folder + "' must not be a file");
Assert.isTrue(!folder.isFile(), () -> "Folder '" + folder + "' must not be a file");
synchronized (this.monitor) {
checkNotStarted();
this.folders.put(folder, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,7 +51,7 @@ class FolderSnapshot {
*/
FolderSnapshot(File folder) {
Assert.notNull(folder, "Folder must not be null");
Assert.isTrue(!folder.isFile(), "Folder '" + folder + "' must not be a file");
Assert.isTrue(!folder.isFile(), () -> "Folder '" + folder + "' must not be a file");
this.folder = folder;
this.time = new Date();
Set<FileSnapshot> files = new LinkedHashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public String toString() {
static ApiVersion parse(String value) {
Assert.hasText(value, "Value must not be empty");
Matcher matcher = PATTERN.matcher(value);
Assert.isTrue(matcher.matches(), "Malformed version number '" + value + "'");
Assert.isTrue(matcher.matches(), () -> "Malformed version number '" + value + "'");
try {
int major = Integer.parseInt(matcher.group(1));
int minor = Integer.parseInt(matcher.group(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BuildOwner implements Owner {

private long getValue(Map<String, String> env, String name) {
String value = env.get(name);
Assert.state(StringUtils.hasText(value), "Missing '" + name + "' value from the builder environment");
Assert.state(StringUtils.hasText(value), () -> "Missing '" + name + "' value from the builder environment");
try {
return Long.parseLong(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static BuilderMetadata fromImageConfig(ImageConfig imageConfig) throws IOExcepti
Assert.notNull(imageConfig, "ImageConfig must not be null");
Map<String, String> labels = imageConfig.getLabels();
String json = (labels != null) ? labels.get(LABEL_NAME) : null;
Assert.notNull(json, "No '" + LABEL_NAME + "' label found in image config");
Assert.notNull(json, () -> "No '" + LABEL_NAME + "' label found in image config");
return fromJson(json);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static StackId fromImage(Image image) {
private static StackId fromImageConfig(ImageConfig imageConfig) {
Map<String, String> labels = imageConfig.getLabels();
String value = (labels != null) ? labels.get(LABEL_NAME) : null;
Assert.state(StringUtils.hasText(value), "Missing '" + LABEL_NAME + "' stack label");
Assert.state(StringUtils.hasText(value), () -> "Missing '" + LABEL_NAME + "' stack label");
return new StackId(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ImageReference withDigest(String digest) {
* @throws IllegalStateException if the image reference contains a digest
*/
public ImageReference inTaggedForm() {
Assert.state(this.digest == null, "Image reference '" + this + "' cannot contain a digest");
Assert.state(this.digest == null, () -> "Image reference '" + this + "' cannot contain a digest");
return new ImageReference(this.name, (this.tag != null) ? this.tag : LATEST, this.digest);
}

Expand All @@ -163,7 +163,7 @@ public ImageReference inTaggedForm() {
*/
public static ImageReference forJarFile(File jarFile) {
String filename = jarFile.getName();
Assert.isTrue(filename.toLowerCase().endsWith(".jar"), "File '" + jarFile + "' is not a JAR");
Assert.isTrue(filename.toLowerCase().endsWith(".jar"), () -> "File '" + jarFile + "' is not a JAR");
filename = filename.substring(0, filename.length() - 4);
int firstDot = filename.indexOf('.');
if (firstDot == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String toString() {
public static LayerId of(String value) {
Assert.hasText(value, "Value must not be empty");
int i = value.indexOf(':');
Assert.isTrue(i >= 0, "Invalid layer ID '" + value + "'");
Assert.isTrue(i >= 0, () -> "Invalid layer ID '" + value + "'");
return new LayerId(value, value.substring(0, i), value.substring(i + 1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private static String getDigest(String name, int length) {
}

private static String asHexString(byte[] digest, int digestLength) {
Assert.isTrue(digestLength <= digest.length, "DigestLength must be less than or equal to " + digest.length);
Assert.isTrue(digestLength <= digest.length,
() -> "DigestLength must be less than or equal to " + digest.length);
byte[] shortDigest = new byte[6];
System.arraycopy(digest, 0, shortDigest, 0, shortDigest.length);
return String.format("%0" + digestLength + "x", new BigInteger(1, shortDigest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
if (declaringClass == Object.class) {
method.invoke(proxy, args);
}
Assert.state(args == null || args.length == 0, "Unsupported method " + method);
Assert.state(args == null || args.length == 0, () -> "Unsupported method " + method);
String name = getName(method.getName());
Class<?> type = method.getReturnType();
return valueForProperty(name, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static class SockaddrUn extends Structure implements Structure.ByReferenc
public byte[] sunPath = new byte[MAX_PATH_LENGTH];

private SockaddrUn(byte sunFamily, byte[] path) {
Assert.isTrue(path.length < MAX_PATH_LENGTH, "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
Assert.isTrue(path.length < MAX_PATH_LENGTH, () -> "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
System.arraycopy(path, 0, this.sunPath, 0, path.length);
this.sunPath[path.length] = 0;
this.sunLen = (byte) (fieldOffset("sunPath") + path.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class SockaddrUn extends Structure implements Structure.ByReferenc
public byte[] sunPath = new byte[MAX_PATH_LENGTH];

private SockaddrUn(byte sunFamily, byte[] path) {
Assert.isTrue(path.length < MAX_PATH_LENGTH, "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
Assert.isTrue(path.length < MAX_PATH_LENGTH, () -> "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
System.arraycopy(path, 0, this.sunPath, 0, path.length);
this.sunPath[path.length] = 0;
this.sunFamily = sunFamily;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getLayer(ZipEntry entry) {
Matcher matcher = LAYER_PATTERN.matcher(name);
if (matcher.matches()) {
String layer = matcher.group(1);
Assert.state(this.layers.contains(layer), "Unexpected layer '" + layer + "'");
Assert.state(this.layers.contains(layer), () -> "Unexpected layer '" + layer + "'");
return layer;
}
return this.layers.contains(APPLICATION_LAYER) ? APPLICATION_LAYER : SPRING_BOOT_APPLICATION_LAYER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void packageImage(Libraries libraries, BiConsumer<ZipEntry, EntryWriter>

private void packageImage(Libraries libraries, AbstractJarWriter writer) throws IOException {
File source = isAlreadyPackaged() ? getBackupFile() : getSource();
Assert.state(source.exists() && source.isFile(), "Unable to read jar file " + source);
Assert.state(!isAlreadyPackaged(source), "Repackaged jar file " + source + " cannot be exported");
Assert.state(source.exists() && source.isFile(), () -> "Unable to read jar file " + source);
Assert.state(!isAlreadyPackaged(source), () -> "Repackaged jar file " + source + " cannot be exported");
try (JarFile sourceJar = new JarFile(source)) {
write(sourceJar, libraries, writer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class Layer {
*/
public Layer(String name) {
Assert.hasText(name, "Name must not be empty");
Assert.isTrue(PATTERN.matcher(name).matches(), "Malformed layer name '" + name + "'");
Assert.isTrue(PATTERN.matcher(name).matches(), () -> "Malformed layer name '" + name + "'");
Assert.isTrue(!name.equalsIgnoreCase("ext") && !name.toLowerCase().startsWith("springboot"),
"Layer name '" + name + "' is reserved");
() -> "Layer name '" + name + "' is reserved");
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public JarArchiveEntry transform(JarArchiveEntry entry) {
private String transformName(String name) {
if (this.layout instanceof LayeredLayout) {
Layer layer = this.layers.getLayer(name);
Assert.state(layer != null, "Invalid 'null' layer from " + this.layers.getClass().getName());
Assert.state(layer != null, () -> "Invalid 'null' layer from " + this.layers.getClass().getName());
return ((LayeredLayout) this.layout).getRepackagedClassesLocation(layer) + name;
}
return this.layout.getRepackagedClassesLocation() + name;
Expand Down Expand Up @@ -455,7 +455,7 @@ private void addLibrary(Library library) {
if (location != null) {
String path = location + library.getName();
Library existing = this.libraries.putIfAbsent(path, library);
Assert.state(existing == null, "Duplicate library " + library.getName());
Assert.state(existing == null, () -> "Duplicate library " + library.getName());
}
}

Expand All @@ -464,7 +464,7 @@ private String getLocation(Library library) {
if (layout instanceof LayeredLayout) {
Layers layers = Packager.this.layers;
Layer layer = layers.getLayer(library);
Assert.state(layer != null, "Invalid 'null' library layer from " + layers.getClass().getName());
Assert.state(layer != null, () -> "Invalid 'null' library layer from " + layers.getClass().getName());
return ((LayeredLayout) layout).getLibraryLocation(library.getName(), library.getScope(), layer);
}
return layout.getLibraryLocation(library.getName(), library.getScope());
Expand All @@ -479,7 +479,7 @@ public boolean requiresUnpack(String name) {
@Override
public String sha1Hash(String name) throws IOException {
Library library = this.libraries.get(name);
Assert.notNull(library, "No library found for entry name '" + name + "'");
Assert.notNull(library, () -> "No library found for entry name '" + name + "'");
return Digest.sha1(library::openStream);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -371,7 +371,7 @@ private ClassLoader wrapWithCustomClassLoader(ClassLoader parent, String classNa
if (classLoader == null) {
classLoader = newClassLoader(type, NO_PARAMS);
}
Assert.notNull(classLoader, "Unable to create class loader for " + className);
Assert.notNull(classLoader, () -> "Unable to create class loader for " + className);
return classLoader;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private Method findMethod(Class<?> testClass, String testMethodName) {
}
}
}
Assert.state(method != null, "Unable to find " + testClass + "." + testMethodName);
Assert.state(method != null, () -> "Unable to find " + testClass + "." + testMethodName);
return method;
}

Expand Down

0 comments on commit e92e818

Please sign in to comment.