MPLUGIN-75: Internationalize PluginXdocGenerator

o added i18n support

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@629078 13f79535-47bb-0310-9956-ffa450edef68
master
Vincent Siveton 2008-02-19 11:48:48 +00:00
parent df38c418d9
commit 617a0214f1
5 changed files with 214 additions and 40 deletions

View File

@ -155,7 +155,7 @@ public class PluginReport
mojoScanner.populatePluginDescriptor( project, pluginDescriptor );
// Generate the plugin's documentation
generatePluginDocumentation( pluginDescriptor );
generatePluginDocumentation( pluginDescriptor, locale );
// Write the overview
PluginOverviewRenderer r = new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor,
@ -192,7 +192,7 @@ public class PluginReport
return "plugin-info";
}
private void generatePluginDocumentation( PluginDescriptor pluginDescriptor )
private void generatePluginDocumentation( PluginDescriptor pluginDescriptor, Locale locale )
throws MavenReportException
{
try
@ -200,7 +200,7 @@ public class PluginReport
File outputDir = new File( getOutputDirectory() );
outputDir.mkdirs();
PluginXdocGenerator generator = new PluginXdocGenerator();
PluginXdocGenerator generator = new PluginXdocGenerator( locale );
generator.execute( outputDir, pluginDescriptor );
}
catch ( IOException e )

View File

