You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/07/04 23:11:07 UTC
svn commit: r674123 - in
/maven/plugins/trunk/maven-project-info-reports-plugin/src:
main/java/org/apache/maven/report/projectinfo/
test/java/org/apache/maven/report/projectinfo/ test/resources/plugin-configs/
Author: vsiveton
Date: Fri Jul 4 14:11:06 2008
New Revision: 674123
URL: http://svn.apache.org/viewvc?rev=674123&view=rev
Log:
MPIR-108: Add validation of SCM urls
o validated SCM urls
o added test case
Added:
maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml (with props)
Modified:
maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java
maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ScmReportTest.java
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java?rev=674123&r1=674122&r2=674123&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ScmReport.java Fri Jul 4 14:11:06 2008
@@ -35,10 +35,13 @@
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Locale;
/**
- * Generates the Project Source Code Management report.
+ * Generates the Project Source Code Management (SCM) report.
*
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
* @version $Id$
@@ -62,7 +65,7 @@
protected ScmManager scmManager;
/**
- * The directory name to checkout right after the scm url
+ * The directory name to checkout right after the SCM url.
*
* @parameter expression="${project.artifactId}"
* @required
@@ -70,23 +73,25 @@
private String checkoutDirectoryName;
/**
- * The scm anonymous connection url.
+ * The SCM anonymous connection url respecting the SCM URL Format.
*
* @parameter default-value="${project.scm.connection}"
* @since 2.1
+ * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
*/
private String anonymousConnection;
/**
- * The scm developer connection url.
+ * The SCM developer connection url respecting the SCM URL Format.
*
* @parameter default-value="${project.scm.developerConnection}"
* @since 2.1
+ * @see <a href="http://maven.apache.org/scm/scm-url-format.html">SCM URL Format< /a>
*/
private String developerConnection;
/**
- * The scm web access url.
+ * The SCM web access url.
*
* @parameter default-value="${project.scm.url}"
* @since 2.1
@@ -294,7 +299,7 @@
/**
* Render the anonymous access section depending the repository.
- * <p>Note: ClearCase, Starteam et Perforce seems to have no anonymous access.</>
+ * <p>Note: ClearCase, Starteam et Perforce seems to have no anonymous access.</p>
*
* @param anonymousRepository the anonymous repository
*/
@@ -326,11 +331,6 @@
{
paragraph( i18n.getString( "project-info-report", locale, "report.scm.anonymousaccess.general.intro" ) );
- if ( anonymousConnection.length() < 4 )
- {
- throw new IllegalArgumentException( "The source repository connection is too short." );
- }
-
verbatimText( anonymousConnection.substring( 4 ) );
}
@@ -385,11 +385,6 @@
{
paragraph( i18n.getString( "project-info-report", locale, "report.scm.devaccess.general.intro" ) );
- if ( devConnection.length() < 4 )
- {
- throw new IllegalArgumentException( "The source repository connection is too short." );
- }
-
verbatimText( devConnection.substring( 4 ) );
}
@@ -660,26 +655,81 @@
*/
public ScmRepository getScmRepository( String scmUrl )
{
+ if ( StringUtils.isEmpty( scmUrl ) )
+ {
+ return null;
+ }
+
ScmRepository repo = null;
- if ( !StringUtils.isEmpty( scmUrl ) )
+ List messages = new ArrayList();
+ try
{
- try
- {
- repo = scmManager.makeScmRepository( scmUrl );
- }
- catch ( NoSuchScmProviderException e )
+ messages.addAll( scmManager.validateScmRepository( scmUrl ) );
+ }
+ catch ( Exception e )
+ {
+ messages.add( e.getMessage() );
+ }
+
+ if ( messages.size() > 0 )
+ {
+ StringBuffer sb = new StringBuffer();
+ boolean isIntroAdded = false;
+ for ( Iterator it = messages.iterator(); it.hasNext(); )
{
- if ( log.isDebugEnabled() )
+ String msg = it.next().toString();
+
+ // Ignore NoSuchScmProviderException msg
+ // See impl of AbstractScmManager#validateScmRepository()
+ if ( msg.startsWith( "No such provider" ) )
{
- log.debug( e.getMessage(), e );
+ continue;
}
- }
- catch ( ScmRepositoryException e )
- {
- if ( log.isDebugEnabled() )
+
+ if ( !isIntroAdded )
{
- log.debug( e.getMessage(), e );
+ sb.append( "This SCM url '" + scmUrl + "' is invalid due to the following errors:" );
+ sb.append( "\n" );
+ isIntroAdded = true;
}
+ sb.append( " * " );
+ sb.append( msg );
+ sb.append( "\n" );
+ }
+
+ if ( StringUtils.isNotEmpty( sb.toString() ) )
+ {
+ sb.append( "For more information about SCM URL Format, please refer to: "
+ + "http://maven.apache.org/scm/scm-url-format.html" );
+
+ throw new IllegalArgumentException( sb.toString() );
+ }
+ }
+
+ try
+ {
+ repo = scmManager.makeScmRepository( scmUrl );
+ }
+ catch ( NoSuchScmProviderException e )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( e.getMessage(), e );
+ }
+ }
+ catch ( ScmRepositoryException e )
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( e.getMessage(), e );
+ }
+ }
+ catch ( Exception e )
+ {
+ // Should be already catched
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( e.getMessage(), e );
}
}
Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ScmReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ScmReportTest.java?rev=674123&r1=674122&r2=674123&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ScmReportTest.java (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ScmReportTest.java Fri Jul 4 14:11:06 2008
@@ -19,8 +19,11 @@
* under the License.
*/
+import java.io.File;
import java.net.URL;
+import org.apache.maven.plugin.Mojo;
+
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.TextBlock;
import com.meterware.httpunit.WebConversation;
@@ -78,4 +81,60 @@
assertEquals( getString( "report.scm.accessbehindfirewall.title" ), textBlocks[4].getText() );
assertEquals( getString( "report.scm.accessbehindfirewall.general.intro" ), textBlocks[5].getText() );
}
+
+ /**
+ * Test report with wrong URL
+ *
+ * @throws Exception if any
+ */
+ public void testReportWithWrongUrl()
+ throws Exception
+ {
+ File pluginXmlFile = new File( getBasedir(), "src/test/resources/plugin-configs/" + "scm-wrong-url-plugin-config.xml" );
+ Mojo mojo = lookupMojo( "scm", pluginXmlFile );
+ assertNotNull( "Mojo found.", mojo );
+
+ setVariableValueToObject( mojo, "anonymousConnection", "scm:svn" );
+ try
+ {
+ mojo.execute();
+ assertTrue( "IllegalArgumentException NOT catched", false );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ assertTrue( "IllegalArgumentException catched", true );
+ }
+
+ tearDown();
+ setUp();
+
+ mojo = lookupMojo( "scm", pluginXmlFile );
+ assertNotNull( "Mojo found.", mojo );
+ setVariableValueToObject( mojo, "anonymousConnection", "scm:svn:http" );
+ try
+ {
+ mojo.execute();
+ assertTrue( "IllegalArgumentException NOT catched", false );
+ }
+ catch ( Exception e )
+ {
+ assertTrue( "IllegalArgumentException catched", true );
+ }
+
+ tearDown();
+ setUp();
+
+ mojo = lookupMojo( "scm", pluginXmlFile );
+ assertNotNull( "Mojo found.", mojo );
+ setVariableValueToObject( mojo, "anonymousConnection", "scm" );
+ try
+ {
+ mojo.execute();
+ assertTrue( "IllegalArgumentException NOT catched", false );
+ }
+ catch ( Exception e )
+ {
+ assertTrue( "IllegalArgumentException catched", true );
+ }
+ }
}
Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml?rev=674123&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml Fri Jul 4 14:11:06 2008
@@ -0,0 +1,49 @@
+<!--
+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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
+ <artifactId>scm</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>scm project info</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <configuration>
+ <outputDirectory>target/test-harness/scm</outputDirectory>
+ <project implementation="org.apache.maven.report.projectinfo.stubs.ScmStub"/>
+ <localRepository>${localRepository}</localRepository>
+ <checkoutDirectoryName>test-artifactId</checkoutDirectoryName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/scm-wrong-url-plugin-config.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision