Riduidel / aadarchi

A maven archetype to generate easily projects allowing architecture description using a mix of C4, agile architecture, Asciidoc and PlantUML
https://riduidel.github.io/aadarchi/
Apache License 2.0
39 stars 12 forks source link

Change log format of aadarchi-maven-plugin #340

Closed Riduidel closed 1 year ago

Riduidel commented 1 year ago

We currently output logs in the form

[INFO] (org.ndx.aadarchi.base.ArchitectureEnhancer) Running enhancement org.ndx.aadarchi.base.enhancers.scm.SCMProjectCheckouter took 00:00:00.021

Can you

  1. Replace the parenthesis around class name by square brackets
  2. Limit the number of characters of this class name to 20
  3. Compress package names to only have first character

This would lead to log being in the form

[INFO] <o.n.a.base.ArchitectureEnhancer> Running enhancement org.ndx.aadarchi.base.enhancers.scm.SCMProjectCheckouter took 00:00:00.021
Riduidel commented 1 year ago

I suggest you take a look at class MavenLoggingRedirectorHandler

Helielzel commented 1 year ago

Compile with -X to display logs ? https://stackoverflow.com/questions/4782089/how-to-change-maven-logging-level-to-display-only-warning-and-errors

Helielzel commented 1 year ago

Shortens the source in the logs

`    public static String shortenSource(String originalSource) {
        String[] parts = originalSource.split("\\.");
        StringBuilder newSource = new StringBuilder();
        for (int i = 0; i < parts.length; i++) {
            if (i > 0) {
                newSource.append(".");
            }
            newSource.append(parts[i].charAt(0));
        }
        return newSource.toString();
    }`
Helielzel commented 1 year ago
`    public static String shortenSource(String originalSource) {
        String[] parts = originalSource.split("\\.");
        StringBuilder newSource = new StringBuilder();
        System.out.println(parts.length);
        for (int i = 0; i < parts.length - 1; i++) {
            if (i > 0) {
                newSource.append(".");
            }
            newSource.append(parts[i].charAt(0));
        }
        newSource.append("." + parts[parts.length - 1]);
        return newSource.toString();
    }`
Riduidel commented 1 year ago

More clearly, if full class name (including packages) is smaller than 20 characters, show everything. If full class name is longer than 20 characters, start by replacing package names by their first letter, starting by the first one. Never compress class name.

Here are some example

I think you could write that in a unit test ...

Helielzel commented 1 year ago
    public static Integer getTotalSize(String[] parts) {
        int totalSize = 0;

        for (int i = 0; i < parts.length - 1; i++) {
            totalSize += parts[i].length() + 1;
        }
        return totalSize;
    }

    public static String shortenSource(String originalSource) {
        if (originalSource.length() <= 20) {
            return originalSource;
        }

        String[] parts = originalSource.split("\\.");
        StringBuilder newSourceBuilder = new StringBuilder();
        int classLength = parts[parts.length - 1].length();
        /*
        if (classLength >= 20) {
            for (int i = 0; i < parts.length - 1; i++) {
                newSourceBuilder.append(parts[i].charAt(0) + ".");
            }
            return newSourceBuilder.append(parts[parts.length - 1]).toString();
        }*/
        for (int i = 0; i < parts.length - 1; i++) {
            if (getTotalSize(parts) + classLength > 20) {
                //parts[i] = parts[i].replace(parts[i], String.valueOf(parts[i].charAt(0)));
                parts[i] = String.valueOf(parts[i].charAt(0));
            }
            newSourceBuilder.append(parts[i] + ".");
        }
        return newSourceBuilder.append(parts[parts.length - 1]).toString();
    }
Helielzel commented 1 year ago
public static Integer getTotalSize(String[] parts) {
        int totalSize = 0;

        for (int i = 0; i < parts.length - 1; i++) {
            totalSize += parts[i].length() + 1;
        }
        return totalSize;
    }
    public static String shortenSource(String originalSource) {
        String[] parts = originalSource.split("\\.");
        int classLength = parts[parts.length - 1].length();

        for (int i = 0; i < parts.length - 1; i++) {
            if (getTotalSize(parts) + classLength > 20) {
                parts[i] = String.valueOf(parts[i].charAt(0));
            }
        }
        return String.join(".", parts);
    }
Helielzel commented 1 year ago
public static Integer getTotalSize(String[] parts) {
    return Arrays.stream(parts)
            .limit(parts.length - 1)
            .mapToInt(String::length)
            .sum() + parts.length - 1;
}

public static String shortenSource(String originalSource) {
    String[] parts = originalSource.split("\\.");
    int classLength = parts[parts.length - 1].length();

    if (getTotalSize(parts) + classLength > 20) {
        parts = Arrays.stream(parts)
                .limit(parts.length - 1)
                .map(s -> s.substring(0, 1))
                .toArray(String[]::new);
    }

    return String.join(".", parts);
}