Skip to content

Commit c848bf1

Browse files
committed
Display build information as detected at runtime
Move away from hardcoded version information for use by toolsUI Fixes #1480
1 parent 104a37c commit c848bf1

File tree

5 files changed

+54
-28
lines changed

5 files changed

+54
-28
lines changed

uicdm/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,14 @@ application {
5252
}
5353

5454
jar.manifest.attributes 'Main-Class': 'ucar.nc2.ui.ToolsUI'
55+
56+
def genBuildInfo = tasks.register("generateBuildInfo", WriteProperties) {
57+
destinationFile = getLayout().buildDirectory.file("resources/main/toolsui.properties")
58+
comment = "Application configuration generated by Gradle"
59+
encoding = "UTF-8"
60+
61+
property("toolsui.version", project.version)
62+
property("toolsui.buildTimestamp", project.buildTimestamp) // Defined in root project.
63+
}
64+
65+
processResources.dependsOn(genBuildInfo)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ucar.nc2.ui;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Properties;
6+
7+
public class BuildInfo {
8+
9+
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(BuildInfo.class);
10+
11+
private final String version, timestamp;
12+
13+
BuildInfo(String version, String timestamp) {
14+
this.version = version;
15+
this.timestamp = timestamp;
16+
}
17+
18+
public String getVersion() {
19+
return version;
20+
}
21+
public String getTimestamp() {
22+
return timestamp;
23+
}
24+
25+
static BuildInfo getToolsUIBuildInfo() {
26+
Properties buildProps = new Properties();
27+
try (InputStream stream = ToolsUI.class.getClassLoader().getResourceAsStream("toolsui.properties")) {
28+
buildProps.load(stream);
29+
} catch (IOException e) {
30+
log.error("Error reading build properties");
31+
}
32+
return new BuildInfo(buildProps.getProperty("toolsui.version", "Unknown"),
33+
buildProps.getProperty("toolsui.buildTimestamp", "Unknown"));
34+
}
35+
36+
}

uicdm/src/main/java/ucar/nc2/ui/ToolsAboutWindow.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* Copyright (c) 1998-2019 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

66
package ucar.nc2.ui;
77

8-
import java.nio.charset.StandardCharsets;
98
import ucar.ui.util.Resource;
109
import ucar.ui.widget.BAMutil;
1110
import java.awt.BorderLayout;
@@ -19,10 +18,6 @@
1918
import java.awt.Toolkit;
2019
import java.awt.event.MouseAdapter;
2120
import java.awt.event.MouseEvent;
22-
import java.io.BufferedReader;
23-
import java.io.InputStream;
24-
import java.io.InputStreamReader;
25-
import java.io.IOException;
2621
import javax.swing.BorderFactory;
2722
import javax.swing.ImageIcon;
2823
import javax.swing.JFrame;
@@ -42,7 +37,8 @@ public ToolsAboutWindow(JFrame parent) {
4237
super(parent);
4338

4439
JLabel lab1 = new JLabel("<html> <body bgcolor=\"#FFECEC\"> <center>"
45-
+ "<h1>Netcdf Tools User Interface (ToolsUI)</h1>" + "<b>" + getVersion() + "</b>"
40+
+ "<h1>Netcdf Tools User Interface (ToolsUI)</h1>" + "<b>" + BuildInfo.getToolsUIBuildInfo().getVersion() + "</b>"
41+
+ "<br>Build Date: " + "<b>" + BuildInfo.getToolsUIBuildInfo().getTimestamp() + "</b>"
4642
+ "<br><i>https://www.unidata.ucar.edu/software/netcdf-java/</i>"
4743
+ "<br><b><i>Developers:</b> John Caron, Sean Arms, Dennis Heimbinger, Ryan May, Christian Ward-Garrison</i></b>"
4844
+ "</center>" + "<br><br>With thanks to these <b>Open Source</b> contributors:" + "<ul>"
@@ -120,23 +116,6 @@ public void mousePressed(MouseEvent e) {
120116
*
121117
*/
122118
private String getVersion() {
123-
String version;
124-
try (InputStream is = Resource.getFileResource("/README")) {
125-
if (is == null) {
126-
return "5.0";
127-
}
128-
BufferedReader dataIS = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
129-
StringBuilder sbuff = new StringBuilder();
130-
for (int i = 0; i < 3; i++) {
131-
sbuff.append(dataIS.readLine());
132-
sbuff.append("<br>");
133-
}
134-
version = sbuff.toString();
135-
} catch (IOException ioe) {
136-
ioe.printStackTrace();
137-
version = "version unknown";
138-
}
139-
140-
return version;
119+
return BuildInfo.getToolsUIBuildInfo().getVersion();
141120
}
142121
}

uicdm/src/main/java/ucar/nc2/ui/ToolsSplashScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998-2019 University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2025 University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

uicdm/src/main/java/ucar/nc2/ui/ToolsUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
public class ToolsUI extends JPanel {
6060
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
6161

62-
private static final String DIALOG_VERSION = "5.0";
62+
private static final String DIALOG_VERSION = BuildInfo.getToolsUIBuildInfo().getVersion();
6363

6464
public static final String WORLD_DETAIL_MAP = "/resources/ui/maps/Countries.shp";
6565
public static final String US_MAP = "/resources/ui/maps/us_state.shp";
@@ -1603,7 +1603,7 @@ public void setMessage(SocketMessage.Event event) {
16031603
} catch (HTTPException e) {
16041604
log.error("Failed to set global credentials");
16051605
}
1606-
HTTPSession.setGlobalUserAgent("ToolsUI v5.0");
1606+
HTTPSession.setGlobalUserAgent(String.format("ToolsUI v%s", BuildInfo.getToolsUIBuildInfo().getVersion()));
16071607

16081608
java.net.Authenticator.setDefault(provider);
16091609
});

0 commit comments

Comments
 (0)