[
http://jira.codehaus.org/browse/MJAVACC-35?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_112892
]
Benjamin Bentmann commented on MJAVACC-35:
------------------------------------------
bq. the equals method on file did not find File("src/main/javacc") to be equal
to File("C:/javacc/src/main/javacc")
Yes, unfortunately File.equals() boils down to something like
{code:java}
f1.getPath().compareToIgnoreCase(f2.getPath());
{code}
on a Win32 filesystem in this case. This does neither account for one path
being relative and the other absolute nor for non-canonical paths.
The best I know to check for file identify in the logical sense is
{code:java}
f1.getCanonicalFile().equals(f1.getCanonicalFile())
{code}
It ensures both paths being checked are absolute and normalized and handles
case-sensitivity properly for the current filesystem. The ugly point about this
approach is that canonicalizing requires disk access and may throw IOException.
Therefore, as a minimum, one should use
{code:java}
f1.getAbsoluteFile().equals(f1.getAbsoluteFile())
{code}
i.e. use File.equals() instead of String.equals() to get case-(in-)sensitivity
correctly.
However, it remains a bad idea for Maven plugins to use
getAbsolutePath()/File() on relative paths as it resolves to a different
directory than one might expect. Usually, relative paths need to be manually
resolved against project.getBasedir(). I recently noticed a Plexus component
called "PathTranslator" that might have been written just for the purpose to
provide plugins with this commonly needed function but I am not really sure.
> If input and output directory are equal then input files are emptied
> --------------------------------------------------------------------
>
> Key: MJAVACC-35
> URL: http://jira.codehaus.org/browse/MJAVACC-35
> Project: Maven 2.x JavaCC Plugin
> Issue Type: Bug
> Affects Versions: 2.3
> Environment: WinXP
> Reporter: Tim Pizey
> Attachments: JavaCCMojo.patch
>
>
> If the inputDirectory is the same as the outputDirectory, a situation which
> no doubt should not happen, but has to in javacc itself,
> then the input files are replaced with zero byte size files.
--
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
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email