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.
This commit is contained in:
Oliver Drotbohm
2023-03-23 13:00:56 +01:00
parent f0aaca2917
commit c58497979d
3 changed files with 22 additions and 4 deletions

View File

@@ -362,7 +362,7 @@ public class ApplicationModule {
builder.append("> Spring beans:\n");
beans.forEach(it -> builder.append(" ") //
.append(Classes.format(it, basePackage.getName()))//
.append(Classes.format(it, basePackage.getName(), isExposed(it)))//
.append('\n'));
}

View File

@@ -442,7 +442,10 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
*/
@Override
public String toString() {
return this.stream().map(ApplicationModule::toString).collect(Collectors.joining("\n"));
return this.stream()
.map(it -> it.toString(this))
.collect(Collectors.joining("\n"));
}
private ApplicationModules withSharedModules(Set<ApplicationModule> sharedModules) {

View File

@@ -241,12 +241,27 @@ class Classes implements DescribedIterable<JavaClass> {
Assert.notNull(type, "Type must not be null!");
Assert.notNull(basePackage, "Base package must not be null!");
var prefix = type.getModifiers().contains(JavaModifier.PUBLIC) ? "+" : "o";
return format(type, basePackage, type.getModifiers().contains(JavaModifier.PUBLIC));
}
/**
* Formats the given {@link JavaClass} into a {@link String}, potentially abbreviating the given base package.
*
* @param type must not be {@literal null}.
* @param basePackage must not be {@literal null}.
* @param exposed whether the given type is considered exposed or not.
* @return will never be {@literal null}.
*/
static String format(JavaClass type, String basePackage, boolean exposed) {
Assert.notNull(type, "Type must not be null!");
Assert.notNull(basePackage, "Base package must not be null!");
var name = StringUtils.hasText(basePackage) //
? type.getName().replace(basePackage, "") //
: type.getName();
return String.format("%s %s", prefix, name);
return String.format("%s %s", exposed ? "+" : "o", name);
}
private static String format(JavaClass type) {