Skip to content

Commit

Permalink
[MPIR-404] Warn and accept invalid mailing list links
Browse files Browse the repository at this point in the history
This closes #28
  • Loading branch information
kwin authored and michael-o committed Jan 26, 2022
1 parent cf0c168 commit 82ea244
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -63,7 +64,7 @@ public boolean canGenerateReport()
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();
}
Expand Down Expand Up @@ -92,13 +93,15 @@ protected String getI18Nsection()
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
Expand Down Expand Up @@ -279,14 +282,22 @@ private String createURILinkPatternedText( String text, String href, String defa
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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ public void testFrenchReport()
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() );
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 82ea244

Please sign in to comment.