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
37 public class ValidateMojo
38 extends AbstractScmMojo
39 {
40
41
42
43
44
45 private String scmConnection;
46
47
48
49
50
51
52 private String scmDeveloperConnection;
53
54
55 public void execute()
56 throws MojoExecutionException
57 {
58 super.execute();
59
60
61 try
62 {
63 validateConnection( getConnectionUrl(), "connectionUrl" );
64 }
65 catch ( NullPointerException e )
66 {
67
68 }
69
70
71 if ( scmConnection != null )
72 {
73 validateConnection( scmConnection, "project.scm.connection" );
74 }
75
76
77 if ( scmDeveloperConnection != null )
78 {
79 validateConnection( scmDeveloperConnection, "project.scm.developerConnection" );
80 }
81
82 }
83
84 private void validateConnection( String connectionString, String type )
85 throws MojoExecutionException
86 {
87 List<String> messages = getScmManager().validateScmRepository( connectionString );
88
89 if ( !messages.isEmpty() )
90 {
91 getLog().error( "Validation of scm url connection (" + type + ") failed :" );
92
93 Iterator<String> iter = messages.iterator();
94
95 while ( iter.hasNext() )
96 {
97 getLog().error( iter.next().toString() );
98 }
99
100 getLog().error( "The invalid scm url connection: '" + connectionString + "'." );
101
102 throw new MojoExecutionException( "Command failed. Bad Scm URL." );
103 }
104 else
105 {
106 getLog().info( type + " scm connection string is valid." );
107 }
108 }
109 }