Skip to content

Commit c584979

Browse files
committed
GH-170 - Improve log output for ApplicationModule.
We now consider whether a type is exposed by a module to determine whether it is reported as public (+) or contained (o) type.
1 parent f0aaca2 commit c584979

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public String toString(@Nullable ApplicationModules modules) {
362362

363363
builder.append("> Spring beans:\n");
364364
beans.forEach(it -> builder.append(" ") //
365-
.append(Classes.format(it, basePackage.getName()))//
365+
.append(Classes.format(it, basePackage.getName(), isExposed(it)))//
366366
.append('\n'));
367367
}
368368

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ public Iterator<ApplicationModule> iterator() {
442442
*/
443443
@Override
444444
public String toString() {
445-
return this.stream().map(ApplicationModule::toString).collect(Collectors.joining("\n"));
445+
446+
return this.stream()
447+
.map(it -> it.toString(this))
448+
.collect(Collectors.joining("\n"));
446449
}
447450

448451
private ApplicationModules withSharedModules(Set<ApplicationModule> sharedModules) {

spring-modulith-core/src/main/java/org/springframework/modulith/core/Classes.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,27 @@ static String format(JavaClass type, String basePackage) {
241241
Assert.notNull(type, "Type must not be null!");
242242
Assert.notNull(basePackage, "Base package must not be null!");
243243

244-
var prefix = type.getModifiers().contains(JavaModifier.PUBLIC) ? "+" : "o";
244+
return format(type, basePackage, type.getModifiers().contains(JavaModifier.PUBLIC));
245+
}
246+
247+
/**
248+
* Formats the given {@link JavaClass} into a {@link String}, potentially abbreviating the given base package.
249+
*
250+
* @param type must not be {@literal null}.
251+
* @param basePackage must not be {@literal null}.
252+
* @param exposed whether the given type is considered exposed or not.
253+
* @return will never be {@literal null}.
254+
*/
255+
static String format(JavaClass type, String basePackage, boolean exposed) {
256+
257+
Assert.notNull(type, "Type must not be null!");
258+
Assert.notNull(basePackage, "Base package must not be null!");
259+
245260
var name = StringUtils.hasText(basePackage) //
246261
? type.getName().replace(basePackage, "…") //
247262
: type.getName();
248263

249-
return String.format("%s %s", prefix, name);
264+
return String.format("%s %s", exposed ? "+" : "o", name);
250265
}
251266

252267
private static String format(JavaClass type) {

0 commit comments

Comments
 (0)