Class LocaleFacet

  • All Implemented Interfaces:
    EnvironmentFacet

    public class LocaleFacet
    extends AbstractLogAwareFacet
    EnvironmentFacet implementation which alters the default Locale for the remainder of the tool execution.
    • Constructor Summary

      Constructors 
      Constructor Description
      LocaleFacet​(org.apache.maven.plugin.logging.Log log, java.util.Locale newLocale)
      Compound constructor creating a LocaleFacet wrapping the supplied instances.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static LocaleFacet createFor​(java.lang.String localeString, org.apache.maven.plugin.logging.Log log)
      Helper method used to parse a locale configuration string into a Locale instance.
      static java.util.Locale findOptimumLocale​(java.lang.String language, java.lang.String country, java.lang.String variant)
      Helper method to find the best matching locale, implying a workaround for problematic case-sensitive Locale detection within the JDK.
      void restore()
      Restores the original Environment, implying that the change performed in setup() method are restored to the state before the setup method was called.
      void setup()
      Sets up this Environment, inferring temporary changes to environment variables or conditions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • originalLocale

        private java.util.Locale originalLocale
      • newLocale

        private java.util.Locale newLocale
    • Constructor Detail

      • LocaleFacet

        public LocaleFacet​(org.apache.maven.plugin.logging.Log log,
                           java.util.Locale newLocale)
        Compound constructor creating a LocaleFacet wrapping the supplied instances.
        Parameters:
        log - The active Maven Log.
        newLocale - The non-null Locale to be set by this LocaleFacet during execution.
    • Method Detail

      • setup

        public void setup()
        Sets up this Environment, inferring temporary changes to environment variables or conditions. The changes must be reversible, and should be restored to their original values in the restore() method.

        Changes the Locale during the execution of the plugin.

      • restore

        public void restore()
        Restores the original Environment, implying that the change performed in setup() method are restored to the state before the setup method was called.

        Restores the original locale following the plugin's execution.

      • createFor

        public static LocaleFacet createFor​(java.lang.String localeString,
                                            org.apache.maven.plugin.logging.Log log)
                                     throws org.apache.maven.plugin.MojoExecutionException
        Helper method used to parse a locale configuration string into a Locale instance.
        Parameters:
        localeString - A configuration string parameter on the form <language>[,<country>[,<variant>]]
        log - The active Maven Log. Cannot be null.
        Returns:
        A fully constructed Locale.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if the localeString was not supplied on the required form.
      • findOptimumLocale

        public static java.util.Locale findOptimumLocale​(java.lang.String language,
                                                         java.lang.String country,
                                                         java.lang.String variant)
        Helper method to find the best matching locale, implying a workaround for problematic case-sensitive Locale detection within the JDK. (C.f. Issue #112).
        Parameters:
        language - The given Language.
        country - The given Country. May be null or empty to indicate that the Locale returned should not contain a Country definition.
        variant - The given Variant. May be null or empty to indicate that the Locale returned should not contain a Variant definition.
        Returns:
        The optimally matching Locale.