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

Fix issue #560: fail to download license file because license name contains invalid characters #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nhuongmh
Copy link

Hi,
As I have mentioned in the issue #560, currently some license file name contains illegal character in name which leads to fail to download license file from remote URL. I check the code and see there's already a regex to remove back slashes, but we need more than that. So I just added couple more illegal characters known as illegal.
I was built and tested on my project and the maven goal worked as expected.

Before:

[DEBUG] Downloading license(s) for project com.github.oshi:oshi-core-java11
[DEBUG] About to download 'https://opensource.org/licenses/MIT'
[DEBUG] Downloading 'https://opensource.org/licenses/MIT' -> 'C:\Users\username\git\projectx\target\generated-resources\licenses\spdx-license-identifier: mit - mit.html'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  20.418 s
[INFO] Finished at: 2024-04-17T15:44:45+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:license-maven-plugin:2.4.0:download-licenses (default-cli) on project projectx: Execution default-cli of goal org.codehaus.mojo:license-maven-plugin:2.4.0:download-licenses failed: Illegal char <:> at index 135: C:\Users\username\git\projectx\target\generated-resources\licenses\spdx-license-identifier: mit - mit.html -> [Help 1]

After:

[DEBUG] About to download 'https://opensource.org/licenses/MIT'
[DEBUG] Downloading 'https://opensource.org/licenses/MIT' -> 'C:\Users\username\git\projectx\target\generated-resources\licenses\spdx-license-identifier_ mit - mit.html'
[DEBUG] Downloading license(s) for project com.google.auto:auto-common
[DEBUG] Downloading license(s) for project com.google.auto.service:auto-service
[DEBUG] Downloading license(s) for project com.google.auto.service:auto-service-annotations
[DEBUG] Downloading license(s) for project com.google.code.findbugs:jsr305
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  33.197 s
[INFO] Finished at: 2024-04-17T15:34:08+07:00

@slawekjaranowski
Copy link
Member

@nhuongmh thanks for fixing ....

method Abstract DownloadLicensesMojo#getLicenseFileName which you change looks like a little complicated.

My proposition for refactor.

Create class like 'LicenseFileNameBuilder' or similar name with body like:

public class LicenseFileNameBuilder {

    public LicenseFileNameBuilder withDepProject(...) {
        return this;
    }

    public LicenseFileNameBuilder withUrl(...) {
        return this;
    }

   // methods for ... rest of params
    
    public String build() {
       // body of current implementation
        return null;
    }
}

Next we can simply create a Unit test for it.

@slawekjaranowski slawekjaranowski self-assigned this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to download license file because license name contains invalid character
3 participants