Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 18336ad

Browse files
authored
Merge branch 'master' into feedback-jclc
2 parents 3aa5403 + 20c171c commit 18336ad

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/command/DownloadExercisesCommand.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void getOptions(Options options) {
2929
options.addOption("a", "all", false,
3030
"Download all available exercises, including previously completed");
3131

32-
// Not implemented in tmc-core yet
32+
// Download old submissions. Not implemented in tmc-core yet
3333
//options.addOption("c", "completed", false, "Download previously completed exercises");
3434
}
3535

@@ -68,7 +68,13 @@ public void run(CommandLine args, Io io) {
6868
TmcCliProgressObserver progobs = new TmcCliProgressObserver(io, color1, color2);
6969

7070
List<Exercise> exercises = TmcUtil.downloadExercises(core, filtered, progobs);
71-
io.println(exercises.toString());
71+
if (exercises.isEmpty()) {
72+
io.println("Failed to download exercises");
73+
return;
74+
} else if (exercises.size() != filtered.size()) {
75+
io.println(Color.colorString("Some exercises could not be downloaded",
76+
Color.AnsiColor.ANSI_RED));
77+
}
7278

7379
Path configFile = app.getWorkDir().getWorkingDirectory()
7480
.resolve(stringArgs[0])
@@ -85,7 +91,9 @@ protected List<Exercise> getFilteredExercises(Course course, CommandLine args) {
8591

8692
List<Exercise> filtered = new ArrayList<>();
8793
for (Exercise exercise : course.getExercises()) {
88-
if (!exercise.isCompleted()) {
94+
// Teachers may get a list of locked exercises but core still refuses to
95+
// download them. Filter locked exercises out.
96+
if (!exercise.isCompleted() && !exercise.isLocked()) {
8997
filtered.add(exercise);
9098
}
9199
}

src/main/java/fi/helsinki/cs/tmc/cli/command/SubmitCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ protected void updateCourseJson(TmcCore core, List<Exercise> submittedExercises,
165165

166166
Course updatedCourse = TmcUtil.findCourse(core, courseInfo.getCourseName());
167167
if (updatedCourse == null) {
168-
io.println("Failed to update .tmc.json file for course " + courseInfo.getCourseName());
168+
io.println("Failed to update config file for course " + courseInfo.getCourseName());
169169
return;
170170
}
171171

172172
for (Exercise submitted : submittedExercises) {
173173
Exercise updatedEx = TmcUtil.findExercise(updatedCourse, submitted.getName());
174174
if (updatedEx == null) {
175175
// Does this reaaally ever happen?
176-
io.println("Failed to update .tmc.json file for exercise " + submitted.getName()
176+
io.println("Failed to update config file for exercise " + submitted.getName()
177177
+ ". The exercise doesn't exist in server anymore.");
178178
continue;
179179
}

src/main/java/fi/helsinki/cs/tmc/cli/command/UpdateCommand.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ public void updateExercises(TmcCore core, CourseInfo info, Path configFile) {
7676
}
7777

7878
if (!exerciseUpdater.updateCourseJson(info, configFile)) {
79-
io.println("Failed to update course info");
79+
io.println("Failed to update course config file");
8080
}
8181
}
8282

8383
private void printExercises(List<Exercise> exercises, String message) {
8484
if (!exercises.isEmpty()) {
8585
io.println(message);
8686
for (Exercise exercise : exercises) {
87-
io.println(" " + exercise.getName());
87+
if (exercise.isCompleted()) {
88+
// already released and completed on another computer/folder
89+
io.println(" " + exercise.getName() + " (already completed)");
90+
} else {
91+
io.println(" " + exercise.getName());
92+
}
8893
}
8994
}
9095
}

src/main/java/fi/helsinki/cs/tmc/cli/tmcstuff/ExerciseUpdater.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.nio.file.Path;
1313
import java.util.ArrayList;
14+
import java.util.Iterator;
1415
import java.util.List;
1516

1617
public class ExerciseUpdater {
@@ -88,7 +89,14 @@ public boolean updatesAvailable() {
8889
}
8990

9091
public List<Exercise> downloadUpdates(TmcCliProgressObserver progobs) {
91-
return TmcUtil.downloadExercises(core, getNewAndUpdatedExercises(), progobs);
92+
List<Exercise> newAndUpdated = getNewAndUpdatedExercises();
93+
for (Iterator<Exercise> iterator = newAndUpdated.iterator(); iterator.hasNext();) {
94+
Exercise next = iterator.next();
95+
if (next.isCompleted()) {
96+
iterator.remove();
97+
}
98+
}
99+
return TmcUtil.downloadExercises(core, newAndUpdated, progobs);
92100
}
93101

94102
public boolean updateCourseJson(CourseInfo info, Path configFile) {

src/test/java/fi/helsinki/cs/tmc/cli/command/DownloadExercisesCommandTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.Before;
3030
import org.junit.Test;
3131

32+
import java.io.File;
3233
import java.io.IOException;
3334
import java.nio.file.Path;
3435
import java.nio.file.Paths;
@@ -138,7 +139,9 @@ public List<Exercise> call() throws Exception {
138139

139140
String[] args = {"download", "course1"};
140141
app.run(args);
141-
assertTrue(testIo.out().contains("exerciseName"));
142+
143+
File courseJson = tempDir.resolve("course1").resolve(".tmc.json").toFile();
144+
assertTrue(courseJson.exists());
142145
}
143146

144147
@Test

0 commit comments

Comments
 (0)