Skip to content

Commit eeb81c8

Browse files
gnodetmichael-o
authored andcommitted
[MPIR-407] Provide a way to map license names
This closes #38
1 parent 9430070 commit eeb81c8

File tree

9 files changed

+222
-9
lines changed

9 files changed

+222
-9
lines changed

src/it/MPIR-407/invoker.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependencies

src/it/MPIR-407/pom.xml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.project-info-reports.its</groupId>
27+
<artifactId>MPIR-407</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<packaging>pom</packaging>
30+
<url>http://maven.apache.org/plugins/it/${project.artifactId}</url>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.apache.maven</groupId>
40+
<artifactId>maven-core</artifactId>
41+
<version>@mavenVersion@</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.fasterxml.jackson.core</groupId>
45+
<artifactId>jackson-core</artifactId>
46+
<version>2.13.1</version>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<artifactId>maven-project-info-reports-plugin</artifactId>
54+
<version>@project.version@</version>
55+
<configuration>
56+
<licenseMappings>
57+
<licenseMapping>
58+
<froms>
59+
<from>The Apache Software License, Version 2.0</from>
60+
<from>Apache Public License 2.0</from>
61+
</froms>
62+
<to>Apache License, Version 2.0</to>
63+
</licenseMapping>
64+
</licenseMappings>
65+
</configuration>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
70+
</project>

src/it/MPIR-407/verify.groovy

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
dependencies = new File( basedir, 'target/site/dependencies.html' ).text;
21+
22+
assert !( dependencies.contains( 'The Apache Software License, Version 2.0' ) );
23+
assert !( dependencies.contains( 'Apache Public License 2.0' ) );

src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java

+24
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ public abstract class AbstractProjectInfoReport
182182
@Parameter( defaultValue = "true" )
183183
protected boolean skipEmptyReport;
184184

185+
/**
186+
* A mapping of license names to group licenses referred to with different names together
187+
*
188+
* @since 3.3.1
189+
*/
190+
@Parameter
191+
private List<LicenseMapping> licenseMappings;
192+
185193
// ----------------------------------------------------------------------
186194
// Public methods
187195
// ----------------------------------------------------------------------
@@ -259,6 +267,22 @@ public String getCategoryName()
259267
// Protected methods
260268
// ----------------------------------------------------------------------
261269

270+
protected Map<String, String> getLicenseMappings()
271+
{
272+
Map<String, String> map = new HashMap<>();
273+
if ( licenseMappings != null )
274+
{
275+
for ( LicenseMapping mapping : licenseMappings )
276+
{
277+
for ( String from : mapping.getFroms() )
278+
{
279+
map.put( from, mapping.getTo() );
280+
}
281+
}
282+
}
283+
return map;
284+
}
285+
262286
/**
263287
* @param coll The collection to be checked.
264288
* @return true if coll is empty false otherwise.

src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void executeReport( Locale locale )
159159
DependenciesRenderer r =
160160
new DependenciesRenderer( getSink(), locale, getI18N( locale ), getLog(), dependencies,
161161
dependencyNode, config, repoUtils, repositorySystem, projectBuilder,
162-
buildingRequest );
162+
buildingRequest, getLicenseMappings() );
163163
r.render();
164164
}
165165

src/main/java/org/apache/maven/report/projectinfo/DependencyManagementReport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void executeReport( Locale locale )
104104
DependencyManagementRenderer r =
105105
new DependencyManagementRenderer( getSink(), locale, getI18N( locale ), getLog(),
106106
getManagementDependencies(), artifactMetadataSource, repositorySystem,
107-
projectBuilder, buildingRequest, repoUtils );
107+
projectBuilder, buildingRequest, repoUtils, getLicenseMappings() );
108108
r.render();
109109
}
110110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.apache.maven.report.projectinfo;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.util.List;
23+
24+
/**
25+
* License mapping
26+
*/
27+
public class LicenseMapping
28+
{
29+
30+
private List<String> froms;
31+
private String to;
32+
33+
public List<String> getFroms()
34+
{
35+
return froms;
36+
}
37+
38+
public void setFroms( List<String> froms )
39+
{
40+
this.froms = froms;
41+
}
42+
43+
public String getTo()
44+
{
45+
return to;
46+
}
47+
48+
public void setTo( String to )
49+
{
50+
this.to = to;
51+
}
52+
53+
}

src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.maven.project.ProjectBuildingException;
5252
import org.apache.maven.project.ProjectBuildingRequest;
5353
import org.apache.maven.report.projectinfo.AbstractProjectInfoRenderer;
54+
import org.apache.maven.report.projectinfo.LicenseMapping;
5455
import org.apache.maven.report.projectinfo.ProjectInfoReportUtils;
5556
import org.apache.maven.report.projectinfo.dependencies.Dependencies;
5657
import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration;
@@ -132,6 +133,8 @@ public Object put( String key, Object value )
132133

133134
private final ProjectBuildingRequest buildingRequest;
134135

