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 | * @version $Id: ValidateMojo.java 533717 2007-04-30 12:12:41Z evenisse $ | |
32 | * @goal validate | |
33 | * @execute phase="validate" | |
34 | * @requiresProject false | |
35 | */ | |
36 | 3 | 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 | 3 | super.execute(); |
57 | ||
58 | //check connectionUrl provided with cli | |
59 | try | |
60 | { | |
61 | 3 | validateConnection( getConnectionUrl(), "connectionUrl" ); |
62 | } | |
63 | 3 | catch ( NullPointerException e ) |
64 | { | |
65 | // nothing to do. connectionUrl isn't defined | |
66 | 0 | } |
67 | ||
68 | //check scm connection | |
69 | 3 | if ( scmConnection != null ) |
70 | { | |
71 | 2 | validateConnection( scmConnection, "project.scm.connection" ); |
72 | } | |
73 | ||
74 | // Check scm developerConnection | |
75 | 2 | if ( scmDeveloperConnection != null ) |
76 | { | |
77 | 1 | validateConnection( scmDeveloperConnection, "project.scm.developerConnection" ); |
78 | } | |
79 | ||
80 | 2 | } |
81 | ||
82 | private void validateConnection( String connectionString, String type ) | |
83 | throws MojoExecutionException | |
84 | { | |
85 | 3 | List messages = getScmManager().validateScmRepository( connectionString ); |
86 | ||
87 | 3 | if ( !messages.isEmpty() ) |
88 | { | |
89 | 1 | getLog().error( "Validation of scm url connection (" + type + ") failed :" ); |
90 | ||
91 | 1 | Iterator iter = messages.iterator(); |
92 | ||
93 | 2 | while ( iter.hasNext() ) |
94 | { | |
95 | 1 | getLog().error( iter.next().toString() ); |
96 | } | |
97 | ||
98 | 1 | getLog().error( "The invalid scm url connection: '" + connectionString + "'." ); |
99 | ||
100 | 1 | throw new MojoExecutionException( "Command failed. Bad Scm URL." ); |
101 | } | |
102 | else | |
103 | { | |
104 | 2 | getLog().info( type + " scm connection string is valid." ); |
105 | } | |
106 | 2 | } |
107 | } |