16 |
* @author Stefan A. Tzeggai |
* @author Stefan A. Tzeggai |
17 |
* |
* |
18 |
* Wer sein Maven Projekt wie folgt konfiguriert kann die Maven + |
* Wer sein Maven Projekt wie folgt konfiguriert kann die Maven + |
19 |
* SVN-Revisionnummer als Programmversion verwenden, z.B. |
* Build-Zeitpunk als Programmversion verwenden, z.B. |
20 |
* "v1.5-SNAPSHOT r123" |
* "v1.5-SNAPSHOT 2010-11-23 23:55" |
21 |
* |
* |
22 |
* <br/> |
* <br/> |
23 |
* 1. pom.xml anpassen: <code> |
* 1. pom.xml anpassen: <code> |
24 |
<plugin> |
<plugin> |
25 |
<groupId>org.codehaus.mojo</groupId> |
<groupId>org.codehaus.mojo</groupId> |
26 |
<artifactId>buildnumber-maven-plugin</artifactId> |
<artifactId>buildnumber-maven-plugin</artifactId> |
27 |
<version>1.0-beta-4</version> |
<version>1.0-beta-4</version> |
35 |
</execution> |
</execution> |
36 |
</executions> |
</executions> |
37 |
<configuration> |
<configuration> |
38 |
|
<!-- <doCheck>false</doCheck> <doUpdate>false</doUpdate> <providerImplementations> |
39 |
<doCheck>false</doCheck> |
<svn>javasvn</svn> </providerImplementations> --> |
40 |
<doUpdate>false</doUpdate> |
<format>{0,date,yyyyMMddHHmm}</format> |
41 |
<providerImplementations> |
<items> |
42 |
<svn>javasvn</svn> |
<item>timestamp</item> |
43 |
</providerImplementations> |
</items> |
44 |
</configuration> |
</configuration> |
45 |
</plugin> |
</plugin> |
46 |
</code><br/> |
</code><br/> |
47 |
* 2. Datei src/main/resources.properties mit foglenden Inhalt anlegen: |
* 2. Datei src/main/resources/release.properties mit foglenden Inhalt |
48 |
* <code> |
* anlegen: <code> |
49 |
#Properties describing this release/build |
#Properties describing this release/build |
50 |
version=${project.version} |
version=${project.version} |
51 |
build=${buildNumber} |
build=${buildNumber} |
70 |
private static Logger log = Logger.getLogger(ReleaseUtil.class); |
private static Logger log = Logger.getLogger(ReleaseUtil.class); |
71 |
|
|
72 |
/** |
/** |
73 |
* This is the main public API method which never throws an exception. |
* Returns all (the most) information in one sting. This is a public method |
74 |
|
* which never throws an Exception. |
75 |
* |
* |
76 |
* @param clazz |
* @param clazz |
77 |
* Pass a class that resides in the same "project" or jar, where |
* Pass a class that resides in the same "project" or jar, where |
96 |
* |
* |
97 |
* @Return the major part of the software version or 0 if a problem occurs. |
* @Return the major part of the software version or 0 if a problem occurs. |
98 |
*/ |
*/ |
99 |
public static int getVersionBuild(Class<?> clazz) { |
public static String getVersionBuild(Class<?> clazz) { |
100 |
try { |
try { |
101 |
final URL releasePropsURL = clazz |
final URL releasePropsURL = clazz |
102 |
.getResource("/release.properties"); |
.getResource("/release.properties"); |
113 |
if (str.equals("${buildNumber}")) { |
if (str.equals("${buildNumber}")) { |
114 |
// We are in development or Maven didn't filter the properties |
// We are in development or Maven didn't filter the properties |
115 |
// while building. |
// while building. |
116 |
return 0; |
return "0"; |
117 |
} |
} |
118 |
|
|
119 |
return Integer.parseInt(str); |
return str; |
120 |
} catch (final Exception e) { |
} catch (final Exception e) { |
121 |
log.error("/release.properties could not be read from " |
log.error( |
122 |
+ clazz.getSimpleName(), e); |
"/release.properties could not be read from " |
123 |
return 0; |
+ clazz.getSimpleName(), e); |
124 |
|
return "0"; |
125 |
} |
} |
126 |
|
|
127 |
} |
} |
156 |
return defaultVer; |
return defaultVer; |
157 |
return versionProperty; |
return versionProperty; |
158 |
} catch (final Exception e) { |
} catch (final Exception e) { |
159 |
log.error("/release.properties could not be read from " |
log.error( |
160 |
+ clazz.getSimpleName(), e); |
"/release.properties could not be read from " |
161 |
|
+ clazz.getSimpleName(), e); |
162 |
return defaultVer; |
return defaultVer; |
163 |
} |
} |
164 |
|
|
211 |
} |
} |
212 |
|
|
213 |
/** |
/** |
214 |
* @param clazz |
* Different types of licenses supported. |
|
* Pass a class that resides in the same "project" or jar, where |
|
|
* the /release.properties resides as well. |
|
|
* |
|
|
* Print the GPL disclaimer to the given {@link Logger} on INFO |
|
|
* level. |
|
215 |
*/ |
*/ |
216 |
public static void logGPLCopyright(final Logger logger) { |
public enum License { |
217 |
logger |
LGPL3, GPL3 |
218 |
.info("\nThis program is free software: you can redistribute it and/or modify\n" |
}; |
219 |
+ "it under the terms of the GNU General Public License as published by\n" |
|
220 |
+ "the Free Software Foundation, either version 3 of the License, or\n" |
/** |
221 |
+ "(at your option) any later version.\n" |
* Print the GPL disclaimer to the given {@link Logger} on INFO level. |
222 |
+ "\n" |
* |
223 |
+ "This program is distributed in the hope that it will be useful,\n" |
* @param progname |
224 |
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
* Name of the program as printed in the license. Will |
225 |
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
* automatically be starting with an upper-case letter. |
226 |
+ "GNU General Public License for more details.\n"); |
* <code>null</code> will fall-back to <code>This program</code> |
227 |
|
*/ |
228 |
|
public static String getLicense(License l, String progname) { |
229 |
|
if (progname == null || progname.isEmpty()) |
230 |
|
progname = "This program"; |
231 |
|
switch (l) { |
232 |
|
case GPL3: |
233 |
|
return ("\n" |
234 |
|
+ progname |
235 |
|
+ " is free software: you can redistribute it and/or modify\n" |
236 |
|
+ "it under the terms of the GNU General Public License as published by\n" |
237 |
|
+ "the Free Software Foundation, either version 3 of the License, or\n" |
238 |
|
+ "(at your option) any later version.\n" |
239 |
|
+ "\n" |
240 |
|
+ progname |
241 |
|
+ " is distributed in the hope that it will be useful,\n" |
242 |
|
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
243 |
|
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n"); |
244 |
|
case LGPL3: |
245 |
|
return ("\n" |
246 |
|
+ progname |
247 |
|
+ " is free software: you can redistribute it and/or modify\n" |
248 |
|
+ "it under the terms of the GNU Lesser General Public License as published by\n" |
249 |
|
+ "the Free Software Foundation, either version 3 of the License, or\n" |
250 |
|
+ "(at your option) any later version.\n" |
251 |
|
+ "\n" |
252 |
|
+ progname |
253 |
|
+ " is distributed in the hope that it will be useful,\n" |
254 |
|
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
255 |
|
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU Lesser General Public License for more details.\n"); |
256 |
|
} |
257 |
|
throw new IllegalArgumentException(); |
258 |
} |
} |
259 |
|
|
260 |
/** |
public static boolean isSnapshot(Class<?> clazz) { |
261 |
* @param clazz |
return getVersionInfo(clazz).contains("SNAPSHOT"); |
|
* Pass a class that resides in the same "project" or jar, where |
|
|
* the /release.properties resides as well. |
|
|
* |
|
|
* Print the LGPL disclaimer to the given {@link Logger} on INFO |
|
|
* level. |
|
|
*/ |
|
|
public static void logLGPLCopyright(final Logger logger) { |
|
|
logger |
|
|
.info("\nThis program is free software: you can redistribute it and/or modify\n" |
|
|
+ "it under the terms of the GNU Lesser General Public License as published by\n" |
|
|
+ "the Free Software Foundation, either version 3 of the License, or\n" |
|
|
+ "(at your option) any later version.\n" |
|
|
+ "\n" |
|
|
+ "This program is distributed in the hope that it will be useful,\n" |
|
|
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
|
|
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
|
|
+ "GNU Lesser General Public License for more details.\n"); |
|
262 |
} |
} |
263 |
} |
} |