| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ValidateMojo |
|
| 4.0;4 |
| 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 | * @author Olivier Lamy | |
| 32 | * @version $Id: ValidateMojo.java 1054215 2011-01-01 09:45:44Z olamy $ | |
| 33 | * @goal validate | |
| 34 | * @execute phase="validate" | |
| 35 | * @requiresProject false | |
| 36 | */ | |
| 37 | 0 | public class ValidateMojo |
| 38 | extends AbstractScmMojo | |
| 39 | { | |
| 40 | /** | |
| 41 | * The scm connection url. | |
| 42 | * | |
| 43 | * @parameter expression="${scmConnection}" default-value="${project.scm.connection}" | |
| 44 | */ | |
| 45 | private String scmConnection; | |
| 46 | ||
| 47 | /** | |
| 48 | * The scm connection url for developers. | |
| 49 | * | |
| 50 | * @parameter expression="${scmDeveloperConnection}" default-value="${project.scm.developerConnection}" | |
| 51 | */ | |
| 52 | private String scmDeveloperConnection; | |
| 53 | ||
| 54 | /** {@inheritDoc} */ | |
| 55 | public void execute() | |
| 56 | throws MojoExecutionException | |
| 57 | { | |
| 58 | 0 | super.execute(); |
| 59 | ||
| 60 | //check connectionUrl provided with cli | |
| 61 | try | |
| 62 | { | |
| 63 | 0 | validateConnection( getConnectionUrl(), "connectionUrl" ); |
| 64 | } | |
| 65 | 0 | catch ( NullPointerException e ) |
| 66 | { | |
| 67 | // nothing to do. connectionUrl isn't defined | |
| 68 | 0 | } |
| 69 | ||
| 70 | //check scm connection | |
| 71 | 0 | if ( scmConnection != null ) |
| 72 | { | |
| 73 | 0 | validateConnection( scmConnection, "project.scm.connection" ); |
| 74 | } | |
| 75 | ||
| 76 | // Check scm developerConnection | |
| 77 | 0 | if ( scmDeveloperConnection != null ) |
| 78 | { | |
| 79 | 0 | validateConnection( scmDeveloperConnection, "project.scm.developerConnection" ); |
| 80 | } | |
| 81 | ||
| 82 | 0 | } |
| 83 | ||
| 84 | private void validateConnection( String connectionString, String type ) | |
| 85 | throws MojoExecutionException | |
| 86 | { | |
| 87 | 0 | List<String> messages = getScmManager().validateScmRepository( connectionString ); |
| 88 | ||
| 89 | 0 | if ( !messages.isEmpty() ) |
| 90 | { | |
| 91 | 0 | getLog().error( "Validation of scm url connection (" + type + ") failed :" ); |
| 92 | ||
| 93 | 0 | Iterator<String> iter = messages.iterator(); |
| 94 | ||
| 95 | 0 | while ( iter.hasNext() ) |
| 96 | { | |
| 97 | 0 | getLog().error( iter.next().toString() ); |
| 98 | } | |
| 99 | ||
| 100 | 0 | getLog().error( "The invalid scm url connection: '" + connectionString + "'." ); |
| 101 | ||
| 102 | 0 | throw new MojoExecutionException( "Command failed. Bad Scm URL." ); |
| 103 | } | |
| 104 | else | |
| 105 | { | |
| 106 | 0 | getLog().info( type + " scm connection string is valid." ); |
| 107 | } | |
| 108 | 0 | } |
| 109 | } |