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