Skip to content

Commit 2a43d0e

Browse files
committed
Base package: wrong package detection
- regression of renaming `io.jooby.kt.Kotlin` - fix #3173 - Allow to override the default package name
1 parent 51f1151 commit 2a43d0e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public class Jooby implements Router, Registry {
121121

122122
private String name;
123123

124+
private String basePackage;
125+
124126
private String version;
125127

126128
private Server server;
@@ -761,9 +763,18 @@ public ServiceRegistry getServices() {
761763
* @return Base application package.
762764
*/
763765
public @Nullable String getBasePackage() {
764-
return System.getProperty(
765-
AvailableSettings.PACKAGE,
766-
Optional.ofNullable(getClass().getPackage()).map(Package::getName).orElse(null));
766+
if (basePackage == null) {
767+
basePackage =
768+
System.getProperty(
769+
AvailableSettings.PACKAGE,
770+
Optional.ofNullable(getClass().getPackage()).map(Package::getName).orElse(null));
771+
}
772+
return basePackage;
773+
}
774+
775+
public @NonNull Jooby setBasePackage(@Nullable String basePackage) {
776+
this.basePackage = basePackage;
777+
return this;
767778
}
768779

769780
@NonNull @Override
@@ -1224,13 +1235,14 @@ private static void configurePackage(Package pkg) {
12241235
}
12251236

12261237
private static void configurePackage(Class owner) {
1227-
if (!owner.getName().equals("io.jooby.Jooby") && !owner.getName().equals("io.jooby.Kooby")) {
1238+
if (!owner.getName().equals("io.jooby.Jooby") && !owner.getName().equals("io.jooby.kt.Kooby")) {
12281239
configurePackage(owner.getPackage());
12291240
}
12301241
}
12311242

12321243
private static void configurePackage(String packageName) {
1233-
if (!packageName.equals("io.jooby")) {
1244+
var defaultPackages = Set.of("io.jooby", "io.jooby.kt");
1245+
if (!defaultPackages.contains(packageName)) {
12341246
ifSystemProp(
12351247
AvailableSettings.PACKAGE,
12361248
(sys, key) -> {

0 commit comments

Comments
 (0)