1 package org.apache.maven.scm.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23
24 import java.util.Iterator;
25 import java.util.List;
26
27
28
29
30
31
32
33
34
35
36 public class ValidateMojo
37 extends AbstractScmMojo
38 {
39
40
41
42
43
44 private String scmConnection;
45
46
47
48
49
50
51 private String scmDeveloperConnection;
52
53 public void execute()
54 throws MojoExecutionException
55 {
56 super.execute();
57
58
59 try
60 {
61 validateConnection( getConnectionUrl(), "connectionUrl" );
62 }
63 catch ( NullPointerException e )
64 {
65
66 }
67
68
69 if ( scmConnection != null )
70 {
71 validateConnection( scmConnection, "project.scm.connection" );
72 }
73
74
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 }