Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPIR-404] accept invalid mailing list links #28

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
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;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -63,7 +65,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 +94,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 +283,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 = new URI( href );
if ( StringUtils.isNotEmpty( hrefUri.getScheme() ) )
{
return createLinkPatternedText( text, href );
}
else
{
return createLinkPatternedText( text, "mailto:" + href );
}
}
else
catch ( URISyntaxException 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
*/
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,33 @@
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.
*/

/**
* @version $Id$
*/
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>