Skip to content

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

Merged
slawekjaranowski merged 1 commit intomojohaus:masterfrom
nhuongmh:master
Sep 14, 2024
Merged

Fix issue #560: fail to download license file because license name contains invalid characters#561
slawekjaranowski merged 1 commit intomojohaus:masterfrom
nhuongmh:master

Conversation

@nhuongmh
Copy link
Copy Markdown

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
Copy Markdown
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
@slawekjaranowski slawekjaranowski merged commit d3080a5 into mojohaus:master Sep 14, 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