
org.codehaus.mojo.license.model.LicenseMap 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!
/**
* Copyright 2010-2012 The Kuali Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ecl2.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.mojo.license.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.license.MojoHelper;
/**
* Map of artifacts (stub in mavenproject) group by their license.
*
* @author tchemit
* @since 1.0
*/
public class LicenseMap extends TreeMap> {
private static final long serialVersionUID = 864199843545688069L;
public static final String unknownLicenseMessage = "Unknown license";
private final Comparator projectComparator;
public LicenseMap() {
projectComparator = MojoHelper.newMavenProjectComparator();
}
public SortedSet put(String key, MavenProject value) {
// handle multiple values as a set to avoid duplicates
SortedSet valueList = get(key);
if (valueList == null) {
valueList = new TreeSet(projectComparator);
}
valueList.add(value);
return put(key, valueList);
}
public SortedMap toDependencyMap() {
SortedMap> tmp = new TreeMap>(projectComparator);
for (Map.Entry> entry : entrySet()) {
String license = entry.getKey();
SortedSet set = entry.getValue();
for (MavenProject p : set) {
Set list = tmp.get(p);
if (list == null) {
list = new HashSet();
tmp.put(p, list);
}
list.add(license);
}
}
SortedMap result = new TreeMap(projectComparator);
for (Map.Entry> entry : tmp.entrySet()) {
List value = new ArrayList(entry.getValue());
Collections.sort(value);
result.put(entry.getKey(), value.toArray(new String[value.size()]));
}
tmp.clear();
return result;
}
public static String getUnknownLicenseMessage() {
return unknownLicenseMessage;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy