Skip to content

Commit bc90c50

Browse files
committed
Try to resolve first inside the workspace as a project-relative
location, after that, take the path as is. Don't ignore the path, as it might not exist yet (e.g. project output folders).
1 parent 42e3c2b commit bc90c50

File tree

2 files changed

+17
-17
lines changed
  • net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd
  • net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd

2 files changed

+17
-17
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCmdTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
public class ReviewCmdTest {
4646
private IProject testProject;
4747

48-
/**
49-
* @see junit.framework.TestCase#setUp()
50-
*/
5148
@Before
5249
public void setUp() throws Exception {
5350

@@ -68,9 +65,6 @@ public void setUp() throws Exception {
6865
properties.setPmdEnabled(true);
6966
}
7067

71-
/**
72-
* @see junit.framework.TestCase#tearDown()
73-
*/
7468
@After
7569
public void tearDown() throws Exception {
7670
try {

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/JavaProjectClassLoader.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,25 @@ private void addURL(IClasspathEntry classpathEntry) {
132132

133133
private void addURL(IPath path) {
134134
try {
135-
File absoluteFile = path.toFile().getAbsoluteFile();
136-
// if the file exists, it is already an absolute path
137-
if (!absoluteFile.exists()) {
138-
// if not, it might have been a workspace relative file reference
139-
absoluteFile = workspace.getRoot().getFile(path).getLocation().toFile().getAbsoluteFile();
135+
File absoluteFile = null;
136+
IPath location = workspace.getRoot().getFile(path).getLocation();
137+
if (location != null) {
138+
// location is only present, if a project exists in the workspace
139+
// in other words: only if path referenced something inside an existing project
140+
absoluteFile = location.toFile().getAbsoluteFile();
141+
}
142+
143+
if (absoluteFile == null) {
144+
// if location couldn't be resolved, then it is already an absolute path
145+
absoluteFile = path.toFile().getAbsoluteFile();
140146
}
141-
if (absoluteFile.exists()) {
142-
URL url = absoluteFile.toURI().toURL();
143-
LOG.debug("auxclasspath: Adding url {}", url);
144-
addURL(url);
145-
} else {
146-
LOG.warn("auxclasspath: Resolved file {} does not exist and is ignored", absoluteFile);
147+
148+
if (!absoluteFile.exists()) {
149+
LOG.warn("auxclasspath: Resolved file {} does not exist", absoluteFile);
147150
}
151+
URL url = absoluteFile.toURI().toURL();
152+
LOG.debug("auxclasspath: Adding url {}", url);
153+
addURL(url);
148154
} catch (MalformedURLException e) {
149155
LOG.warn("MalformedURLException occurred: {}", e.getMessage(), e);
150156
}

0 commit comments

Comments
 (0)