@ -25,6 +25,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -45,6 +47,31 @@ import org.w3c.tidy.Tidy;
public class PluginXdocGenerator
implements Generator
{
private final Locale locale;
/**
* Default constructor using <code>Locale.ENGLISH</code> as locale.
*/
public PluginXdocGenerator()
{
this.locale = Locale.ENGLISH;
}
/**
* @param locale not null wanted locale.
*/
public PluginXdocGenerator( Locale locale )
{
if ( locale == null )
{
this.locale = Locale.ENGLISH;
}
else
{
this.locale = locale;
}
}
/** {@inheritDoc} */
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
@ -111,14 +138,26 @@ public class PluginXdocGenerator
w.addAttribute( "name", mojoDescriptor.getFullGoalName() );
w.startElement( "p" );
w.writeMarkup( "<strong>"+ getBundle( locale ).getString( "pluginxdoc.fullname" ) + "</strong>:" );
w.endElement(); //p
w.startElement( "p" );
w.writeMarkup( mojoDescriptor.getPluginDescriptor().getGroupId() + ":"
+ mojoDescriptor.getPluginDescriptor().getArtifactId() + ":"
+ mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getFullGoalName() );
w.endElement(); //p
w.startElement( "p" );
w.writeMarkup( "<strong>"+ getBundle( locale ).getString( "pluginxdoc.description" ) + "</strong>:" );
w.endElement(); //p
w.startElement( "p" );
if ( mojoDescriptor.getDescription() != null )
{
w.writeMarkup( makeHtmlValid( mojoDescriptor.getDescription() ) );
}
else
{
w.writeText( "No description." );
w.writeText( getBundle( locale ).getString( "pluginxdoc.nodescription" ) );
}
w.endElement(); // p
@ -137,36 +176,37 @@ public class PluginXdocGenerator
private void writeGoalAttributes( MojoDescriptor mojoDescriptor, XMLWriter w )
{
w.startElement( "p" );
w.writeMarkup( "<strong>Mojo Attributes</strong>:" );
w.writeMarkup( "<strong>"+ getBundle( locale ).getString( "pluginxdoc.mojodescriptor.attributes" ) + "</strong>:" );
w.endElement(); //p
w.startElement( "ul" );
String value = mojoDescriptor.getDeprecated();
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "This plugin goal has been deprecated: " + value + "" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.deprecated" ) + ": " + value + "." );
w.endElement(); //li
}
if ( mojoDescriptor.isProjectRequired() )
{
w.startElement( "li" );
w.writeMarkup( "Requires a Maven 2.0 project to execute." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.projectRequired" ) );
w.endElement(); //li
}
if ( mojoDescriptor.isAggregator() )
{
w.startElement( "li" );
w.writeMarkup( "Executes as an aggregator plugin." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.aggregator" ) );
w.endElement(); //li
}
if ( mojoDescriptor.isDirectInvocationOnly() )
{
w.startElement( "li" );
w.writeMarkup( "Executes by direct invocation only." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.directInvocationOnly" ) );
w.endElement(); //li
}
@ -174,7 +214,7 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Requires dependency resolution of artifacts in scope: <code>" + value + "</code>" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.dependencyResolutionRequired" ) + ": <code>" + value + "</code>." );
w.endElement(); //li
}
@ -182,7 +222,7 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Since version: <code>" + value + "</code>" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.since" ) + ": <code>" + value + "</code>." );
w.endElement(); //li
}
@ -190,7 +230,7 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Automatically executes within the lifecycle phase: <code>" + value + "</code>" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.phase" ) + ": <code>" + value + "</code>." );
w.endElement(); //li
}
@ -198,8 +238,8 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Invokes the execution of the lifecycle phase <code>" + value
+ "</code> prior to executing itself." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.executePhase1" ) + " <code>" + value
+ "</code>" + getBundle( locale ).getString( "pluginxdoc.mojodescriptor.executePhase2" ) + "." );
w.endElement(); //li
}
@ -207,8 +247,8 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Invokes the execution of this plugin's goal <code>" + value
+ "</code> prior to executing itself." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.executeGoal1" ) + " <code>" + value
+ "</code> " + getBundle( locale ).getString( "pluginxdoc.mojodescriptor.executeGoal2" ) + "." );
w.endElement(); //li
}
@ -216,21 +256,21 @@ public class PluginXdocGenerator
if ( StringUtils.isNotEmpty( value ) )
{
w.startElement( "li" );
w.writeMarkup( "Executes in its own lifecycle: <code>" + value + "</code>" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.executeLifecycle" ) + ": <code>" + value + "</code>." );
w.endElement(); //li
}
if ( mojoDescriptor.isOnlineRequired() )
{
w.startElement( "li" );
w.writeMarkup( "Requires that mvn runs in online mode." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.onlineRequired" ) );
w.endElement(); //li
}
if ( !mojoDescriptor.isInheritedByDefault() )
{
w.startElement( "li" );
w.writeMarkup( "Is NOT inherited by default in multi-project builds." );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.inheritedByDefault" ) );
w.endElement(); //li
}
@ -280,20 +320,20 @@ public class PluginXdocGenerator
private void writeParameterDetails( MojoDescriptor mojoDescriptor, List parameterList, XMLWriter w )
{
w.startElement( "subsection" );
w.addAttribute( "name", "Parameter Details" );
w.addAttribute( "name", getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.details" ) );
for ( Iterator parameters = parameterList.iterator(); parameters.hasNext(); )
{
Parameter parameter = (Parameter) parameters.next();
w.startElement( "p" );
w.writeMarkup( "<strong><a name=\"" + parameter.getName() + "\">" + parameter.getName() + "</a></strong>" );
w.writeMarkup( "<strong><a name=\"" + parameter.getName() + "\">" + parameter.getName() + "</a>:</strong>" );
w.endElement(); //p
String description = parameter.getDescription();
if ( StringUtils.isEmpty( description ) )
{
description = "No Description.";
description = getBundle( locale ).getString( "pluginxdoc.nodescription" );
}
else
{
@ -305,34 +345,34 @@ public class PluginXdocGenerator
w.startElement( "ul" );
writeDetail( "Deprecated", parameter.getDeprecated(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.deprecated" ), parameter.getDeprecated(), w );
writeDetail( "Type", parameter.getType(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.type" ), parameter.getType(), w );
if ( StringUtils.isNotEmpty( parameter.getSince() ) )
{
writeDetail( "Since", parameter.getSince(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.since" ), parameter.getSince(), w );
}
else
{
if ( StringUtils.isNotEmpty( mojoDescriptor.getSince() ) )
{
writeDetail( "Since", mojoDescriptor.getSince(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.since" ), mojoDescriptor.getSince(), w );
}
}
if ( parameter.isRequired() )
{
writeDetail( "Required", "Yes", w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.required" ), getBundle( locale ).getString( "pluginxdoc.yes" ), w );
}
else
{
writeDetail( "Required", "No", w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.required" ), getBundle( locale ).getString( "pluginxdoc.no" ), w );
}
writeDetail( "Expression", parameter.getExpression(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.expression" ), parameter.getExpression(), w );
writeDetail( "Default", parameter.getDefaultValue(), w );
writeDetail( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.default" ), parameter.getDefaultValue(), w );
w.endElement();//ul
@ -362,13 +402,13 @@ public class PluginXdocGenerator
List requiredParams = getParametersByRequired( true, parameterList );
if ( requiredParams.size() > 0 )
{
writeParameterList( mojoDescriptor, "Required Parameters", requiredParams, w );
writeParameterList( mojoDescriptor, getBundle( locale ).getString( "pluginxdoc.mojodescriptor.requiredParameters" ), requiredParams, w );
}
List optionalParams = getParametersByRequired( false, parameterList );
if ( optionalParams.size() > 0 )
{
writeParameterList( mojoDescriptor, "Optional Parameters", optionalParams, w );
writeParameterList( mojoDescriptor, getBundle( locale ).getString( "pluginxdoc.mojodescriptor.optionalParameters" ), optionalParams, w );
}
}
@ -381,16 +421,16 @@ public class PluginXdocGenerator
w.startElement( "tr" );
w.startElement( "th" );
w.writeText( "Name" );
w.writeText( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.name" ) );
w.endElement();//th
w.startElement( "th" );
w.writeText( "Type" );
w.writeText( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.type" ) );
w.endElement();//th
w.startElement( "th" );
w.writeText( "Since" );
w.writeText( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.since" ) );
w.endElement();//th
w.startElement( "th" );
w.writeText( "Description" );
w.writeText( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.description" ) );
w.endElement();//th
w.endElement();//tr
@ -427,7 +467,7 @@ public class PluginXdocGenerator
String description = parameter.getDescription();
if ( StringUtils.isEmpty( description ) )
{
description = "No description.";
description = getBundle( locale ).getString( "pluginxdoc.nodescription" );
}
else
{
@ -435,13 +475,13 @@ public class PluginXdocGenerator
}
if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) )
{
description = "<strong>Deprecated</strong>. " + description;
description = "<strong>" + getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.deprecated" ) + "</strong>. " + description;
}
w.writeMarkup( description );
w.writeMarkup( description + " " );
if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) )
{
w.writeMarkup( " Default value is <code>" );
w.writeMarkup( getBundle( locale ).getString( "pluginxdoc.mojodescriptor.parameter.defaultValue" ) + ": <code>" );
w.writeText( parameter.getDefaultValue() );
w.writeMarkup( "</code>." );
}
@ -617,4 +657,15 @@ public class PluginXdocGenerator
}
return sb.toString();
}
/**
* Gets the resource bundle for the specified locale.
*
* @param locale The locale of the currently generated report.
* @return The resource bundle for the requested locale.
*/
private ResourceBundle getBundle( Locale locale )
{
return ResourceBundle.getBundle( "pluginxdoc", locale, getClass().getClassLoader() );
}
}

View File

@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
pluginxdoc.yes=Yes
pluginxdoc.no=No
pluginxdoc.description=Description
pluginxdoc.nodescription=None.
pluginxdoc.fullname=Full name
pluginxdoc.mojodescriptor.attributes=Attributes
pluginxdoc.mojodescriptor.deprecated=This plugin goal has been deprecated
pluginxdoc.mojodescriptor.projectRequired=Requires a Maven 2.0 project to be executed.
pluginxdoc.mojodescriptor.aggregator=Executes as an aggregator plugin.
pluginxdoc.mojodescriptor.directInvocationOnly=Executes by direct invocation only.
pluginxdoc.mojodescriptor.dependencyResolutionRequired=Requires dependency resolution of artifacts in scope
pluginxdoc.mojodescriptor.since=Since version
pluginxdoc.mojodescriptor.phase=Automatically executes within the lifecycle phase
pluginxdoc.mojodescriptor.executePhase1=Invokes the execution of the lifecycle phase
pluginxdoc.mojodescriptor.executePhase2=prior to executing itself.
pluginxdoc.mojodescriptor.executeGoal1=Invokes the execution of this plugin's goal
pluginxdoc.mojodescriptor.executeGoal2=prior to executing itself.
pluginxdoc.mojodescriptor.executeLifecycle=Executes in its own lifecycle
pluginxdoc.mojodescriptor.onlineRequired=Requires that Maven runs in online mode.
pluginxdoc.mojodescriptor.inheritedByDefault=Is NOT inherited by default in multi-project builds.
pluginxdoc.mojodescriptor.parameter.details=Parameter Details
pluginxdoc.mojodescriptor.parameter.deprecated=Deprecated
pluginxdoc.mojodescriptor.parameter.name=Name
pluginxdoc.mojodescriptor.parameter.description=Description
pluginxdoc.mojodescriptor.parameter.type=Type
pluginxdoc.mojodescriptor.parameter.since=Since
pluginxdoc.mojodescriptor.parameter.required=Required
pluginxdoc.mojodescriptor.parameter.expression=Expression
pluginxdoc.mojodescriptor.parameter.default=Default
pluginxdoc.mojodescriptor.parameter.defaultValue=Default value is
pluginxdoc.mojodescriptor.requiredParameters=Required Parameters
pluginxdoc.mojodescriptor.optionalParameters=Optional Parameters

View File

@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# NOTE:
# This bundle is intentionally empty because English strings are provided by the base bundle via the parent chain. It
# must be provided nevertheless such that a request for locale "en" will not errorneously pick up the bundle for the
# JVM's default locale (which need not be "en"). See the method javadoc about
# ResourceBundle.getBundle(String, Locale, ClassLoader)
# for a full description of the lookup strategy.

View File

@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
pluginxdoc.yes=Oui
pluginxdoc.no=Non
pluginxdoc.description=Description
pluginxdoc.nodescription=Aucune.
pluginxdoc.fullname=Nom complet
pluginxdoc.mojodescriptor.attributes=Attributs
pluginxdoc.mojodescriptor.deprecated=Le goal de ce plugin goal est obsol\u00e8te
pluginxdoc.mojodescriptor.projectRequired=Exige un projet Maven 2.0 pour \u00eatre ex\u00e9cut\u00e9.
pluginxdoc.mojodescriptor.aggregator=S'ex\u00e9cute comme un plugin agr\u00e9g\u00e9.
pluginxdoc.mojodescriptor.directInvocationOnly=S'ex\u00e9cute par l'invocation directe seulement.
pluginxdoc.mojodescriptor.dependencyResolutionRequired=Exige une r\u00e9solution de d\u00e9pendances des artefacts dans le scope
pluginxdoc.mojodescriptor.since=Depuis la version
pluginxdoc.mojodescriptor.phase=S'ex\u00e9cute automatiquement dans la phase du cycle de vie
pluginxdoc.mojodescriptor.executePhase1=Appelle l'ex\u00e9cution de la phase du cycle de vie
pluginxdoc.mojodescriptor.executePhase2=avant de s'ex\u00e9cuter.
pluginxdoc.mojodescriptor.executeGoal1=Appelle l'ex\u00e9cution du goal de ce plugin
pluginxdoc.mojodescriptor.executeGoal2=avant de s'ex\u00e9cuter.
pluginxdoc.mojodescriptor.executeLifecycle=S'ex\u00e9cute dans son propre cycle de vie
pluginxdoc.mojodescriptor.onlineRequired=Exige que Maven s'ex\u00e9cute en ligne.
pluginxdoc.mojodescriptor.inheritedByDefault=N'est PAS h\u00e9rit\u00e9 par d\u00e9faut dans une construction multi-projet.
pluginxdoc.mojodescriptor.parameter.details=D\u00e9tails des param\u00e8tres
pluginxdoc.mojodescriptor.parameter.deprecated=Obsol\u00e8te
pluginxdoc.mojodescriptor.parameter.name=Nom
pluginxdoc.mojodescriptor.parameter.description=Description
pluginxdoc.mojodescriptor.parameter.type=Type
pluginxdoc.mojodescriptor.parameter.since=Depuis
pluginxdoc.mojodescriptor.parameter.required=Exig\u00e9
pluginxdoc.mojodescriptor.parameter.expression=Expression
pluginxdoc.mojodescriptor.parameter.default=D\u00e9faut
pluginxdoc.mojodescriptor.parameter.defaultValue=Valeur par d\u00e9faut est
pluginxdoc.mojodescriptor.requiredParameters=Param\u00e8tres requis
pluginxdoc.mojodescriptor.optionalParameters=Param\u00e8tres optionnels