Skip to content

Commit

Permalink
[highsource#438] get version of XJC at runtime and dump it on source …
Browse files Browse the repository at this point in the history
…generation
  • Loading branch information
laurentschoelens authored and mattrpav committed Oct 13, 2023
1 parent 6c8e84a commit 7085316
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
public abstract class AbstractXJCMojo<O> extends AbstractMojo implements
DependencyResourceResolver {

/**
* This method should be overriden in extending classes to get real value
* @return currently running XJC version
*/
public XJCVersion getVersion() {
return XJCVersion.UNDEFINED;
}

@Parameter(defaultValue = "${settings}", readonly = true)
private Settings settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ public abstract class RawXJCMojo<O> extends AbstractXJCMojo<O> {
public static final String ADD_IF_EXISTS_TO_EPISODE_SCHEMA_BINDINGS_TRANSFORMATION_RESOURCE_NAME = "/"
+ RawXJCMojo.class.getPackage().getName().replace('.', '/') + "/addIfExistsToEpisodeSchemaBindings.xslt";

private final XJCVersion version;

private Collection<Artifact> xjcPluginArtifacts;

private Collection<File> xjcPluginFiles;

private List<URL> xjcPluginURLs;

public Collection<Artifact> getXjcPluginArtifacts() {
public RawXJCMojo(XJCVersion version) {
this.version = version;
}

public XJCVersion getVersion() {
return version;
}

public Collection<Artifact> getXjcPluginArtifacts() {
return xjcPluginArtifacts;
}

Expand Down Expand Up @@ -469,9 +479,9 @@ protected void doExecute() throws MojoExecutionException {
} else {
final boolean isUpToDate = isUpToDate();
if (!isUpToDate) {
getLog().info("Sources are not up-to-date, XJC will be executed.");
getLog().info("Sources are not up-to-date, XJC (version " + getVersion().getRaw() + ") will be executed.");
} else {
getLog().info("Sources are up-to-date, XJC will be skipped.");
getLog().info("Sources are up-to-date, XJC (version " + getVersion().getRaw() + ") will be skipped.");
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.jvnet.jaxb.maven;

public class XJCVersion {
public static final XJCVersion UNDEFINED = new XJCVersion(null);
private String raw = "UNDEFINED";
private int major;
private int minor;
private int bugfix;

public XJCVersion(String version) {
if (version != null) {
this.raw = version;
int indexOfSnapshot = version.indexOf("-SNAPSHOT");
if (indexOfSnapshot >= 0) {
version = version.substring(0, indexOfSnapshot);
}
String[] split = version.split("\\.");
if (split.length >= 3) {
major = Integer.valueOf(split[0]);
minor = Integer.valueOf(split[1]);
bugfix = Integer.valueOf(split[2]);
}
}
}

public String getRaw() {
return raw;
}

public int getMajor() {
return major;
}

public int getMinor() {
return minor;
}

public int getBugfix() {
return bugfix;
}

public boolean isKnown() {
return !(this.major == 0 && this.minor == 0 && this.bugfix == 0);
}

public boolean gte(int major, int minor, int bugfix) {
return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix >= bugfix);
}

public boolean gt(int major, int minor, int bugfix) {
return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix > bugfix);
}

public boolean lte(int major, int minor, int bugfix) {
return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix <= bugfix);
}

public boolean lt(int major, int minor, int bugfix) {
return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix < bugfix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void createJarFile() throws Exception {
public void collectBindingUrisFromDependencies() throws Exception {
List<URI> bindings = new ArrayList<>();

final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>() {
final RawXJCMojo<Void> mojo = new RawXJCMojo<>(XJCVersion.UNDEFINED) {

@Override
public MavenProject getProject() {
Expand Down Expand Up @@ -106,7 +106,7 @@ public void doExecute(Void options) throws MojoExecutionException {
public void collectsBindingUrisFromArtifact() throws Exception {
List<URI> bindings = new ArrayList<>();

final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>() {
final RawXJCMojo<Void> mojo = new RawXJCMojo<Void>(XJCVersion.UNDEFINED) {

@Override
protected IOptionsFactory<Void> getOptionsFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.text.MessageFormat;
import java.util.Iterator;

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

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

@Override
public XJCMojo() {
super(parseXJCVersion());
}

private static XJCVersion parseXJCVersion() {
return new XJCVersion(Messages.format("Driver.BuildID"));
}

@Override
protected IOptionsFactory<Options> getOptionsFactory() {
return optionsFactory;
}
Expand Down

0 comments on commit 7085316

Please sign in to comment.