136+
private final Map<String, String> licenseMappings;
137+
135138
static
136139
{
137140
Set<String> jarSubtype = new HashSet<>();
@@ -161,12 +164,13 @@ public Object put( String key, Object value )
161164
* @param repositorySystem {@link RepositorySystem}
162165
* @param projectBuilder {@link ProjectBuilder}
163166
* @param buildingRequest {@link ProjectBuildingRequest}
167+
* @param licenseMappings {@link LicenseMapping}
164168
*/
165169
public DependenciesRenderer( Sink sink, Locale locale, I18N i18n, Log log,
166170
Dependencies dependencies, DependencyNode dependencyTreeNode,
167171
DependenciesReportConfiguration config, RepositoryUtils repoUtils,
168172
RepositorySystem repositorySystem, ProjectBuilder projectBuilder,
169-
ProjectBuildingRequest buildingRequest )
173+
ProjectBuildingRequest buildingRequest, Map<String, String> licenseMappings )
170174
{
171175
super( sink, i18n, locale );
172176

@@ -178,6 +182,7 @@ public DependenciesRenderer( Sink sink, Locale locale, I18N i18n, Log log,
178182
this.repositorySystem = repositorySystem;
179183
this.projectBuilder = projectBuilder;
180184
this.buildingRequest = buildingRequest;
185+
this.licenseMappings = licenseMappings;
181186

182187
// Using the right set of symbols depending of the locale
183188
DEFAULT_DECIMAL_FORMAT.setDecimalFormatSymbols( new DecimalFormatSymbols( locale ) );
@@ -800,7 +805,12 @@ private void renderArtifactRow( Artifact artifact, boolean withClassifier, boole
800805
List<License> licenses = artifactProject.getLicenses();
801806
for ( License license : licenses )
802807
{
803-
sb.append( ProjectInfoReportUtils.getArtifactIdCell( license.getName(), license.getUrl() ) );
808+
String name = license.getName();
809+
if ( licenseMappings != null && licenseMappings.containsKey( name ) )
810+
{
811+
name = licenseMappings.get( name );
812+
}
813+
sb.append( ProjectInfoReportUtils.getArtifactIdCell( name, license.getUrl() ) );
804814
}
805815
}
806816
catch ( ProjectBuildingException e )
@@ -956,6 +966,10 @@ private void printDescriptionsAndURLs( DependencyNode node, String uid )
956966
License license = it.next();
957967

958968
String licenseName = license.getName();
969+
if ( licenseMappings != null && licenseMappings.containsKey( licenseName ) )
970+
{
971+
licenseName = licenseMappings.get( licenseName );
972+
}
959973
if ( StringUtils.isEmpty( licenseName ) )
960974
{
961975
licenseName = getI18nString( "unnamed" );

src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.maven.project.ProjectBuildingException;
4242
import org.apache.maven.project.ProjectBuildingRequest;
4343
import org.apache.maven.report.projectinfo.AbstractProjectInfoRenderer;
44+
import org.apache.maven.report.projectinfo.LicenseMapping;
4445
import org.apache.maven.report.projectinfo.ProjectInfoReportUtils;
4546
import org.apache.maven.report.projectinfo.dependencies.ManagementDependencies;
4647
import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
@@ -69,6 +70,8 @@ public class DependencyManagementRenderer
6970

7071
private final RepositoryUtils repoUtils;
7172

73+
private final Map<String, String> licenseMappings;
74+
7275
/**
7376
* Default constructor
7477
*
@@ -82,12 +85,14 @@ public class DependencyManagementRenderer
8285
* @param projectBuilder {@link ProjectBuilder}
8386
* @param buildingRequest {@link ProjectBuildingRequest}
8487
* @param repoUtils {@link RepositoryUtils}
88+
* @param licenseMappings {@link LicenseMapping}
8589
*/
8690
public DependencyManagementRenderer( Sink sink, Locale locale, I18N i18n, Log log,
8791
ManagementDependencies dependencies,
8892
ArtifactMetadataSource artifactMetadataSource,
8993
RepositorySystem repositorySystem, ProjectBuilder projectBuilder,
90-
ProjectBuildingRequest buildingRequest, RepositoryUtils repoUtils )
94+
ProjectBuildingRequest buildingRequest, RepositoryUtils repoUtils,
95+
Map<String, String> licenseMappings )
9196
{
9297
super( sink, i18n, locale );
9398

@@ -98,6 +103,7 @@ public DependencyManagementRenderer( Sink sink, Locale locale, I18N i18n, Log lo
98103
this.projectBuilder = projectBuilder;
99104
this.buildingRequest = buildingRequest;
100105
this.repoUtils = repoUtils;
106+
this.licenseMappings = licenseMappings;
101107
}
102108

103109
// ----------------------------------------------------------------------
@@ -255,7 +261,12 @@ private String[] getDependencyRow( Dependency dependency, boolean hasClassifier
255261
List<License> licenses = artifactProject.getLicenses();
256262
for ( License license : licenses )
257263
{
258-
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell( license.getName(), license.getUrl() );
264+
String name = license.getName();
265+
if ( licenseMappings != null && licenseMappings.containsKey( name ) )
266+
{
267+
name = licenseMappings.get( name );
268+
}
269+
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell( name, license.getUrl() );
259270
if ( licensesBuffer.length() > 0 )
260271
{
261272
licensesBuffer.append( ", " );
@@ -273,11 +284,11 @@ private String[] getDependencyRow( Dependency dependency, boolean hasClassifier
273284
}
274285
catch ( ProjectBuildingException e )
275286
{
276-
if ( log.isDebugEnabled() )
287+
if ( log.isDebugEnabled() )
277288
{
278289
log.warn( "Unable to create Maven project for " + artifact.getId() + " from repository.", e );
279-
}
280-
else
290+
}
291+
else
281292
{
282293
log.warn( "Unable to create Maven project for " + artifact.getId() + " from repository." );
283294
}

0 commit comments

Comments
 (0)