Class GenerateMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="generate",
          defaultPhase=GENERATE_SOURCES,
          requiresProject=false,
          threadSafe=true)
    public class GenerateMojo
    extends org.apache.maven.plugin.AbstractMojo
    Generate an I18N class from an I18N resource file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.String bundleName
      The bundle name to generate an I18N class for.
      (package private) java.lang.String className
      The fully qualified name of the I18N class to generate.
      (package private) java.lang.String inputEncoding
      The input encoding.
      private java.lang.String licenseCopyrightHolder
      The copyright holder to be inserted into the license text.
      private java.lang.String licenseCopyrightYear
      The copyright year to be inserted into the license text.
      (package private) java.lang.String licenseText
      The license text.
      (package private) java.io.File outputDirectory
      The output directory where the I18N class will be written to, without the package structure.
      (package private) java.lang.String outputEncoding
      The output encoding.
      (package private) org.apache.maven.project.MavenProject project  
      private boolean publicVisibility
      If true, generated classes and methods will have public visibility; otherwise they will be package private.
      (package private) Scope scope
      The scope of the project source root, compile or test.
      (package private) java.io.File sourceDirectory
      The source directory where the I18N resource file can be found, without the package structure.
      private java.util.Set<java.lang.String> suppressWarnings
      Warnings that will be suppressed using SuppressWarnings.
      private boolean useMessageFormat
      If true, MessageFormat will be used to format messages; otherwise String.format(java.util.Locale, String, Object...) will be used.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      GenerateMojo()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void appendSourcePath()  
      private void appendSourcePath​(java.util.List<java.lang.String> sourceRoots, java.util.function.Consumer<java.lang.String> addSourceRoot)  
      private java.lang.String capitalize​(java.lang.String s)  
      private java.net.URL createURL​(java.lang.String url)  
      void execute()  
      (package private) java.lang.String getI18NClassName()  
      (package private) java.nio.charset.Charset getInputCharset()  
      (package private) java.lang.String getLicenseText()  
      private java.lang.String getLicenseText​(java.io.File licenseFile)  
      private java.lang.String getLicenseText​(java.io.Reader input)  
      private java.lang.String getLicenseText​(java.net.URL licenseURL)  
      (package private) java.nio.charset.Charset getOutputCharset()  
      private java.io.File getSourceFile()  
      private I18N.Node readI18N()  
      (package private) java.util.Map<java.lang.String,​java.lang.String> readProperties()  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

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

      • project

        @Parameter(defaultValue="${project}",
                   readonly=true)
        org.apache.maven.project.MavenProject project
      • bundleName

        @Parameter(property="i18n.bundleName",
                   required=true)
        java.lang.String bundleName
        The bundle name to generate an I18N class for. The matching bundle file will be resolved relative to the configured source directory.
        Since:
        1.0
      • sourceDirectory

        @Parameter(property="i18n.sourceDirectory",
                   defaultValue="${project.build.resources[0].directory}",
                   required=true)
        java.io.File sourceDirectory
        The source directory where the I18N resource file can be found, without the package structure.
        Since:
        1.0
      • className

        @Parameter(property="i18n.className")
        java.lang.String className
        The fully qualified name of the I18N class to generate. If not specified, the class name will be based on the bundle name.
        Since:
        1.0
      • outputDirectory

        @Parameter(property="i18n.outputDirectory",
                   defaultValue="${project.build.directory}/generated-sources/resource-bundles",
                   required=true)
        java.io.File outputDirectory
        The output directory where the I18N class will be written to, without the package structure. This directory will be added as a project source root if needed.
        Since:
        1.0
      • scope

        @Parameter(property="i18n.scope",
                   defaultValue="compile")
        Scope scope
        The scope of the project source root, compile or test.
        Since:
        1.0
      • inputEncoding

        @Parameter(property="i18n.inputEncoding",
                   defaultValue="${project.build.sourceEncoding}")
        java.lang.String inputEncoding
        The input encoding.
        Since:
        1.0
      • outputEncoding

        @Parameter(property="i18n.outputEncoding",
                   defaultValue="${project.build.sourceEncoding}")
        java.lang.String outputEncoding
        The output encoding.
        Since:
        1.0
      • licenseText

        @Parameter(property="i18n.license.text")
        java.lang.String licenseText
        The license text. This can be specified in a few ways:
        • Using one of the pre-defined licenses:
          • Apache-2.0: the Apache License 2.0
          • BSD-2-Clause: the 2-Clause BSD License / FreeBSD License / Simplified BSD License
          • EPL-1.0: the Eclipse Public License 1.0
          • EPL-2.0: the Eclipse Public License 2.0
          • GPL-2.0: the GNU General Public License version 2
          • GPL-3.0: the GNU General Public License version 3
          • LGPL-2.0: the GNU Library General Public License version 2
          • LGPL-2.1: the GNU Lesser General Public License version 2.1
          • MIT: the MIT License
          • MPL-2.0: the Mozilla Public License 2.0
        • As a relative or absolute path to the file containing the license text.
        • As a URL to the file containing the license text.
        • As a literal license text.
        Inside the license text three place holders can be used:
        • ${fileName} for the file name.
        • ${copyrightYear} for the copyright year.
        • ${copyrightHolder} for the copyright holder.
        Since:
        1.0
      • licenseCopyrightYear

        @Parameter(property="i18n.license.copyrightYear")
        private java.lang.String licenseCopyrightYear
        The copyright year to be inserted into the license text. If not configured the current year will be used.
        Since:
        1.0
      • licenseCopyrightHolder

        @Parameter(property="i18n.license.copyrightHolder",
                   defaultValue="${user.name}")
        private java.lang.String licenseCopyrightHolder
        The copyright holder to be inserted into the license text.
        Since:
        1.0
      • publicVisibility

        @Parameter(property="i18n.publicVisibility",
                   defaultValue="true")
        private boolean publicVisibility
        If true, generated classes and methods will have public visibility; otherwise they will be package private.
        Since:
        1.0
      • suppressWarnings

        @Parameter(property="i18n.suppressWarnings")
        private java.util.Set<java.lang.String> suppressWarnings
        Warnings that will be suppressed using SuppressWarnings.
        Since:
        1.0
      • useMessageFormat

        @Parameter(property="i18n.useMessageFormat",
                   defaultValue="false")
        private boolean useMessageFormat
        If true, MessageFormat will be used to format messages; otherwise String.format(java.util.Locale, String, Object...) will be used.
        Since:
        1.0
    • Constructor Detail

      • GenerateMojo

        public GenerateMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • readI18N

        private I18N.Node readI18N()
                            throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • readProperties

        java.util.Map<java.lang.String,​java.lang.String> readProperties()
                                                                       throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getSourceFile

        private java.io.File getSourceFile()
      • getInputCharset

        java.nio.charset.Charset getInputCharset()
      • getOutputCharset

        java.nio.charset.Charset getOutputCharset()
      • getLicenseText

        java.lang.String getLicenseText()
                                 throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • createURL

        private java.net.URL createURL​(java.lang.String url)
      • getLicenseText

        private java.lang.String getLicenseText​(java.net.URL licenseURL)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getLicenseText

        private java.lang.String getLicenseText​(java.io.File licenseFile)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getLicenseText

        private java.lang.String getLicenseText​(java.io.Reader input)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getI18NClassName

        java.lang.String getI18NClassName()
      • capitalize

        private java.lang.String capitalize​(java.lang.String s)
      • appendSourcePath

        void appendSourcePath()
      • appendSourcePath

        private void appendSourcePath​(java.util.List<java.lang.String> sourceRoots,
                                      java.util.function.Consumer<java.lang.String> addSourceRoot)