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

FileAlreadyExists exception when organizeLicensesByDependencies is true and a license is cached #312

Open
srdo opened this issue Mar 26, 2019 · 2 comments

Comments

@srdo
Copy link
Contributor

srdo commented Mar 26, 2019

Trying to download licenses with organizeLicensesByDependencies set to true.

[WARNING] Unable to retrieve license from URL 'http://www.apache.org/licenses/LICENSE-2.0.txt' for dependency 'org.apache.commons:commons-lang3': /mnt/c/Users/Esran/Documents/NetbeansProjects/storm/target/generated-resources/licenses/org.apache.commons.commons-lang3_the_apache_software_license,_version_2.0
[DEBUG] 
java.nio.file.FileAlreadyExistsException: /mnt/c/Users/Esran/Documents/NetbeansProjects/storm/target/generated-resources/licenses/org.apache.commons.commons-lang3_the_apache_software_license,_version_2.0
    at sun.nio.fs.UnixCopyFile.copy (UnixCopyFile.java:551)
    at sun.nio.fs.UnixFileSystemProvider.copy (UnixFileSystemProvider.java:253)
    at java.nio.file.Files.copy (Files.java:1274)
    at org.codehaus.mojo.license.AbstractDownloadLicensesMojo.downloadLicenses (AbstractDownloadLicensesMojo.java:1082)

The broken code seems to be https://github.com/mojohaus/license-maven-plugin/blob/license-maven-plugin-1.19/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java#L1082

I'm not sure what that code is supposed to do, but if the target file is supposed to be overwritten, the copy call should set CopyOption.REPLACE_EXISTING.

@ppalaga
Copy link
Contributor

ppalaga commented Mar 27, 2019

Thanks for the report.

Yes, I think adding CopyOption.REPLACE_EXISTING could fix it.

Looks like we have just two integration tests with organizeLicensesByDependencies=true which apparently do not cover this situation. Please add a test in https://github.com/mojohaus/license-maven-plugin/tree/master/src/it that reproduces your scenario and make sure it fails before and passes after applying your fix.

@Vlatombe
Copy link
Contributor

This happens if a dependency with the same ga appears several times in the dependency tree with different versions. Since the current filename mapping doesn't contain the version, the second execution fails.

Vlatombe added a commit to Vlatombe/license-maven-plugin that referenced this issue Dec 16, 2019
When using organizeLicensesByDependencies=true, if you have several
dependencies with the same license, and the same dependency appears
in the dependency tree with different versions/types, then the cached
file will be copied several times over to the destination, which can
already exist.
Vlatombe added a commit to cloudbees/license-maven-plugin that referenced this issue Jan 28, 2020
When using organizeLicensesByDependencies=true, if you have several
dependencies with the same license, and the same dependency appears
in the dependency tree with different versions/types, then the cached
file will be copied several times over to the destination, which can
already exist.
Vlatombe added a commit to Vlatombe/license-maven-plugin that referenced this issue May 2, 2023
When using organizeLicensesByDependencies=true, if you have several
dependencies with the same license, and the same dependency appears
in the dependency tree with different versions/types, then the cached
file will be copied several times over to the destination, which can
already exist.
olamy pushed a commit that referenced this issue May 3, 2023
When using organizeLicensesByDependencies=true, if you have several
dependencies with the same license, and the same dependency appears
in the dependency tree with different versions/types, then the cached
file will be copied several times over to the destination, which can
already exist.
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

3 participants