diff --git a/modello-plugins/modello-plugin-snakeyaml/pom.xml b/modello-plugins/modello-plugin-snakeyaml/pom.xml index 4703c41e1..4dd692391 100644 --- a/modello-plugins/modello-plugin-snakeyaml/pom.xml +++ b/modello-plugins/modello-plugin-snakeyaml/pom.xml @@ -26,5 +26,19 @@ snakeyaml 2.2 + + org.xmlunit + xmlunit-core + 2.9.1 + test + + + + + + maven-dependency-plugin + + + diff --git a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java index 78f5c3485..ae1fcd9f9 100644 --- a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java +++ b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java @@ -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 );"); @@ -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"); @@ -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(""); @@ -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(""); diff --git a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java index 33e2112ca..60534fb71 100644 --- a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java +++ b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java @@ -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 + " )"); @@ -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 ) );"); @@ -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('>'); diff --git a/modello-plugins/modello-plugin-snakeyaml/src/test/java/org/codehaus/modello/plugin/snakeyaml/SnakeyamlGeneratorTest.java b/modello-plugins/modello-plugin-snakeyaml/src/test/java/org/codehaus/modello/plugin/snakeyaml/SnakeyamlGeneratorTest.java new file mode 100644 index 000000000..5aa4925a0 --- /dev/null +++ b/modello-plugins/modello-plugin-snakeyaml/src/test/java/org/codehaus/modello/plugin/snakeyaml/SnakeyamlGeneratorTest.java @@ -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 Simone Tripodi + */ +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 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"); + } +} diff --git a/modello-plugins/modello-plugin-snakeyaml/src/test/resources/ibcore-executor.mdo b/modello-plugins/modello-plugin-snakeyaml/src/test/resources/ibcore-executor.mdo new file mode 100644 index 000000000..5d194485b --- /dev/null +++ b/modello-plugins/modello-plugin-snakeyaml/src/test/resources/ibcore-executor.mdo @@ -0,0 +1,174 @@ + + + execution + ProcessExecutionModel + Model for ProcessExecution instances + + + + package + org.infrastructurebuilder.util.executor.execution.model + + + + + + + GeneratedProcessExecution + Persistence for ibcore-executor ProcessExecution instances + 1.0.0+ + + + id + 1.0.0+ + true + Processing ID + String + + + executable + 1.0.0+ + true + Path to executable + String + + + arguments + 1.0.0+ + true + + String + * + + Arguments passed to execution + + + timeout + 1.0.0+ + false + Optional timeout + String + + + optional + 1.0.0+ + false + false + Is the successful execution of this optional + boolean + + + background + 1.0.0+ + false + false + Is the execution to be in the background + boolean + + + environment + 1.0.0+ + Environment variables + Properties + + String + * + + + + exy + Extra vocabulary as key/value. + 1.0.0+ + true + Map + + String + * + + + + + workDirectory + 1.0.0+ + false + String + Work directory + + + exitValues + 1.0.0+ + false + + String + * + + "successful" exit codes(parsed as integers) + + + stdOutPath + 1.0.0+ + false + Path to write stdout + String + + + stdErrPath + 1.0.0+ + false + Path to write stderr + String + + + stdInPath + 1.0.0+ + false + Path to read as stdin + String + + + relativeRoot + 1.0.0+ + false + Path to Relative root + String + + + + + + + + IBExecInputLocation + 1.0.0+ + + + + + + IBExecInputSource + 1.0.0+ + + + + +