/tycho-its/src/test/java/org/sonatype/tycho/test/util/EnvironmentUtil.java

https://github.com/jsievers/sonatype-tycho · Java · 80 lines · 59 code · 20 blank · 1 comment · 3 complexity · 455649eaef8f6b1960a0ba98293149cf MD5 · raw file

  1. package org.sonatype.tycho.test.util;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.util.Properties;
  6. import org.sonatype.tycho.test.AbstractTychoIntegrationTest;
  7. public class EnvironmentUtil {
  8. private static final Properties props;
  9. static {
  10. props = new Properties();
  11. ClassLoader cl = AbstractTychoIntegrationTest.class.getClassLoader();
  12. InputStream is = cl.getResourceAsStream("baseTest.properties");
  13. if (is != null) {
  14. try {
  15. try {
  16. props.load(is);
  17. } finally {
  18. is.close();
  19. }
  20. } catch (IOException e) {
  21. throw new RuntimeException(e);
  22. }
  23. }
  24. }
  25. static synchronized String getProperty(String key) {
  26. return props.getProperty(key);
  27. }
  28. private static final String WINDOWS_OS = "windows";
  29. private static final String MAC_OS = "mac os x";
  30. private static final String MAC_OS_DARWIN = "darwin";
  31. private static final String LINUX_OS = "linux";
  32. private static final String OS = System.getProperty("os.name")
  33. .toLowerCase();
  34. public static boolean isWindows() {
  35. return OS.startsWith(WINDOWS_OS);
  36. }
  37. public static boolean isLinux() {
  38. return OS.startsWith(LINUX_OS);
  39. }
  40. public static boolean isMac() {
  41. return OS.startsWith(MAC_OS) || OS.startsWith(MAC_OS_DARWIN);
  42. }
  43. // TODO find a more reliable way
  44. public static boolean isEclipse32Platform() {
  45. return new File(getTargetPlatforn(), "startup.jar").exists();
  46. }
  47. public static String getTargetPlatforn() {
  48. return getProperty("eclipse-dir");
  49. }
  50. public static String getMavenHome() {
  51. return getProperty("maven-dir");
  52. }
  53. public static String getTychoVersion() {
  54. return getProperty("tycho-version");
  55. }
  56. public static int getHttpServerPort() {
  57. String port = getProperty("server-port");
  58. return Integer.parseInt(port);
  59. }
  60. }