Skip to content

Commit f2ffa44

Browse files
committed
Implement CSharp cleanup task
1 parent 11663cf commit f2ffa44

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tmc-langs-csharp/src/main/java/fi/helsinki/cs/tmc/langs/csharp/CSharpPlugin.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableMap;
2323
import com.google.common.collect.Maps;
2424

25+
import org.apache.commons.io.FileUtils;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728

@@ -57,6 +58,10 @@ public class CSharpPlugin extends AbstractLanguagePlugin {
5758
private static final String CANNOT_SCAN_PROJECT_TYPE_MESSAGE =
5859
"Failed to scan project files.";
5960
private static final String COMPILATION_FAILED_MESSAGE = "Failed to compile excercise.";
61+
private static final String CANNOT_CLEANUP =
62+
"Failed to run cleanup task.";
63+
private static final String CANNOT_CLEANUP_DIR =
64+
"Failed to run cleanup task on a directory.";
6065

6166
private static Logger log = LoggerFactory.getLogger(CSharpPlugin.class);
6267

@@ -154,6 +159,24 @@ public Map<File, List<ValidationError>> getValidationErrors() {
154159

155160
@Override
156161
public void clean(Path path) {
162+
try {
163+
Files.walk(path).filter(Files::isDirectory).forEach(dir -> {
164+
Path fileName = dir.getFileName();
165+
166+
if (!fileName.equals(Paths.get("bin"))
167+
&& !fileName.equals(Paths.get("obj"))) {
168+
return;
169+
}
170+
171+
try {
172+
FileUtils.deleteDirectory(dir.toFile());
173+
} catch (IOException e) {
174+
log.error(CANNOT_CLEANUP_DIR, e);
175+
}
176+
});
177+
} catch (IOException e) {
178+
log.error(CANNOT_CLEANUP, e);
179+
}
157180
}
158181

159182
private void deleteOldResults(Path path) {

0 commit comments

Comments
 (0)