├── src
├── main
│ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── com.sun.tools.xjc.Plugin
│ └── java
│ │ └── de
│ │ └── plushnikov
│ │ └── xjc
│ │ └── lombok
│ │ └── XjcLombokPlugin.java
└── test
│ ├── java
│ └── de
│ │ └── plushnikov
│ │ └── xjc
│ │ └── lombok
│ │ └── XjcLombokPluginTest.java
│ └── resources
│ └── test.wsdl
├── .gitignore
├── .travis.yml
├── .github
└── dependabot.yml
├── README.md
└── pom.xml
/src/main/resources/META-INF/services/com.sun.tools.xjc.Plugin:
--------------------------------------------------------------------------------
1 | de.plushnikov.xjc.lombok.XjcLombokPlugin
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #eclipse files
2 | .project
3 | .classpath
4 | .settings
5 | #idea
6 | *.iml
7 | .idea
8 |
9 | #maven
10 | target
11 |
12 | # Package Files #
13 | *.jar
14 | *.war
15 | *.ear
16 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk8
4 | git:
5 | submodules: false
6 |
7 | install: mvn install -DskipTests=true -Dgpg.skip=true -q
8 | script: mvn verify -Dgpg.skip=true -B -q
9 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: maven
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "04:00"
8 | open-pull-requests-limit: 10
9 | ignore:
10 | - dependency-name: org.projectlombok:lombok
11 | versions:
12 | - 1.18.18
13 | - dependency-name: org.apache.cxf:cxf-codegen-plugin
14 | versions:
15 | - 3.4.2
16 | - dependency-name: com.sun.xml.bind:jaxb-xjc
17 | versions:
18 | - 3.0.0
19 |
--------------------------------------------------------------------------------
/src/test/java/de/plushnikov/xjc/lombok/XjcLombokPluginTest.java:
--------------------------------------------------------------------------------
1 | package de.plushnikov.xjc.lombok;
2 |
3 | import com.sun.codemodel.JCodeModel;
4 | import com.sun.codemodel.JDefinedClass;
5 | import com.sun.codemodel.JFieldVar;
6 | import com.sun.codemodel.JMethod;
7 | import com.sun.codemodel.JMod;
8 | import com.sun.codemodel.JPackage;
9 | import com.sun.codemodel.JVar;
10 | import org.junit.Test;
11 |
12 | import static org.junit.Assert.assertTrue;
13 |
14 | public class XjcLombokPluginTest {
15 |
16 | private final XjcLombokPlugin plugin = new XjcLombokPlugin();
17 | private final JDefinedClass aClass;
18 |
19 | public XjcLombokPluginTest() throws Exception {
20 | JCodeModel aModel = new JCodeModel();
21 | JPackage aPackage = aModel._package("test");
22 | aClass = aPackage._class("AClass");
23 |
24 | JMethod aSetter = aClass.method(JMod.PUBLIC, aModel.VOID, "setField");
25 |
26 | JFieldVar aField = aClass.field(JMod.PRIVATE, aModel.INT, "field");
27 | aClass.field(JMod.PRIVATE, aModel.BOOLEAN, "anotherField");
28 | aClass.field(JMod.STATIC | JMod.PUBLIC, aModel.SHORT, "staticField");
29 | JMethod aGetter = aClass.method(JMod.PUBLIC, aModel.INT, "getField");
30 | aGetter.body()._return(aField);
31 | final JVar setterParam = aSetter.param(aModel.INT, "field");
32 | aSetter.body().assign(aField, setterParam);
33 |
34 | JDefinedClass aSuperClass = aPackage._class("ASuperClass");
35 | aClass._extends(aSuperClass);
36 | aSuperClass.field(JMod.PRIVATE, aModel.DOUBLE, "superClassField");
37 | }
38 |
39 | @Test
40 | public void testGenerateToString() {
41 | plugin.generateLombokAnnotations(aClass);
42 | assertTrue(true);
43 | }
44 | }
--------------------------------------------------------------------------------
/src/main/java/de/plushnikov/xjc/lombok/XjcLombokPlugin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Michail Plushnikov
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License")
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package de.plushnikov.xjc.lombok;
17 |
18 | import com.sun.codemodel.JAnnotationUse;
19 | import com.sun.codemodel.JDefinedClass;
20 | import com.sun.tools.xjc.BadCommandLineException;
21 | import com.sun.tools.xjc.Options;
22 | import com.sun.tools.xjc.Plugin;
23 | import com.sun.tools.xjc.outline.ClassOutline;
24 | import com.sun.tools.xjc.outline.Outline;
25 | import lombok.EqualsAndHashCode;
26 | import lombok.ToString;
27 | import org.xml.sax.ErrorHandler;
28 |
29 | import java.io.IOException;
30 |
31 | /**
32 | *
Generates hashCode, equals and toString annotations using Lombok.
33 | *
34 | * @author Michail Plushnikov
35 | */
36 | public class XjcLombokPlugin extends Plugin {
37 |
38 | public static final String OPTION_NAME = "Xlombok";
39 |
40 | @Override
41 | public String getOptionName() {
42 | return OPTION_NAME;
43 | }
44 |
45 | @Override
46 | public String getUsage() {
47 | return " -" + OPTION_NAME + "\t: enable generation of lombok @ToString, @EqualsAndHashCode annotations";
48 | }
49 |
50 | @Override
51 | public int parseArgument(Options opt, String[] args, int i) throws BadCommandLineException, IOException {
52 | return 0;
53 | }
54 |
55 | @Override
56 | public boolean run(final Outline outline, final Options options, final ErrorHandler errorHandler) {
57 | // For each defined class
58 | for (final ClassOutline classOutline : outline.getClasses()) {
59 | final JDefinedClass implClass = classOutline.implClass;
60 |
61 | generateLombokAnnotations(implClass);
62 | }
63 | return true;
64 | }
65 |
66 | protected void generateLombokAnnotations(JDefinedClass implClass) {
67 | final JAnnotationUse toStringAnnotation = implClass.annotate(ToString.class);
68 | final JAnnotationUse equalsAndHashCodeAnnotation = implClass.annotate(EqualsAndHashCode.class);
69 | if (implClass._extends() instanceof JDefinedClass) {
70 | toStringAnnotation.param("callSuper", true);
71 | equalsAndHashCodeAnnotation.param("callSuper", true);
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/test/resources/test.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | xjc-lombok-plugin
2 | ================
3 |
4 | [](https://travis-ci.org/mplushnikov/xjc-lombok-plugin.svg)
5 | [](https://maven-badges.herokuapp.com/maven-central/de.plushnikov.xjc/xjc-lombok-plugin)
6 |
7 | *Fell in love with lombok [@ToString](http://projectlombok.org/features/ToString.html),
8 | [@EqualsAndHashCode](http://projectlombok.org/features/EqualsAndHashCode.html)?
9 | Tired of writing StringBuilders for JAX-WS wsgen generated Beans? This XJC Compiler plugin comes to the rescue and creates yummie standards methods for your JAX-B/WS Beans - with a taste of [Lombok](http://projectlombok.org/).*
10 |
11 | Profit!
12 |
13 | Example
14 | ---------------------
15 | This plugin generates lombok standard annotations for toString, hashCode and equals:
16 | ```java
17 | @ToString
18 | @EqualsAndHashCode
19 | @XmlAccessorType(XmlAccessType.FIELD)
20 | @XmlType(name = "thunderbolt", propOrder = {
21 | "intensity"
22 | })
23 | public class Thunderbolt {
24 |
25 | protected Double intensity;
26 |
27 | public Double getIntensity() {
28 | return intensity;
29 | }
30 |
31 | public void setIntensity(Double value) {
32 | this.intensity = value;
33 | }
34 |
35 | }
36 | ```
37 |
38 |
39 | Usage
40 | ---------------------
41 |
42 | In contract first scenarios webservice clients models are often generated with jaxws.wsgen or cxf-codegen-plugin
43 |
44 | # using jaxws-maven-plugin
45 | ```xml
46 |
47 |
48 |
49 | org.jvnet.jax-ws-commons
50 | jaxws-maven-plugin
51 |
52 |
53 | generate-sources
54 |
55 | wsimport
56 |
57 |
58 |
59 | ${basedir}/src/test/resources/test.wsdl
60 |
61 |
62 | -B-Xlombok
63 |
64 |
65 |
66 |
67 |
68 |
69 | de.plushnikov.xjc
70 | xjc-lombok-plugin
71 | 1.0
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | org.projectlombok
80 | lombok
81 | 1.14.8
82 | provided
83 |
84 |
85 | ```
86 |
87 | # using cxf-codegen-plugin
88 |
89 | ```xml
90 |
91 |
92 |
93 | org.apache.cxf
94 | cxf-codegen-plugin
95 | 2.7.1
96 |
97 |
98 | generate-sources
99 |
100 | ${project.build.directory}/generated-sources/cxf
101 |
102 |
103 |
104 |
105 | -xjc-Xlombok
106 |
107 | ${basedir}/src/test/resources/test.wsdl
108 |
109 |
110 |
111 |
112 | wsdl2java
113 |
114 |
115 |
116 |
117 |
118 | de.plushnikov.xjc
119 | xjc-lombok-plugin
120 | 1.0
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | org.projectlombok
129 | lombok
130 | 1.14.8
131 | provided
132 |
133 |
134 |
135 | ```
136 | #jaxb2-maven-plugin
137 |
138 | ```xml
139 |
140 |
141 |
142 | org.codehaus.mojo
143 | jaxb2-maven-plugin
144 | 1.6
145 |
146 |
147 | de.plushnikov.xjc
148 | xjc-lombok-plugin
149 | 1.0
150 |
151 |
152 | xerces
153 | xercesImpl
154 | 2.11.0
155 |
156 |
157 |
158 | -Xlombok
159 |
160 |
161 |
162 | generate-model
163 |
164 | xjc
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 | org.projectlombok
173 | lombok
174 | 1.14.8
175 | provided
176 |
177 |
178 |
179 | ```
180 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | de.plushnikov.xjc
5 | xjc-lombok-plugin
6 | 1.1-SNAPSHOT
7 |
8 | org.sonatype.oss
9 | oss-parent
10 | 7
11 |
12 |
13 | https://github.com/mplushnikov/xjc-guava-plugin
14 |
15 |
16 | Apache License, Version 2.0
17 | http://www.apache.org/licenses/LICENSE-2.0
18 |
19 |
20 |
21 |
22 |
23 | 1.6
24 | 1.6
25 | UTF-8
26 | UTF-8
27 |
28 | 1.18.12
29 |
30 | lombok/AccessLevel.java,lombok/*ArgsConstructor.java,lombok/Data.java,
31 | lombok/Getter.java,lombok/Setter.java,lombok/Equals*.java,
32 | lombok/ToString.java
33 |
34 |
35 |
36 |
37 | https://github.com/mplushnikov/xjc-lombok-plugin/issues
38 | GitHub Issues
39 |
40 |
41 |
42 | scm:git:git@github.com:mplushnikov/xjc-lombok-plugin.git
43 | scm:git:git@github.com:mplushnikov/xjc-lombok-plugin.git
44 | git@github.com:mplushnikov/xjc-lombok-plugin.git
45 | HEAD
46 |
47 |
48 |
49 |
50 | mplushnikov@gmail.com
51 | Michail Plushnikov
52 | https://github.com/mplushnikov
53 | mplushnikov
54 |
55 |
56 |
57 |
58 |
59 | com.sun.xml.bind
60 | jaxb-xjc
61 | 2.3.3
62 | provided
63 |
64 |
65 | junit
66 | junit
67 | 4.13
68 | test
69 |
70 |
71 | org.hamcrest
72 | hamcrest-library
73 | 2.2
74 | test
75 |
76 |
77 |
78 | org.projectlombok
79 | lombok
80 | ${lombok.version}
81 | test
82 |
83 |
84 |
85 |
86 |
87 | selftest
88 |
89 |
90 |
91 | org.jvnet.jax-ws-commons
92 | jaxws-maven-plugin
93 | 2.3
94 |
95 |
96 | generate-test-sources
97 |
98 | wsimport
99 |
100 |
101 |
102 | -Djavax.xml.accessExternalSchema=all
103 |
104 |
105 |
106 | ${basedir}/src/test/resources/test.wsdl
107 |
108 |
109 | -B-Xlombok
110 |
111 |
112 | com.github.mplushnikov.jaxws
113 |
114 | ${project.build.directory}/generated-test-sources/jaxws
115 |
116 |
117 |
118 |
119 |
120 | ${project.artifactId}
121 | ${project.groupId}
122 | ${project.version}
123 |
124 |
125 |
126 |
127 | org.apache.cxf
128 | cxf-codegen-plugin
129 | 3.4.0
130 |
131 |
132 | generate-test-sources
133 |
134 | ${project.build.directory}/generated-test-sources/cxf
135 |
136 |
137 | ${basedir}/src/test/resources/test.wsdl
138 |
139 | -xjc-Xlombok
140 | -p
141 | com.github.mplushnikov.cxf
142 |
143 |
144 |
145 |
146 |
147 | wsdl2java
148 |
149 |
150 |
151 |
152 |
153 | ${project.artifactId}
154 | ${project.groupId}
155 | ${project.version}
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | maven-dependency-plugin
169 | 3.1.2
170 |
171 |
172 |
173 | unpack
174 |
175 | generate-sources
176 |
177 |
178 |
179 | org.projectlombok
180 | lombok
181 | ${lombok.version}
182 | jar
183 | sources
184 | true
185 | ${project.build.directory}/generated-sources/lombok
186 |
187 |
188 | ${lombok-annotations.includes}
189 |
190 |
191 |
192 |
193 |
194 | org.codehaus.mojo
195 | build-helper-maven-plugin
196 | 3.2.0
197 |
198 |
199 | generate-sources
200 |
201 | add-source
202 |
203 |
204 |
205 | ${project.build.directory}/generated-sources/lombok
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 | org.apache.maven.plugins
215 | maven-gpg-plugin
216 | 1.6
217 |
218 |
219 | sign-artifacts
220 | verify
221 |
222 | sign
223 |
224 |
225 |
226 |
227 |
228 | org.apache.maven.plugins
229 | maven-compiler-plugin
230 | 3.8.1
231 |
232 | 1.6
233 | 1.6
234 |
235 |
236 |
237 | org.apache.maven.plugins
238 | maven-jar-plugin
239 | 3.2.0
240 |
241 |
242 |
243 | true
244 | true
245 |
246 |
247 |
248 |
249 |
250 | org.apache.maven.plugins
251 | maven-javadoc-plugin
252 | 3.2.0
253 |
254 | com.github.mplushnikov.cxf:com.github.mplushnikov.jaxws:lombok
255 |
256 |
257 |
258 |
259 | jar
260 |
261 |
262 |
263 |
264 |
265 | org.apache.maven.plugins
266 | maven-source-plugin
267 | 3.2.1
268 |
269 |
270 |
271 | jar
272 |
273 |
274 |
275 |
276 |
277 | org.apache.maven.plugins
278 | maven-release-plugin
279 | 2.5.3
280 |
281 |
282 |
283 |
284 |
285 |
--------------------------------------------------------------------------------