Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Linux, generated folder may be added twice using different absolute path. #55

Closed
Riduidel opened this issue Sep 26, 2016 · 3 comments
Assignees
Milestone

Comments

@Riduidel
Copy link
Contributor

This issue come from the linked StackOverflow question.

How to reproduce it ?

On a Linux machine, create a jaxb test project under, as a example, /home/User/project1. Link that folder into project2. You should then have the following situation

project1
project2 => project1

Now, in project2, run xjc transformation using jaxb2-maven-plugin. It will fail with duplicated generated classes.

How does it happens ?

In AjbstractJaxbPlugin, there is this code fragment which resolves the path to its canonical representation

    // 4) If the output directories exist, add them to the MavenProject's source directories
    if(getOutputDirectory().exists() && getOutputDirectory().isDirectory()) {

        final String canonicalPathToOutputDirectory = FileSystemUtilities.getCanonicalPath(getOutputDirectory());

        if(log.isDebugEnabled()) {
            log.debug("Adding existing JAXB outputDirectory [" + canonicalPathToOutputDirectory
                    + "] to Maven's sources.");
        }

        // Add the output Directory.
        getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
    }

However, in XjcMojo, source directory is added using the following code

protected void addGeneratedSourcesToProjectSourceRoot() {
    getProject().addCompileSourceRoot(getOutputDirectory().getAbsolutePath());
}

Which do not resolve the path to its canonical version.

As a consequence, directory is added twice to maven compiler roots, and code appear as duplicated in compiler.

How to solve it ?

Replace code in XjcMojo replace the method with the following code

protected void addGeneratedSourcesToProjectSourceRoot() {
    getProject().addCompileSourceRoot(FileSystemUtilities.getCanonicalPath(getOutputDirectory()));
}

Why don't you fix it by yourself ?

I'm behind a corporate firewall, but will try to edit code directly on Github interface

Riduidel added a commit to Riduidel/jaxb2-maven-plugin that referenced this issue Sep 26, 2016
Fixes mojohaus#55 by using standard `FileSystemUtilities` canonicalization instead of the simple absolute dir which may file on linked Linux paths
@lennartj lennartj added this to the Release 2.4 milestone Oct 13, 2016
@lennartj lennartj self-assigned this Oct 13, 2016
@JWT007
Copy link

JWT007 commented May 23, 2017

Hello, also affected by this problem in jaxb2-maven-plugin versions 2.3 / 2.3.1.

Locally on windows development machine there are no problems. However, on our Jenkins Linux build-servers the plugin has problems with symbolic links in the working directory.

As such 2 source-files are generated and both paths are added automatically by the JAXB plugin to the build-path.
/export/build/jenkins-localfs/workspace/.../MyJAXBClass.java
/export1/build/jenkins-localfs/workspace/.../MyJAXBClass.java

This results in duplicate classes during the build.

The above behaviour is new in 2.3+. With 2.2 the Jenkins build runs without problems.

@poireauxvinaigrette
Copy link

Same pb, do we have to wait for 2.4 ?

@veithen
Copy link
Contributor

veithen commented Sep 19, 2017

I think the underlying problem is that the plugin adds the source folder twice to the project. This would actually be fixed as a side effect of #94.

lennartj pushed a commit that referenced this issue Mar 5, 2018
Fixes #55 by using standard `FileSystemUtilities` canonicalization instead of the simple absolute dir which may file on linked Linux paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants