Class GenerateMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- com.github.robtimus.maven.plugins.i18n.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.AbstractMojoGenerate an I18N class from an I18N resource file.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.StringbundleNameThe bundle name to generate an I18N class for.(package private) java.lang.StringclassNameThe fully qualified name of the I18N class to generate.(package private) java.lang.StringinputEncodingThe input encoding.private java.lang.StringlicenseCopyrightHolderThe copyright holder to be inserted into the license text.private java.lang.StringlicenseCopyrightYearThe copyright year to be inserted into the license text.(package private) java.lang.StringlicenseTextThe license text.(package private) java.io.FileoutputDirectoryThe output directory where the I18N class will be written to, without the package structure.(package private) java.lang.StringoutputEncodingThe output encoding.(package private) org.apache.maven.project.MavenProjectprojectprivate booleanpublicVisibilityIftrue, generated classes and methods will have public visibility; otherwise they will be package private.(package private) ScopescopeThe scope of the project source root,compileortest.(package private) java.io.FilesourceDirectoryThe source directory where the I18N resource file can be found, without the package structure.private java.util.Set<java.lang.String>suppressWarningsWarnings that will be suppressed usingSuppressWarnings.private booleanuseMessageFormatIftrue,MessageFormatwill be used to format messages; otherwiseString.format(java.util.Locale, String, Object...)will be used.
-
Constructor Summary
Constructors Constructor Description GenerateMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidappendSourcePath()private voidappendSourcePath(java.util.List<java.lang.String> sourceRoots, java.util.function.Consumer<java.lang.String> addSourceRoot)private java.lang.Stringcapitalize(java.lang.String s)private java.net.URLcreateURL(java.lang.String url)voidexecute()(package private) java.lang.StringgetI18NClassName()(package private) java.nio.charset.CharsetgetInputCharset()(package private) java.lang.StringgetLicenseText()private java.lang.StringgetLicenseText(java.io.File licenseFile)private java.lang.StringgetLicenseText(java.io.Reader input)private java.lang.StringgetLicenseText(java.net.URL licenseURL)(package private) java.nio.charset.CharsetgetOutputCharset()private java.io.FilegetSourceFile()private I18N.NodereadI18N()(package private) java.util.Map<java.lang.String,java.lang.String>readProperties()
-
-
-
Field Detail
-
project
@Parameter(defaultValue="${project}", readonly=true) org.apache.maven.project.MavenProject project
-
bundleName
@Parameter(property="i18n.bundleName", required=true) java.lang.String bundleNameThe 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 sourceDirectoryThe 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 outputDirectoryThe 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 scopeThe scope of the project source root,compileortest.- Since:
- 1.0
-
inputEncoding
@Parameter(property="i18n.inputEncoding", defaultValue="${project.build.sourceEncoding}") java.lang.String inputEncodingThe input encoding.- Since:
- 1.0
-
outputEncoding
@Parameter(property="i18n.outputEncoding", defaultValue="${project.build.sourceEncoding}") java.lang.String outputEncodingThe 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.
${fileName}for the file name.${copyrightYear}for the copyright year.${copyrightHolder}for the copyright holder.
- Since:
- 1.0
- Using one of the pre-defined licenses:
-
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 licenseCopyrightHolderThe copyright holder to be inserted into the license text.- Since:
- 1.0
-
publicVisibility
@Parameter(property="i18n.publicVisibility", defaultValue="true") private boolean publicVisibilityIftrue, 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 usingSuppressWarnings.- Since:
- 1.0
-
useMessageFormat
@Parameter(property="i18n.useMessageFormat", defaultValue="false") private boolean useMessageFormatIftrue,MessageFormatwill be used to format messages; otherwiseString.format(java.util.Locale, String, Object...)will be used.- Since:
- 1.0
-
-
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)
-
-