Skip to content

Commit dd803eb

Browse files
committed
Merge branch 'master' of https://github.com/TMC-C/tmc-langs
2 parents 4adad97 + f2ffa44 commit dd803eb

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

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

Lines changed: 26 additions & 7 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) {
@@ -178,13 +201,9 @@ private String getBootstrapPath() {
178201
return envVarPath;
179202
}
180203

181-
try {
182-
Scanner in = new Scanner(new FileReader("tmc-langs-csharp/bootstrapPath.txt"));
183-
return in.nextLine();
184-
} catch (Exception e) {
185-
log.error(CANNOT_LOCATE_RUNNER_MESSAGE, e);
186-
return null;
187-
}
204+
log.error(CANNOT_LOCATE_RUNNER_MESSAGE);
205+
206+
return null;
188207
}
189208

190209
private boolean doesProjectContainCSharpFiles(Path path) {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,23 @@ public CSharpStudentFilePolicy(Path configFileParent) {
1313

1414
@Override
1515
public boolean isStudentSourceFile(Path path, Path projectRootPath) {
16+
if (this.isChildOfBinaryDir(path)) {
17+
return false;
18+
}
19+
1620
return path.startsWith(Paths.get("src"));
1721
}
18-
22+
23+
private boolean isChildOfBinaryDir(Path path) {
24+
for (Path testPath : path) {
25+
Path fileName = testPath.getFileName();
26+
27+
if (fileName.equals(Paths.get("bin"))
28+
|| fileName.equals(Paths.get("obj"))) {
29+
return true;
30+
}
31+
}
32+
33+
return false;
34+
}
1935
}

0 commit comments

Comments
 (0)