public static String pathToMaven()

in common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java [633:676]


    public static String pathToMaven(String location) {
        String[] p = location.split("/");
        if (p.length >= 4) {
            final String artifactId = p[p.length - 3];
            final String version = p[p.length - 2];
            final String fileName = p[p.length - 1];
            final int artifactIdVersionLength = artifactId.length() + 1 /* the dash */ + version.length();
            if (fileName.length() > artifactIdVersionLength) {
                /* We use fileName.length() > to avoid https://github.com/apache/maven-mvnd/issues/929
                 * In the code below, we assume that the fileName ends either with `.<extension>`
                 * or `-<classifier>.<extension>` */
                final int lastPeriodPos = fileName.lastIndexOf('.');
                if (lastPeriodPos >= 0) {
                    final String classifier;
                    final String type;
                    final StringBuilder sb = new StringBuilder();
                    if (fileName.charAt(artifactIdVersionLength) == '-') {
                        classifier = fileName.substring(artifactIdVersionLength + 1, lastPeriodPos);
                    } else {
                        classifier = null;
                    }
                    type = fileName.substring(lastPeriodPos + 1);
                    for (int j = 0; j < p.length - 3; j++) {
                        if (j > 0) {
                            sb.append('.');
                        }
                        sb.append(p[j]);
                    }
                    sb.append(':').append(artifactId).append(':').append(version);
                    if (!"jar".equals(type) || classifier != null) {
                        sb.append(':');
                        if (!"jar".equals(type)) {
                            sb.append(type);
                        }
                        if (classifier != null) {
                            sb.append(':').append(classifier);
                        }
                    }
                    return sb.toString();
                }
            }
        }
        return location;
    }