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

slachiewicz 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 af95f42  Link remote licenses instead of downloading them by default
af95f42 is described below

commit af95f42ec6f6c003d870f4f44fc60344f18239a1
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sun Nov 1 13:31:29 2026 +0000

    Link remote licenses instead of downloading them by default
    
    A license given by an http or https URL is rendered as a link unless 
downloadRemoteLicenses (-Dlicenses.downloadRemote) is set, so building a site 
no longer sends a request to the server hosting each license. Local license 
files are still inlined. Refs #586.
---
 .../maven/report/projectinfo/LicensesReport.java   | 41 +++++++++++++++++--
 src/site/markdown/faq.md                           |  9 +++++
 .../report/projectinfo/LicensesReportTest.java     | 26 ++++++++++--
 .../licenses-plugin-config-download.xml            | 47 ++++++++++++++++++++++
 4 files changed, 116 insertions(+), 7 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java 
b/src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java
index 47b05e3..f8a6d14 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java
@@ -70,13 +70,23 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
      * <br/>
      * If the system is in {@link #offline} mode, the linkOnly parameter will 
be always <code>true</code>.
      * <br/>
-     * The user property <code>licenses.linkOnly</code> is available since 
3.9.1.
+     * The user property <code>licenses.linkOnly</code> is available since 
3.10.0.
      *
      * @since 2.3
      */
     @Parameter(property = "licenses.linkOnly", defaultValue = "false")
     private boolean linkOnly;
 
+    /**
+     * Whether to download licenses given by an <code>http</code> or 
<code>https</code> URL and inline their text.
+     * By default such licenses are rendered as links, so that building a site 
does not send a request to the server
+     * hosting each license; licenses in local files are always inlined unless 
{@link #linkOnly} is set.
+     *
+     * @since 3.10.0
+     */
+    @Parameter(property = "licenses.downloadRemote", defaultValue = "false")
+    private boolean downloadRemoteLicenses;
+
     /**
      * Specifies the input encoding of the project's license file(s).
      *
@@ -143,6 +153,7 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
                 locale,
                 settings,
                 linkOnly,
+                downloadRemoteLicenses,
                 licenseFileEncoding,
                 getLicenseContentCache());
 
@@ -262,6 +273,8 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
 
         private final boolean linkOnly;
 
+        private final boolean downloadRemoteLicenses;
+
         private final String licenseFileEncoding;
 
         /**
@@ -276,6 +289,7 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
                 Locale locale,
                 Settings settings,
                 boolean linkOnly,
+                boolean downloadRemoteLicenses,
                 String licenseFileEncoding,
                 Map<String, Object> licenseContentCache) {
             super(sink, i18n, locale);
@@ -286,6 +300,8 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
 
             this.linkOnly = linkOnly;
 
+            this.downloadRemoteLicenses = downloadRemoteLicenses;
+
             this.licenseFileEncoding = licenseFileEncoding;
 
             this.licenseContentCache = licenseContentCache;
@@ -324,7 +340,7 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
                 // multiple licenses
                 paragraph(getI18nString("multiple"));
 
-                if (!linkOnly) {
+                if (licenses.stream().anyMatch(this::isInlined)) {
                     // add an index before licenses content
                     sink.list();
                     for (License license : licenses) {
@@ -360,7 +376,7 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
                     try {
                         URL licenseUrl = getLicenseURL(project, url);
 
-                        if (linkOnly) {
+                        if (!isInlined(licenseUrl)) {
                             link(licenseUrl.toExternalForm(), 
licenseUrl.toExternalForm());
                         } else {
                             renderLicenseContent(licenseUrl);
@@ -377,6 +393,25 @@ public class LicensesReport extends 
AbstractProjectInfoReport {
             endSection();
         }
 
+        /**
+         * Whether a license's text is inlined: never with {@link #linkOnly}, 
and a remote license only when asked
+         * for, to spare the server hosting it.
+         */
+        private boolean isInlined(URL licenseUrl) {
+            return !linkOnly && ("file".equals(licenseUrl.getProtocol()) || 
downloadRemoteLicenses);
+        }
+
+        private boolean isInlined(License license) {
+            if (license.getUrl() == null) {
+                return false;
+            }
+            try {
+                return isInlined(getLicenseURL(project, license.getUrl()));
+            } catch (IOException e) {
+                return false;
+            }
+        }
+
         /**
          * Render the license content into the report.
          *
diff --git a/src/site/markdown/faq.md b/src/site/markdown/faq.md
index 303cd11..7ea4186 100644
--- a/src/site/markdown/faq.md
+++ b/src/site/markdown/faq.md
@@ -29,6 +29,7 @@ under the License.
 2. [How to exclude SCM access info?](#How_to_exclude_SCM_anonymous_access_info)
 3. [How to use developer/contributor time 
zone?](#How_to_use_developer.2Fcontributor_time_zone)
 4. [Is it possible to customize the reports 
rendering?](#Is_it_possible_to_customize_the_reports_rendering)
+5. [Why does the Licenses report link to my license instead of showing its 
text?](#Why_does_the_Licenses_report_link_to_my_license_instead_of_showing_its_text)
 
 <a id="Is_it_possible_to_customize_the_labels_of_the_Project_Reports_Menu"></a>
 
@@ -54,3 +55,11 @@ Please refer to the [developer 
section](http://maven.apache.org/pom.html#Develop
 
 Not yet, but 
[patches](https://github.com/apache/maven-project-info-reports-plugin/issues/) 
are always welcome!
 You could only [customize](./examples/custom-report.html) the texts in the 
reports.
+
+<a 
id="Why_does_the_Licenses_report_link_to_my_license_instead_of_showing_its_text"></a>
+
+### Why does the Licenses report link to my license instead of showing its 
text?
+
+Since version 3.10.0, a license given by an `http` or `https` URL is rendered 
as a link instead of being downloaded and inlined, so that building a site does 
not send a request to the server hosting each license. A license in a local 
file, for example `<url>LICENSE.txt</url>` next to the POM, is still inlined.
+
+To download remote licenses and inline their text as before, set 
[`downloadRemoteLicenses`](./licenses-mojo.html#downloadRemoteLicenses) to 
`true`, or pass `-Dlicenses.downloadRemote=true`.
diff --git 
a/src/test/java/org/apache/maven/report/projectinfo/LicensesReportTest.java 
b/src/test/java/org/apache/maven/report/projectinfo/LicensesReportTest.java
index a1ec980..0f9e69f 100644
--- a/src/test/java/org/apache/maven/report/projectinfo/LicensesReportTest.java
+++ b/src/test/java/org/apache/maven/report/projectinfo/LicensesReportTest.java
@@ -92,7 +92,24 @@ class LicensesReportTest extends AbstractProjectInfoTest {
         assertEquals(getString("report.licenses.title"), 
textBlocks[3].getText());
         assertEquals("The Apache Software License, Version 2.0", 
textBlocks[4].getText());
 
-        // only 1 link in default report
+        // a remote license is linked by default, not downloaded
+        final WebLink[] links = response.getLinks();
+        assertEquals(3, links.length);
+        assertEquals("https://www.apache.org/licenses/LICENSE-2.0.txt";, 
links[1].getURLString());
+    }
+
+    @Test
+    @InjectMojo(goal = "licenses", pom = "licenses-plugin-config-download.xml")
+    void testReportDownloadsRemoteLicenseWhenAskedTo(LicensesReport mojo) 
throws Exception {
+        readMavenProjectModel(mavenProject, 
"licenses-plugin-config-download.xml");
+        mojo.execute();
+
+        URL reportURL =
+                
getTestFile("target/licenses-download/licenses.html").toURI().toURL();
+        WebResponse response = WEB_CONVERSATION.getResponse(new 
GetMethodWebRequest(reportURL.toString()));
+        assertTrue(response.isHTML());
+
+        // the license text is inlined: the only link left is the license's 
own one inside the text
         final WebLink[] links = response.getLinks();
         assertEquals(2, links.length);
         assertEquals("https://maven.apache.org/";, links[1].getURLString());
@@ -140,9 +157,9 @@ class LicensesReportTest extends AbstractProjectInfoTest {
      * whatever the session-scoped cache holds for the URL.
      */
     @Test
-    @InjectMojo(goal = "licenses", pom = "licenses-plugin-config.xml")
+    @InjectMojo(goal = "licenses", pom = "licenses-plugin-config-download.xml")
     void testLicenseContentComesFromSessionCache(LicensesReport mojo) throws 
Exception {
-        readMavenProjectModel(mavenProject, "licenses-plugin-config.xml");
+        readMavenProjectModel(mavenProject, 
"licenses-plugin-config-download.xml");
 
         String cachedText = "License text cached earlier in this build 
(MPIR-586)";
         Map<String, Object> cache = new ConcurrentHashMap<>();
@@ -153,7 +170,8 @@ class LicensesReportTest extends AbstractProjectInfoTest {
 
         mojo.execute();
 
-        URL reportURL = 
getTestFile("target/licenses/licenses.html").toURI().toURL();
+        URL reportURL =
+                
getTestFile("target/licenses-download/licenses.html").toURI().toURL();
         WebResponse response = WEB_CONVERSATION.getResponse(new 
GetMethodWebRequest(reportURL.toString()));
         assertTrue(response.getText().contains(cachedText), "report should 
render the cached license text");
         assertEquals(1, cache.size(), "no other URL should have been fetched");
diff --git 
a/src/test/resources/plugin-configs/licenses-plugin-config-download.xml 
b/src/test/resources/plugin-configs/licenses-plugin-config-download.xml
new file mode 100644
index 0000000..7a88f19
--- /dev/null
+++ b/src/test/resources/plugin-configs/licenses-plugin-config-download.xml
@@ -0,0 +1,47 @@
+<!--
+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.plugin.projectinfo.tests</groupId>
+  <artifactId>licenses</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>licenses project info</name>
+  <url>http://maven.apache.org</url>
+  <licenses>
+    <license>
+      <name>The Apache Software License, Version 2.0</name>
+      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <configuration>
+          <outputDirectory>target/licenses-download</outputDirectory>
+          <downloadRemoteLicenses>true</downloadRemoteLicenses>
+          <offline>false</offline>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Reply via email to