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 java.util.Iterator;
23 import java.util.List;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugins.annotations.Execute;
27 import org.apache.maven.plugins.annotations.LifecyclePhase;
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.Parameter;
30
31
32
33
34
35
36
37 @Mojo( name = "validate", requiresProject = false )
38 @Execute( phase = LifecyclePhase.VALIDATE )
39 public class ValidateMojo
40 extends AbstractScmMojo
41 {
42
43
44
45 @Parameter( property = "scmConnection", defaultValue = "${project.scm.connection}" )
46 private String scmConnection;
47
48
49
50
51 @Parameter( property = "scmDeveloperConnection", defaultValue = "${project.scm.developerConnection}" )
52 private String scmDeveloperConnection;
53
54
55
56
57
58 @Parameter( property = "scmCheckWorkingDirectoryUrl", defaultValue = "false" )
59
60
61 private boolean scmCheckWorkingDirectoryUrl;
62
63
64 public void execute()
65 throws MojoExecutionException
66 {
67 super.execute();
68
69
70 try
71 {
72 validateConnection( getConnectionUrl(), "connectionUrl" );
73 }
74 catch ( NullPointerException e )
75 {
76
77 }
78
79
80 if ( scmConnection != null )
81 {
82 validateConnection( scmConnection, "project.scm.connection" );
83 }
84
85
86 if ( scmDeveloperConnection != null )
87 {
88 validateConnection( scmDeveloperConnection, "project.scm.developerConnection" );
89 }
90
91 }
92
93 private void validateConnection( String connectionString, String type )
94 throws MojoExecutionException
95 {
96 List<String> messages = getScmManager().validateScmRepository( connectionString );
97
98 if ( !messages.isEmpty() )
99 {
100 getLog().error( "Validation of scm url connection (" + type + ") failed :" );
101
102 Iterator<String> iter = messages.iterator();
103
104 while ( iter.hasNext() )
105 {
106 getLog().error( iter.next().toString() );
107 }
108
109 getLog().error( "The invalid scm url connection: '" + connectionString + "'." );
110
111 throw new MojoExecutionException( "Command failed. Bad Scm URL." );
112 }
113 else
114 {
115 getLog().info( type + " scm connection string is valid." );
116 }
117 }
118 }