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 @Parameter(property = "scmCheckWorkingDirectoryUrl", defaultValue = "false")
58
59
60 private boolean scmCheckWorkingDirectoryUrl;
61
62
63 public void execute()
64 throws MojoExecutionException
65 {
66 super.execute();
67
68
69 try
70 {
71 validateConnection( getConnectionUrl(), "connectionUrl" );
72 }
73 catch ( NullPointerException e )
74 {
75
76 }
77
78
79 if ( scmConnection != null )
80 {
81 validateConnection( scmConnection, "project.scm.connection" );
82 }
83
84
85 if ( scmDeveloperConnection != null )
86 {
87 validateConnection( scmDeveloperConnection, "project.scm.developerConnection" );
88 }
89
90 }
91
92 private void validateConnection( String connectionString, String type )
93 throws MojoExecutionException
94 {
95 List<String> messages = getScmManager().validateScmRepository( connectionString );
96
97 if ( !messages.isEmpty() )
98 {
99 getLog().error( "Validation of scm url connection (" + type + ") failed :" );
100
101 Iterator<String> iter = messages.iterator();
102
103 while ( iter.hasNext() )
104 {
105 getLog().error( iter.next().toString() );
106 }
107
108 getLog().error( "The invalid scm url connection: '" + connectionString + "'." );
109
110 throw new MojoExecutionException( "Command failed. Bad Scm URL." );
111 }
112 else
113 {
114 getLog().info( type + " scm connection string is valid." );
115 }
116 }
117 }