Skip to content

Commit 559a929

Browse files
committed
Repackager: pluggable layouts. Fix null handling in layout resolution. Improved error reporting.
1 parent 7ec646d commit 559a929

File tree

1 file changed

+16
-3
lines changed
  • spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools

1 file changed

+16
-3
lines changed

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Layouts.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,30 @@ public class Layouts {
4343
}
4444
}};
4545

46+
/**
47+
* Resolves and instantiates named layout.
48+
* If name is undefined, default layout is returned (JAR).
49+
* If given name refers to one of the layout aliases (JAR, ZIP, etc), it is returned.
50+
* Otherwise, assume layout name is an actual class name, and try to load it.
51+
* @param name
52+
* @return
53+
* @throws RuntimeException
54+
*/
4655
static public Layout resolve(String name) throws RuntimeException {
4756
try {
57+
if (name == null) { return defaultLayout.newInstance(); }
58+
4859
Class<?> cls = null;
49-
if (cls == null) { cls = map.get(name); };
60+
if (cls == null) { cls = map.get(name); }
5061
if (cls == null) { cls = Class.forName(name); }
51-
if (cls == null) { cls = defaultLayout; }
62+
5263
return (Layout) cls.newInstance();
5364
}
5465
catch (Exception e) {
5566
throw new RuntimeException(String.format(
56-
"Cannot resolve layout `%s`. Provide a fully qualified class name or of the following: %s",
67+
"Cannot resolve layout `%s`. " +
68+
"Provide a fully qualified name of the class implementing Layout interface, " +
69+
"or one of the following: %s",
5770
name, map.keySet()
5871
), e);
5972
}

0 commit comments

Comments
 (0)