All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tools.bestquality.maven.ci.VersionTemplate Maven / Gradle / Ivy

There is a newer version: 0.0.20
Show newest version
package tools.bestquality.maven.ci;

import static java.lang.String.format;
import static org.codehaus.plexus.util.StringUtils.isEmpty;

@FunctionalInterface
public interface VersionTemplate {
    String expand(String revision, String sha1, String changelist)
            throws Exception;

    static VersionTemplate template(String template) {
        return (revision, sha1, changelist) -> {
            // First expand all ci-friendly property references
            String expanded = template
                    .replace("${revision}", revision != null ? revision : "${revision}")
                    .replace("${sha1}", sha1 != null ? sha1 : "${sha1}")
                    .replace("${changelist}", changelist != null ? changelist : "${changelist}");
            // Next update the property definitions
            if (revision != null) {
                expanded = expanded.replaceAll(".*|",
                        isEmpty(revision)
                                ? ""
                                : format("%s", revision));
            }
            if (sha1 != null) {
                expanded = expanded.replaceAll(".*|",
                        isEmpty(sha1)
                                ? ""
                                : format("%s", sha1));
            }
            if (changelist != null) {
                expanded = expanded.replaceAll(".*|",
                        isEmpty(changelist)
                                ? ""
                                : format("%s", changelist));
            }
            return expanded;
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy