From c6747419bf16f55b92a2d0eec2e87da09d9a1507 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 29 May 2024 18:51:31 +0200 Subject: [PATCH 1/3] Upgrade to SnakeYaml 2.2 (#439) Upgrade to SnakeYaml 2.2 --- .../modello-plugin-snakeyaml/pom.xml | 10 +- .../snakeyaml/SnakeYamlReaderGenerator.java | 16 +- .../snakeyaml/SnakeYamlWriterGenerator.java | 4 +- .../snakeyaml/SnakeYamlGeneratorTest.java | 50 + .../src/test/resources/models/maven.mdo | 1668 +++++++++++++++++ 5 files changed, 1744 insertions(+), 4 deletions(-) create mode 100644 modello-plugins/modello-plugin-snakeyaml/src/test/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlGeneratorTest.java create mode 100644 modello-plugins/modello-plugin-snakeyaml/src/test/resources/models/maven.mdo diff --git a/modello-plugins/modello-plugin-snakeyaml/pom.xml b/modello-plugins/modello-plugin-snakeyaml/pom.xml index 656a26fa..418654cc 100644 --- a/modello-plugins/modello-plugin-snakeyaml/pom.xml +++ b/modello-plugins/modello-plugin-snakeyaml/pom.xml @@ -24,7 +24,15 @@ org.yaml snakeyaml - 1.33 + 2.2 + + + + + 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 d53a40a5..532afe6e 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 @@ -210,7 +210,7 @@ public class SnakeYamlReaderGenerator extends AbstractSnakeYamlGenerator { 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 );"); @@ -288,6 +288,7 @@ public class SnakeYamlReaderGenerator extends AbstractSnakeYamlGenerator { 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 @@ public class SnakeYamlReaderGenerator extends AbstractSnakeYamlGenerator { 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 @@ public class SnakeYamlReaderGenerator extends AbstractSnakeYamlGenerator { 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(""); @@ -1041,7 +1052,8 @@ public class SnakeYamlReaderGenerator extends AbstractSnakeYamlGenerator { 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 += " )"; 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 cd1a5f9d..00da62ff 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 @@ -74,6 +74,7 @@ public class SnakeYamlWriterGenerator extends AbstractSnakeYamlGenerator { JClass jClass = new JClass(packageName + '.' + marshallerName); initHeader(jClass); + suppressAllWarnings(objectModel, jClass); jClass.addImport("org.yaml.snakeyaml.DumperOptions"); jClass.addImport("org.yaml.snakeyaml.DumperOptions.Version"); @@ -290,7 +291,8 @@ public class SnakeYamlWriterGenerator extends AbstractSnakeYamlGenerator { 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 + " )"); 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 00000000..a9bb50fb --- /dev/null +++ b/modello-plugins/modello-plugin-snakeyaml/src/test/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlGeneratorTest.java @@ -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.Map; + +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")); + + Map parameters = getModelloParameters("4.0.0"); + + modello.generate(model, "java", parameters); + modello.generate(model, "snakeyaml-writer", parameters); + modello.generate(model, "snakeyaml-reader", parameters); + + addDependency("org.yaml", "snakeyaml"); + compileGeneratedSources(); + } +} diff --git a/modello-plugins/modello-plugin-snakeyaml/src/test/resources/models/maven.mdo b/modello-plugins/modello-plugin-snakeyaml/src/test/resources/models/maven.mdo new file mode 100644 index 00000000..4ebfc768 --- /dev/null +++ b/modello-plugins/modello-plugin-snakeyaml/src/test/resources/models/maven.mdo @@ -0,0 +1,1668 @@ + + + maven + Maven + + + + package + org.codehaus.modello.test.model + + + + + Model + 3.0.0+ + + + extend + 3.0.0+ + + String + + + parent + 4.0.0 + + + Parent + + + + + modelVersion + 4.0.0 + true + + String + + + pomVersion + 3.0.0 + true + String + + + id + 3.0.0 + true + + String + + + groupId + 3.0.0+ + true + + String + + + artifactId + 3.0.0+ + true + + String + + + type + 4.0.0 + + String + jar + + + name + 3.0.0+ + true + + String + + + currentVersion + 3.0.0 + true + String + + + version + 4.0.0 + true + + String + + + shortDescription + 3.0.0+ + + String + + + description + 3.0.0+ + front page + of the project's web site. + ]]> + String + + + url + 3.0.0+ + + String + + + logo + 3.0.0+ + + String + + + issueTrackingUrl + 3.0.0 + + + String + + + issueManagement + 4.0.0 + + + IssueManagement + + + + ciManagement + 4.0.0 + + + CiManagement + + + + inceptionYear + 3.0.0+ + true + + String + + + gumpRepositoryId + 3.0.0 + + String + + + siteAddress + 3.0.0 + + String + + + siteDirectory + 3.0.0 + + + String + + + distributionSite + 3.0.0 + + String + This naming is inconsistent and distribution should occur from a repository structure. + + + distributionDirectory + 3.0.0 + + + String + This naming is inconsistent and distribution should occur from a repository structure. + + + + repositories + 4.0.0 + + + Repository + * + + + + pluginRepositories + 4.0.0 + + + Repository + * + + This may be removed or relocated in the near future. It is undecided whether plugins really need a + remote repository set of their own. + + + mailingLists + 3.0.0+ + + + MailingList + * + + + + developers + 3.0.0+ + developer element, which is then described by + additional elements (described below). The auto-generated site + documentation references this information. + ]]> + + Developer + * + + + + contributors + 3.0.0+ + contributor element, which is then describe by additional + elements (described below). The auto-generated site documentation + references this information. + ]]> + + Contributor + * + + + + dependencies + 3.0.0+ + dependency element, which is then described by + additional elements (described below). + ]]> + + Dependency + * + + These should ultimately only be compile time dependencies when transitive dependencies come into + play. + + + overrides + 4.0.0 + override element, which is then described by + additional elements (described below). + ]]> + + Override + * + + + + licenses + 3.0.0+ + license element, which is then describe by additional + elements (described below). The auto-generated site documentation + references this information. Projects should only list the license(s) that + applies to the project and not the licenses that apply to dependencies. + ]]> + + License + * + + + + versions + 3.0.0 + + + Version + * + + + + branches + 3.0.0 + + + Branch + * + + + + packageGroups + 3.0.0+ + + + PackageGroup + * + + + + reports + 3.0.0+ + maven site. All of the + reports will be included in the navigation bar for browsing in + the order they are specified. + ]]> + + String + * + + + + scm + 4.0.0 + + + Scm + + + + repository + 3.0.0 + + + Repository + + This element needs to be renamed as it conflicts with the existing notion of repositories in + Maven. + + + build + 3.0.0+ + true + + + Build + + + + organization + 3.0.0+ + + + Organization + + + + distributionManagement + 4.0.0 + + + DistributionManagement + + + + local + 4.0.0 + false + + + Local + + + + + properties + 3.0.0+ + + Properties + + String + * + + + + preGoals + 4.0.0 + + + PreGoal + * + + + + postGoals + 4.0.0 + + + PostGoal + * + + + + + + + + 3.0.0 + + public void setVersion(String version) + { + this.currentVersion = version; + } + + public String getVersion() + { + return currentVersion; + } + + + + 3.0.0+ + + private String packageName; + + public void setPackage(String packageName) + { + this.packageName = packageName; + } + + public String getPackage() + { + return packageName; + } + + + + 4.0.0 + + public String getId() + { + StringBuilder id = new StringBuilder(); + + id.append( getGroupId() ); + id.append( ":" ); + id.append( getArtifactId() ); + id.append( ":" ); + id.append( getType() ); + id.append( ":" ); + id.append( getVersion() ); + + return id.toString(); + } + + + + + + + Branch + 3.0.0+ + tag + element + ]]> + + + tag + 3.0.0+ + true + + String + + + description + 4.0.0 + + String + + + lastMergeTag + 4.0.0 + + String + + + + + Build + 3.0.0+ + + + nagEmailAddress + 3.0.0 + maven:gump-descriptor + target. + ]]> + String + This should be moved out of the build section. Vestigal for use with Gump. + + + sourceDirectory + 3.0.0+ + true + + String + + + unitTestSourceDirectory + 3.0.0+ + true + + String + + + aspectSourceDirectory + 3.0.0+ + Aspectj goals document). + The path given is relative to the project descriptor. + ]]> + String + + + integrationUnitTestSourceDirectory + 3.0.0+ + + String + + + sourceModifications + 3.0.0+ + true + sourceModification element, which is then described by + additional elements (described below). These modifications are used + to exclude or include various source depending on the environment + the build is running in. + ]]> + + SourceModification + * + + + + unitTest + 3.0.0+ + true + + new UnitTest() + + UnitTest + + + + resources + 3.0.0+ + below). These resources are used to + complete the jar file or to run unit test. + ]]> + + Resource + * + + + + directory + 4.0.0 + + String + + + output + 4.0.0 + + String + + + finalName + 4.0.0 + + String + + + testOutput + 4.0.0 + + String + + + + + CiManagement + 4.0.0 + + + system + 4.0.0 + + String + + + url + 4.0.0 + + String + + + nagEmailAddress + 4.0.0 + + String + + + + + Contributor + 3.0.0+ + + + name + 3.0.0+ + + String + + + email + 3.0.0+ + + String + + + url + 3.0.0+ + + String + + + organization + 3.0.0+ + + String + + + roles + 3.0.0+ + role element, the body of which is a + role name. + ]]> + + String + * + + + + timezone + 3.0.0+ + + String + + + + + Dependency + 3.0.0+ + + + id + 3.0.0 + true + + String + + + groupId + 3.0.0+ + true + geronimo. + ]]> + String + + + artifactId + 3.0.0+ + true + germonimo-jms + ]]> + String + + + version + 3.0.0+ + true + 3.2.1 + ]]> + String + + + url + 3.0.0+ + + String + The URL should really be gleaned from a shared database of dependency information. + + + jar + 3.0.0 + + String + + + artifact + 4.0.0+ + + String + + + type + 3.0.0+ + ejb and + plugin. + ]]> + String + jar + + + properties + 3.0.0+ + mark dependencies with properties. For example the + war plugin looks for a + war.bundle property, and if found will include the dependency + in + WEB-INF/lib. For example syntax, check the war plugin docs. + ]]> + Properties + + String + * + + + + + + 3.0.0+ + + public String toString() + { + return groupId + "/" + type + "s:" + artifactId + "-" + version; + } + + + + 4.0.0 + + public String getId() + { + return groupId + ":" + artifactId + ":" + type + ":" + version; + } + + + + 3.0.0 + element is explicity used in the POM. + if ( getJar() != null) + { + return getJar(); + } + + return getArtifactId() + "-" + getVersion() + "." + getExtension(); + } + + public String getExtension() + { + if ("ejb".equals(getType()) || "plugin".equals(getType()) || "aspect".equals(getType())) return "jar"; + return getType(); + } + + public boolean isAddedToClasspath() + { + return ("jar".equals(getType()) || "ejb".equals(getType())); + } + + public boolean isPlugin() + { + return ("plugin".equals(getType())); + } + + public String getProperty( String property ) + { + return getProperties().getProperty( property ); + } + + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + + if ( !( o instanceof Dependency ) ) + { + return false; + } + + Dependency d = (Dependency) o; + return getId().equals( d.getId() ); + } + + public int hashCode() + { + return getId().hashCode(); + } + ]]> + + + + + Override + 4.0.0 + + + groupId + 4.0.0 + true + geronimo. + ]]> + String + + + artifactId + 4.0.0 + true + germonimo-jms + ]]> + String + + + type + 4.0.0 + ejb and + plugin. + ]]> + String + jar + + + + version + 4.0.0 + true + 3.2.1 + ]]> + String + + + file + 4.0.0 + true + lib/non-distributable-code-1.3.jar + ]]> + String + + + + + Contributor + Developer + 3.0.0+ + + + id + 3.0.0+ + + String + + + + + IssueManagement + 4.0.0 + + + system + 4.0.0 + + String + + + url + 4.0.0 + + String + + + + + DistributionManagement + 4.0.0 + + + + repository + 4.0.0 + + + + Repository + + + + site + + 4.0.0 + + Site + + + + + + License + 3.0.0+ + + + name + 3.0.0+ + + String + + + url + 3.0.0+ + + String + + + distribution + 3.0.0 + +
repo
+
may be downloaded from the Maven repository
+
manual
+
user must manually download and install the dependency.
+ + ]]>
+ String +
+ + comments + 3.0.0+ + + String + +
+
+ + MailingList + 3.0.0+ + mailingList element, which is then described by + additional elements (described below). The auto-generated site + documentation references this information. + ]]> + + + name + 3.0.0+ + + String + + + subscribe + 3.0.0+ + mailto: link will automatically be created when + the documentation is created. + ]]> + String + + + unsubscribe + 3.0.0+ + mailto: link will automatically be created + when the documentation is created. + ]]> + String + + + post + 4.0.0 + mailto: link will automatically be created + when the documentation is created. + ]]> + String + + + archive + 3.0.0+ + + String + This should probably be removed from 4.0.0 before alpha-1 + + + archives + 4.0.0 + + + String + * + + + + + We could probably have a specific element for a dev mailing list for + things like CI, and maybe even a specific element for the user and scm + mailing lists. Then leave the more lose structure for any other type + of mailing list. + + + + Organization + 3.0.0+ + + + name + 3.0.0+ + + String + + + url + 3.0.0+ + + String + + + logo + 3.0.0+ + /images/org-logo.png) or an absolute URL + (e.g., + http://my.corp/logo.png). This value is used + when generating the project documentation. + ]]> + String + + + + + PackageGroup + 3.0.0+ + + + title + 3.0.0+ + + String + + + packages + 3.0.0+ + + String + + + + + PatternSet + 3.0.0+ + + + includes + 3.0.0+ + + + String + * + + + + excludes + 3.0.0+ + + + String + * + + + + + + 3.0.0+ + + + public java.util.List getDefaultExcludes() + { + java.util.List defaultExcludes = new java.util.ArrayList(); + defaultExcludes.add( "**/*~" ); + defaultExcludes.add( "**/#*#" ); + defaultExcludes.add( "**/.#*" ); + defaultExcludes.add( "**/%*%" ); + defaultExcludes.add( "**/._*" ); + + // CVS + defaultExcludes.add( "**/CVS" ); + defaultExcludes.add( "**/CVS/**" ); + defaultExcludes.add( "**/.cvsignore" ); + + // SCCS + defaultExcludes.add( "**/SCCS" ); + defaultExcludes.add( "**/SCCS/**" ); + + // Visual SourceSafe + defaultExcludes.add( "**/vssver.scc" ); + + // Subversion + defaultExcludes.add( "**/.svn" ); + defaultExcludes.add( "**/.svn/**" ); + + // Mac + defaultExcludes.add( "**/.DS_Store" ); + return defaultExcludes; + } + + + + + + Parent + 4.0.0 + + + artifactId + 4.0.0 + + String + + + groupId + 4.0.0 + + String + + + version + 4.0.0 + on of the project to extend.]]> + String + + + + + Repository + 3.0.0 + + + connection + 3.0.0 + building versions + from specific ID. + ]]> + String + + + developerConnection + 3.0.0 + + String + + + url + 3.0.0 + + String + + + + + Scm + 4.0.0 + + + connection + 4.0.0 + building versions + from specific ID. + ]]> + String + + + developerConnection + 4.0.0 + + String + + + url + 4.0.0 + + String + + + branches + 4.0.0 + + + + String + * + + + + + + Resource + 3.0.0+ + PatternSet + + + directory + 3.0.0+ + + String + + + targetPath + 3.0.0+ + org.apache.maven.messages), you must specify this + element with this value : + org/apache/maven/messages + ]]> + String + + + filtering + 3.0.0+ + + boolean + false + + + + + SourceModification + 3.0.0+ + Resource + + + className + 3.0.0+ + not be + loaded, then the includes and excludes specified below + will be applied to the contents of the + sourceDirectory + ]]> + String + + + property + 3.0.0+ + + String + + + + + UnitTest + 3.0.0+ + PatternSet + + + resources + 3.0.0+ + + + Resource + * + + + + + + Version + 3.0.0 + version + element + ]]> + + + name + 3.0.0 + 1.0, + 1.1-alpha1, + 1.2-beta, + 1.3.2 etc. + ]]> + String + + + tag + 3.0.0 + + String + + + id + 3.0.0 + + maven:dist + builds. + ]]> + String + + + + + + Repository + 4.0.0 + + + + id + 4.0.0 + + String + + + name + 4.0.0 + + String + + + url + 4.0.0 + + String + + + + + 4.0.0 + + public boolean equals( Object obj ) + { + Repository other = ( Repository ) obj; + + boolean retValue = false; + + if ( id != null ) + { + retValue = id.equals( other.id ); + } + + return retValue; + } + + + + + + + Site + 4.0.0 + + + + id + 4.0.0 + + String + + + name + 4.0.0 + + String + + + url + 4.0.0 + + String + + + + + GoalDecorator + 4.0.0 + + + name + 4.0.0 + + String + + + attain + 4.0.0 + + String + + + + + GoalDecorator + PreGoal + 4.0.0 + + + + GoalDecorator + PostGoal + 4.0.0 + + + + + + Local + 4.0.0 + + + + + repository + 4.0.0 + + String + + + + online + 4.0.0 + + boolean + true + + + + +
+
-- 2.45.1