32
32
import java .util .Locale ;
33
33
import java .util .Map ;
34
34
import java .util .Set ;
35
+ import java .util .logging .Level ;
35
36
36
37
/*
37
38
* TODO: unstaticify this class
@@ -43,7 +44,10 @@ public final class Main {
43
44
private static final Logger logger = LoggerFactory .getLogger (Main .class );
44
45
45
46
private static final String EXERCISE_PATH = "exercisePath" ;
47
+ private static final String SUBMISSION_PATH = "submissionPath" ;
46
48
private static final String OUTPUT_PATH = "outputPath" ;
49
+ private static final String TMC_RUN_PATH = "tmcRunPath" ;
50
+ private static final String TMC_LANGS_PATH = "tmcLangsPath" ;
47
51
private static final String LOCALE = "locale" ;
48
52
49
53
@ VisibleForTesting static Map <String , String > argsMap = Maps .newHashMap ();
@@ -60,8 +64,11 @@ public final class Main {
60
64
+ " Prepare a presentable solution from the original.\n "
61
65
+ " prepare-stubs --exercisePath -- outputPath"
62
66
+ " Prepare a stub exercise from the original.\n "
63
- + " prepare-submission --clonePath --submissionPath --outputPath"
64
- + " Prepares from submission and solution project for which the tests"
67
+ // TODO: Not implemented yet
68
+ // + " prepare-submission --exercisePath --submissionPath --outputPath"
69
+ // + " Prepares from submission and solution project for which the tests.\n"
70
+ + " prepare-sandbox-task --exercisePath --submissionPath --outputPath --tmcRunPath --tmcLangsPath"
71
+ + " Creates a tarball that sandbox can consume.\n "
65
72
+ " can be run in sandbox\n "
66
73
+ " run-tests --exercisePath --outputPath"
67
74
+ " Run the tests for the exercise.\n "
@@ -133,6 +140,9 @@ private static void run(String command) {
133
140
case "prepare-solutions" :
134
141
runPrepareSolutions ();
135
142
break ;
143
+ case "prepare-sandbox-task" :
144
+ runPrepareSandboxTask ();
145
+ break ;
136
146
case "get-exercise-packaging-configuration" :
137
147
runGetExercisePackagingConfiguration ();
138
148
break ;
@@ -151,6 +161,13 @@ private static Path getExercisePathFromArgs() {
151
161
}
152
162
throw new IllegalStateException ("No " + EXERCISE_PATH + " provided" );
153
163
}
164
+
165
+ private static Path getSubmissionPathFromArgs () {
166
+ if (argsMap .containsKey (SUBMISSION_PATH )) {
167
+ return Paths .get (argsMap .get (SUBMISSION_PATH ));
168
+ }
169
+ throw new IllegalStateException ("No " + SUBMISSION_PATH + " provided" );
170
+ }
154
171
155
172
private static Locale getLocaleFromArgs () {
156
173
if (argsMap .containsKey (LOCALE )) {
@@ -165,18 +182,28 @@ private static Path getOutputPathFromArgs() {
165
182
}
166
183
throw new IllegalStateException ("No " + OUTPUT_PATH + " provided" );
167
184
}
168
-
185
+
186
+ private static Path getTmcRunPathFromArgs () {
187
+ if (argsMap .containsKey (TMC_RUN_PATH )) {
188
+ return Paths .get (argsMap .get (TMC_RUN_PATH ));
189
+ }
190
+ throw new IllegalStateException ("No " + TMC_RUN_PATH + " provided" );
191
+ }
192
+
193
+ private static Path getTmcLangsPathFromArgs () {
194
+ if (argsMap .containsKey (TMC_LANGS_PATH )) {
195
+ return Paths .get (argsMap .get (TMC_LANGS_PATH ));
196
+ }
197
+ throw new IllegalStateException ("No " + TMC_LANGS_PATH + " provided" );
198
+ }
199
+
169
200
private static void runCheckCodeStyle () {
170
201
ValidationResult validationResult = null ;
171
202
try {
172
- validationResult =
173
- executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
203
+ validationResult = executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
174
204
} catch (NoLanguagePluginFoundException e ) {
175
- logger .error (
176
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
177
- printErrAndExit (
178
- "ERROR: Could not find suitable language plugin for the given exercise "
179
- + "path." );
205
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
206
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
180
207
}
181
208
182
209
try {
@@ -199,18 +226,13 @@ private static void runScanExercise() {
199
226
printErrAndExit ("ERROR: Could not scan the exercises." );
200
227
}
201
228
} catch (NoLanguagePluginFoundException e ) {
202
- logger .error (
203
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
204
- printErrAndExit (
205
- "ERROR: Could not find suitable language plugin for the given "
206
- + "exercise path." );
229
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
230
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
207
231
}
208
232
209
233
try {
210
234
JsonWriter .writeObjectIntoJsonFormat (exerciseDesc .get (), getOutputPathFromArgs ());
211
- System .out .println (
212
- "Exercises scanned successfully, results can be found in "
213
- + getOutputPathFromArgs ());
235
+ System .out .println ("Exercises scanned successfully, results can be found in " + getOutputPathFromArgs ());
214
236
} catch (IOException e ) {
215
237
logger .error ("Could not write output to {}" , getOutputPathFromArgs (), e );
216
238
printErrAndExit ("ERROR: Could not write the results to the given file." );
@@ -256,11 +278,8 @@ private static void runTests() {
256
278
try {
257
279
runResult = executor .runTests (getExercisePathFromArgs ());
258
280
} catch (NoLanguagePluginFoundException e ) {
259
- logger .error (
260
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
261
- printErrAndExit (
262
- "ERROR: Could not find suitable language plugin for the given "
263
- + "exercise path." );
281
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
282
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
264
283
}
265
284
266
285
try {
@@ -279,23 +298,17 @@ private static void runPrepareStubs() {
279
298
getExercisePathFromArgs (),
280
299
getOutputPathFromArgs ());
281
300
} catch (NoLanguagePluginFoundException e ) {
282
- logger .error (
283
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
284
- printErrAndExit (
285
- "ERROR: Could not find suitable language plugin for the given "
286
- + "exercise path." );
301
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
302
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
287
303
}
288
304
}
289
305
290
306
private static void runClean () {
291
307
try {
292
308
executor .clean (getExercisePathFromArgs ());
293
309
} catch (NoLanguagePluginFoundException e ) {
294
- logger .error (
295
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
296
- printErrAndExit (
297
- "ERROR: Could not find suitable language plugin for the given "
298
- + "exercise path." );
310
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
311
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
299
312
}
300
313
}
301
314
@@ -338,11 +351,26 @@ private static void runPrepareSolutions() {
338
351
getExercisePathFromArgs (),
339
352
getOutputPathFromArgs ());
340
353
} catch (NoLanguagePluginFoundException e ) {
341
- logger .error (
342
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
343
- printErrAndExit (
344
- "ERROR: Could not find suitable language plugin for the given "
345
- + "exercise path." );
354
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
355
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
356
+ }
357
+ }
358
+
359
+ private static void runPrepareSandboxTask () {
360
+ Path exercisePath = getExercisePathFromArgs ();
361
+ Path submissionPath = getSubmissionPathFromArgs ();
362
+ Path outputPath = getOutputPathFromArgs ();
363
+ Path tmcRunPath = getTmcRunPathFromArgs ();
364
+ Path tmcLangsPath = getTmcLangsPathFromArgs ();
365
+
366
+ try {
367
+ executor .prepareSandboxTask (exercisePath , submissionPath , outputPath , tmcRunPath , tmcLangsPath );
368
+ } catch (NoLanguagePluginFoundException ex ) {
369
+ logger .error ("No suitable language plugin for project at {}" , exercisePath , ex );
370
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
371
+ } catch (IOException e ) {
372
+ logger .error ("An error occurred while preparing task." , e );
373
+ printErrAndExit ("ERROR: Could not prepare task." );
346
374
}
347
375
}
348
376
@@ -351,11 +379,8 @@ private static void runGetExercisePackagingConfiguration() {
351
379
try {
352
380
configuration = executor .getExercisePackagingConfiguration (getExercisePathFromArgs ());
353
381
} catch (NoLanguagePluginFoundException e ) {
354
- logger .error (
355
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
356
- printErrAndExit (
357
- "ERROR: Could not find suitable language plugin for the given "
358
- + "exercise path." );
382
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
383
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
359
384
}
360
385
361
386
try {
0 commit comments