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.

Constants.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2011 James Moger.
  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.iciql;
  17. import java.net.URL;
  18. import java.util.jar.Attributes;
  19. import java.util.jar.Manifest;
  20. /**
  21. * Iciql constants.
  22. */
  23. public class Constants {
  24. public static final String NAME = "iciql";
  25. // The build script extracts this exact line so be careful editing it
  26. // and only use A-Z a-z 0-9 .-_ in the string.
  27. public static final String API_CURRENT = "15";
  28. public static String getVersion() {
  29. return getManifestValue("implementation-version", "0.0.0-SNAPSHOT");
  30. }
  31. public static String getBuildDate() {
  32. return getManifestValue("build-date", "PENDING");
  33. }
  34. private static String getManifestValue(String attrib, String defaultValue) {
  35. Class<?> clazz = Constants.class;
  36. String className = clazz.getSimpleName() + ".class";
  37. String classPath = clazz.getResource(className).toString();
  38. try {
  39. String manifestPath;
  40. if (classPath.indexOf('!') > -1) {
  41. manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
  42. } else {
  43. String pkgPath = "/" + clazz.getPackage().getName().replace('.', '/');
  44. manifestPath = classPath.substring(0, classPath.indexOf(pkgPath)) + "/META-INF/MANIFEST.MF";
  45. }
  46. Manifest manifest = new Manifest(new URL(manifestPath).openStream());
  47. Attributes attr = manifest.getMainAttributes();
  48. String value = attr.getValue(attrib);
  49. return value;
  50. } catch (Exception e) {
  51. }
  52. return defaultValue;
  53. }
  54. }