forked from eclipse-xpect/Xpect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironmentUtil.java
More file actions
51 lines (44 loc) · 1.7 KB
/
Copy pathEnvironmentUtil.java
File metadata and controls
51 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
* Copyright (c) 2012-2017 TypeFox GmbH and itemis AG.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Moritz Eysholdt - Initial contribution and API
*******************************************************************************/
package org.eclipse.xpect.util;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.xpect.Environment;
import org.eclipse.xpect.runner.XpectTestGlobalState;
import com.google.common.base.Joiner;
public class EnvironmentUtil {
public static final Environment ENVIRONMENT = detectEnvironement();
private static Environment detectEnvironement() {
if (XpectTestGlobalState.INSTANCE.testClass() != null) {
if (EcorePlugin.IS_ECLIPSE_RUNNING)
return Environment.PLUGIN_TEST;
else
return Environment.STANDALONE_TEST;
} else {
if (EcorePlugin.IS_ECLIPSE_RUNNING)
return Environment.WORKBENCH;
else
throw new IllegalStateException("not (yet) supported environment: standalone, but without JUnit.");
}
}
public static void requireEnvironment(Environment... environments) {
for (Environment env : environments)
if (ENVIRONMENT == env)
return;
StringBuilder msg = new StringBuilder();
msg.append("This class in only applicable in environment(s) ");
Joiner.on(" or ").appendTo(msg, environments);
msg.append(", but environment ");
msg.append(EnvironmentUtil.ENVIRONMENT);
msg.append(" has been found.");
throw new RuntimeException(msg.toString());
}
}