You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Joe Freeman (JIRA)" <ji...@codehaus.org> on 2008/04/15 22:52:59 UTC

[jira] Updated: (MECLIPSE-427) .springBeans definition throws NullPointer if BaseDir does not exist

     [ http://jira.codehaus.org/browse/MECLIPSE-427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joe Freeman updated MECLIPSE-427:
---------------------------------

    Attachment: MyEclipseSpringBeansWriter.java

This file fixes two problems in our build.

1)  It eliminates the null pointer exception that occurs when the build path is pointed to a place that doesn't exist.

2)  The spring beans writer only worked if your current working directory was the root of the project that you were building a .springBeans file in.  It didn't work if you had multiple, hierarchical, projects where the current working directory stays at the top.  The Spring Bean Writer now works for project where it is sitting outside the root of any one code project.

I don't have time to create test cases at this time even though they should be easy.

1)  Create a project where the spring basedir for the searching for spring beans doesn't exist.  You will get a null pointer exception.

2)  Create two hierarchical projects where all the spring files exist in the lower level project.  Put the eclipse configuration with <spring></spring> in the top level pom.  Then run "mvn eclipse:myeclipse".  The .springBeans file will be created but with no spring files listed.  Use the patch and you get a .springBeans file with the spring xml files listed in it.

I'm not sure if the path manipulation I did is the approved maven way of fixing this.  Another way to fix this would be to have maven cd down into the directory being investigated so that the project root is the current working directory.

> .springBeans definition throws NullPointer if BaseDir does not exist
> --------------------------------------------------------------------
>
>                 Key: MECLIPSE-427
>                 URL: http://jira.codehaus.org/browse/MECLIPSE-427
>             Project: Maven 2.x Eclipse Plugin
>          Issue Type: Bug
>          Components: MyEclipse support
>    Affects Versions: 2.5, 2.5.1
>            Reporter: Joe Freeman
>         Attachments: MyEclipseSpringBeansWriter.java
>
>
> This is related to the fix submitted for MECLIPSE-359
> We have an application with 40 eclipse projects in it.  About  half of them have spring beans and 1/2 don't. The top level pom describes how the eclipse plugin should function and includes the Spring configuration component for the myeclipse target.  A null pointer is thrown when running eclipse:myeclipse when the base dir doesn't exist, in our case in one of the projects that doesn't have any spring components.  Our pom.xml fragment looks like
>                     <spring>
>                         <version>2.0</version>
>                         <file-pattern>*.xml</file-pattern>
>                         <basedir>src/main/resources/conf</basedir>
>                     </spring>
> The exception stack trace looks like
> java.lang.NullPointerException
>         at org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseSpringBeansWriter.getConfigurationFilesList(MyEclipseSpringBeansWriter.java:142)
>         at org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseSpringBeansWriter.write(MyEclipseSpringBeansWriter.java:93)
> The following code block with the problem throws NullPointer when directory.listFiles() returns a null into subdirs. Wrap the for() loop in a nullcheck
>        try
>         {
>             File directory = new File( basedir );
>             File[] subdirs = directory.listFiles( new FileFilter()
>             {
>                 public boolean accept( File pathname )
>                 {
>                     return pathname.isDirectory();
>                 }
>             } );
>             for ( int i = 0; i < subdirs.length; i++ )
>             {
>                 configFiles.addAll( getConfigurationFilesList( subdirs[i].getPath(), pattern ) );
>             }
>             configFiles.addAll( FileUtils.getFileNames( directory, pattern, null, true ) );
>         }
> Testing:
> Take one of the test cases and remove the directory that is pointed to by the basedir attribute.

-- 
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