View Javadoc

1   package org.apache.maven.scm.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /**
28   * Validate scm connection string.
29   *
30   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
31   * @version $Id: ValidateMojo.java 533717 2007-04-30 12:12:41Z evenisse $
32   * @goal validate
33   * @execute phase="validate"
34   * @requiresProject false
35   */
36  public class ValidateMojo
37      extends AbstractScmMojo
38  {
39      /**
40       * The scm connection url.
41       *
42       * @parameter expression="${scmConnection}" default-value="${project.scm.connection}"
43       */
44      private String scmConnection;
45  
46      /**
47       * The scm connection url for developers.
48       *
49       * @parameter expression="${scmDeveloperConnection}" default-value="${project.scm.developerConnection}"
50       */
51      private String scmDeveloperConnection;
52  
53      public void execute()
54          throws MojoExecutionException
55      {
56          super.execute();
57  
58          //check connectionUrl provided with cli
59          try
60          {
61              validateConnection( getConnectionUrl(), "connectionUrl" );
62          }
63          catch ( NullPointerException e )
64          {
65              // nothing to do. connectionUrl isn't defined
66          }
67  
68          //check scm connection
69          if ( scmConnection != null )
70          {
71              validateConnection( scmConnection, "project.scm.connection" );
72          }
73  
74          // Check scm developerConnection
75          if ( scmDeveloperConnection != null )
76          {
77              validateConnection( scmDeveloperConnection, "project.scm.developerConnection" );
78          }
79  
80      }
81  
82      private void validateConnection( String connectionString, String type )
83          throws MojoExecutionException
84      {
85          List messages = getScmManager().validateScmRepository( connectionString );
86  
87          if ( !messages.isEmpty() )
88          {
89              getLog().error( "Validation of scm url connection (" + type + ") failed :" );
90  
91              Iterator iter = messages.iterator();
92  
93              while ( iter.hasNext() )
94              {
95                  getLog().error( iter.next().toString() );
96              }
97  
98              getLog().error( "The invalid scm url connection: '" + connectionString + "'." );
99  
100             throw new MojoExecutionException( "Command failed. Bad Scm URL." );
101         }
102         else
103         {
104             getLog().info( type + " scm connection string is valid." );
105         }
106     }
107 }