3232import java .util .Locale ;
3333import java .util .Map ;
3434import java .util .Set ;
35+ import java .util .logging .Level ;
3536
3637/*
3738 * TODO: unstaticify this class
@@ -43,7 +44,10 @@ public final class Main {
4344 private static final Logger logger = LoggerFactory .getLogger (Main .class );
4445
4546 private static final String EXERCISE_PATH = "exercisePath" ;
47+ private static final String SUBMISSION_PATH = "submissionPath" ;
4648 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" ;
4751 private static final String LOCALE = "locale" ;
4852
4953 @ VisibleForTesting static Map <String , String > argsMap = Maps .newHashMap ();
@@ -60,8 +64,11 @@ public final class Main {
6064 + " Prepare a presentable solution from the original.\n "
6165 + " prepare-stubs --exercisePath -- outputPath"
6266 + " 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 "
6572 + " can be run in sandbox\n "
6673 + " run-tests --exercisePath --outputPath"
6774 + " Run the tests for the exercise.\n "
@@ -133,6 +140,9 @@ private static void run(String command) {
133140 case "prepare-solutions" :
134141 runPrepareSolutions ();
135142 break ;
143+ case "prepare-sandbox-task" :
144+ runPrepareSandboxTask ();
145+ break ;
136146 case "get-exercise-packaging-configuration" :
137147 runGetExercisePackagingConfiguration ();
138148 break ;
@@ -151,6 +161,13 @@ private static Path getExercisePathFromArgs() {
151161 }
152162 throw new IllegalStateException ("No " + EXERCISE_PATH + " provided" );
153163 }
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+ }
154171
155172 private static Locale getLocaleFromArgs () {
156173 if (argsMap .containsKey (LOCALE )) {
@@ -165,18 +182,28 @@ private static Path getOutputPathFromArgs() {
165182 }
166183 throw new IllegalStateException ("No " + OUTPUT_PATH + " provided" );
167184 }
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+
169200 private static void runCheckCodeStyle () {
170201 ValidationResult validationResult = null ;
171202 try {
172- validationResult =
173- executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
203+ validationResult = executor .runCheckCodeStyle (getExercisePathFromArgs (), getLocaleFromArgs ());
174204 } 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." );
180207 }
181208
182209 try {
@@ -199,18 +226,13 @@ private static void runScanExercise() {
199226 printErrAndExit ("ERROR: Could not scan the exercises." );
200227 }
201228 } 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." );
207231 }
208232
209233 try {
210234 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 ());
214236 } catch (IOException e ) {
215237 logger .error ("Could not write output to {}" , getOutputPathFromArgs (), e );
216238 printErrAndExit ("ERROR: Could not write the results to the given file." );
@@ -256,11 +278,8 @@ private static void runTests() {
256278 try {
257279 runResult = executor .runTests (getExercisePathFromArgs ());
258280 } 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." );
264283 }
265284
266285 try {
@@ -279,23 +298,17 @@ private static void runPrepareStubs() {
279298 getExercisePathFromArgs (),
280299 getOutputPathFromArgs ());
281300 } 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." );
287303 }
288304 }
289305
290306 private static void runClean () {
291307 try {
292308 executor .clean (getExercisePathFromArgs ());
293309 } 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." );
299312 }
300313 }
301314
@@ -338,11 +351,26 @@ private static void runPrepareSolutions() {
338351 getExercisePathFromArgs (),
339352 getOutputPathFromArgs ());
340353 } 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." );
346374 }
347375 }
348376
@@ -351,11 +379,8 @@ private static void runGetExercisePackagingConfiguration() {
351379 try {
352380 configuration = executor .getExercisePackagingConfiguration (getExercisePathFromArgs ());
353381 } 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." );
359384 }
360385
361386 try {
0 commit comments