From 871560032e7a973f256e94ba8077d86b348051ad Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 8 Apr 2021 13:50:20 -0500 Subject: [PATCH 1/2] Issue #6148 - update jetty.tag.version behavior Signed-off-by: Joakim Erdfelt --- jetty-start/pom.xml | 23 ++++++++++ .../java/org/eclipse/jetty/start/Props.java | 23 ++++++++++ .../org/eclipse/jetty/start/StartArgs.java | 46 +++++-------------- .../org/eclipse/jetty/start/build.properties | 4 ++ 4 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 jetty-start/src/main/resources/org/eclipse/jetty/start/build.properties diff --git a/jetty-start/pom.xml b/jetty-start/pom.xml index 99999d1cd4d0..520843da97ff 100644 --- a/jetty-start/pom.xml +++ b/jetty-start/pom.xml @@ -13,7 +13,30 @@ org.eclipse.jetty.start.* + + + src/main/resources + true + + + + org.codehaus.mojo + buildnumber-maven-plugin + + + create-buildnumber + + create + + + false + false + ${nonCanonicalRevision} + + + + maven-jar-plugin diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java index dcd70002048a..178058935194 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java @@ -19,7 +19,9 @@ package org.eclipse.jetty.start; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -365,4 +367,25 @@ public String toString() { return props.toString(); } + + public static Props load(URL url) + { + Props props = new Props(); + if (url != null) + { + try (InputStream in = url.openStream()) + { + Properties properties = new Properties(); + properties.load(in); + String urlStr = url.toExternalForm(); + properties.stringPropertyNames().forEach((name) -> + props.setProperty(name, properties.getProperty(name), urlStr)); + } + catch (IOException x) + { + StartLog.debug(x); + } + } + return props; + } } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index f1040ec8b462..0bb228c3428e 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -21,9 +21,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -69,8 +67,8 @@ public class StartArgs static { // Use command line versions - String ver = System.getProperty("jetty.version", null); - String tag = System.getProperty("jetty.tag.version", "master"); + String ver = System.getProperty("jetty.version"); + String tag = System.getProperty("jetty.tag.version"); // Use META-INF/MANIFEST.MF versions if (ver == null) @@ -82,42 +80,22 @@ public class StartArgs .orElse(null); } - // Use jetty-version.properties values - if (ver == null) - { - URL url = Thread.currentThread().getContextClassLoader().getResource("jetty-version.properties"); - if (url != null) - { - try (InputStream in = url.openStream()) - { - Properties props = new Properties(); - props.load(in); - ver = props.getProperty("jetty.version"); - } - catch (IOException x) - { - StartLog.debug(x); - } - } - } + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + // use old jetty-version.properties (as seen within various linux distro repackaging of Jetty) + Props jettyVerProps = Props.load(classLoader.getResource("jetty-version.properties")); + // use build-time properties (included in start.jar) to pull version and buildNumber + Props buildProps = Props.load(classLoader.getResource("/org/eclipse/jetty/version/build.properties")); - // Default values - if (ver == null) + if (Utils.isBlank(ver)) { - ver = "0.0"; - if (tag == null) - tag = "master"; + ver = jettyVerProps.getString("version", buildProps.getString("version", "0.0")); } - else + + if (Utils.isBlank(tag)) { - if (tag == null) - tag = "jetty-" + ver; + tag = jettyVerProps.getString("buildNumber", buildProps.getString("buildNumber", "jetty-" + ver)); } - // Set Tag Defaults - if (tag.contains("-SNAPSHOT")) - tag = "master"; - VERSION = ver; System.setProperty("jetty.version", VERSION); System.setProperty("jetty.tag.version", tag); diff --git a/jetty-start/src/main/resources/org/eclipse/jetty/start/build.properties b/jetty-start/src/main/resources/org/eclipse/jetty/start/build.properties new file mode 100644 index 000000000000..c9d20227f6c1 --- /dev/null +++ b/jetty-start/src/main/resources/org/eclipse/jetty/start/build.properties @@ -0,0 +1,4 @@ +buildNumber=${buildNumber} +timestamp=${timestamp} +version=${project.version} +scmUrl=${project.scm.connection} \ No newline at end of file From 19a1b0c74fbadb42b50b229f5292c8d1f0ee6ef3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 9 Apr 2021 16:52:40 -0500 Subject: [PATCH 2/2] Issue #6148 - introduce jetty.build to show git sha for build Signed-off-by: Joakim Erdfelt --- .../java/org/eclipse/jetty/start/Props.java | 7 ++++ .../org/eclipse/jetty/start/StartArgs.java | 34 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java index 178058935194..a88e8452b328 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java @@ -368,11 +368,18 @@ public String toString() return props.toString(); } + public static Props load(ClassLoader classLoader, String resourceName) + { + StartLog.debug("Looking for classloader resource: %s", resourceName); + return load(classLoader.getResource(resourceName)); + } + public static Props load(URL url) { Props props = new Props(); if (url != null) { + StartLog.debug("Loading Props: %s", url.toExternalForm()); try (InputStream in = url.openStream()) { Properties properties = new Properties(); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 0bb228c3428e..9aa254ea5628 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -38,6 +38,7 @@ import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; +import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -64,27 +65,37 @@ public class StartArgs public static final Set ARG_PARTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( "args"))); + private static final String JETTY_VERSION_KEY = "jetty.version"; + private static final String JETTY_TAG_NAME_KEY = "jetty.tag.version"; + private static final String JETTY_BUILDNUM_KEY = "jetty.build"; + static { // Use command line versions - String ver = System.getProperty("jetty.version"); - String tag = System.getProperty("jetty.tag.version"); + String ver = System.getProperty(JETTY_VERSION_KEY); + String tag = System.getProperty(JETTY_TAG_NAME_KEY); // Use META-INF/MANIFEST.MF versions if (ver == null) { ver = ManifestUtils.getManifest(StartArgs.class) .map(Manifest::getMainAttributes) - .filter(attributes -> "Eclipse Jetty Project".equals(attributes.getValue("Implementation-Vendor"))) - .map(attributes -> attributes.getValue("Implementation-Version")) + .filter(attributes -> "Eclipse Jetty Project".equals(attributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR))) + .map(attributes -> attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION)) .orElse(null); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // use old jetty-version.properties (as seen within various linux distro repackaging of Jetty) - Props jettyVerProps = Props.load(classLoader.getResource("jetty-version.properties")); + Props jettyVerProps = Props.load(classLoader, "jetty-version.properties"); // use build-time properties (included in start.jar) to pull version and buildNumber - Props buildProps = Props.load(classLoader.getResource("/org/eclipse/jetty/version/build.properties")); + Props buildProps = Props.load(classLoader, "org/eclipse/jetty/start/build.properties"); + + String sha = buildProps.getString("buildNumber", System.getProperty(JETTY_BUILDNUM_KEY)); + if (Utils.isNotBlank(sha)) + { + System.setProperty(JETTY_BUILDNUM_KEY, sha); + } if (Utils.isBlank(ver)) { @@ -93,12 +104,12 @@ public class StartArgs if (Utils.isBlank(tag)) { - tag = jettyVerProps.getString("buildNumber", buildProps.getString("buildNumber", "jetty-" + ver)); + tag = jettyVerProps.getString("tag", buildProps.getString("tag", "jetty-" + ver)); } VERSION = ver; - System.setProperty("jetty.version", VERSION); - System.setProperty("jetty.tag.version", tag); + System.setProperty(JETTY_VERSION_KEY, VERSION); + System.setProperty(JETTY_TAG_NAME_KEY, tag); } private static final String MAIN_CLASS = "org.eclipse.jetty.xml.XmlConfiguration"; @@ -301,8 +312,9 @@ public void dumpEnvironment() System.out.println(); System.out.println("Jetty Environment:"); System.out.println("-----------------"); - dumpProperty("jetty.version"); - dumpProperty("jetty.tag.version"); + dumpProperty(JETTY_VERSION_KEY); + dumpProperty(JETTY_TAG_NAME_KEY); + dumpProperty(JETTY_BUILDNUM_KEY); dumpProperty("jetty.home"); dumpProperty("jetty.base");