Property java.class.path modified by the user, it is not taken into account by
ClassLoader
------------------------------------------------------------------------------------------
Key: MNG-3264
URL: http://jira.codehaus.org/browse/MNG-3264
Project: Maven 2
Issue Type: Bug
Components: Errors
Affects Versions: 2.0.7
Reporter: David Leal
Attachments: FileUtils.java, TestFileUtils2.java
I have a simple class that just find a file on classpath, i.e.:
public final class FileUtils extends org.apache.commons.io.FileUtils {
public static File findFileInClasspath(String fileName)
throws UnsupportedEncodingException, FileNotFoundException {
return findFileInClasspath(fileName, FileUtils.LATIN_CODE);
}
public static File findFileInClasspath(String fileName, String encoding)
throws UnsupportedEncodingException, FileNotFoundException {
URL url = FileUtils.class.getClassLoader().getResource(fileName);
if (url == null) {
throw new FileNotFoundException(fileName);
}
String file = URLDecoder.decode(url.getFile(), encoding);
return new File(file);
}
}
I would like to test this method, without leaving a testing file on
test/resources, so I want to use at valid location on classpath, so I
configurate the pluggin:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<systemProperties>
<property>
<name>java.class.path</name>
<value>${user.dir}</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
Note: if I add the variable: ${maven.test.classpath} its value is not
translated into the corresponding value.
On my testing process I look on the property variable: java.class.path in
effect its point into: ${user.dir} but the testing method still fails. Under
Eclipse the same test, doesn't fail.
Under Maven the test for some reason it fails even the on the java.class.path
there is directory (that's the condition I need in order to run the test).
On the atached file you can find the source and testing file.
I now it is possible to desing a different test using a resource file for this
purpose, but I am very suprise about this behavour. It open for me the question
about: How really the user control de classpath during the testing process.
After running the testing file I get:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.ceb2b2000.commons.io.TestFileUtils2
30-oct-2007 0:25:34 com.ceb2b2000.commons.io.TestFileUtils2 findDirectoryOnClass
path
INFO: classpath = P:\ceb2b2000-commons\ceb2b2000-commons-io
<<< FAILURE!
Results :
Tests in error:
testFindFileInClasspath(com.ceb2b2000.commons.io.TestFileUtils2)
Tests run: 4, Failures: 0, Errors: 3, Skipped: 0
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira