org.codehaus.mojo.license.model.LicenseRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of license-maven-plugin Show documentation
Show all versions of license-maven-plugin Show documentation
Maven plugin to download and collect license files from project dependencies.
The newest version!
package org.codehaus.mojo.license.model;
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2008 - 2011 CodeLutin, Codehaus, Tony Chemit
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.mojo.license.utils.MojoHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author tchemit [email protected]
* @since 1.0
*/
public class LicenseRepository implements Iterable {
private static final Logger LOG = LoggerFactory.getLogger(LicenseRepository.class);
public static final String REPOSITORY_DEFINITION_FILE = "licenses.properties";
public static final Pattern LICENSE_DESCRIPTION_PATTERN =
Pattern.compile("(.*)\\s*~~\\s*license\\s*:\\s*(.*)\\s*~~\\s*header\\s*:\\s*(.*)\\s*");
/**
* the base url of the licenses repository.
*/
protected URL baseURL;
/**
* licenses of this repository.
*/
protected List licenses;
/**
* flag to known if repository was init (pass to {@code true} when invoking
* the method {@link #load()}).
*/
protected boolean init;
public URL getBaseURL() {
return baseURL;
}
public void setBaseURL(URL baseURL) {
checkNotInit("setBaseURL");
this.baseURL = baseURL;
}
protected URL getDefinitionURL() {
if (baseURL == null || StringUtils.isEmpty(baseURL.toString())) {
throw new IllegalStateException("no baseURL defined in " + this);
}
URL definitionURL = MojoHelper.getUrl(getBaseURL(), REPOSITORY_DEFINITION_FILE);
return definitionURL;
}
protected URL getLicenseBaseURL(String licenseName) {
URL licenseBaseURL = MojoHelper.getUrl(baseURL, licenseName);
return licenseBaseURL;
}
public void load() throws IOException {
checkNotInit("load");
try {
URL definitionURL = getDefinitionURL();
if (licenses != null) {
licenses.clear();
} else {
licenses = new ArrayList<>();
}
if (!checkExists(definitionURL)) {
throw new IllegalArgumentException(
"no licenses.properties found with url [" + definitionURL + "] for resolver " + this);
}
Properties p = new Properties();
try (InputStream in = definitionURL.openStream()) {
p.load(in);
}
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy