@@ -4,6 +4,7 @@ TRACK=java
44TRACK_REPO=" $TRACK "
55TRACK_SRC_EXT=" java"
66CPU_CORES=` getconf NPROCESSORS_ONLN 2> /dev/null || getconf _NPROCESSORS_ONLN 2> /dev/null || echo 1`
7+ EXERCISE_TO_SOLVE=$1
78
89on_exit () {
910 echo " >>> on_exit()"
@@ -256,6 +257,41 @@ solve_all_exercises() {
256257 popd
257258}
258259
260+ solve_single_exercise () {
261+ local exercism_exercises_dir=" $1 "
262+ local exercism_configfile=" $2 "
263+ local exercise_to_solve=" $3 "
264+ echo " >>> solve_all_exercises(exercism_exercises_dir=\" ${exercism_exercises_dir} \" , exercism_configfile=\" ${exercism_configfile} \" , exercise_to_solve=\" $exercise_to_solve \" )"
265+
266+ local track_root=$( pwd )
267+ local exercism_cli=" ./exercism --config ${exercism_configfile} "
268+
269+ pushd ${exercism_exercises_dir}
270+
271+ echo -e " \n\n"
272+ echo " =================================================="
273+ echo " Solving ${exercise_to_solve} "
274+ echo " =================================================="
275+
276+ ${exercism_cli} fetch ${TRACK} $exercise_to_solve
277+ cp -R -H ${track_root} /exercises/${exercise_to_solve} /src/example/${TRACK} /* ${exercism_exercises_dir} /${TRACK} /${exercise_to_solve} /src/main/${TRACK} /
278+
279+ pushd ${exercism_exercises_dir} /${TRACK} /${exercise_to_solve}
280+ # Check that tests compile before we strip @Ignore annotations
281+ " $EXECPATH " /gradlew compileTestJava
282+ # Ensure we run all the tests (as delivered, all but the first is @Ignore'd)
283+ for testfile in ` find . -name " *Test.${TRACK_SRC_EXT} " ` ; do
284+ # Strip @Ignore annotations to ensure we run the tests (as delivered, all but the first is @Ignore'd).
285+ # Note that unit-test.sh also strips @Ignore annotations via the Gradle task copyTestsFilteringIgnores.
286+ # The stripping implementations here and in copyTestsFilteringIgnores should be kept consistent.
287+ sed ' s/@Ignore\(\(.*\)\)\{0,1\}//' ${testfile} > " ${tempfile} " && mv " ${tempfile} " " ${testfile} "
288+ done
289+ " $EXECPATH " /gradlew test
290+ popd
291+
292+ popd
293+ }
294+
259295main () {
260296 # all functions assume current working directory is repository root.
261297 cd " ${SCRIPTPATH} /.."
@@ -296,7 +332,11 @@ main() {
296332 # Create a CLI install and config just for this build; this script does not use your CLI install.
297333 configure_exercism_cli " ${exercism_home} " " ${exercism_configfile} " " ${xapi_port} "
298334
299- solve_all_exercises " ${exercism_home} " " ${exercism_configfile} "
335+ if [[ ${EXERCISE_TO_SOLVE} == " " ]]; then
336+ solve_all_exercises " ${exercism_home} " " ${exercism_configfile} "
337+ else
338+ solve_single_exercise " ${exercism_home} " " ${exercism_configfile} " " ${EXERCISE_TO_SOLVE} "
339+ fi
300340}
301341
302342# #########################################################################
0 commit comments