You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/09/12 18:42:21 UTC
git commit: Create an XJC plugin that can work around
https://java.net/jira/browse/JAXB-986
Repository: cxf-xjc-utils
Updated Branches:
refs/heads/master 718f8afa4 -> 6ae96ffed
Create an XJC plugin that can work around https://java.net/jira/browse/JAXB-986
Project: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/commit/6ae96ffe
Tree: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/tree/6ae96ffe
Diff: http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/diff/6ae96ffe
Branch: refs/heads/master
Commit: 6ae96ffedb82f01c3dab3f76841a10395a5595d1
Parents: 718f8af
Author: Daniel Kulp <dk...@apache.org>
Authored: Fri Sep 12 12:40:56 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Fri Sep 12 12:40:56 2014 -0400
----------------------------------------------------------------------
bug986/pom.xml | 60 +++++++++++
.../addon/apache_cxf/bug986/Bug986Plugin.java | 65 ++++++++++++
.../org/apache/cxf/xjc/bug986/Bug986Plugin.java | 103 +++++++++++++++++++
.../META-INF/services/com.sun.tools.xjc.Plugin | 1 +
pom.xml | 51 +++++++++
5 files changed, 280 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/6ae96ffe/bug986/pom.xml
----------------------------------------------------------------------
diff --git a/bug986/pom.xml b/bug986/pom.xml
new file mode 100644
index 0000000..8ea63df
--- /dev/null
+++ b/bug986/pom.xml
@@ -0,0 +1,60 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.cxf.xjcplugins</groupId>
+ <artifactId>cxf-xjc-bug986</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache CXF XJC Plugin To Workaround JAXB Bug 986</name>
+ <url>http://cxf.apache.org</url>
+
+ <parent>
+ <groupId>org.apache.cxf.xjc-utils</groupId>
+ <artifactId>xjc-utils</artifactId>
+ <version>3.0.2-SNAPSHOT</version>
+ </parent>
+
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-xjc</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/6ae96ffe/bug986/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug986/Bug986Plugin.java
----------------------------------------------------------------------
diff --git a/bug986/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug986/Bug986Plugin.java b/bug986/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug986/Bug986Plugin.java
new file mode 100644
index 0000000..365080d
--- /dev/null
+++ b/bug986/src/main/java/com/sun/tools/xjc/addon/apache_cxf/bug986/Bug986Plugin.java
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+
+package com.sun.tools.xjc.addon.apache_cxf.bug986;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+
+import com.sun.tools.xjc.BadCommandLineException;
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.Plugin;
+import com.sun.tools.xjc.outline.Outline;
+
+/**
+ * Thin wrapper around the Bug986Plugin. This must be in the com.sun.tools.xjc.addon package
+ * for it to work with Java 6. See https://issues.apache.org/jira/browse/CXF-1880.
+ */
+public class Bug986Plugin extends Plugin {
+
+ org.apache.cxf.xjc.bug986.Bug986Plugin impl = new org.apache.cxf.xjc.bug986.Bug986Plugin(this);
+
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#getOptionName()
+ */
+ @Override
+ public String getOptionName() {
+ return impl.getOptionName();
+ }
+
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#getUsage()
+ */
+ @Override
+ public String getUsage() {
+ return impl.getUsage();
+ }
+ public void onActivated(Options opts) throws BadCommandLineException {
+
+ }
+ /* (non-Javadoc)
+ * @see com.sun.tools.xjc.Plugin#run(com.sun.tools.xjc.outline.Outline,
+ * com.sun.tools.xjc.Options, org.xml.sax.ErrorHandler)
+ */
+ @Override
+ public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException {
+ return impl.run(outline, opt, errorHandler);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/6ae96ffe/bug986/src/main/java/org/apache/cxf/xjc/bug986/Bug986Plugin.java
----------------------------------------------------------------------
diff --git a/bug986/src/main/java/org/apache/cxf/xjc/bug986/Bug986Plugin.java b/bug986/src/main/java/org/apache/cxf/xjc/bug986/Bug986Plugin.java
new file mode 100644
index 0000000..476c39a
--- /dev/null
+++ b/bug986/src/main/java/org/apache/cxf/xjc/bug986/Bug986Plugin.java
@@ -0,0 +1,103 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.xjc.bug986;
+
+
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.xml.bind.annotation.XmlSchemaType;
+
+import org.xml.sax.ErrorHandler;
+
+import com.sun.codemodel.JAnnotationUse;
+import com.sun.codemodel.JAnnotationValue;
+import com.sun.codemodel.JFieldVar;
+import com.sun.codemodel.JFormatter;
+import com.sun.codemodel.JVar;
+import com.sun.tools.xjc.Options;
+import com.sun.tools.xjc.Plugin;
+import com.sun.tools.xjc.outline.ClassOutline;
+import com.sun.tools.xjc.outline.Outline;
+
+/**
+ * Modifies the JAXB code model to handle package naming that run into:
+ * https://jaxb.dev.java.net/issues/show_bug.cgi?id=671
+ */
+public class Bug986Plugin {
+ private static final Logger LOG = Logger.getLogger(Bug986Plugin.class.getName()); //NOPMD
+
+ final Plugin plugin;
+
+ public Bug986Plugin(Plugin p) {
+ plugin = p;
+ }
+
+
+ public String getOptionName() {
+ return "Xbug986";
+ }
+
+ public String getUsage() {
+ return " -Xbug986 : Activate plugin remove XmlSchemaType(anySimpleType) from fields that shouldn't have it.";
+ }
+
+ public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {
+ // kind of a bogus thing to have to do to workaround bug:
+ // https://java.net/jira/browse/JAXB-986
+ LOG.info("Running Bug986Plugin plugin.");
+ for (ClassOutline classOutline : outline.getClasses()) {
+ Map<String, JFieldVar> fields = classOutline.implClass.fields();
+ for (JFieldVar field : fields.values()) {
+ Collection<JAnnotationUse> annotations = field.annotations();
+ List<JAnnotationUse> toRemove = new ArrayList<JAnnotationUse>();
+ for (JAnnotationUse j : annotations) {
+ if (XmlSchemaType.class.getName().equals(j.getAnnotationClass().fullName())) {
+ JAnnotationValue st = j.getAnnotationMembers().get("name");
+ StringWriter sw = new StringWriter();
+ st.generate(new JFormatter(sw));
+ if (sw.toString().equals("\"anySimpleType\"")
+ && field.type().fullName().startsWith("java.util.List")
+ && !field.type().fullName().contains("<java.lang.String>")) {
+ toRemove.add(j);
+ }
+ }
+ }
+ for (JAnnotationUse j : toRemove) {
+ try {
+ Field f = JVar.class.getDeclaredField("annotations");
+ f.setAccessible(true);
+ List<?> anns = (List<?>)f.get(field);
+ anns.remove(j);
+ } catch (Throwable t) {
+ //ignore for now
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/6ae96ffe/bug986/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
----------------------------------------------------------------------
diff --git a/bug986/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin b/bug986/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
new file mode 100644
index 0000000..573eead
--- /dev/null
+++ b/bug986/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin
@@ -0,0 +1 @@
+com.sun.tools.xjc.addon.apache_cxf.bug986.Bug986Plugin
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cxf-xjc-utils/blob/6ae96ffe/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5786851..0c64564 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,7 @@
<module>wsdlextension</module>
<module>wsdlextension-test</module>
<module>bug671</module>
+ <module>bug986</module>
<module>property-listener</module>
<module>javadoc</module>
<module>runtime</module>
@@ -442,6 +443,56 @@
</execution>
</executions>
</plugin>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-checkstyle-plugin
+ </artifactId>
+ <versionRange>
+ [2.9.1,)
+ </versionRange>
+ <goals>
+ <goal>checkstyle</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.apache.maven.plugins
+ </groupId>
+ <artifactId>
+ maven-pmd-plugin
+ </artifactId>
+ <versionRange>
+ [3.0.1,)
+ </versionRange>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore></ignore>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
</plugins>
</pluginManagement>
</build>