33
33
import java .util .Locale ;
34
34
import java .util .Map ;
35
35
import java .util .Set ;
36
+ import java .util .logging .Level ;
36
37
37
38
/*
38
39
* TODO: unstaticify this class
@@ -44,7 +45,10 @@ public final class Main {
44
45
private static final Logger logger = LoggerFactory .getLogger (Main .class );
45
46
46
47
private static final String EXERCISE_PATH = "exercisePath" ;
48
+ private static final String SUBMISSION_PATH = "submissionPath" ;
47
49
private static final String OUTPUT_PATH = "outputPath" ;
50
+ private static final String TMC_RUN_PATH = "tmcRunPath" ;
51
+ private static final String TMC_LANGS_PATH = "tmcLangsPath" ;
48
52
private static final String LOCALE = "locale" ;
49
53
50
54
@ VisibleForTesting static Map <String , String > argsMap = Maps .newHashMap ();
@@ -62,8 +66,11 @@ public final class Main {
62
66
+ " Prepare a presentable solution from the original.\n "
63
67
+ " prepare-stubs --exercisePath -- outputPath"
64
68
+ " Prepare a stub exercise from the original.\n "
65
- + " prepare-submission --clonePath --submissionPath --outputPath"
66
- + " Prepares from submission and solution project for which the tests"
69
+ // TODO: Not implemented yet
70
+ // + " prepare-submission --exercisePath --submissionPath --outputPath"
71
+ // + " Prepares from submission and solution project for which the tests.\n"
72
+ + " prepare-sandbox-task --exercisePath --submissionPath --outputPath --tmcRunPath --tmcLangsPath"
73
+ + " Creates a tarball that sandbox can consume.\n "
67
74
+ " can be run in sandbox\n "
68
75
+ " run-tests --exercisePath --outputPath"
69
76
+ " Run the tests for the exercise.\n "
@@ -138,6 +145,9 @@ private static void run(String command) {
138
145
case "prepare-solutions" :
139
146
runPrepareSolutions ();
140
147
break ;
148
+ case "prepare-sandbox-task" :
149
+ runPrepareSandboxTask ();
150
+ break ;
141
151
case "get-exercise-packaging-configuration" :
142
152
runGetExercisePackagingConfiguration ();
143
153
break ;
@@ -157,6 +167,13 @@ private static Path getExercisePathFromArgs() {
157
167
throw new IllegalStateException ("No " + EXERCISE_PATH + " provided" );
158
168
}
159
169
170
+ private static Path getSubmissionPathFromArgs () {
171
+ if (argsMap .containsKey (SUBMISSION_PATH )) {
172
+ return Paths .get (argsMap .get (SUBMISSION_PATH ));
173
+ }
174
+ throw new IllegalStateException ("No " + SUBMISSION_PATH + " provided" );
175
+ }
176
+
160
177
private static Locale getLocaleFromArgs () {
161
178
if (argsMap .containsKey (LOCALE )) {
162
179
return new Locale (argsMap .get (LOCALE ));
@@ -182,17 +199,28 @@ private static void runCompressProject() {
182
199
}
183
200
}
184
201
202
+
203
+ private static Path getTmcRunPathFromArgs () {
204
+ if (argsMap .containsKey (TMC_RUN_PATH )) {
205
+ return Paths .get (argsMap .get (TMC_RUN_PATH ));
206
+ }
207
+ throw new IllegalStateException ("No " + TMC_RUN_PATH + " provided" );
208
+ }
209
+
210
+ private static Path getTmcLangsPathFromArgs () {
211
+ if (argsMap .containsKey (TMC_LANGS_PATH )) {
212
+ return Paths .get (argsMap .get (TMC_LANGS_PATH ));
213
+ }
214
+ throw new IllegalStateException ("No " + TMC_LANGS_PATH + " provided" );
215
+ }
216
+
185
217
private static void runCheckCodeStyle () {
186
218
ValidationResult validationResult = null ;
187
219
try {
188
- validationResult =
189
- executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
220
+ validationResult = executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
190
221
} catch (NoLanguagePluginFoundException e ) {
191
- logger .error (
192
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
193
- printErrAndExit (
194
- "ERROR: Could not find suitable language plugin for the given exercise "
195
- + "path." );
222
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
223
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
196
224
}
197
225
198
226
try {
@@ -215,18 +243,13 @@ private static void runScanExercise() {
215
243
printErrAndExit ("ERROR: Could not scan the exercises." );
216
244
}
217
245
} catch (NoLanguagePluginFoundException e ) {
218
- logger .error (
219
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
220
- printErrAndExit (
221
- "ERROR: Could not find suitable language plugin for the given "
222
- + "exercise path." );
246
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
247
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
223
248
}
224
249
225
250
try {
226
251
JsonWriter .writeObjectIntoJsonFormat (exerciseDesc .get (), getOutputPathFromArgs ());
227
- System .out .println (
228
- "Exercises scanned successfully, results can be found in "
229
- + getOutputPathFromArgs ());
252
+ System .out .println ("Exercises scanned successfully, results can be found in " + getOutputPathFromArgs ());
230
253
} catch (IOException e ) {
231
254
logger .error ("Could not write output to {}" , getOutputPathFromArgs (), e );
232
255
printErrAndExit ("ERROR: Could not write the results to the given file." );
@@ -272,11 +295,8 @@ private static void runTests() {
272
295
try {
273
296
runResult = executor .runTests (getExercisePathFromArgs ());
274
297
} catch (NoLanguagePluginFoundException e ) {
275
- logger .error (
276
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
277
- printErrAndExit (
278
- "ERROR: Could not find suitable language plugin for the given "
279
- + "exercise path." );
298
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
299
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
280
300
}
281
301
282
302
try {
@@ -295,23 +315,17 @@ private static void runPrepareStubs() {
295
315
getExercisePathFromArgs (),
296
316
getOutputPathFromArgs ());
297
317
} catch (NoLanguagePluginFoundException e ) {
298
- logger .error (
299
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
300
- printErrAndExit (
301
- "ERROR: Could not find suitable language plugin for the given "
302
- + "exercise path." );
318
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
319
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
303
320
}
304
321
}
305
322
306
323
private static void runClean () {
307
324
try {
308
325
executor .clean (getExercisePathFromArgs ());
309
326
} catch (NoLanguagePluginFoundException e ) {
310
- logger .error (
311
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
312
- printErrAndExit (
313
- "ERROR: Could not find suitable language plugin for the given "
314
- + "exercise path." );
327
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
328
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
315
329
}
316
330
}
317
331
@@ -354,11 +368,26 @@ private static void runPrepareSolutions() {
354
368
getExercisePathFromArgs (),
355
369
getOutputPathFromArgs ());
356
370
} catch (NoLanguagePluginFoundException e ) {
357
- logger .error (
358
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
359
- printErrAndExit (
360
- "ERROR: Could not find suitable language plugin for the given "
361
- + "exercise path." );
371
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
372
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
373
+ }
374
+ }
375
+
376
+ private static void runPrepareSandboxTask () {
377
+ Path exercisePath = getExercisePathFromArgs ();
378
+ Path submissionPath = getSubmissionPathFromArgs ();
379
+ Path outputPath = getOutputPathFromArgs ();
380
+ Path tmcRunPath = getTmcRunPathFromArgs ();
381
+ Path tmcLangsPath = getTmcLangsPathFromArgs ();
382
+
383
+ try {
384
+ executor .prepareSandboxTask (exercisePath , submissionPath , outputPath , tmcRunPath , tmcLangsPath );
385
+ } catch (NoLanguagePluginFoundException ex ) {
386
+ logger .error ("No suitable language plugin for project at {}" , exercisePath , ex );
387
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
388
+ } catch (IOException e ) {
389
+ logger .error ("An error occurred while preparing task." , e );
390
+ printErrAndExit ("ERROR: Could not prepare task." );
362
391
}
363
392
}
364
393
@@ -367,11 +396,8 @@ private static void runGetExercisePackagingConfiguration() {
367
396
try {
368
397
configuration = executor .getExercisePackagingConfiguration (getExercisePathFromArgs ());
369
398
} catch (NoLanguagePluginFoundException e ) {
370
- logger .error (
371
- "No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
372
- printErrAndExit (
373
- "ERROR: Could not find suitable language plugin for the given "
374
- + "exercise path." );
399
+ logger .error ("No suitable language plugin for project at {}" , getExercisePathFromArgs (), e );
400
+ printErrAndExit ("ERROR: Could not find suitable language plugin for the given exercise path." );
375
401
}
376
402
377
403
try {
0 commit comments