diff --git a/0001-MODELLO-284-Fix-handling-of-Boolean-fields-in-StAX-r.patch b/0001-MODELLO-284-Fix-handling-of-Boolean-fields-in-StAX-r.patch new file mode 100644 index 0000000..696ddb8 --- /dev/null +++ b/0001-MODELLO-284-Fix-handling-of-Boolean-fields-in-StAX-r.patch @@ -0,0 +1,129 @@ +From d2f183ad877f3c4a59840cc6180bbb4142fa669c Mon Sep 17 00:00:00 2001 +From: Mikolaj Izdebski +Date: Fri, 24 Jan 2014 16:27:12 +0100 +Subject: [PATCH 1/2] [MODELLO-284] Fix handling of Boolean fields in StAX + reader + +--- + .../modello/plugin/stax/StaxReaderGenerator.java | 4 +- + .../xml/stax/BooleanTypeStaxGeneratorTest.java | 51 ++++++++++++++++++++++ + .../src/test/resources/boolean.mdo | 27 ++++++++++++ + 3 files changed, 80 insertions(+), 2 deletions(-) + create mode 100644 modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/BooleanTypeStaxGeneratorTest.java + create mode 100644 modello-plugins/modello-plugin-stax/src/test/resources/boolean.mdo + +diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java +index 7e0a39f..83e617d 100644 +--- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java ++++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java +@@ -1406,7 +1406,7 @@ public class StaxReaderGenerator + parserGetter = "getTrimmedValue( " + parserGetter + " )"; + } + +- if ( "boolean".equals( type ) ) ++ if ( "boolean".equals( type ) || "Boolean".equals( type ) ) + { + sc.add( objectName + "." + setterName + "( getBooleanValue( " + parserGetter + ", \"" + tagName + + "\", xmlStreamReader ) );" ); +@@ -1446,7 +1446,7 @@ public class StaxReaderGenerator + sc.add( objectName + "." + setterName + "( getByteValue( " + parserGetter + ", \"" + tagName + + "\", xmlStreamReader, strict ) );" ); + } +- else if ( "String".equals( type ) || "Boolean".equals( type ) ) ++ else if ( "String".equals( type ) ) + { + // TODO: other Primitive types + sc.add( objectName + "." + setterName + "( " + parserGetter + " );" ); +diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/BooleanTypeStaxGeneratorTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/BooleanTypeStaxGeneratorTest.java +new file mode 100644 +index 0000000..3072e97 +--- /dev/null ++++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/BooleanTypeStaxGeneratorTest.java +@@ -0,0 +1,51 @@ ++package org.codehaus.modello.generator.xml.stax; ++ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one ++ * or more contributor license agreements. See the NOTICE file ++ * distributed with this work for additional information ++ * regarding copyright ownership. The ASF licenses this file ++ * to you under the Apache License, Version 2.0 (the ++ * "License"); you may not use this file except in compliance ++ * with the License. You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, ++ * software distributed under the License is distributed on an ++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ++ * KIND, either express or implied. See the License for the ++ * specific language governing permissions and limitations ++ * under the License. ++ */ ++ ++import java.util.Properties; ++ ++import org.codehaus.modello.AbstractModelloJavaGeneratorTest; ++import org.codehaus.modello.core.ModelloCore; ++import org.codehaus.modello.model.Model; ++ ++public class BooleanTypeStaxGeneratorTest ++ extends AbstractModelloJavaGeneratorTest ++{ ++ public BooleanTypeStaxGeneratorTest() ++ { ++ super( "testBooleanType" ); ++ } ++ ++ public void testBooleanType() ++ throws Throwable ++ { ++ ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); ++ ++ Model model = modello.loadModel( getXmlResourceReader( "/boolean.mdo" ) ); ++ ++ Properties parameters = getModelloParameters( "1.0.0" ); ++ ++ modello.generate( model, "java", parameters ); ++ modello.generate( model, "stax-reader", parameters ); ++ modello.generate( model, "stax-writer", parameters ); ++ ++ compileGeneratedSources(); ++ } ++} +diff --git a/modello-plugins/modello-plugin-stax/src/test/resources/boolean.mdo b/modello-plugins/modello-plugin-stax/src/test/resources/boolean.mdo +new file mode 100644 +index 0000000..790c9c3 +--- /dev/null ++++ b/modello-plugins/modello-plugin-stax/src/test/resources/boolean.mdo +@@ -0,0 +1,27 @@ ++ ++ ++ test ++ Test ++ ++ ++ package ++ org.codehaus.modello.generator.xml.stax.test.testboolean ++ ++ ++ ++ ++ BooleanTest ++ 1.0.0+ ++ ++ ++ property ++ 1.0.0+ ++ Boolean ++ ++ ++ ++ ++ +-- +1.8.4.2 + diff --git a/0002-MODELLO-285-Fix-StAX-reader-in-case-no-field-adder-i.patch b/0002-MODELLO-285-Fix-StAX-reader-in-case-no-field-adder-i.patch new file mode 100644 index 0000000..5bb487b --- /dev/null +++ b/0002-MODELLO-285-Fix-StAX-reader-in-case-no-field-adder-i.patch @@ -0,0 +1,152 @@ +From a2354ea0736fd371e870120ee7c3eeedfdc2191b Mon Sep 17 00:00:00 2001 +From: Mikolaj Izdebski +Date: Fri, 24 Jan 2014 17:01:18 +0100 +Subject: [PATCH 2/2] [MODELLO-285] Fix StAX reader in case no field adder is + defined + +In generated StAX readers don't use adders for fields which have +adders explicitly disabled. +--- + .../modello/plugin/stax/StaxReaderGenerator.java | 4 +- + .../xml/stax/NoAdderStaxGeneratorTest.java | 51 ++++++++++++++++++++++ + .../src/test/resources/noAdder.mdo | 41 +++++++++++++++++ + 3 files changed, 95 insertions(+), 1 deletion(-) + create mode 100644 modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/NoAdderStaxGeneratorTest.java + create mode 100644 modello-plugins/modello-plugin-stax/src/test/resources/noAdder.mdo + +diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java +index 83e617d..5081871 100644 +--- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java ++++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java +@@ -38,6 +38,7 @@ import org.codehaus.modello.plugin.java.javasource.JParameter; + import org.codehaus.modello.plugin.java.javasource.JSourceCode; + import org.codehaus.modello.plugin.java.javasource.JSourceWriter; + import org.codehaus.modello.plugin.java.javasource.JType; ++import org.codehaus.modello.plugin.java.metadata.JavaAssociationMetadata; + import org.codehaus.modello.plugin.java.metadata.JavaFieldMetadata; + import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; + import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; +@@ -1097,6 +1098,7 @@ public class StaxReaderGenerator + if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) ) + { + JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) association.getMetadata( JavaFieldMetadata.ID ); ++ JavaAssociationMetadata javaAssociationMetadata = (JavaAssociationMetadata) association.getAssociationMetadata( JavaAssociationMetadata.ID ); + + String adder; + +@@ -1171,7 +1173,7 @@ public class StaxReaderGenerator + addCodeToAddReferences( association, jClass, sc, referenceIdentifierField, objectName ); + } + +- if ( association.getTo().equals( field.getModelClass().getName() ) ) ++ if ( association.getTo().equals( field.getModelClass().getName() ) || !javaAssociationMetadata.isAdder() ) + { + // HACK: the addXXX method will cause an OOME when compiling a self-referencing class, so we + // just add it to the array. This could disrupt the links if you are using break/create +diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/NoAdderStaxGeneratorTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/NoAdderStaxGeneratorTest.java +new file mode 100644 +index 0000000..57d2087 +--- /dev/null ++++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/NoAdderStaxGeneratorTest.java +@@ -0,0 +1,51 @@ ++package org.codehaus.modello.generator.xml.stax; ++ ++/* ++ * Licensed to the Apache Software Foundation (ASF) under one ++ * or more contributor license agreements. See the NOTICE file ++ * distributed with this work for additional information ++ * regarding copyright ownership. The ASF licenses this file ++ * to you under the Apache License, Version 2.0 (the ++ * "License"); you may not use this file except in compliance ++ * with the License. You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, ++ * software distributed under the License is distributed on an ++ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ++ * KIND, either express or implied. See the License for the ++ * specific language governing permissions and limitations ++ * under the License. ++ */ ++ ++import java.util.Properties; ++ ++import org.codehaus.modello.AbstractModelloJavaGeneratorTest; ++import org.codehaus.modello.core.ModelloCore; ++import org.codehaus.modello.model.Model; ++ ++public class NoAdderStaxGeneratorTest ++ extends AbstractModelloJavaGeneratorTest ++{ ++ public NoAdderStaxGeneratorTest() ++ { ++ super( "testNoAdder" ); ++ } ++ ++ public void testNoAdder() ++ throws Throwable ++ { ++ ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE ); ++ ++ Model model = modello.loadModel( getXmlResourceReader( "/noAdder.mdo" ) ); ++ ++ Properties parameters = getModelloParameters( "1.0.0" ); ++ ++ modello.generate( model, "java", parameters ); ++ modello.generate( model, "stax-reader", parameters ); ++ modello.generate( model, "stax-writer", parameters ); ++ ++ compileGeneratedSources(); ++ } ++} +diff --git a/modello-plugins/modello-plugin-stax/src/test/resources/noAdder.mdo b/modello-plugins/modello-plugin-stax/src/test/resources/noAdder.mdo +new file mode 100644 +index 0000000..d2fdb9a +--- /dev/null ++++ b/modello-plugins/modello-plugin-stax/src/test/resources/noAdder.mdo +@@ -0,0 +1,41 @@ ++ ++ ++ test ++ Test ++ ++ ++ package ++ org.codehaus.modello.generator.xml.stax.test.noadder ++ ++ ++ ++ ++ MyType ++ 1.0.0+ ++ ++ ++ test ++ 1.0.0+ ++ String ++ ++ ++ ++ ++ NoAdderTest ++ 1.0.0+ ++ ++ ++ property ++ 1.0.0+ ++ ++ MyType ++ * ++ ++ ++ ++ ++ ++ +-- +1.8.4.2 + diff --git a/modello.spec b/modello.spec index e0b5e96..10c3452 100644 --- a/modello.spec +++ b/modello.spec @@ -1,6 +1,6 @@ Name: modello Version: 1.8.1 -Release: 2%{?dist} +Release: 3%{?dist} Epoch: 0 Summary: Modello Data Model toolkit # The majority of files are under MIT license, but some of them are @@ -10,6 +10,9 @@ URL: http://modello.codehaus.org/ Source0: http://repo2.maven.org/maven2/org/codehaus/%{name}/%{name}/%{version}/%{name}-%{version}-source-release.zip Source1: http://www.apache.org/licenses/LICENSE-2.0.txt +Patch0001: 0001-MODELLO-284-Fix-handling-of-Boolean-fields-in-StAX-r.patch +Patch0002: 0002-MODELLO-285-Fix-StAX-reader-in-case-no-field-adder-i.patch + BuildArch: noarch BuildRequires: maven-local @@ -49,7 +52,9 @@ Summary: Javadoc for %{name} API documentation for %{name}. %prep -%setup -q +%setup -q +%patch0001 -p1 +%patch0002 -p1 cp -p %{SOURCE1} LICENSE # We don't generate site; don't pull extra dependencies. %pom_remove_plugin :maven-site-plugin @@ -74,6 +79,9 @@ sed -i s/maven-project/maven-core/ modello-maven-plugin/pom.xml %doc LICENSE %changelog +* Tue Feb 18 2014 Mikolaj Izdebski - 0:1.8.1-3 +- Backport upstream patches for MODELLO-284 and MODELLO-285 + * Mon Jan 27 2014 Mikolaj Izdebski - 0:1.8.1-2 - Use Maven 3.x APIs