|
3 | 3 |
|
4 | 4 | package com.oracle.weblogic.imagetool.cli;
|
5 | 5 |
|
| 6 | +import java.io.IOException; |
6 | 7 | import java.io.InputStream;
|
7 |
| -import java.util.ArrayList; |
8 |
| -import java.util.List; |
9 | 8 | import java.util.Properties;
|
10 | 9 |
|
11 | 10 | import picocli.CommandLine.IVersionProvider;
|
12 | 11 |
|
13 | 12 | public class HelpVersionProvider implements IVersionProvider {
|
14 | 13 |
|
15 |
| - @Override |
16 |
| - public String[] getVersion() throws Exception { |
17 |
| - List<String> retList = new ArrayList<>(); |
18 |
| - try (InputStream versionInfoStream = this.getClass().getResourceAsStream("/version-info.properties")) { |
19 |
| - if (versionInfoStream != null) { |
20 |
| - Properties versionProps = new Properties(); |
21 |
| - versionProps.load(versionInfoStream); |
22 |
| - retList.add(String.format("%s:%s", versionProps.getProperty("project_name", "imagetool"), |
23 |
| - versionProps.getProperty("project_version", "0.0"))); |
| 14 | + private static final Properties projectProps = new Properties(); |
| 15 | + |
| 16 | + /** |
| 17 | + * Get the project name and version declared in the POM. |
| 18 | + * @return project name and version number |
| 19 | + * @throws IOException if loading version properties fails. |
| 20 | + */ |
| 21 | + public static Properties projectProperties() throws IOException { |
| 22 | + if (projectProps.isEmpty()) { |
| 23 | + try (InputStream versionInfoStream = |
| 24 | + HelpVersionProvider.class.getResourceAsStream("/version-info.properties")) { |
| 25 | + if (versionInfoStream != null) { |
| 26 | + projectProps.load(versionInfoStream); |
| 27 | + } |
24 | 28 | }
|
25 | 29 | }
|
26 |
| - return retList.toArray(new String[0]); |
| 30 | + return projectProps; |
| 31 | + } |
| 32 | + |
| 33 | + public static String versionString() throws IOException { |
| 34 | + return "WebLogic Image Tool version " + projectProperties().getProperty("project_version"); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public String[] getVersion() throws Exception { |
| 39 | + Properties p = projectProperties(); |
| 40 | + String[] result = new String[1]; |
| 41 | + result[0] = p.getProperty("project_name") + ":" + p.getProperty("project_version"); |
| 42 | + return result; |
27 | 43 | }
|
28 | 44 | }
|
0 commit comments