You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/07/06 21:15:25 UTC

[maven-project-info-reports-plugin] branch master updated: [MPIR-407] Provide a way to map license names

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new eeb81c8  [MPIR-407] Provide a way to map license names
eeb81c8 is described below

commit eeb81c8660fabecc5465b5ba514402737933f55c
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Jun 2 15:09:44 2022 +0200

    [MPIR-407] Provide a way to map license names
    
    This closes #38
---
 src/it/MPIR-407/invoker.properties                 | 18 ++++++
 src/it/MPIR-407/pom.xml                            | 70 ++++++++++++++++++++++
 src/it/MPIR-407/verify.groovy                      | 23 +++++++
 .../projectinfo/AbstractProjectInfoReport.java     | 24 ++++++++
 .../report/projectinfo/DependenciesReport.java     |  2 +-
 .../projectinfo/DependencyManagementReport.java    |  2 +-
 .../maven/report/projectinfo/LicenseMapping.java   | 53 ++++++++++++++++
 .../renderer/DependenciesRenderer.java             | 18 +++++-
 .../renderer/DependencyManagementRenderer.java     | 21 +++++--
 9 files changed, 222 insertions(+), 9 deletions(-)

diff --git a/src/it/MPIR-407/invoker.properties b/src/it/MPIR-407/invoker.properties
new file mode 100644
index 0000000..4afd7fd
--- /dev/null
+++ b/src/it/MPIR-407/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache 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.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:dependencies
diff --git a/src/it/MPIR-407/pom.xml b/src/it/MPIR-407/pom.xml
new file mode 100644
index 0000000..eba370b
--- /dev/null
+++ b/src/it/MPIR-407/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache 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.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.project-info-reports.its</groupId>
+  <artifactId>MPIR-407</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <url>http://maven.apache.org/plugins/it/${project.artifactId}</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>@mavenVersion@</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+      <version>2.13.1</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <licenseMappings>
+            <licenseMapping>
+              <froms>
+                <from>The Apache Software License, Version 2.0</from>
+                <from>Apache Public License 2.0</from>
+              </froms>
+              <to>Apache License, Version 2.0</to>
+            </licenseMapping>
+          </licenseMappings>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/MPIR-407/verify.groovy b/src/it/MPIR-407/verify.groovy
new file mode 100644
index 0000000..570c5d2
--- /dev/null
+++ b/src/it/MPIR-407/verify.groovy
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache 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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+dependencies = new File( basedir, 'target/site/dependencies.html' ).text;
+
+assert !( dependencies.contains( 'The Apache Software License, Version 2.0' ) );
+assert !( dependencies.contains( 'Apache Public License 2.0' ) );
diff --git a/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java b/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
index 83e7504..b1ab8f3 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
@@ -182,6 +182,14 @@ public abstract class AbstractProjectInfoReport
     @Parameter( defaultValue = "true" )
     protected boolean skipEmptyReport;
 
+    /**
+     * A mapping of license names to group licenses referred to with different names together
+     *
+     * @since 3.3.1
+     */
+    @Parameter
+    private List<LicenseMapping> licenseMappings;
+
     // ----------------------------------------------------------------------
     // Public methods
     // ----------------------------------------------------------------------
@@ -259,6 +267,22 @@ public abstract class AbstractProjectInfoReport
     // Protected methods
     // ----------------------------------------------------------------------
 
