Skip to content
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

Issue #367 related fixes #419

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions modello-plugins/modello-plugin-snakeyaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@
<artifactId>snakeyaml</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void writeClassReaders(ModelClass modelClass, JClass jClass, boolean roo

sc = unmarshall.getSourceCode();

sc.add("Parser parser = new ParserImpl( new StreamReader( reader ) );");
sc.add("Parser parser = new ParserImpl( new StreamReader( reader ), new LoaderOptions() );");

sc.add("return " + readerMethodName + "( parser, strict );");

Expand Down Expand Up @@ -287,6 +287,7 @@ private void generateSnakeYamlReader() throws ModelloException, IOException {
jClass.addImport("org.yaml.snakeyaml.parser.ParserException");
jClass.addImport("org.yaml.snakeyaml.parser.ParserImpl");
jClass.addImport("org.yaml.snakeyaml.reader.StreamReader");
jClass.addImport("org.yaml.snakeyaml.LoaderOptions");
jClass.addImport("java.io.InputStream");
jClass.addImport("java.io.InputStreamReader");
jClass.addImport("java.io.IOException");
Expand Down Expand Up @@ -820,6 +821,8 @@ private void writeHelpers(JClass jClass) {

sc = method.getSourceCode();

sc.add("if (!(event instanceof ScalarEvent))");
sc.addIndented("return false;");
sc.add("String currentName = ( (ScalarEvent) event ).getValue();");

sc.add("");
Expand Down Expand Up @@ -855,9 +858,17 @@ private void writeHelpers(JClass jClass) {

sc.add("if ( strict )");

sc.add("{");
sc.indent();
sc.add("if ( event instanceof ScalarEvent )");
sc.add("{");
sc.addIndented(
"throw new ParserException( \"Unrecognised tag: '\" + ( (ScalarEvent) event ).getValue() + \"'\", event.getStartMark(), \"\", null );");
sc.add("} else {");
sc.addIndented(
"return ; // throw new ParserException( \"Unrecognised : '\" + event.getEventId() + \"'\", event.getStartMark(), \"\", null );");
sc.add("}");
sc.unindent();
sc.add("}");

sc.add("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ private void writeClass(ModelClass modelClass, JClass jClass) throws ModelloExce
sc.indent();

writeScalarKey(sc, fieldTagName);
sc.add("generator.emit( new SequenceStartEvent( null, null, true, null, null, false ) );");
sc.add(
"generator.emit( new SequenceStartEvent( null, null, true, null, null, FlowStyle.BLOCK ) );");

if (useJava5) {
sc.add("for ( " + toType + " o : " + value + " )");
Expand Down Expand Up @@ -330,7 +331,8 @@ private void writeClass(ModelClass modelClass, JClass jClass) throws ModelloExce
writeScalarKey(sc, fieldTagName);

if (xmlAssociationMetadata.isMapExplode()) {
sc.add("generator.emit( new SequenceStartEvent( null, null, true, null, null, false ) );");
sc.add(
"generator.emit( new SequenceStartEvent( null, null, true, null, null, FlowStyle.BLOCK) );");
} else {
sc.add(
"generator.emit( new MappingStartEvent( null, null, true, null, null, FlowStyle.BLOCK ) );");
Expand All @@ -344,7 +346,7 @@ private void writeClass(ModelClass modelClass, JClass jClass) throws ModelloExce
if (association.getType().equals(ModelDefault.PROPERTIES)) {
entryTypeBuilder.append("Object, Object");
} else {
entryTypeBuilder.append("String, ").append(association.getTo());
entryTypeBuilder.append("Object, ").append(association.getTo());
}

entryTypeBuilder.append('>');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.codehaus.modello.plugin.snakeyaml;

/*
* Copyright (c) 2013, 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.List;
import java.util.Properties;

import org.codehaus.modello.AbstractModelloJavaGeneratorTest;
import org.codehaus.modello.core.ModelloCore;
import org.codehaus.modello.model.Model;
import org.codehaus.modello.model.ModelClass;
import org.codehaus.modello.model.Version;

/**
* @author <a href="mailto:simonetripodi@apache.org">Simone Tripodi</a>
*/
public class SnakeyamlGeneratorTest extends AbstractModelloJavaGeneratorTest {
public SnakeyamlGeneratorTest() {
super("snakeyaml");
}

public void testGenerator() throws Throwable {
ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE);

Model model = modello.loadModel(getXmlResourceReader("/ibcore-executor.mdo"));

// check some elements read from the model
List<ModelClass> classesList = model.getClasses(new Version("4.0.0"));

assertEquals(3, classesList.size());

ModelClass clazz = (ModelClass) classesList.get(0);

assertEquals("GeneratedProcessExecution", clazz.getName());

// now generate sources and test them
Properties parameters = getModelloParameters("4.0.0");

modello.generate(model, "java", parameters);
modello.generate(model, "snakeyaml-reader", parameters);
modello.generate(model, "snakeyaml-writer", parameters);

addDependency("org.yaml", "snakeyaml");
compileGeneratedSources();

// TODO: see why without this, version system property is set to "2.4.1" value after verify
System.setProperty("version", getModelloVersion());

verifyCompiledGeneratedSources("org.codehaus.modello.generator.xml.sax.SaxVerifier");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<model
xmlns="http://codehaus-plexus.github.io/MODELLO/1.8.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://codehaus-plexus.github.io/MODELLO/1.8.0 http://codehaus-plexus.github.io/modello/xsd/modello-1.8.0.xsd"
java.suppressAllWarnings="false"
xml.namespace="https://resources.infrastructurebuilder.org/IBDataSet/${apiVersion}"
xml.schemaLocation="https://resources.infrastructurebuilder.org/xsd/IBDataSet-${apiVersion}"
xsd.namespace="https://resources.infrastructurebuilder.org/IBDataSet/${apiVersion}"
xsd.targetNamespace="https://resources.infrastructurebuilder.org/IBDataSet/${apiVersion}"
>
<id>execution</id>
<name>ProcessExecutionModel</name> <!-- Must be a single (no spaces, no dashes, no periods) identifier in order
to create reader/writer -->
<description>Model for ProcessExecution instances</description>

<defaults>
<default>
<key>package</key>
<value>org.infrastructurebuilder.util.executor.execution.model</value>
</default>
</defaults>

<classes>
<!-- MODEL -->
<class
xml.tagName="processExecution"
rootElement="true"
java.clone="deep"
>
<name>GeneratedProcessExecution</name>
<description>Persistence for ibcore-executor ProcessExecution instances</description>
<version>1.0.0+</version>
<fields>
<field>
<name>id</name>
<version>1.0.0+</version>
<required>true</required>
<description>Processing ID</description>
<type>String</type>
</field>
<field>
<name>executable</name>
<version>1.0.0+</version>
<required>true</required>
<description>Path to executable</description>
<type>String</type>
</field>
<field>
<name>arguments</name>
<version>1.0.0+</version>
<required>true</required>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>Arguments passed to execution</description>
</field>
<field>
<name>timeout</name>
<version>1.0.0+</version>
<required>false</required>
<description>Optional timeout</description>
<type>String</type>
</field>
<field>
<name>optional</name>
<version>1.0.0+</version>
<required>false</required>
<defaultValue>false</defaultValue>
<description>Is the successful execution of this optional</description>
<type>boolean</type>
</field>
<field>
<name>background</name>
<version>1.0.0+</version>
<required>false</required>
<defaultValue>false</defaultValue>
<description>Is the execution to be in the background</description>
<type>boolean</type>
</field>
<field xdoc.separator="blank">
<name>environment</name>
<version>1.0.0+</version>
<description>Environment variables</description>
<type>Properties</type>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>exy</name>
<description>Extra vocabulary as key/value.</description>
<version>1.0.0+</version>
<identifier>true</identifier>
<type>Map</type>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>

<field>
<name>workDirectory</name>
<version>1.0.0+</version>
<required>false</required>
<type>String</type>
<description>Work directory</description>
</field>
<field>
<name>exitValues</name>
<version>1.0.0+</version>
<required>false</required>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
<description>"successful" exit codes(parsed as integers)</description>
</field>
<field>
<name>stdOutPath</name>
<version>1.0.0+</version>
<required>false</required>
<description>Path to write stdout</description>
<type>String</type>
</field>
<field>
<name>stdErrPath</name>
<version>1.0.0+</version>
<required>false</required>
<description>Path to write stderr</description>
<type>String</type>
</field>
<field>
<name>stdInPath</name>
<version>1.0.0+</version>
<required>false</required>
<description>Path to read as stdin</description>
<type>String</type>
</field>
<field>
<name>relativeRoot</name>
<version>1.0.0+</version>
<required>false</required>
<description>Path to Relative root</description>
<type>String</type>
</field>


</fields>

</class>
<class
locationTracker="locations"
java.clone="shallow"
>
<name>IBExecInputLocation</name>
<version>1.0.0+</version>
<fields>
<!-- line, column and source fields are auto-generated by Modello -->
</fields>
</class>
<class
sourceTracker="source"
java.clone="shallow"
>
<name>IBExecInputSource</name>
<version>1.0.0+</version>
<fields>
</fields>
</class>
</classes>
</model>