Skip to content

Commit ab87d0f

Browse files
Add main method to print build info
1 parent 5be5c71 commit ab87d0f

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,35 @@
5656
<target>${java.version}</target>
5757
</configuration>
5858
</plugin>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-jar-plugin</artifactId>
62+
<version>2.1</version>
63+
<configuration>
64+
<archive>
65+
<manifestEntries>
66+
<Implementation-Title>Oracle R2DBC</Implementation-Title>
67+
<Implementation-Version>
68+
${project.version}
69+
</Implementation-Version>
70+
<Implementation-Vendor>Oracle Corporation</Implementation-Vendor>
71+
<Specification-Title>
72+
R2DBC - Reactive Relational Database Connectivity
73+
</Specification-Title>
74+
<Specification-Version>${r2dbc.version}</Specification-Version>
75+
<Specification-Vendor>
76+
Pivotal Software, Inc
77+
</Specification-Vendor>
78+
<Build-Info>
79+
Oracle R2DBC ${project.version} compiled with JDK ${java.vm.version} from ${java.vm.vendor} on ${maven.build.timestamp}
80+
</Build-Info>
81+
<Main-Class>
82+
oracle.r2dbc.impl.Main
83+
</Main-Class>
84+
</manifestEntries>
85+
</archive>
86+
</configuration>
87+
</plugin>
5988
<plugin>
6089
<groupId>org.apache.maven.plugins</groupId>
6190
<artifactId>maven-deploy-plugin</artifactId>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
3+
4+
This software is dual-licensed to you under the Universal Permissive License
5+
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
6+
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
either license.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
*/
21+
22+
package oracle.r2dbc.impl;
23+
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.Objects;
27+
import java.util.jar.Manifest;
28+
29+
/**
30+
* <p>
31+
* A public class implementing a main method that may be executed from a
32+
* command line. This class is specified as the Main-Class attribute in
33+
* the META-INF/MANIFEST.MF of the Oracle R2DBC jar.
34+
* </p><p><i>
35+
* The behavior implemented by this class may change between minor and patch
36+
* version release updates.
37+
* </i></p><p>
38+
* The following command, in
39+
* which "x.y.z" is the semantic version number of the jar,
40+
* executes the main method of this class:
41+
* </p><pre>
42+
* java -jar oracle-r2dbc-x.y.z.jar
43+
* </pre><p>
44+
* Since version 0.1.1, the main method is implemented to exit after printing
45+
* a message to the standard output stream. The message includes the version
46+
* numbers of the Oracle R2DBC Driver along with the JDK that compiled it. A
47+
* timestamp captured at the moment when the jar was compiled is also included.
48+
* </p>
49+
*
50+
* @since 0.1.1
51+
* @author Michael-A-McMahon
52+
*/
53+
public final class Main {
54+
55+
private Main() {/*This class has no instance fields*/}
56+
57+
/**
58+
* Prints information about this build of Oracle R2DBC. This method attempts
59+
* to read a "Build-Info" attribute from META-INF/MANIFEST.MF. If the
60+
* manifest is not available to the class loader, or if the manifest does
61+
* not contain a Build-Info attribute, then this method prints a message
62+
* indicating that build information can not be located.
63+
* @param args ignored
64+
* @throws IOException If the META-INF/MANIFEST.MF resource can not be read.
65+
*/
66+
public static void main(String[] args) throws IOException {
67+
68+
InputStream manifestStream =
69+
Main.class.getModule().getResourceAsStream("META-INF/MANIFEST.MF");
70+
71+
if (manifestStream == null) {
72+
System.out.println("META-INF/MANIFEST.MF not found");
73+
return;
74+
}
75+
76+
try (manifestStream) {
77+
System.out.println(Objects.requireNonNullElse(
78+
new Manifest(manifestStream)
79+
.getMainAttributes()
80+
.getValue("Build-Info"),
81+
"Build-Info is missing from the manifest"));
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)