3333import java .util .Locale ;
3434import java .util .Map ;
3535import java .util .Set ;
36+ import java .util .logging .Level ;
3637
3738/*
3839 * TODO: unstaticify this class
@@ -44,7 +45,10 @@ public final class Main {
4445 private static final Logger logger = LoggerFactory .getLogger (Main .class );
4546
4647 private static final String EXERCISE_PATH = "exercisePath" ;
48+ private static final String SUBMISSION_PATH = "submissionPath" ;
4749 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" ;
4852 private static final String LOCALE = "locale" ;
4953
5054 @ VisibleForTesting static Map <String , String > argsMap = Maps .newHashMap ();
@@ -62,8 +66,11 @@ public final class Main {
6266 + " Prepare a presentable solution from the original.\n "
6367 + " prepare-stubs --exercisePath -- outputPath"
6468 + " 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 "
6774 + " can be run in sandbox\n "
6875 + " run-tests --exercisePath --outputPath"
6976 + " Run the tests for the exercise.\n "
@@ -138,6 +145,9 @@ private static void run(String command) {
138145 case "prepare-solutions" :
139146 runPrepareSolutions ();
140147 break ;
148+ case "prepare-sandbox-task" :
149+ runPrepareSandboxTask ();
150+ break ;
141151 case "get-exercise-packaging-configuration" :
142152 runGetExercisePackagingConfiguration ();
143153 break ;
@@ -157,6 +167,13 @@ private static Path getExercisePathFromArgs() {
157167 throw new IllegalStateException ("No " + EXERCISE_PATH + " provided" );
158168 }
159169
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+
160177 private static Locale getLocaleFromArgs () {
161178 if (argsMap .containsKey (LOCALE )) {
162179 return new Locale (argsMap .get (LOCALE ));
@@ -182,17 +199,28 @@ private static void runCompressProject() {
182199 }
183200 }
184201
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+
185217 private static void runCheckCodeStyle () {
186218 ValidationResult validationResult = null ;
187219 try {
188- validationResult =
189- executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
220+ validationResult = executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
190221 } 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." );
196224 }
197225
198226 try {
@@ -215,18 +243,13 @@ private static void runScanExercise() {
215243 printErrAndExit ("ERROR: Could not scan the exercises." );
216244 }
217245 } 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." );
223248 }
224249
225250 try {
226251 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 ());
230253 } catch (IOException e ) {
231254 logger .error ("Could not write output to {}" , getOutputPathFromArgs (), e );
232255 printErrAndExit ("ERROR: Could not write the results to the given file." );
@@ -272,11 +295,8 @@ private static void runTests() {
272295 try {
273296 runResult = executor .runTests (getExercisePathFromArgs ());
274297 } 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." );
280300 }
281301
282302 try {
@@ -295,23 +315,17 @@ private static void runPrepareStubs() {
295315 getExercisePathFromArgs (),
296316 getOutputPathFromArgs ());
297317 } 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." );
303320 }
304321 }
305322
306323 private static void runClean () {
307324 try {
308325 executor .clean (getExercisePathFromArgs ());
309326 } 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." );
315329 }
316330 }
317331
@@ -354,11 +368,26 @@ private static void runPrepareSolutions() {
354368 getExercisePathFromArgs (),
355369 getOutputPathFromArgs ());
356370 } 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." );
362391 }
363392 }
364393
@@ -367,11 +396,8 @@ private static void runGetExercisePackagingConfiguration() {
367396 try {
368397 configuration = executor .getExercisePackagingConfiguration (getExercisePathFromArgs ());
369398 } 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." );
375401 }
376402
377403 try {
0 commit comments