22
22
import com .google .common .collect .ImmutableMap ;
23
23
import com .google .common .collect .Maps ;
24
24
25
+ import org .apache .commons .io .FileUtils ;
25
26
import org .slf4j .Logger ;
26
27
import org .slf4j .LoggerFactory ;
27
28
@@ -57,6 +58,10 @@ public class CSharpPlugin extends AbstractLanguagePlugin {
57
58
private static final String CANNOT_SCAN_PROJECT_TYPE_MESSAGE =
58
59
"Failed to scan project files." ;
59
60
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." ;
60
65
61
66
private static Logger log = LoggerFactory .getLogger (CSharpPlugin .class );
62
67
@@ -154,6 +159,24 @@ public Map<File, List<ValidationError>> getValidationErrors() {
154
159
155
160
@ Override
156
161
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
+ }
157
180
}
158
181
159
182
private void deleteOldResults (Path path ) {
@@ -178,13 +201,9 @@ private String getBootstrapPath() {
178
201
return envVarPath ;
179
202
}
180
203
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 ;
188
207
}
189
208
190
209
private boolean doesProjectContainCSharpFiles (Path path ) {
0 commit comments