/[schmitzm]/trunk/src/skrueger/versionnumber/ReleaseUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/versionnumber/ReleaseUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 801 by alfonx, Wed Apr 14 19:30:11 2010 UTC revision 1140 by alfonx, Sat Oct 16 12:02:19 2010 UTC
# Line 3  package skrueger.versionnumber; Line 3  package skrueger.versionnumber;
3  import java.io.InputStream;  import java.io.InputStream;
4  import java.net.URL;  import java.net.URL;
5  import java.util.Properties;  import java.util.Properties;
6    import java.util.regex.Matcher;
7    import java.util.regex.Pattern;
8    
9  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
10    
# Line 19  import org.apache.log4j.Logger; Line 21  import org.apache.log4j.Logger;
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>
# Line 33  import org.apache.log4j.Logger; Line 35  import org.apache.log4j.Logger;
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/>
# Line 93  public class ReleaseUtil { Line 95  public class ReleaseUtil {
95           *           *
96           * @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.
97           */           */
98          public static int getVersionBuild(Class<?> clazz) {          public static String getVersionBuild(Class<?> clazz) {
99                  try {                  try {
100                          final URL releasePropsURL = clazz                          final URL releasePropsURL = clazz
101                                          .getResource("/release.properties");                                          .getResource("/release.properties");
# Line 110  public class ReleaseUtil { Line 112  public class ReleaseUtil {
112                          if (str.equals("${buildNumber}")) {                          if (str.equals("${buildNumber}")) {
113                                  // We are in development or Maven didn't filter the properties                                  // We are in development or Maven didn't filter the properties
114                                  // while building.                                  // while building.
115                                  return 0;                                  return "0";
116                          }                          }
117    
118                          return Integer.parseInt(str);                          return str;
119                  } catch (final Exception e) {                  } catch (final Exception e) {
120                          log.error("/release.properties could not be read from "                          log.error(
121                                          + clazz.getSimpleName(), e);                                          "/release.properties could not be read from "
122                          return 0;                                                          + clazz.getSimpleName(), e);
123                            return "0";
124                  }                  }
125    
126          }          }
# Line 152  public class ReleaseUtil { Line 155  public class ReleaseUtil {
155                                  return defaultVer;                                  return defaultVer;
156                          return versionProperty;                          return versionProperty;
157                  } catch (final Exception e) {                  } catch (final Exception e) {
158                          log.error("/release.properties could not be read from "                          log.error(
159                                          + clazz.getSimpleName(), e);                                          "/release.properties could not be read from "
160                                                            + clazz.getSimpleName(), e);
161                          return defaultVer;                          return defaultVer;
162                  }                  }
163    
# Line 188  public class ReleaseUtil { Line 192  public class ReleaseUtil {
192           */           */
193          public static int getVersionMin(Class<?> clazz) {          public static int getVersionMin(Class<?> clazz) {
194                  try {                  try {
195                          return Integer.parseInt(getVersion(clazz).split("\\.")[1]);                          return extractMinVersionFromString(getVersion(clazz));
196                  } catch (final Exception e) {                  } catch (final Exception e) {
197                          log.error("Minor version number '" + getVersion(clazz)                          log.error("Minor version number '" + getVersion(clazz)
198                                          + "' part could not be parsed from could not parsed (from "                                          + "' part could not be parsed from could not parsed (from "
# Line 198  public class ReleaseUtil { Line 202  public class ReleaseUtil {
202    
203          }          }
204    
205            public static int extractMinVersionFromString(String versionString) {
206                    Pattern minVersionPattern = Pattern.compile("\\d*\\.(\\d*).*");
207                    Matcher matcher = minVersionPattern.matcher(versionString);
208                    matcher.find();
209                    return Integer.parseInt(matcher.group(1));
210            }
211    
212          /**          /**
213           * @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.  
214           */           */
215          public static void logGPLCopyright(final Logger logger) {          public enum License {
216                  logger                  LGPL3, GPL3
217                                  .info("\nThis program is free software: you can redistribute it and/or modify\n"          };
                                                 + "it under the terms of the GNU 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 General Public License for more details.\n");  
         }  
218    
219          /**          /**
220           * @param clazz           * Print the GPL disclaimer to the given {@link Logger} on INFO level.
          *            Pass a class that resides in the same "project" or jar, where  
          *            the /release.properties resides as well.  
221           *           *
222           *            Print the LGPL disclaimer to the given {@link Logger} on INFO           * @param progname
223           *            level.           *            Name of the program as printed in the license. Will
224             *            automatically be starting with an upper-case letter.
225             *            <code>null</code> will fall-back to <code>This program</code>
226           */           */
227          public static void logLGPLCopyright(final Logger logger) {          public static String getLicense(License l, String progname) {
228                  logger                  if (progname == null || progname.isEmpty())
229                                  .info("\nThis program is free software: you can redistribute it and/or modify\n"                          progname = "This program";
230                                                  + "it under the terms of the GNU Lesser General Public License as published by\n"                  switch (l) {
231                                                  + "the Free Software Foundation, either version 3 of the License, or\n"                  case GPL3:
232                                                  + "(at your option) any later version.\n"                          return ("\n"
233                                                  + "\n"                                          + progname
234                                                  + "This program is distributed in the hope that it will be useful,\n"                                          + " is free software: you can redistribute it and/or modify\n"
235                                                  + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"                                          + "it under the terms of the GNU General Public License as published by\n"
236                                                  + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"                                          + "the Free Software Foundation, either version 3 of the License, or\n"
237                                                  + "GNU Lesser General Public License for more details.\n");                                          + "(at your option) any later version.\n"
238                                            + "\n"
239                                            + progname
240                                            + " is distributed in the hope that it will be useful,\n"
241                                            + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
242                                            + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" + "GNU General Public License for more details.\n");
243                    case LGPL3:
244                            return ("\n"
245                                            + progname
246                                            + " is free software: you can redistribute it and/or modify\n"
247                                            + "it under the terms of the GNU Lesser General Public License as published by\n"
248                                            + "the Free Software Foundation, either version 3 of the License, or\n"
249                                            + "(at your option) any later version.\n"
250                                            + "\n"
251                                            + progname
252                                            + " is distributed in the hope that it will be useful,\n"
253                                            + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
254                                            + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" + "GNU Lesser General Public License for more details.\n");
255                    }
256                    throw new IllegalArgumentException();
257            }
258    
259            public static boolean isSnapshow(Class<?> clazz) {
260                    return getVersionInfo(clazz).contains("SNAPSHOT");
261          }          }
262  }  }

Legend:
Removed from v.801  
changed lines
  Added in v.1140

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26