internal.heylogs.maven.plugin.MojoFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of heylogs-maven-plugin Show documentation
Show all versions of heylogs-maven-plugin Show documentation
Keep-a-changelog tool - Maven Plugin
package internal.heylogs.maven.plugin;
import lombok.NonNull;
import nbbrd.design.StaticFactoryMethod;
import nbbrd.heylogs.Extractor;
import org.apache.maven.plugin.MojoExecutionException;
import java.time.LocalDate;
import java.util.function.Function;
import java.util.regex.Pattern;
@FunctionalInterface
public interface MojoFunction {
Y applyWithMojo(X x) throws MojoExecutionException;
static @NonNull MojoFunction of(@NonNull Function function, @NonNull String errorMessage) {
return x -> {
try {
return function.apply(x);
} catch (IllegalArgumentException ex) {
throw new MojoExecutionException(errorMessage, ex);
}
};
}
@StaticFactoryMethod
static @NonNull MojoFunction onPattern(@NonNull String errorMessage) {
return of(Pattern::compile, errorMessage);
}
@StaticFactoryMethod
static @NonNull MojoFunction onLocalDate(@NonNull String errorMessage) {
return of(Extractor::parseLocalDate, errorMessage);
}
}