You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* ********************************************************************
  2. * Copyright (c) 1998-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * *******************************************************************/
  13. package org.aspectj.bridge;
  14. import java.io.IOException;
  15. import java.net.URL;
  16. import java.text.ParsePosition;
  17. import java.text.SimpleDateFormat;
  18. import java.util.Date;
  19. import java.util.Properties;
  20. /** release-specific version information */
  21. public class Version {
  22. // generated from build/lib/BridgeVersion.java
  23. /** default version value for development version */
  24. public static final String DEVELOPMENT = "DEVELOPMENT";
  25. // VersionUptodate.java depends on this value
  26. /** default time value for development version */
  27. public static final long NOTIME = 0L;
  28. public static final String UNREPLACED_TEXT = "${project.version}";
  29. public static final String UNREPLACED_TIME_TEXT = "${version.time_text}";
  30. /** set by build script */
  31. private static String text;// = "DEVELOPMENT";
  32. // VersionUptodate.java scans for "static final String text = "
  33. /**
  34. * Time text set by build script using SIMPLE_DATE_FORMAT.
  35. * (if DEVELOPMENT version, invalid)
  36. */
  37. private static String time_text;// = "Tuesday Jan 15, 2019 at 00:53:54 GMT";
  38. /**
  39. * time in seconds-since-... format, used by programmatic clients.
  40. * (if DEVELOPMENT version, NOTIME)
  41. */
  42. private static long time = -1; // -1 == uninitialized
  43. /** format used by build script to set time_text */
  44. public static final String SIMPLE_DATE_FORMAT = "EEEE MMM d, yyyy 'at' HH:mm:ss z";
  45. static {
  46. try {
  47. URL resource = Version.class.getResource("version.properties");
  48. Properties p = new Properties();
  49. p.load(resource.openStream());
  50. text = p.getProperty("version.text","");
  51. if (text.equals(UNREPLACED_TEXT)) {
  52. text="DEVELOPMENT";
  53. }
  54. time_text = p.getProperty("version.time_text","");
  55. if (time_text.equals(UNREPLACED_TIME_TEXT)) {
  56. time_text="";
  57. }
  58. } catch (IOException e) {
  59. text="DEVELOPMENT";
  60. time_text = "";
  61. }
  62. }
  63. public static long getTime() {
  64. if (time==-1) {
  65. long foundTime = NOTIME;
  66. // if not DEVELOPMENT version, read time text using format used to set time
  67. try {
  68. SimpleDateFormat format = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
  69. ParsePosition pos = new ParsePosition(0);
  70. Date date = format.parse(time_text, pos);
  71. if (date!=null) foundTime = date.getTime();
  72. } catch (Throwable t) {
  73. }
  74. time = foundTime;
  75. }
  76. return time;
  77. }
  78. /**
  79. * Test whether the version is as specified by any first argument.
  80. * Emit text to System.err on failure
  81. * @param args String[] with first argument equal to Version.text
  82. * @see Version#text
  83. */
  84. public static void main(String[] args) {
  85. if ((null != args) && (0 < args.length)) {
  86. if (!Version.text.equals(args[0])) {
  87. System.err.println("version expected: \""
  88. + args[0]
  89. + "\" actual=\""
  90. + Version.text
  91. + "\"");
  92. }
  93. }
  94. }
  95. public static String getTimeText() {
  96. return time_text;
  97. }
  98. public static String getText() {
  99. return text;
  100. }
  101. }