+    protected Map<String, String> getLicenseMappings()
+    {
+        Map<String, String> map = new HashMap<>();
+        if ( licenseMappings != null )
+        {
+            for ( LicenseMapping mapping : licenseMappings )
+            {
+                for ( String from : mapping.getFroms() )
+                {
+                    map.put( from, mapping.getTo() );
+                }
+            }
+        }
+        return map;
+    }
+
     /**
      * @param coll The collection to be checked.
      * @return true if coll is empty false otherwise.
diff --git a/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java b/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
index a7b4cfc..1f3b963 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/DependenciesReport.java
@@ -159,7 +159,7 @@ public class DependenciesReport
         DependenciesRenderer r =
             new DependenciesRenderer( getSink(), locale, getI18N( locale ), getLog(), dependencies,
                                       dependencyNode, config, repoUtils, repositorySystem, projectBuilder,
-                                      buildingRequest );
+                                      buildingRequest, getLicenseMappings() );
         r.render();
     }
 
diff --git a/src/main/java/org/apache/maven/report/projectinfo/DependencyManagementReport.java b/src/main/java/org/apache/maven/report/projectinfo/DependencyManagementReport.java
index 3b2a88f..4778e4d 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/DependencyManagementReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/DependencyManagementReport.java
@@ -104,7 +104,7 @@ public class DependencyManagementReport
         DependencyManagementRenderer r =
             new DependencyManagementRenderer( getSink(), locale, getI18N( locale ), getLog(),
                                               getManagementDependencies(), artifactMetadataSource, repositorySystem,
-                                              projectBuilder, buildingRequest, repoUtils );
+                                              projectBuilder, buildingRequest, repoUtils, getLicenseMappings() );
         r.render();
     }
 
diff --git a/src/main/java/org/apache/maven/report/projectinfo/LicenseMapping.java b/src/main/java/org/apache/maven/report/projectinfo/LicenseMapping.java
new file mode 100644
index 0000000..2022a26
--- /dev/null
+++ b/src/main/java/org/apache/maven/report/projectinfo/LicenseMapping.java
@@ -0,0 +1,53 @@
+package org.apache.maven.report.projectinfo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache 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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+import java.util.List;
+
+/**
+ * License mapping
+ */
+public class LicenseMapping
+{
+
+    private List<String> froms;
+    private String to;
+
+    public List<String> getFroms()
+    {
+        return froms;
+    }
+
+    public void setFroms( List<String> froms )
+    {
+        this.froms = froms;
+    }
+
+    public String getTo()
+    {
+        return to;
+    }
+
+    public void setTo( String to )
+    {
+        this.to = to;
+    }
+
+}
diff --git a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
index e44fdb7..43eb156 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java
@@ -51,6 +51,7 @@ import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.report.projectinfo.AbstractProjectInfoRenderer;
+import org.apache.maven.report.projectinfo.LicenseMapping;
 import org.apache.maven.report.projectinfo.ProjectInfoReportUtils;
 import org.apache.maven.report.projectinfo.dependencies.Dependencies;
 import org.apache.maven.report.projectinfo.dependencies.DependenciesReportConfiguration;
@@ -132,6 +133,8 @@ public class DependenciesRenderer
 
     private final ProjectBuildingRequest buildingRequest;
 
+    private final Map<String, String> licenseMappings;
+
     static
     {
         Set<String> jarSubtype = new HashSet<>();
@@ -161,12 +164,13 @@ public class DependenciesRenderer
      * @param repositorySystem {@link RepositorySystem}
      * @param projectBuilder {@link ProjectBuilder}
      * @param buildingRequest {@link ProjectBuildingRequest}
+     * @param licenseMappings {@link LicenseMapping}
      */
     public DependenciesRenderer( Sink sink, Locale locale, I18N i18n, Log log,
                                  Dependencies dependencies, DependencyNode dependencyTreeNode,
                                  DependenciesReportConfiguration config, RepositoryUtils repoUtils,
                                  RepositorySystem repositorySystem, ProjectBuilder projectBuilder,
-                                 ProjectBuildingRequest buildingRequest )
+                                 ProjectBuildingRequest buildingRequest, Map<String, String> licenseMappings )
     {
         super( sink, i18n, locale );
 
@@ -178,6 +182,7 @@ public class DependenciesRenderer
         this.repositorySystem = repositorySystem;
         this.projectBuilder = projectBuilder;
         this.buildingRequest = buildingRequest;
+        this.licenseMappings = licenseMappings;
 
         // Using the right set of symbols depending of the locale
         DEFAULT_DECIMAL_FORMAT.setDecimalFormatSymbols( new DecimalFormatSymbols( locale ) );
@@ -800,7 +805,12 @@ public class DependenciesRenderer
             List<License> licenses = artifactProject.getLicenses();
             for ( License license : licenses )
             {
-                sb.append( ProjectInfoReportUtils.getArtifactIdCell( license.getName(), license.getUrl() ) );
+                String name = license.getName();
+                if ( licenseMappings != null && licenseMappings.containsKey( name ) )
+                {
+                    name = licenseMappings.get( name );
+                }
+                sb.append( ProjectInfoReportUtils.getArtifactIdCell( name, license.getUrl() ) );
             }
         }
         catch ( ProjectBuildingException e )
