|
7 | 7 |
|
8 | 8 | import java.io.File;
|
9 | 9 | import java.io.IOException;
|
| 10 | +import java.nio.file.Path; |
| 11 | +import java.nio.file.Paths; |
10 | 12 | import java.util.ArrayList;
|
11 | 13 | import java.util.Arrays;
|
12 | 14 | import java.util.Collection;
|
@@ -114,21 +116,21 @@ public File getCourseRootDir(String courseName) {
|
114 | 116 | * <p>
|
115 | 117 | * The exercise must have a course name set.
|
116 | 118 | */
|
117 |
| - public File getProjectDirForExercise(Exercise ex) { |
118 |
| - String path = |
119 |
| - getProjectRootDir() + File.separator + |
120 |
| - ex.getCourseName() + File.separator + |
121 |
| - ex.getName().replaceAll("/", "-"); |
122 |
| - return new File(path); |
| 119 | + public Path getProjectDirForExercise(Exercise ex) { |
| 120 | + Path path = Paths.get( |
| 121 | + getProjectRootDir(), |
| 122 | + ex.getCourseName(), |
| 123 | + ex.getName().replaceAll("/", "-")); |
| 124 | + return tryGetRealPath(path); |
123 | 125 | }
|
124 | 126 |
|
125 | 127 | /**
|
126 | 128 | * Returns the exercise associated with the given project, or null if none.
|
127 | 129 | */
|
128 | 130 | public Exercise tryGetExerciseForProject(TmcProjectInfo project, CourseDb courseDb) {
|
129 |
| - File projectDir = FileUtil.toFile(project.getProjectDir()); |
| 131 | + Path projectDir = FileUtil.toFile(project.getProjectDir()).toPath(); |
130 | 132 | for (Exercise ex : courseDb.getCurrentCourseExercises()) {
|
131 |
| - if (getProjectDirForExercise(ex).equals(projectDir)) { |
| 133 | + if (getProjectDirForExercise(ex).equals(tryGetRealPath(projectDir))) { |
132 | 134 | return ex;
|
133 | 135 | }
|
134 | 136 | }
|
@@ -164,7 +166,7 @@ public TmcProjectInfo tryGetProjectOwningFile(FileObject fo) {
|
164 | 166 | public TmcProjectInfo tryGetProjectForExercise(Exercise exercise) {
|
165 | 167 | projectManager.clearNonProjectCache(); // Just to be sure.
|
166 | 168 |
|
167 |
| - File path = getProjectDirForExercise(exercise); |
| 169 | + File path = getProjectDirForExercise(exercise).toFile(); |
168 | 170 | FileObject fo = FileUtil.toFileObject(path);
|
169 | 171 | if (fo != null) {
|
170 | 172 | try {
|
@@ -259,4 +261,12 @@ public void scanForExternalChanges(Collection<TmcProjectInfo> projects) {
|
259 | 261 | fs.refresh(true);
|
260 | 262 | }
|
261 | 263 | }
|
| 264 | + |
| 265 | + private Path tryGetRealPath(Path path) { |
| 266 | + try { |
| 267 | + return path.toRealPath(); |
| 268 | + } catch (IOException ex) { |
| 269 | + return path; |
| 270 | + } |
| 271 | + } |
262 | 272 | }
|
0 commit comments