You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "James Shiell (JIRA)" <ji...@codehaus.org> on 2008/06/18 16:27:27 UTC
[jira] Created: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Specified classesDirectory is added to the end of the classpath
---------------------------------------------------------------
Key: SUREFIRE-502
URL: http://jira.codehaus.org/browse/SUREFIRE-502
Project: Maven Surefire
Issue Type: Bug
Components: classloading
Affects Versions: 2.4.3
Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
Reporter: James Shiell
When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
The problem appears to be the following code:
if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
{
classpathElements.remove( project.getBuild().getOutputDirectory() );
classpathElements.add( classesDirectory.getAbsolutePath() );
}
The classes directory should replace the build output directory, e.g.
if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
{
final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
if (replacementIndex >= 0)
{
classpathElements.remove( project.getBuild().getOutputDirectory() );
classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
}
else
{
classpathElements.add( classesDirectory.getAbsolutePath() );
}
}
--
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
[jira] Updated: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Posted by "James Shiell (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James Shiell updated SUREFIRE-502:
----------------------------------
Attachment: SUREFIRE-502.patch
Patch with suggested fix.
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Attachments: SUREFIRE-502.patch
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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
[jira] Updated: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Posted by "Paul Gier (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Gier updated SUREFIRE-502:
-------------------------------
Patch Submitted: [Yes]
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Assignee: Paul Gier
> Fix For: 2.5
>
> Attachments: SUREFIRE-502.patch, SurefirePlugin.java
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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
[jira] Updated: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Posted by "Paul Gier (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Gier updated SUREFIRE-502:
-------------------------------
Assignee: Paul Gier
Fix Version/s: 2.5
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Assignee: Paul Gier
> Fix For: 2.5
>
> Attachments: SUREFIRE-502.patch, SurefirePlugin.java
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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
[jira] Updated: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Posted by "M. Dahm (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
M. Dahm updated SUREFIRE-502:
-----------------------------
Attachment: SurefirePlugin.java
Well, here comes the code in a more readable fashion...
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Attachments: SUREFIRE-502.patch, SurefirePlugin.java
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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
[jira] Commented: (SUREFIRE-502) Specified classesDirectory is
added to the end of the classpath
Posted by "M. Dahm (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=143830#action_143830 ]
M. Dahm commented on SUREFIRE-502:
----------------------------------
the original code looks like this:
getLog().debug("Test Classpath :");
// Check if we need to add configured classes/test classes directories here.
// If they are configured, we should remove the default to avoid conflicts.
// Check if we need to add configured classes/test classes directories here.
// If they are configured, we should remove the default to avoid conflicts.
if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
{
getLog().debug( "Warning: changing classpath! " + project.getBuild().getOutputDirectory() + " != " + classesDirectory.getAbsolutePath() );
classpathElements.remove( project.getBuild().getOutputDirectory() );
classpathElements.add( classesDirectory.getAbsolutePath() );
}
if ( !project.getBuild().getTestOutputDirectory().equals( testClassesDirectory.getAbsolutePath() ) )
{
getLog().debug( "Warning: changing classpath! " + project.getBuild().getTestOutputDirectory() + " != " + testClassesDirectory.getAbsolutePath() );
classpathElements.remove( project.getBuild().getTestOutputDirectory() );
classpathElements.add( testClassesDirectory.getAbsolutePath() );
}
However there are two problems here:
1.) In a Windows environment (which I'm forced to use ... :-) the may be paths with mixed separators like C:\foo\bar/target/classes.
This cause the above equals() to return false, also the paths may not be different actually.
2.) The order of the classes and the test-classes folder may be swapped if both if() apply
I'd suggest the following code which uses Files to compare the paths and ensures that the test class path entry always comes first:
getLog().debug("Test Classpath :");
// Check if we need to add configured classes/test classes directories here.
// If they are configured, we should remove the default to avoid conflicts.
// Ensure that test classes always come first
final File outputDirectory = new File(project.getBuild().getOutputDirectory());
classpathElements.remove(project.getBuild().getOutputDirectory());
final File testOutputDirectory = new File(project.getBuild().getTestOutputDirectory());
classpathElements.remove(project.getBuild().getTestOutputDirectory());
if (outputDirectory.equals(classesDirectory)) {
// Add again at start of the list
classpathElements.add(0, outputDirectory.getAbsolutePath());
} else {
getLog().debug(
"Warning: changing classpath! " + outputDirectory.getAbsolutePath() + " != " + classesDirectory.getAbsolutePath());
classpathElements.add(0, classesDirectory.getAbsolutePath());
}
if (testOutputDirectory.equals(testClassesDirectory)) {
// Add again at the very start of the list
classpathElements.add(0, testOutputDirectory.getAbsolutePath());
} else {
getLog().debug(
"Warning: changing classpath! " + testOutputDirectory.getAbsolutePath() + " != "
+ testClassesDirectory.getAbsolutePath());
classpathElements.add(0, testClassesDirectory.getAbsolutePath());
}
Cheers
Markus
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Attachments: SUREFIRE-502.patch
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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
[jira] Closed: (SUREFIRE-502) Specified classesDirectory is added
to the end of the classpath
Posted by "Paul Gier (JIRA)" <ji...@codehaus.org>.
[ http://jira.codehaus.org/browse/SUREFIRE-502?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Gier closed SUREFIRE-502.
------------------------------
Resolution: Fixed
Fixed in [r806311|http://svn.apache.org/viewvc?view=rev&revision=806311].
> Specified classesDirectory is added to the end of the classpath
> ---------------------------------------------------------------
>
> Key: SUREFIRE-502
> URL: http://jira.codehaus.org/browse/SUREFIRE-502
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.4.3
> Environment: Windows Vista SP1, Java 1.5.0_13, Maven 2.0.9
> Reporter: James Shiell
> Assignee: Paul Gier
> Fix For: 2.5
>
> Attachments: SUREFIRE-502.patch, SurefirePlugin.java
>
>
> When you specify a classesDirectory in the configuration element of the Surefire plugin definition the classesDirectory is appended to the end of the classpath rather than replacing the build output directory. This means included dependencies take precedence over your source code.
> The problem appears to be the following code:
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> The classes directory should replace the build output directory, e.g.
> if ( !project.getBuild().getOutputDirectory().equals( classesDirectory.getAbsolutePath() ) )
> {
> final int replacementIndex = classpathElements.indexOf(project.getBuild().getOutputDirectory());
> if (replacementIndex >= 0)
> {
> classpathElements.remove( project.getBuild().getOutputDirectory() );
> classpathElements.add( replacementIndex, classesDirectory.getAbsolutePath() );
> }
> else
> {
> classpathElements.add( classesDirectory.getAbsolutePath() );
> }
> }
--
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