Skip to content

Commit

Permalink
Fix Snakeyaml
Browse files Browse the repository at this point in the history
Move to 2.2, but cannot get past one error: seems
Model is not imported??
  • Loading branch information
cstamas committed Apr 30, 2024
1 parent c90d219 commit a21cf2c
Show file tree
Hide file tree
Showing 5 changed files with 1,732 additions and 3 deletions.
10 changes: 9 additions & 1 deletion modello-plugins/modello-plugin-snakeyaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.33</version>
<version>2.2</version>
</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 @@ -1040,7 +1040,8 @@ private void writeNewLocation(String trackerVariable, JSourceCode sc) {
return;
}

String constr = "new " + locationTracker.getName() + "( parser.getLineNumber(), parser.getColumnNumber()";
String constr = "new " + locationTracker.getName()
+ "( parser.peekEvent().getStartMark().getLine(), parser.peekEvent().getStartMark().getColumn()";
constr += (sourceTracker != null) ? ", " + SOURCE_PARAM : "";
constr += " )";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private void generateSnakeYamlWriter() throws ModelloException, IOException {

JClass jClass = new JClass(packageName + '.' + marshallerName);
initHeader(jClass);
suppressAllWarnings(objectModel, jClass);

jClass.addImport("org.yaml.snakeyaml.DumperOptions");
jClass.addImport("org.yaml.snakeyaml.DumperOptions.Version");
Expand Down Expand Up @@ -289,7 +290,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.AUTO ) );");

sc.add("for ( " + toType + " o : " + value + " )");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.codehaus.modello.plugin.snakeyaml;

/*
* 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.codehaus.modello.AbstractModelloJavaGeneratorTest;
import org.codehaus.modello.core.ModelloCore;
import org.codehaus.modello.model.Model;

public class SnakeYamlGeneratorTest extends AbstractModelloJavaGeneratorTest {
public SnakeYamlGeneratorTest() {
super("snakeyaml");
}

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

Model model = modello.loadModel(getXmlResourceReader("/models/maven.mdo"));

Properties parameters = getModelloParameters("4.0.0");

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

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

0 comments on commit a21cf2c

Please sign in to comment.