File tree Expand file tree Collapse file tree 7 files changed +58
-10
lines changed
org.eclipse.xpect.ui/src/org/eclipse/xpect/ui/util
org.eclipse.xpect/src/org/eclipse/xpect Expand file tree Collapse file tree 7 files changed +58
-10
lines changed Original file line number Diff line number Diff line change 3030import org .eclipse .xpect .XpectFile ;
3131import org .eclipse .xpect .registry .ILanguageInfo ;
3232import org .eclipse .xpect .runner .XpectRunner ;
33+ import org .eclipse .xpect .runner .XpectTestGlobalState ;
3334
3435import com .google .inject .Injector ;
3536
@@ -67,8 +68,8 @@ protected static ResourceSet cloneResourceSet(ResourceSet rs) {
6768 // need delegation or nothing because of "java" protocol
6869 // result.setResourceFactoryRegistry(rs.getResourceFactoryRegistry());
6970 result .setURIConverter (rs .getURIConverter ());
70- if (XpectRunner . testClassloader != null ) {
71- result .setClasspathURIContext (XpectRunner . testClassloader );
71+ if (XpectTestGlobalState . INSTANCE . testClass () != null ) {
72+ result .setClasspathURIContext (XpectTestGlobalState . INSTANCE . testClass (). getClassLoader () );
7273 result .setClasspathUriResolver (new ClassloaderClasspathUriResolver ());
7374 } else if (rs instanceof XtextResourceSet ) {
7475 XtextResourceSet xrs = (XtextResourceSet ) rs ;
Original file line number Diff line number Diff line change 2828import org .eclipse .xpect .XpectFile ;
2929import org .eclipse .xpect .XpectJavaModel ;
3030import org .eclipse .xpect .runner .XpectRunner ;
31+ import org .eclipse .xpect .runner .XpectTestGlobalState ;
3132import org .eclipse .xpect .ui .internal .XpectActivator ;
3233
3334import com .google .inject .Injector ;
@@ -40,8 +41,8 @@ public static XpectFile loadFile(IFile file) {
4041 Injector injector = XpectActivator .getInstance ().getInjector (XpectActivator .ORG_ECLIPSE_XPECT_XPECT );
4142 XtextResourceSet rs = new XtextResourceSet ();
4243 IJavaProject javaProject = JavaCore .create (file .getProject ());
43- if (XpectRunner . testClassloader != null ) {
44- rs .setClasspathURIContext (XpectRunner . testClassloader );
44+ if (XpectTestGlobalState . INSTANCE . testClass () != null ) {
45+ rs .setClasspathURIContext (XpectTestGlobalState . INSTANCE . testClass (). getClassLoader () );
4546 rs .setClasspathUriResolver (new ClassloaderClasspathUriResolver ());
4647 } else if (javaProject != null && javaProject .exists ()) {
4748 rs .setClasspathURIContext (javaProject );
Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ public XpectRunner(Class<?> testClass) throws InitializationError {
7272 this .uriProvider = findUriProvider (testClass );
7373 this .xpectInjector = findXpectInjector ();
7474 this .xpectJavaModel = XpectJavaModelManager .createJavaModel (testClass );
75+ /*
76+ * NOTE:
77+ * Do this before the state creation, otherwise the parts that depend on
78+ * the singleton won't initialize properly and tests will fail to run!
79+ */
80+ XpectTestGlobalState .INSTANCE .set (xpectJavaModel , testClass );
7581 this .state = TestExecutor .createState (createRootConfiguration ());
7682 }
7783
Original file line number Diff line number Diff line change 1+ /*******************************************************************************
2+ * Copyright (c) 2024 Simeon Andreev and others.
3+ * This program and the accompanying materials are made
4+ * available under the terms of the Eclipse Public License 2.0
5+ * which is available at https://www.eclipse.org/legal/epl-2.0/
6+ *
7+ * SPDX-License-Identifier: EPL-2.0
8+ *
9+ * Contributors:
10+ * Simeon Andreev - Initial contribution and API
11+ *******************************************************************************/
12+ package org .eclipse .xpect .runner ;
13+
14+ import org .eclipse .xpect .XpectJavaModel ;
15+
16+ /**
17+ * @author Simeon Andreev - Initial contribution and API
18+ */
19+ public class XpectTestGlobalState {
20+
21+ public static final XpectTestGlobalState INSTANCE = new XpectTestGlobalState ();
22+
23+ private XpectJavaModel model ;
24+ private Class <?> testClass ;
25+
26+ public void set (XpectJavaModel model , Class <?> testClass ) {
27+ this .model = model ;
28+ this .testClass = testClass ;
29+ }
30+
31+ public XpectJavaModel model () {
32+ return model ;
33+ }
34+
35+ public Class <?> testClass () {
36+ return testClass ;
37+ }
38+ }
Original file line number Diff line number Diff line change 1717import org .eclipse .xpect .XpectConstants ;
1818import org .eclipse .xpect .registry .ILanguageInfo ;
1919import org .eclipse .xpect .runner .XpectRunner ;
20+ import org .eclipse .xpect .runner .XpectTestGlobalState ;
2021import org .eclipse .xpect .util .IXtInjectorProvider ;
2122
2223import com .google .inject .Injector ;
@@ -32,8 +33,8 @@ private XtResourceServiceProviderProvider() {
3233 }
3334
3435 public IResourceServiceProvider get (URI uri , String contentType ) {
35- if (XpectRunner .INSTANCE != null ) {
36- Injector injector = IXtInjectorProvider .INSTANCE .getInjector (XpectRunner .INSTANCE .getXpectJavaModel (), uri );
36+ if (XpectTestGlobalState .INSTANCE . model () != null ) {
37+ Injector injector = IXtInjectorProvider .INSTANCE .getInjector (XpectTestGlobalState .INSTANCE .model (), uri );
3738 if (injector != null )
3839 return injector .getInstance (IResourceServiceProvider .class );
3940 }
Original file line number Diff line number Diff line change 2626
2727import org .apache .log4j .Logger ;
2828import org .eclipse .xpect .runner .XpectRunner ;
29+ import org .eclipse .xpect .runner .XpectTestGlobalState ;
2930
3031import com .google .common .base .Joiner ;
3132import com .google .common .collect .Sets ;
@@ -81,8 +82,8 @@ public static Collection<URL> findResources(String... fileNames) {
8182 }
8283 }
8384 // for some reason, ucl.getURLs() doesn't catch the current project in standalone maven surefire
84- if (XpectRunner .INSTANCE != null ) {
85- Class <?> clazz = XpectRunner .INSTANCE .getTestClass (). getJavaClass ();
85+ if (XpectTestGlobalState .INSTANCE . testClass () != null ) {
86+ Class <?> clazz = XpectTestGlobalState .INSTANCE .testClass ();
8687 String [] segments = clazz .getName ().split ("\\ ." );
8788 String fileName = Joiner .on ('/' ).join (segments ) + ".class" ;
8889 URL resource = clazz .getClassLoader ().getResource (fileName );
Original file line number Diff line number Diff line change 1414
1515import org .eclipse .emf .ecore .plugin .EcorePlugin ;
1616import org .eclipse .xpect .Environment ;
17- import org .eclipse .xpect .runner .XpectRunner ;
17+ import org .eclipse .xpect .runner .XpectTestGlobalState ;
1818
1919import com .google .common .base .Joiner ;
2020
2121public class EnvironmentUtil {
2222 public static final Environment ENVIRONMENT = detectEnvironement ();
2323
2424 private static Environment detectEnvironement () {
25- if (XpectRunner . testClassloader != null ) {
25+ if (XpectTestGlobalState . INSTANCE . testClass () != null ) {
2626 if (EcorePlugin .IS_ECLIPSE_RUNNING )
2727 return Environment .PLUGIN_TEST ;
2828 else
You can’t perform that action at this time.
0 commit comments