MNG-695: Added more tests on anonymousConnection, devConnection and scmUrl to prevent NPE. Added the test case num 11.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@230612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vincent Siveton 2005-08-07 00:07:50 +00:00
parent f862da60b6
commit 08da2ff248
2 changed files with 88 additions and 3 deletions

View File

@ -196,6 +196,19 @@ public class ScmReport
anonymousConnection = scm.getConnection();
devConnection = scm.getDeveloperConnection();
if ( StringUtils.isEmpty( anonymousConnection ) &&
StringUtils.isEmpty( devConnection ) &&
StringUtils.isEmpty( scm.getUrl() ) )
{
startSection( getTitle() );
paragraph( getBundle( locale ).getString( "report.scm.noscm" ) );
endSection();
return;
}
ScmRepository anonymousRepository = getScmRepository( anonymousConnection );
ScmRepository devRepository = getScmRepository( devConnection );
@ -264,7 +277,7 @@ public class ScmReport
{
startSection( getBundle( locale ).getString( "report.scm.webaccess.title" ) );
if ( scmUrl == null )
if ( StringUtils.isEmpty( scmUrl ) )
{
paragraph( getBundle( locale ).getString( "report.scm.webaccess.nourl" ) );
}
@ -288,7 +301,8 @@ public class ScmReport
{
if ( ( isScmSystem( anonymousRepository, "clearcase" ) )
|| ( isScmSystem( anonymousRepository, "perforce" ) )
|| ( isScmSystem( anonymousRepository, "starteam" ) ) )
|| ( isScmSystem( anonymousRepository, "starteam" ) )
|| ( StringUtils.isEmpty( anonymousConnection ) ) )
{
return;
}
@ -313,6 +327,11 @@ public class ScmReport
{
paragraph( getBundle( locale ).getString( "report.scm.anonymousaccess.general.intro" ) );
if ( anonymousConnection.length() < 4 )
{
throw new IllegalArgumentException( "The source repository connection is too short." );
}
verbatimText( anonymousConnection.substring( 4 ) );
}
@ -326,6 +345,11 @@ public class ScmReport
*/
private void renderDeveloperAccessSection( ScmRepository devRepository )
{
if ( StringUtils.isEmpty( devConnection ) )
{
return;
}
startSection( getBundle( locale ).getString( "report.scm.devaccess.title" ) );
if ( ( devRepository != null ) && ( isScmSystem( devRepository, "clearcase" ) ) )
@ -365,6 +389,11 @@ public class ScmReport
{
paragraph( getBundle( locale ).getString( "report.scm.devaccess.general.intro" ) );
if ( devConnection.length() < 4 )
{
throw new IllegalArgumentException( "The source repository connection is too short." );
}
verbatimText( devConnection.substring( 4 ) );
}
@ -622,7 +651,7 @@ public class ScmReport
*/
public ScmRepository getScmRepository( String scmUrl )
{
if ( scmUrl == null )
if ( StringUtils.isEmpty( scmUrl ) )
{
return null;
}

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed 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>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.report.projectinfo.test11</groupId>
<artifactId>project-info-reports-plugin-test11</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2005</inceptionYear>
<name>Maven ProjectInfo Report Test11</name>
<description>MNG-695 developerConnection is empty</description>
<url>http://maven.apache.org</url>
<scm>
<connection>scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven-plugins/dist</connection>
<developerConnection/>
<url>http://cvs.apache.org/</url>
</scm>
<developers>
<developer>
<id>vsiveton</id>
<name>Vincent Siveton</name>
<email>vsiveton@apache.org</email>
<organization>Apache Software Foundation</organization>
<roles>
<role>Java Developer</role>
</roles>
<timezone>-5</timezone>
</developer>
</developers>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>