001 /*
002 * #%L
003 * License Maven Plugin
004 *
005 * $Id: ThirdPartyTool.java 14409 2011-08-10 15:30:41Z tchemit $
006 * $HeadURL: http://svn.codehaus.org/mojo/tags/license-maven-plugin-1.0/src/main/java/org/codehaus/mojo/license/ThirdPartyTool.java $
007 * %%
008 * Copyright (C) 2011 CodeLutin, Codehaus, Tony Chemit
009 * %%
010 * This program is free software: you can redistribute it and/or modify
011 * it under the terms of the GNU Lesser General Public License as
012 * published by the Free Software Foundation, either version 3 of the
013 * License, or (at your option) any later version.
014 *
015 * This program is distributed in the hope that it will be useful,
016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018 * GNU General Lesser Public License for more details.
019 *
020 * You should have received a copy of the GNU General Lesser Public
021 * License along with this program. If not, see
022 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
023 * #L%
024 */
025 package org.codehaus.mojo.license;
026
027 import java.io.File;
028 import java.io.IOException;
029 import java.util.Collection;
030 import java.util.List;
031 import java.util.SortedMap;
032 import java.util.SortedSet;
033
034 import org.apache.maven.artifact.repository.ArtifactRepository;
035 import org.apache.maven.model.License;
036 import org.apache.maven.project.MavenProject;
037 import org.codehaus.mojo.license.model.LicenseMap;
038
039 /**
040 * A tool to load third party files missing files.
041 * <p/>
042 * We should put here all the logic code written in some mojo and licenseMap...
043 *
044 * @author tchemit <chemit@codelutin.com>
045 * @since 1.0
046 */
047 public interface ThirdPartyTool {
048
049 /**
050 * Plexus Role
051 */
052 String ROLE = ThirdPartyTool.class.getName();
053
054 /**
055 * @param encoding
056 * encoding used to read or write properties files
057 * @param projects
058 * all projects where to read third parties descriptors
059 * @param unsafeProjects
060 * all unsafe projects
061 * @param licenseMap
062 * license map where to store new licenses
063 * @param localRepository
064 * local repository
065 * @param remoteRepositories
066 * remote repositories
067 * @return the map of loaded missing from the remote missing third party files
068 * @throws ThirdPartyToolException
069 * if any
070 * @throws IOException
071 * if any
072 */
073 SortedProperties loadThirdPartyDescriptorsForUnsafeMapping(String encoding, Collection<MavenProject> projects,
074 SortedSet<MavenProject> unsafeProjects, LicenseMap licenseMap, ArtifactRepository localRepository,
075 List<ArtifactRepository> remoteRepositories) throws ThirdPartyToolException, IOException;
076
077 /**
078 * For the given {@code project}, attach the given {@code file} as a third-party file.
079 * <p/>
080 * The file will be attached as with a classifier {@code third-parties} and a type {@code properties}.
081 *
082 * @param project
083 * the project on which to attch the third-party file
084 * @param file
085 * the third-party file to attach.
086 */
087 void attachThirdPartyDescriptor(MavenProject project, File file);
088
089 /**
090 * Obtain the third party file from the repository.
091 * <p/>
092 * Will first search in the local repository, then into the remote repositories and will resolv it.
093 *
094 * @param project
095 * the project
096 * @param localRepository
097 * the local repository
098 * @param repositories
099 * the remote repositories
100 * @return the locale file resolved into the local repository
101 * @throws ThirdPartyToolException
102 * if any
103 */
104 File resolvThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository,
105 List<ArtifactRepository> repositories) throws ThirdPartyToolException;
106
107 /**
108 * From the given {@code licenseMap}, obtain all the projects with no license.
109 *
110 * @param licenseMap
111 * the license map to query
112 * @param doLog
113 * a flag to add debug logs
114 * @return the set of projects with no license
115 */
116 SortedSet<MavenProject> getProjectsWithNoLicense(LicenseMap licenseMap, boolean doLog);
117
118 SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
119 String encoding, File missingFile) throws IOException;
120
121 /**
122 * Add a license (name and url are {@code licenseName}) to the given {@code licenseMap} for the given
123 * {@code project}.
124 *
125 * @param licenseMap
126 * the license map where to add the license
127 * @param project
128 * the project
129 * @param licenseName
130 * the name of the license
131 */
132 void addLicense(LicenseMap licenseMap, MavenProject project, String licenseName);
133
134 /**
135 * Add a given {@code license} to the given {@code licenseMap} for the given {@code project}.
136 *
137 * @param licenseMap
138 * the license map where to add the license
139 * @param project
140 * the project
141 * @param license
142 * the license to add
143 */
144 void addLicense(LicenseMap licenseMap, MavenProject project, License license);
145
146 /**
147 * Add a given {@code licenses} to the given {@code licenseMap} for the given {@code project}.
148 *
149 * @param licenseMap
150 * the license map where to add the licenses
151 * @param project
152 * the project
153 * @param licenses
154 * the licenses to add
155 */
156 void addLicense(LicenseMap licenseMap, MavenProject project, List<?> licenses);
157
158 /**
159 * For a given {@code licenseMap}, merge all {@code licenses}.
160 * <p/>
161 * The first value of the {@code licenses} is the license to keep and all other values will be merged into the first
162 * one.
163 *
164 * @param licenseMap
165 * the license map to merge
166 * @param licenses
167 * all the licenses to merge (the first license will be the unique one to kkep)
168 */
169 void mergeLicenses(LicenseMap licenseMap, String... licenses);
170 }