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/01/26 09:41:39 UTC
[maven-project-info-reports-plugin] branch master updated: [MPIR-404] Warn and accept invalid mailing list links
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 82ea244 [MPIR-404] Warn and accept invalid mailing list links
82ea244 is described below
commit 82ea24458afcab14f2cbbbc165d64114b7454640
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Aug 10 12:16:44 2021 +0200
[MPIR-404] Warn and accept invalid mailing list links
This closes #28
---
.../report/projectinfo/MailingListsReport.java | 27 +++++++----
.../report/projectinfo/MailingListsReportTest.java | 12 +++++
.../stubs/MailingListsInvalidLinkStub.java | 30 ++++++++++++
.../mailing-lists-plugin-config-invalidlink.xml | 55 ++++++++++++++++++++++
4 files changed, 116 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
index f0fef47..6e138d9 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
@@ -22,6 +22,7 @@ package org.apache.maven.report.projectinfo;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;
@@ -63,7 +64,7 @@ public class MailingListsReport
public void executeReport( Locale locale )
{
MailingListsRenderer r =
- new MailingListsRenderer( getSink(), getProject().getModel(), getI18N( locale ), locale );
+ new MailingListsRenderer( getLog(), getSink(), getProject().getModel(), getI18N( locale ), locale );
r.render();
}
@@ -92,13 +93,15 @@ public class MailingListsReport
protected static class MailingListsRenderer
extends AbstractProjectInfoRenderer
{
+
+ private final Log log;
private final Model model;
- MailingListsRenderer( Sink sink, Model model, I18N i18n, Locale locale )
+ MailingListsRenderer( Log log, Sink sink, Model model, I18N i18n, Locale locale )
{
super( sink, i18n, locale );
this.model = model;
-
+ this.log = log;
}
@Override
@@ -279,14 +282,22 @@ public class MailingListsReport
return createLinkPatternedText( text, defaultHref );
}
- URI hrefUri = URI.create( href );
- if ( StringUtils.isNotEmpty( hrefUri.getScheme() ) )
+ try
{
- return createLinkPatternedText( text, href );
+ URI hrefUri = URI.create( href );
+ if ( StringUtils.isNotEmpty( hrefUri.getScheme() ) )
+ {
+ return createLinkPatternedText( text, href );
+ }
+ else
+ {
+ return createLinkPatternedText( text, "mailto:" + href );
+ }
}
- else
+ catch ( IllegalArgumentException e )
{
- return createLinkPatternedText( text, "mailto:" + href );
+ log.warn( "Invalid mailing list link provided '" + href + "': " + e.getMessage() );
+ return href;
}
}
}
diff --git a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
index 3437f88..aba5387 100644
--- a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
+++ b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
@@ -111,4 +111,16 @@ public class MailingListsReportTest
Locale.setDefault( oldLocale );
}
}
+
+ /**
+ * Test invalid links (MPIR-404)
+ * Those should only lead to a WARN but not an exception
+ * @throws Exception if any
+ */
+ public void testInvalidLink()
+ throws Exception
+ {
+ generateReport( "mailing-lists", "mailing-lists-plugin-config-invalidlink.xml" );
+ assertTrue( "Test html generated", getGeneratedReport( "mailing-lists.html" ).exists() );
+ }
}
diff --git a/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsInvalidLinkStub.java b/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsInvalidLinkStub.java
new file mode 100644
index 0000000..565edb1
--- /dev/null
+++ b/src/test/java/org/apache/maven/report/projectinfo/stubs/MailingListsInvalidLinkStub.java
@@ -0,0 +1,30 @@
+package org.apache.maven.report.projectinfo.stubs;
+
+/*
+ * 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.
+ */
+
+public class MailingListsInvalidLinkStub
+ extends ProjectInfoProjectStub
+{
+ @Override
+ protected String getPOM()
+ {
+ return "mailing-lists-plugin-config-invalidlink.xml";
+ }
+}
diff --git a/src/test/resources/plugin-configs/mailing-lists-plugin-config-invalidlink.xml b/src/test/resources/plugin-configs/mailing-lists-plugin-config-invalidlink.xml
new file mode 100644
index 0000000..6f4cde9
--- /dev/null
+++ b/src/test/resources/plugin-configs/mailing-lists-plugin-config-invalidlink.xml
@@ -0,0 +1,55 @@
+<!--
+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>mailing-lists</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>mailing lists project info</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <mailingLists>
+ <mailingList>
+ <name>Test List</name>
+ <!-- invalid link to prevent easy scraping -->
+ <post>test at maven.apache.org</post>
+ <subscribe>MAILTO:test-subscribe@maven.apache.org</subscribe>
+ </mailingList>
+ </mailingLists>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <configuration>
+ <outputDirectory>target/test-harness/mailing-lists</outputDirectory>
+ <localRepository>${localRepository}</localRepository>
+ <project implementation="org.apache.maven.report.projectinfo.stubs.MailingListsInvalidLinkStub"/>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>