Skip to content

Commit 9a02b9e

Browse files
committed
Simplify detokenisation logic by removing long-disused project dir marker
1 parent 1e5e97c commit 9a02b9e

2 files changed

Lines changed: 10 additions & 21 deletions

File tree

src/main/java/org/infernus/idea/checkstyle/util/ProjectFilePaths.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
import java.io.File;
1010
import java.util.function.Function;
1111

12-
import static java.util.Arrays.asList;
13-
1412
public class ProjectFilePaths {
1513

1614
private static final Logger LOG = Logger.getInstance(ProjectFilePaths.class);
1715

1816
private static final String IDEA_PROJECT_DIR = "$PROJECT_DIR$";
19-
private static final String LEGACY_PROJECT_DIR = "$PRJ_DIR$";
2017

2118
private final ProjectPaths projectPaths;
2219
private final Project project;
@@ -114,18 +111,16 @@ public String detokenise(@Nullable final String tokenisedPath) {
114111
}
115112

116113
private String replaceProjectToken(final String path) {
117-
for (String projectDirToken : asList(IDEA_PROJECT_DIR, LEGACY_PROJECT_DIR)) {
118-
int prefixLocation = path.indexOf(projectDirToken);
119-
if (prefixLocation >= 0) {
120-
final File projectPath = projectPath();
121-
if (projectPath != null) {
122-
final String projectRelativePath = toSystemPath(path.substring(prefixLocation + projectDirToken.length()));
123-
final String completePath = projectPath + File.separator + projectRelativePath;
124-
return absolutePathOf.apply(new File(completePath));
125-
126-
} else {
127-
LOG.warn("Could not detokenise path as project dir is unset: " + path);
128-
}
114+
int prefixLocation = path.indexOf(IDEA_PROJECT_DIR);
115+
if (prefixLocation >= 0) {
116+
final File projectPath = projectPath();
117+
if (projectPath != null) {
118+
final String projectRelativePath = toSystemPath(path.substring(prefixLocation + IDEA_PROJECT_DIR.length()));
119+
final String completePath = projectPath + File.separator + projectRelativePath;
120+
return absolutePathOf.apply(new File(completePath));
121+
122+
} else {
123+
LOG.warn("Could not detokenise path as project dir is unset: " + path);
129124
}
130125
}
131126
return null;

src/test/java/org/infernus/idea/checkstyle/util/ProjectFilePathsTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ public void aUnixLocationContainingTheProjectPathTokenShouldBeDetokenisedCorrect
6161
is(equalTo(UNIX_PROJECT_BASE_PATH + "/a-path/to/checkstyle.xml")));
6262
}
6363

64-
@Test
65-
public void aUnixLocationContainingTheLegacyProjectPathTokenShouldBeDetokenisedCorrectly() {
66-
assertThat(underTest.detokenise("$PRJ_DIR$/a-path/to/checkstyle.xml"),
67-
is(equalTo(UNIX_PROJECT_BASE_PATH + "/a-path/to/checkstyle.xml")));
68-
}
69-
7064
@Test
7165
public void directoryTraversalsInARelativePathShouldNotBeAlteredByDetokenisation() {
7266
assertThat(underTest.detokenise(UNIX_PROJECT_BASE_PATH + "/../a-path/to/checkstyle.xml"),

0 commit comments

Comments
 (0)