/
DownloadLicensesMojo.java
95 lines (85 loc) · 3.42 KB
/
DownloadLicensesMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.codehaus.mojo.license;
/*
* #%L
* License Maven Plugin
* %%
* Copyright (C) 2010 - 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
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
import java.util.Map;
import java.util.TreeMap;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
import org.codehaus.mojo.license.download.LicensedArtifact;
/**
* Download the license files of all the current project's dependencies, and generate a summary file containing a list
* of all dependencies and their licenses.
* <p>
* The license files will be downloaded to {@link AbstractDownloadLicensesMojo#licensesOutputDirectory} to be included
* in the final packaging of the project if desired. The licenses are downloaded from the url field of the dependency
* POM.
* <p>
* If the license information (license name and license URL) is missing or otherwise broken in a dependency POM, this
* mojo offers several fallback options:
* <ul>
* <li>{@link AbstractDownloadLicensesMojo#licensesConfigFile}</li>
* <li>{@link AbstractDownloadLicensesMojo#errorRemedy}</li>
* <li>{@link AbstractDownloadLicensesMojo#licenseUrlReplacements}</li>
* <li>{@link AbstractDownloadLicensesMojo#licenseUrlFileNames}</li>
* </ul>
*
* @author Paul Gier
* @since 1.0
*/
@Mojo( name = "download-licenses", requiresDependencyResolution = ResolutionScope.TEST,
defaultPhase = LifecyclePhase.PACKAGE )
public class DownloadLicensesMojo
extends AbstractDownloadLicensesMojo
{
// ----------------------------------------------------------------------
// Mojo Parameters
// ----------------------------------------------------------------------
/**
* A flag to skip the goal.
*
* @since 1.5
*/
@Parameter( property = "license.skipDownloadLicenses", defaultValue = "false" )
protected boolean skipDownloadLicenses;
// ----------------------------------------------------------------------
// AbstractDownloadLicensesMojo Implementation
// ----------------------------------------------------------------------
/**
* {@inheritDoc}
*/
protected boolean isSkip()
{
return skipDownloadLicenses;
}
@SuppressWarnings( "unchecked" )
protected Map<String, LicensedArtifact> getDependencies()
{
final Map<String, LicensedArtifact> result = new TreeMap<>();
licensedArtifactResolver.loadProjectDependencies(
new ResolvedProjectDependencies( project.getArtifacts(), project.getDependencyArtifacts() ),
this, remoteRepositories, result );
return result;
}
}