PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/logback-core/src/main/java/ch/qos/logback/core/util/EnvUtil.java

https://github.com/Mahoney/logback
Java | 71 lines | 42 code | 11 blank | 18 comment | 6 complexity | ae7098968e3378e52d972c12bb7d0ae4 MD5 | raw file
  1. /**
  2. * Logback: the reliable, generic, fast and flexible logging framework.
  3. * Copyright (C) 1999-2013, QOS.ch. All rights reserved.
  4. *
  5. * This program and the accompanying materials are dual-licensed under
  6. * either the terms of the Eclipse Public License v1.0 as published by
  7. * the Eclipse Foundation
  8. *
  9. * or (per the licensee's choosing)
  10. *
  11. * under the terms of the GNU Lesser General Public License version 2.1
  12. * as published by the Free Software Foundation.
  13. */
  14. package ch.qos.logback.core.util;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. /**
  18. * @author Ceki Gücü
  19. */
  20. public class EnvUtil {
  21. static private boolean isJDK_N_OrHigher(int n) {
  22. List<String> versionList = new ArrayList<String>();
  23. // this code should work at least until JDK 10 (assuming n parameter is
  24. // always 6 or more)
  25. for (int i = 0; i < 5; i++) {
  26. versionList.add("1." + (n + i));
  27. }
  28. String javaVersion = System.getProperty("java.version");
  29. if (javaVersion == null) {
  30. return false;
  31. }
  32. for (String v : versionList) {
  33. if (javaVersion.startsWith(v))
  34. return true;
  35. }
  36. return false;
  37. }
  38. static public boolean isJDK5() {
  39. return isJDK_N_OrHigher(5);
  40. }
  41. static public boolean isJDK6OrHigher() {
  42. return isJDK_N_OrHigher(6);
  43. }
  44. static public boolean isJDK7OrHigher() {
  45. return isJDK_N_OrHigher(7);
  46. }
  47. static public boolean isJaninoAvailable() {
  48. ClassLoader classLoader = EnvUtil.class.getClassLoader();
  49. try {
  50. Class<?> bindingClass = classLoader.loadClass("org.codehaus.janino.ScriptEvaluator");
  51. return (bindingClass != null);
  52. } catch (ClassNotFoundException e) {
  53. return false;
  54. }
  55. }
  56. public static boolean isWindows() {
  57. String os = System.getProperty("os.name");
  58. return os.startsWith("Windows");
  59. }
  60. }