protected static URL getLicenseURL()

in src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java [157:188]


    protected static URL getLicenseURL(MavenProject project, String url) throws IOException {
        URL licenseUrl;
        UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES);
        // UrlValidator does not accept file URLs because the file
        // URLs do not contain a valid authority (no hostname).
        // As a workaround accept license URLs that start with the
        // file scheme.
        if (urlValidator.isValid(url) || StringUtils.defaultString(url).startsWith("file://")) {
            try {
                licenseUrl = new URL(url);
            } catch (MalformedURLException e) {
                throw new MalformedURLException("The license url '" + url + "' seems to be invalid: " + e.getMessage());
            }
        } else {
            File licenseFile = new File(project.getBasedir(), url);
            if (!licenseFile.exists()) {
                // Workaround to allow absolute path names while
                // staying compatible with the way it was...
                licenseFile = new File(url);
            }
            if (!licenseFile.exists()) {
                throw new IOException("Maven can't find the file '" + licenseFile + "' on the system.");
            }
            try {
                licenseUrl = licenseFile.toURI().toURL();
            } catch (MalformedURLException e) {
                throw new MalformedURLException("The license url '" + url + "' seems to be invalid: " + e.getMessage());
            }
        }

        return licenseUrl;
    }