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