View Javadoc

1   /**
2    * Copyright 2010-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.license;
17  
18  import java.io.File;
19  import java.io.IOException;
20  import java.util.Collection;
21  import java.util.List;
22  import java.util.SortedMap;
23  import java.util.SortedSet;
24  
25  import org.apache.maven.artifact.repository.ArtifactRepository;
26  import org.apache.maven.model.License;
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.mojo.license.model.LicenseMap;
29  
30  /**
31   * A tool to load third party files missing files.
32   * <p/>
33   * We should put here all the logic code written in some mojo and licenseMap...
34   *
35   * @author tchemit <chemit@codelutin.com>
36   * @since 1.0
37   */
38  public interface ThirdPartyTool {
39  
40      /**
41       * Plexus Role
42       */
43      String ROLE = ThirdPartyTool.class.getName();
44  
45      /**
46       * @param encoding
47       *            encoding used to read or write properties files
48       * @param projects
49       *            all projects where to read third parties descriptors
50       * @param unsafeProjects
51       *            all unsafe projects
52       * @param licenseMap
53       *            license map where to store new licenses
54       * @param localRepository
55       *            local repository
56       * @param remoteRepositories
57       *            remote repositories
58       * @return the map of loaded missing from the remote missing third party files
59       * @throws ThirdPartyToolException
60       *             if any
61       * @throws IOException
62       *             if any
63       */
64      SortedProperties loadThirdPartyDescriptorsForUnsafeMapping(String encoding, Collection<MavenProject> projects,
65              SortedSet<MavenProject> unsafeProjects, LicenseMap licenseMap, ArtifactRepository localRepository,
66              List<ArtifactRepository> remoteRepositories) throws ThirdPartyToolException, IOException;
67  
68      /**
69       * For the given {@code project}, attach the given {@code file} as a third-party file.
70       * <p/>
71       * The file will be attached as with a classifier {@code third-parties} and a type {@code properties}.
72       *
73       * @param project
74       *            the project on which to attch the third-party file
75       * @param file
76       *            the third-party file to attach.
77       */
78      void attachThirdPartyDescriptor(MavenProject project, File file);
79  
80      /**
81       * Obtain the third party file from the repository.
82       * <p/>
83       * Will first search in the local repository, then into the remote repositories and will resolv it.
84       *
85       * @param project
86       *            the project
87       * @param localRepository
88       *            the local repository
89       * @param repositories
90       *            the remote repositories
91       * @return the locale file resolved into the local repository
92       * @throws ThirdPartyToolException
93       *             if any
94       */
95      File resolvThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository,
96              List<ArtifactRepository> repositories) throws ThirdPartyToolException;
97  
98      /**
99       * From the given {@code licenseMap}, obtain all the projects with no license.
100      *
101      * @param licenseMap
102      *            the license map to query
103      * @param doLog
104      *            a flag to add debug logs
105      * @return the set of projects with no license
106      */
107     SortedSet<MavenProject> getProjectsWithNoLicense(LicenseMap licenseMap, boolean doLog);
108 
109     SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
110             String encoding, File missingFile) throws IOException;
111 
112     /**
113      * Add a license (name and url are {@code licenseName}) to the given {@code licenseMap} for the given
114      * {@code project}.
115      *
116      * @param licenseMap
117      *            the license map where to add the license
118      * @param project
119      *            the project
120      * @param licenseName
121      *            the name of the license
122      */
123     void addLicense(LicenseMap licenseMap, MavenProject project, String licenseName);
124 
125     /**
126      * Add a given {@code license} to the given {@code licenseMap} for the given {@code project}.
127      *
128      * @param licenseMap
129      *            the license map where to add the license
130      * @param project
131      *            the project
132      * @param license
133      *            the license to add
134      */
135     void addLicense(LicenseMap licenseMap, MavenProject project, License license);
136 
137     /**
138      * Add a given {@code licenses} to the given {@code licenseMap} for the given {@code project}.
139      *
140      * @param licenseMap
141      *            the license map where to add the licenses
142      * @param project
143      *            the project
144      * @param licenses
145      *            the licenses to add
146      */
147     void addLicense(LicenseMap licenseMap, MavenProject project, List<?> licenses);
148 
149     /**
150      * For a given {@code licenseMap}, merge all {@code licenses}.
151      * <p/>
152      * The first value of the {@code licenses} is the license to keep and all other values will be merged into the first
153      * one.
154      *
155      * @param licenseMap
156      *            the license map to merge
157      * @param licenses
158      *            all the licenses to merge (the first license will be the unique one to kkep)
159      */
160     void mergeLicenses(LicenseMap licenseMap, String... licenses);
161 }