1
1
package io .quarkus .test .junit .launcher ;
2
2
3
3
import java .io .IOException ;
4
- import java .nio .file .Files ;
5
4
import java .nio .file .Path ;
6
5
import java .nio .file .Paths ;
6
+ import java .util .Arrays ;
7
+ import java .util .Set ;
7
8
8
9
import org .eclipse .microprofile .config .ConfigProvider ;
9
10
import org .junit .platform .launcher .LauncherDiscoveryListener ;
18
19
import io .quarkus .bootstrap .model .ApplicationModel ;
19
20
import io .quarkus .bootstrap .resolver .AppModelResolverException ;
20
21
import io .quarkus .bootstrap .utils .BuildToolHelper ;
22
+ import io .quarkus .bootstrap .workspace .WorkspaceModule ;
21
23
import io .quarkus .deployment .dev .testing .CoreQuarkusTestExtension ;
22
24
import io .quarkus .deployment .dev .testing .CurrentTestApplication ;
23
25
import io .quarkus .deployment .dev .testing .TestSupport ;
@@ -104,53 +106,14 @@ public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
104
106
System .out .println ("HOLLY interceipt original" + originalClassLoader );
105
107
CoreQuarkusTestExtension coreQuarkusTestExtension = new CoreQuarkusTestExtension ();
106
108
107
- // TODO we normally start with a test class and work out the runtime classpath
108
- // from that;
109
- // here we need to go in the other direction. There's probably existing logic we
110
- // can re-use, because this
111
- // is seriously brittle
112
- // TODO massi ve assumptions, completely ignoring multi module projects
113
- // Assume the test class lives in the first element on the classpath
114
109
Path projectRoot = Paths .get ("" )
115
110
.normalize ()
116
111
.toAbsolutePath ();
117
112
118
- // TODO can we be more elegant about this? What about multi-module?
119
- // TODO should we cross-reference against the classpath?
120
-
121
- Path targetDir = projectRoot .resolve ("target/test-classes" );
122
-
123
- // The gradle case; can we know in advance which it is?
124
- Path buildDir = projectRoot .resolve ("build" );
125
-
126
- System .out .println (
127
- "HOLLY whole class path is " + System .getProperty ("java.class.path" ));
128
- Path applicationRoot ;
129
-
130
- // TODO probably pointless, to make sure it's shown as set
131
- if (Files .exists (targetDir )) {
132
- applicationRoot = targetDir ;
133
- } else {
134
- applicationRoot = buildDir ;
135
- }
136
-
137
- String [] ses = System .getProperty ("java.class.path" )
138
- .split (":" );
139
- for (String s : ses ) {
140
- Path path = Paths .get (s );
141
- if (path .normalize ()
142
- .toAbsolutePath ()
143
- .startsWith (projectRoot )) {
144
- System .out .println ("CANDIDATE CLASSPATH " + s );
145
- // TODO ugly; set it if we didn't set it to something on the classpath
146
- // TODO fragile, we miss other modules in multi-module
147
- // things like us to take the first element on the classpath that fits
148
- if (applicationRoot == targetDir || applicationRoot == buildDir ) {
149
- applicationRoot = path ;
150
- System .out .println ("made app root" + applicationRoot );
151
- }
152
- }
153
- }
113
+ // Why do we do this rather than just using the project root?
114
+ // BootstrapConstants.OUTPUT_SOURCES_DIR does not have gradle additional source sets, but the classpath does
115
+ // Path applicationRoot = getTestClassesLocationWithNoContext();
116
+ Path applicationRoot = projectRoot ;
154
117
155
118
CuratedApplication curatedApplication ;
156
119
// TODO this makes no sense here because we're on the wrong classloader unless a
@@ -164,7 +127,7 @@ public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
164
127
165
128
System .out .println ("An alternate root we couuld do is " + projectRoot );
166
129
System .out .println (
167
- "That gives gradlle " + getGradleAppModelForIDE (Paths .get ("" )
130
+ "That gives gradle " + getGradleAppModelForIDE (Paths .get ("" )
168
131
.normalize ()
169
132
.toAbsolutePath ()));
170
133
@@ -208,6 +171,26 @@ public void launcherDiscoveryStarted(LauncherDiscoveryRequest request) {
208
171
// currentTestAppConsumer.accept(curatedApplication);
209
172
210
173
// TODO move this to close shutdownTasks.add(curatedApplication::close);
174
+
175
+ var appModelFactory = curatedApplication .getQuarkusBootstrap ().newAppModelFactory ();
176
+ appModelFactory .setBootstrapAppModelResolver (null );
177
+ appModelFactory .setTest (true );
178
+ appModelFactory .setLocalArtifacts (Set .of ());
179
+ // TODO if (!mainModule) {
180
+ // appModelFactory.setAppArtifact(null);
181
+ appModelFactory .setProjectRoot (projectRoot );
182
+ // }
183
+
184
+ // To do this deserialization, we need to have an app root, so we can't use it to find the application model
185
+
186
+ final ApplicationModel testModel = appModelFactory .resolveAppModel ().getApplicationModel ();
187
+ System .out .println ("HOLLY test model is " + testModel );
188
+ System .out .println (
189
+ "module dir is " + Arrays .toString (testModel .getWorkspaceModules ().toArray ()));
190
+ System .out .println (
191
+ "module dir is " + ((WorkspaceModule ) testModel .getWorkspaceModules ().toArray ()[0 ]).getModuleDir ());
192
+ System .out .println (
193
+ "app dir is " + testModel .getApplicationModule ().getModuleDir ());
211
194
}
212
195
213
196
System .out .println ("HOLLY after launch mode is " + LaunchMode .current ());
0 commit comments