Skip to content

Commit 07968b9

Browse files
[#438] get version of XJC at runtime and dump it on source generation
1 parent eb62cc7 commit 07968b9

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/AbstractXJCMojo.java

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
public abstract class AbstractXJCMojo<O> extends AbstractMojo implements
4242
DependencyResourceResolver {
4343

44+
/**
45+
* This method should be overriden in extending classes to get real value
46+
* @return currently running XJC version
47+
*/
48+
public XJCVersion getVersion() {
49+
return XJCVersion.UNDEFINED;
50+
}
51+
4452
@Parameter(defaultValue = "${settings}", readonly = true)
4553
private Settings settings;
4654

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJCMojo.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,23 @@ public abstract class RawXJCMojo<O> extends AbstractXJCMojo<O> {
9595
public static final String ADD_IF_EXISTS_TO_EPISODE_SCHEMA_BINDINGS_TRANSFORMATION_RESOURCE_NAME = "/"
9696
+ RawXJCMojo.class.getPackage().getName().replace('.', '/') + "/addIfExistsToEpisodeSchemaBindings.xslt";
9797

98+
private final XJCVersion version;
99+
98100
private Collection<Artifact> xjcPluginArtifacts;
99101

100102
private Collection<File> xjcPluginFiles;
101103

102104
private List<URL> xjcPluginURLs;
103105

104-
public Collection<Artifact> getXjcPluginArtifacts() {
106+
public RawXJCMojo(XJCVersion version) {
107+
this.version = version;
108+
}
109+
110+
public XJCVersion getVersion() {
111+
return version;
112+
}
113+
114+
public Collection<Artifact> getXjcPluginArtifacts() {
105115
return xjcPluginArtifacts;
106116
}
107117

@@ -469,9 +479,9 @@ protected void doExecute() throws MojoExecutionException {
469479
} else {
470480
final boolean isUpToDate = isUpToDate();
471481
if (!isUpToDate) {
472-
getLog().info("Sources are not up-to-date, XJC will be executed.");
482+
getLog().info("Sources are not up-to-date, XJC (version " + getVersion().getRaw() + ") will be executed.");
473483
} else {
474-
getLog().info("Sources are up-to-date, XJC will be skipped.");
484+
getLog().info("Sources are up-to-date, XJC (version " + getVersion().getRaw() + ") will be skipped.");
475485
return;
476486
}
477487
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.jvnet.jaxb.maven;
2+
3+
public class XJCVersion {
4+
public static final XJCVersion UNDEFINED = new XJCVersion(null);
5+
private String raw = "UNDEFINED";
6+
private int major;
7+
private int minor;
8+
private int bugfix;
9+
10+
public XJCVersion(String version) {
11+
if (version != null) {
12+
this.raw = version;
13+
int indexOfSnapshot = version.indexOf("-SNAPSHOT");
14+
if (indexOfSnapshot >= 0) {
15+
version = version.substring(0, indexOfSnapshot);
16+
}
17+
String[] split = version.split("\\.");
18+
if (split.length >= 3) {
19+
major = Integer.valueOf(split[0]);
20+
minor = Integer.valueOf(split[1]);
21+
bugfix = Integer.valueOf(split[2]);
22+
}
23+
}
24+
}
25+
26+
public String getRaw() {
27+
return raw;
28+
}
29+
30+
public int getMajor() {
31+
return major;
32+
}
33+
34+
public int getMinor() {
35+
return minor;
36+
}
37+
38+
public int getBugfix() {
39+
return bugfix;
40+
}
41+
42+
public boolean isKnown() {
43+
return !(this.major == 0 && this.minor == 0 && this.bugfix == 0);
44+
}
45+
46+
public boolean gte(int major, int minor, int bugfix) {
47+
return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix >= bugfix);
48+
}
49+
50+
public boolean gt(int major, int minor, int bugfix) {
51+
return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix > bugfix);
52+
}
53+
54+
public boolean lte(int major, int minor, int bugfix) {
55+
return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix <= bugfix);
56+
}
57+
58+
public boolean lt(int major, int minor, int bugfix) {
59+
return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix < bugfix);
60+
}
61+
}

maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/RawXJCMojoTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void createJarFile() throws Exception {
5050
public void collectBindingUrisFromDependencies() throws Exception {
5151
List<URI> bindings = new ArrayList<>();
5252

53-
final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>() {
53+
final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>(XJCVersion.UNDEFINED) {
5454

5555
@Override
5656
public MavenProject getProject() {
@@ -106,7 +106,7 @@ public void doExecute(Void options) throws MojoExecutionException {
106106
public void collectsBindingUrisFromArtifact() throws Exception {
107107
List<URI> bindings = new ArrayList<>();
108108

109-
final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>() {
109+
final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>(XJCVersion.UNDEFINED) {
110110

111111
@Override
112112
protected IOptionsFactory<Void> getOptionsFactory() {

maven-plugin/plugin/src/main/java/org/jvnet/jaxb/maven/XJCMojo.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.text.MessageFormat;
66
import java.util.Iterator;
77

8+
import com.sun.tools.xjc.Messages;
89
import org.apache.maven.plugin.MojoExecutionException;
910
import org.apache.maven.plugins.annotations.LifecyclePhase;
1011
import org.apache.maven.plugins.annotations.Mojo;
@@ -29,7 +30,15 @@ public class XJCMojo extends RawXJCMojo<Options> {
2930

3031
private final IOptionsFactory<Options> optionsFactory = new OptionsFactory();
3132

32-
@Override
33+
public XJCMojo() {
34+
super(parseXJCVersion());
35+
}
36+
37+
private static XJCVersion parseXJCVersion() {
38+
return new XJCVersion(Messages.format("Driver.BuildID"));
39+
}
40+
41+
@Override
3342
protected IOptionsFactory<Options> getOptionsFactory() {
3443
return optionsFactory;
3544
}

0 commit comments

Comments
 (0)