@@ -956,6 +966,10 @@ public class DependenciesRenderer
                         License license = it.next();
 
                         String licenseName = license.getName();
+                        if ( licenseMappings != null && licenseMappings.containsKey( licenseName ) )
+                        {
+                            licenseName = licenseMappings.get( licenseName );
+                        }
                         if ( StringUtils.isEmpty( licenseName ) )
                         {
                             licenseName = getI18nString( "unnamed" );
diff --git a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java
index 77b7d35..292bd7c 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependencyManagementRenderer.java
@@ -41,6 +41,7 @@ import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.report.projectinfo.AbstractProjectInfoRenderer;
+import org.apache.maven.report.projectinfo.LicenseMapping;
 import org.apache.maven.report.projectinfo.ProjectInfoReportUtils;
 import org.apache.maven.report.projectinfo.dependencies.ManagementDependencies;
 import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
@@ -69,6 +70,8 @@ public class DependencyManagementRenderer
 
     private final RepositoryUtils repoUtils;
 
+    private final Map<String, String> licenseMappings;
+
     /**
      * Default constructor
      *
@@ -82,12 +85,14 @@ public class DependencyManagementRenderer
      * @param projectBuilder {@link ProjectBuilder}
      * @param buildingRequest {@link ProjectBuildingRequest}
      * @param repoUtils {@link RepositoryUtils}
+     * @param licenseMappings {@link LicenseMapping}
      */
     public DependencyManagementRenderer( Sink sink, Locale locale, I18N i18n, Log log,
                                          ManagementDependencies dependencies,
                                          ArtifactMetadataSource artifactMetadataSource,
                                          RepositorySystem repositorySystem, ProjectBuilder projectBuilder,
-                                         ProjectBuildingRequest buildingRequest, RepositoryUtils repoUtils )
+                                         ProjectBuildingRequest buildingRequest, RepositoryUtils repoUtils,
+                                         Map<String, String> licenseMappings )
     {
         super( sink, i18n, locale );
 
@@ -98,6 +103,7 @@ public class DependencyManagementRenderer
         this.projectBuilder = projectBuilder;
         this.buildingRequest = buildingRequest;
         this.repoUtils = repoUtils;
+        this.licenseMappings = licenseMappings;
     }
 
     // ----------------------------------------------------------------------
@@ -255,7 +261,12 @@ public class DependencyManagementRenderer
             List<License> licenses = artifactProject.getLicenses();
             for ( License license : licenses )
             {
-                String licenseCell = ProjectInfoReportUtils.getArtifactIdCell( license.getName(), license.getUrl() );
+                String name = license.getName();
+                if ( licenseMappings != null && licenseMappings.containsKey( name ) )
+                {
+                    name = licenseMappings.get( name );
+                }
+                String licenseCell = ProjectInfoReportUtils.getArtifactIdCell( name, license.getUrl() );
                 if ( licensesBuffer.length() > 0 )
                 {
                     licensesBuffer.append( ", " );
@@ -273,11 +284,11 @@ public class DependencyManagementRenderer
         }
         catch ( ProjectBuildingException e )
         {
-            if ( log.isDebugEnabled() ) 
+            if ( log.isDebugEnabled() )
             {
                 log.warn( "Unable to create Maven project for " + artifact.getId() + " from repository.", e );
-            } 
-            else 
+            }
+            else
             {
                 log.warn( "Unable to create Maven project for " + artifact.getId() + " from repository." );
             }