|
| 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