Skip to content

Xpp3 extended writer #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modello-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public class ModelloParameterConstants
*/
public static final String DOM_AS_XPP3 = "modello.dom.xpp3";

/**
* @since 1.10
*/
public static final String EXTENDED_CLASSNAME_SUFFIX = "modello.xpp3.extended.suffix";

private ModelloParameterConstants()
{
}
Expand Down
2 changes: 1 addition & 1 deletion modello-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.codehaus.modello.maven;

/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import java.util.Properties;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.modello.ModelloParameterConstants;

/**
* Creates an XPP3 extended writer from the model. An extended writer renders the content with comments about the
* line/column from which the data was read if the model supports this.
*
* @author Hervé Boutemy
* @since 1.10
*/
@Mojo( name = "xpp3-extended-writer", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
public class ModelloXpp3ExtendedWriterMojo
extends ModelloXpp3WriterMojo
{
/**
* The class name suffix for the generated writer.
*/
@Parameter( defaultValue = "Ex" )
private String extendedClassnameSuffix;

@Override
protected String getGeneratorType()
{
return "xpp3-extended-writer";
}

protected void customizeParameters( Properties parameters )
{
super.customizeParameters( parameters );

if ( extendedClassnameSuffix != null )
{
parameters.put( ModelloParameterConstants.EXTENDED_CLASSNAME_SUFFIX, extendedClassnameSuffix );
}
}
}
5 changes: 4 additions & 1 deletion modello-maven-plugin/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ Modello Maven Plugin
* {{{./xpp3-reader-mojo.html}modello:xpp3-reader}} Generates an XML Pull Parser reader from the Modello model.

* {{{./xpp3-extended-reader-mojo.html}modello:xpp3-extended-reader}} Generates an XML Pull Parser reader from the
Modello model that records line/column number metadata in the parsed model.
Modello model that records line/column number metadata and eventual source in the parsed model.

* {{{./xpp3-extended-writer-mojo.html}modello:xpp3-extended-writer}} Generates an XML Pull Parser writer from the
Modello model that writes line/column number and source info as comments on each line.

* {{{./dom4j-writer-mojo.html}modello:dom4j-writer}} Generates a DOM4J writer from the Modello model.

Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-converters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-dom4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected void addModelImports( JClass jClass, BaseElement baseElem )
}
}

private void addModelImport( JClass jClass, ModelType modelType, String basePackageName )
protected void addModelImport( JClass jClass, ModelType modelType, String basePackageName )
{
String packageName = modelType.getPackageName( isPackageWithVersion(), getGeneratedVersion() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ private void generateLocationBean( JClass jClass, ModelClass locationClass, Mode
}

JType fieldType = new JMapType( "java.util.Map", new JType(locationClass.getName()), useJava5 );
JType fieldImpl = new JMapType("java.util.LinkedHashMap", new JType(locationClass.getName()), useJava5);
JType fieldImpl = new JMapType( "java.util.LinkedHashMap", new JType( locationClass.getName() ), useJava5 );

// public Map<Object, Location> getLocations()
JMethod jMethod = new JMethod( "get" + capitalise( locationsField ), fieldType, null );
Expand Down Expand Up @@ -1044,6 +1044,15 @@ private void generateLocationBean( JClass jClass, ModelClass locationClass, Mode
sc.add( "" );
sc.add( "return result;" );
jClass.addMethod( jMethod );

JClass stringFormatterClass = jClass.createInnerClass( "StringFormatter" );
stringFormatterClass.getModifiers().setStatic( true );
stringFormatterClass.getModifiers().setAbstract( true );

jMethod = new JMethod( "toString", new JType( "String" ), null );
jMethod.getModifiers().setAbstract( true );
jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "location" ) );
stringFormatterClass.addMethod( jMethod );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-jdom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-jsonschema/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-sax/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-snakeyaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-stax/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-xdoc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion modello-plugins/modello-plugin-xpp3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.2-SNAPSHOT</version>
<version>1.10.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* SOFTWARE.
*/

import java.util.Properties;

import org.codehaus.modello.ModelloException;
import org.codehaus.modello.model.Model;
import org.codehaus.modello.model.ModelClass;
import org.codehaus.modello.plugins.xml.AbstractXmlJavaGenerator;

/**
Expand All @@ -30,4 +35,36 @@
public abstract class AbstractXpp3Generator
extends AbstractXmlJavaGenerator
{
protected boolean requiresDomSupport;

protected ModelClass locationTracker;

protected ModelClass sourceTracker;

protected boolean isLocationTracking()
{
return false;
}

@Override
protected void initialize( Model model, Properties parameters )
throws ModelloException
{
super.initialize( model, parameters );

requiresDomSupport = false;
locationTracker = sourceTracker = null;

if ( isLocationTracking() )
{
locationTracker = model.getLocationTracker( getGeneratedVersion() );
if ( locationTracker == null )
{
throw new ModelloException( "No model class has been marked as location tracker"
+ " via the attribute locationTracker=\"locations\", cannot generate extended reader." );
}

sourceTracker = model.getSourceTracker( getGeneratedVersion() );
}
}
}
Loading