Version.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2008, Yahoo! Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.yahoo.zookeeper;
  17. public class Version implements com.yahoo.zookeeper.version.Info{
  18. public static int getRevision() {
  19. return REVISION;
  20. }
  21. public static String getBuildDate() {
  22. return BUILD_DATE;
  23. }
  24. public static String getVersion() {
  25. return MAJOR + "." + MINOR + "." + MICRO;
  26. }
  27. public static String getVersionRevision() {
  28. return getVersion() + "-" + getRevision();
  29. }
  30. public static String getFullVersion() {
  31. return getVersionRevision() + ", built on " + getBuildDate();
  32. }
  33. public static void printUsage() {
  34. System.out
  35. .print("Usage:\tjava -cp ... com.yahoo.zookeeper.Version "
  36. + "[--full | --short | --revision],\n\tPrints --full version "
  37. + "info if no arg specified.");
  38. System.exit(1);
  39. }
  40. /**
  41. * Prints the current version, revision and build date to the standard out.
  42. *
  43. * @param args
  44. * <ul>
  45. * <li> --short - prints a short version string "1.2.3"
  46. * <li> --revision - prints a short version string with the SVN
  47. * repository revision "1.2.3-94"
  48. * <li> --full - prints the revision and the build date
  49. * </ul>
  50. */
  51. public static void main(String[] args) {
  52. if (args.length > 1) {
  53. printUsage();
  54. }
  55. if (args.length == 0 || (args.length == 1 && args[0].equals("--full"))) {
  56. System.out.println(getFullVersion());
  57. System.exit(0);
  58. }
  59. if (args[0].equals("--short"))
  60. System.out.println(getVersion());
  61. else if (args[0].equals("--revision"))
  62. System.out.println(getVersionRevision());
  63. else
  64. printUsage();
  65. System.exit(0);
  66. }
  67. }