/tycho-testing-harness/src/main/java/org/eclipse/tycho/test/util/EnvironmentUtil.java

https://github.com/oberlies/tycho · Java · 114 lines · 75 code · 22 blank · 17 comment · 10 complexity · 9f0688a97f2fa20ce56af061766ffedc MD5 · raw file

  1. /*******************************************************************************
  2. * Copyright (c) 2008, 2011 Sonatype Inc. and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Sonatype Inc. - initial API and implementation
  10. *******************************************************************************/
  11. package org.eclipse.tycho.test.util;
  12. import java.io.File;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import java.util.Properties;
  16. import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
  17. /**
  18. * Provides system properties and certain properties from the test code build ("outer build"), like
  19. * the location of the local Maven repository. For this class to work, the outer build must
  20. * configure the <tt>maven-properties-plugin</tt> to capture the values in a file called
  21. * baseTest.properties (see tycho-its/pom.xml for an example).
  22. */
  23. public class EnvironmentUtil {
  24. private static final Properties props;
  25. static {
  26. props = new Properties();
  27. ClassLoader cl = AbstractTychoIntegrationTest.class.getClassLoader();
  28. InputStream is = cl.getResourceAsStream("baseTest.properties");
  29. if (is != null) {
  30. try {
  31. try {
  32. props.load(is);
  33. } finally {
  34. is.close();
  35. }
  36. } catch (IOException e) {
  37. throw new RuntimeException(e);
  38. }
  39. }
  40. }
  41. static synchronized String getProperty(String key) {
  42. return props.getProperty(key);
  43. }
  44. private static final String WINDOWS_OS = "windows";
  45. private static final String MAC_OS = "mac os x";
  46. private static final String MAC_OS_DARWIN = "darwin";
  47. private static final String LINUX_OS = "linux";
  48. private static final String OS = System.getProperty("os.name").toLowerCase();
  49. public static boolean isWindows() {
  50. return OS.startsWith(WINDOWS_OS);
  51. }
  52. public static boolean isLinux() {
  53. return OS.startsWith(LINUX_OS);
  54. }
  55. public static boolean isMac() {
  56. return OS.startsWith(MAC_OS) || OS.startsWith(MAC_OS_DARWIN);
  57. }
  58. // TODO find a more reliable way
  59. public static boolean isEclipse32Platform() {
  60. return new File(getTargetPlatform(), "startup.jar").exists();
  61. }
  62. public static String getTargetPlatform() {
  63. String systemValue = System.getProperty("tychodev-testTargetPlatform");
  64. if (systemValue != null) {
  65. return systemValue;
  66. }
  67. return getProperty("its-target-platform");
  68. }
  69. public static String getTestSettings() {
  70. String value = getProperty("its-settings");
  71. if (value == null || value.contains("$"))
  72. return null;
  73. return value;
  74. }
  75. public static String getMavenHome() {
  76. String systemValue = System.getProperty("tychodev-maven.home");
  77. if (systemValue != null) {
  78. return systemValue;
  79. }
  80. return getProperty("maven-dir");
  81. }
  82. public static String getTychoVersion() {
  83. return getProperty("tycho-version");
  84. }
  85. public static int getHttpServerPort() {
  86. String port = getProperty("server-port");
  87. return Integer.parseInt(port);
  88. }
  89. public static String getLocalRepo() {
  90. return getProperty("local-repo");
  91. }
  92. }