Class MavenUtils

java.lang.Object
net.microfalx.talos.core.MavenUtils

public class MavenUtils extends Object
Various Maven utilities.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static net.microfalx.metrics.Metrics
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatDuration(long duration)
    Formats duration Maven style.
    static String
    Formats duration Maven style.
    static String
    formatDuration(Duration duration, boolean brackets)
    Formats duration Maven style.
    static String
    formatDuration(Duration duration, boolean brackets, boolean padding)
    Formats duration Maven style.
    static String
    formatInteger(int value, int length)
    Returns a formatted integer, left padded.
    static String
    formatInteger(int value, int length, boolean digits)
    Returns a formatted integer, left padded.
    static String
    formatMemory(long used, long maximum)
    Formats memory usage as a string.
    static String
    getGoal(org.apache.maven.plugin.MojoExecution execution)
    Returns the goal executed for a given Mojo.
    static String
    getId(org.apache.maven.artifact.Artifact artifact)
    Returns the identifier of an artifact.
    static String
    getId(org.apache.maven.model.Dependency dependency)
    Returns the identifier of a dependency.
    static String
    getId(org.apache.maven.model.Plugin plugin)
    Returns the identifier of a plugin.
    static String
    getId(org.apache.maven.plugin.Mojo mojo)
    Returns the identifier of a mojo.
    static String
    getId(org.apache.maven.project.MavenProject project)
    Returns the identifier of a project.
    static String
    getId(org.eclipse.aether.artifact.Artifact artifact)
    Returns the identifier of an artifact.
    static String
    getId(org.eclipse.aether.metadata.Metadata metadata)
    Returns the identifier of an artifact.
    static String
    getName(org.apache.maven.plugin.Mojo mojo)
    Returns the name of the Mojo.
    static boolean
    getProperty(org.apache.maven.execution.MavenSession session, String name, boolean defaultValue)
    Returns a property value as a boolean.
    static int
    getProperty(org.apache.maven.execution.MavenSession session, String name, int defaultValue)
    Returns a property value as an integer.
    static String
    getProperty(org.apache.maven.execution.MavenSession session, String name, String defaultValue)
    Returns a property or environment variable value.
    static Duration
    getProperty(org.apache.maven.execution.MavenSession session, String name, Duration defaultValue)
    Returns a property value as a Duration.
    static Collection<URI>
    getRemoteRepositories(org.apache.maven.execution.MavenSession session)
    Returns the remote repositories.
    static boolean
    Returns whether a known logger to intercept is available.
    static boolean
    Returns whether the Maven logger is available.
    static boolean
    Returns whether the name indicates a property which stores secrets.
    static String
    leftPad(String text, int length)
    Returns a left padded (with spaces) text.
    static String
    leftPad(String text, int length, char fill)
    Returns a left padded (with spaces) text.
    static String
    maskSecret(String name, String value)
    Masks the value the name indicates a property which stores secrets.
    static void
    registerName(String mojoClass, String name)
    Registers a name for a Mojo.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • METRICS

      public static net.microfalx.metrics.Metrics METRICS
    • ZERO_DURATION

      public static final String ZERO_DURATION
      See Also:
  • Constructor Details

    • MavenUtils

      public MavenUtils()
  • Method Details

    • isLoggerAvailable

      public static boolean isLoggerAvailable()
      Returns whether a known logger to intercept is available.
      Returns:
      true if Maven logger, false otherwise
    • isMavenLoggerAvailable

      public static boolean isMavenLoggerAvailable()
      Returns whether the Maven logger is available.
      Returns:
      true if Maven logger, false otherwise
    • getId

      public static String getId(org.eclipse.aether.artifact.Artifact artifact)
      Returns the identifier of an artifact.
      Parameters:
      artifact - the artifact
      Returns:
      a non-null instance
    • getId

      public static String getId(org.apache.maven.artifact.Artifact artifact)
      Returns the identifier of an artifact.
      Parameters:
      artifact - the artifact
      Returns:
      a non-null instance
    • getId

      public static String getId(org.apache.maven.model.Dependency dependency)
      Returns the identifier of a dependency.
      Parameters:
      dependency - the dependency
      Returns:
      a non-null instance
    • getId

      public static String getId(org.apache.maven.model.Plugin plugin)
      Returns the identifier of a plugin.
      Parameters:
      plugin - the plugin
      Returns:
      a non-null instance
    • getId

      public static String getId(org.apache.maven.plugin.Mojo mojo)
      Returns the identifier of a mojo.
      Parameters:
      mojo - the Mojo
      Returns:
      a non-null instance
    • getId

      public static String getId(org.apache.maven.project.MavenProject project)
      Returns the identifier of a project.
      Parameters:
      project - the project
      Returns:
      a non-null instance
    • getId

      public static String getId(org.eclipse.aether.metadata.Metadata metadata)
      Returns the identifier of an artifact.
      Parameters:
      metadata - the artifact
      Returns:
      a non-null instance
    • formatInteger

      public static String formatInteger(int value, int length)
      Returns a formatted integer, left padded.
      Parameters:
      value - the value to format
      length - the minimum length
      Returns:
      a padded number
    • formatInteger

      public static String formatInteger(int value, int length, boolean digits)
      Returns a formatted integer, left padded.
      Parameters:
      value - the value to format
      length - the minimum length
      Returns:
      a padded number
    • leftPad

      public static String leftPad(String text, int length)
      Returns a left padded (with spaces) text.
      Parameters:
      text - the text to pad
      length - the minimum length
      Returns:
      a non null padded string
    • leftPad

      public static String leftPad(String text, int length, char fill)
      Returns a left padded (with spaces) text.
      Parameters:
      text - the text to pad
      length - the minimum length
      fill - the character to be used to fill the empty space
      Returns:
      a non null padded string
    • formatDuration

      public static String formatDuration(Duration duration)
      Formats duration Maven style.
      Parameters:
      duration - the duration
      Returns:
      the duration as string
    • formatDuration

      public static String formatDuration(Duration duration, boolean brackets)
      Formats duration Maven style.
      Parameters:
      duration - the duration
      Returns:
      the duration as string
    • formatDuration

      public static String formatDuration(Duration duration, boolean brackets, boolean padding)
      Formats duration Maven style.
      Parameters:
      duration - the duration
      Returns:
      the duration as string
    • formatDuration

      public static String formatDuration(long duration)
      Formats duration Maven style.
      Parameters:
      duration - the duration
      Returns:
      the duration as string
    • formatMemory

      public static String formatMemory(long used, long maximum)
      Formats memory usage as a string.
      Parameters:
      used - the used memory
      maximum - the maximum memory
      Returns:
      a non-null instance
    • getProperty

      public static Duration getProperty(org.apache.maven.execution.MavenSession session, String name, Duration defaultValue)
      Returns a property value as a Duration.
      Parameters:
      session - the session
      name - the property name
      defaultValue - the default value
      Returns:
      the value
      See Also:
      • TimeUtils.parseDuration(String)
    • getProperty

      public static boolean getProperty(org.apache.maven.execution.MavenSession session, String name, boolean defaultValue)
      Returns a property value as a boolean.
      Parameters:
      session - the session
      name - the property name
      defaultValue - the default value
      Returns:
      the value
    • getProperty

      public static int getProperty(org.apache.maven.execution.MavenSession session, String name, int defaultValue)
      Returns a property value as an integer.
      Parameters:
      session - the session
      name - the property name
      defaultValue - the default value
      Returns:
      the value
    • getProperty

      public static String getProperty(org.apache.maven.execution.MavenSession session, String name, String defaultValue)
      Returns a property or environment variable value.

      The environment variable is created out of full property name, upper case and replacing "." with "_".

      Parameters:
      session - the session
      name - the property name
      defaultValue - the default value
      Returns:
      the value
    • registerName

      public static void registerName(String mojoClass, String name)
      Registers a name for a Mojo.
      Parameters:
      mojoClass - the Mojo class.
      name - the name
    • getName

      public static String getName(org.apache.maven.plugin.Mojo mojo)
      Returns the name of the Mojo.
      Parameters:
      mojo - the mojo
      Returns:
      a non-null string
    • getGoal

      public static String getGoal(org.apache.maven.plugin.MojoExecution execution)
      Returns the goal executed for a given Mojo.
      Parameters:
      execution - the mojo execution
      Returns:
      a non-null string
    • getRemoteRepositories

      public static Collection<URI> getRemoteRepositories(org.apache.maven.execution.MavenSession session)
      Returns the remote repositories.
      Parameters:
      session - the session
      Returns:
      a non-null collection
    • maskSecret

      public static String maskSecret(String name, String value)
      Masks the value the name indicates a property which stores secrets.
      Parameters:
      name - the property name
      value - the property value
      Returns:
      the original value or a masked one
    • isSecret

      public static boolean isSecret(String name)
      Returns whether the name indicates a property which stores secrets.
      Parameters:
      name - the property name
      Returns:
      true if it stores a secret, false otherwise