Issue #6148 - introduce jetty.build to show git sha for build

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2021-04-09 16:52:40 -05:00
parent 871560032e
commit 19a1b0c74f
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
2 changed files with 30 additions and 11 deletions

View File

@ -368,11 +368,18 @@ public final class Props implements Iterable<Prop>
return props.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) public static Props load(URL url)
{ {
Props props = new Props(); Props props = new Props();
if (url != null) if (url != null)
{ {
StartLog.debug("Loading Props: %s", url.toExternalForm());
try (InputStream in = url.openStream()) try (InputStream in = url.openStream())
{ {
Properties properties = new Properties(); Properties properties = new Properties();

View File

@ -38,6 +38,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
@ -64,27 +65,37 @@ public class StartArgs
public static final Set<String> ARG_PARTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( public static final Set<String> ARG_PARTS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"args"))); "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 static
{ {
// Use command line versions // Use command line versions
String ver = System.getProperty("jetty.version"); String ver = System.getProperty(JETTY_VERSION_KEY);
String tag = System.getProperty("jetty.tag.version"); String tag = System.getProperty(JETTY_TAG_NAME_KEY);
// Use META-INF/MANIFEST.MF versions // Use META-INF/MANIFEST.MF versions
if (ver == null) if (ver == null)
{ {
ver = ManifestUtils.getManifest(StartArgs.class) ver = ManifestUtils.getManifest(StartArgs.class)
.map(Manifest::getMainAttributes) .map(Manifest::getMainAttributes)
.filter(attributes -> "Eclipse Jetty Project".equals(attributes.getValue("Implementation-Vendor"))) .filter(attributes -> "Eclipse Jetty Project".equals(attributes.getValue(Attributes.Name.IMPLEMENTATION_VENDOR)))
.map(attributes -> attributes.getValue("Implementation-Version")) .map(attributes -> attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION))
.orElse(null); .orElse(null);
} }
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// use old jetty-version.properties (as seen within various linux distro repackaging of Jetty) // 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 // 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)) if (Utils.isBlank(ver))
{ {
@ -93,12 +104,12 @@ public class StartArgs
if (Utils.isBlank(tag)) if (Utils.isBlank(tag))
{ {
tag = jettyVerProps.getString("buildNumber", buildProps.getString("buildNumber", "jetty-" + ver)); tag = jettyVerProps.getString("tag", buildProps.getString("tag", "jetty-" + ver));
} }
VERSION = ver; VERSION = ver;
System.setProperty("jetty.version", VERSION); System.setProperty(JETTY_VERSION_KEY, VERSION);
System.setProperty("jetty.tag.version", tag); System.setProperty(JETTY_TAG_NAME_KEY, tag);
} }
private static final String MAIN_CLASS = "org.eclipse.jetty.xml.XmlConfiguration"; private static final String MAIN_CLASS = "org.eclipse.jetty.xml.XmlConfiguration";
@ -301,8 +312,9 @@ public class StartArgs
System.out.println(); System.out.println();
System.out.println("Jetty Environment:"); System.out.println("Jetty Environment:");
System.out.println("-----------------"); System.out.println("-----------------");
dumpProperty("jetty.version"); dumpProperty(JETTY_VERSION_KEY);
dumpProperty("jetty.tag.version"); dumpProperty(JETTY_TAG_NAME_KEY);
dumpProperty(JETTY_BUILDNUM_KEY);
dumpProperty("jetty.home"); dumpProperty("jetty.home");
dumpProperty("jetty.base"); dumpProperty("jetty.base");