summaryrefslogtreecommitdiffstats
path: root/vespa-application-maven-plugin
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-04-20 09:17:26 +0200
committerjonmv <venstad@gmail.com>2022-04-20 09:17:26 +0200
commit797d486434d2cb428fa8e41b92f9b78eca2f2ba7 (patch)
tree9e72127fc4334bff15dc7214a5b1d9586684ea44 /vespa-application-maven-plugin
parenta539f34d4e1788183484b17b38a7cb6339f2386d (diff)
Check parentArtifact version for robustness, and only when it is (recursively) is a vespa parent
Diffstat (limited to 'vespa-application-maven-plugin')
-rw-r--r--vespa-application-maven-plugin/src/main/java/com/yahoo/container/plugin/mojo/ApplicationMojo.java37
1 files changed, 24 insertions, 13 deletions
diff --git a/vespa-application-maven-plugin/src/main/java/com/yahoo/container/plugin/mojo/ApplicationMojo.java b/vespa-application-maven-plugin/src/main/java/com/yahoo/container/plugin/mojo/ApplicationMojo.java
index 5873db262d9..fc24e03c9d2 100644
--- a/vespa-application-maven-plugin/src/main/java/com/yahoo/container/plugin/mojo/ApplicationMojo.java
+++ b/vespa-application-maven-plugin/src/main/java/com/yahoo/container/plugin/mojo/ApplicationMojo.java
@@ -2,6 +2,7 @@
package com.yahoo.container.plugin.mojo;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -56,20 +57,30 @@ public class ApplicationMojo extends AbstractMojo {
/** Writes meta data about this package if the destination directory exists. */
private void addBuildMetaData(File applicationDestination) throws MojoExecutionException {
- if ( ! applicationDestination.exists())
- return;
-
- // Compile version is the build version of the parent project, unless specifically set.
- MavenProject parent = project;
- while (parent.getParent() != null) parent = parent.getParent();
- Version parentVersion = Version.from(parent.getVersion());
- Version compileVersion = vespaversion == null ? parentVersion : Version.from(vespaversion);
- if (parentVersion.compareTo(compileVersion) < 0)
- throw new IllegalArgumentException("compile version (" + compileVersion + ") cannot be higher than parent version (" + parentVersion + ")");
-
- String metaData = String.format("{\"compileVersion\": \"%s\",\n \"buildTime\": %d}",
+ if ( ! applicationDestination.exists()) return;
+
+ if (vespaversion == null)
+ vespaversion = project.getPlugin("com.yahoo.vespa:vespa-application-maven-plugin").getVersion();
+
+ Version compileVersion = Version.from(vespaversion);
+
+ MavenProject current = project;
+ while (current.getParent() != null && current.getParent().getParentArtifact() != null)
+ current = current.getParent();
+
+ boolean hasVespaParent = false;
+ Artifact parentArtifact = current.getParentArtifact();
+ if (parentArtifact != null && parentArtifact.getGroupId().startsWith("com.yahoo.vespa")) {
+ hasVespaParent = true;
+ Version parentVersion = Version.from(parentArtifact.getVersion());
+ if (parentVersion.compareTo(compileVersion) < 0)
+ throw new IllegalArgumentException("compile version (" + compileVersion + ") cannot be higher than parent version (" + parentVersion + ")");
+ }
+
+ String metaData = String.format("{\n \"compileVersion\": \"%s\",\n \"buildTime\": %d,\n \"hasVespaParent\": %b\n}",
compileVersion,
- System.currentTimeMillis());
+ System.currentTimeMillis(),
+ hasVespaParent);
try {
Files.write(applicationDestination.toPath().resolve("build-meta.json"),
metaData.getBytes(StandardCharsets.UTF_8));