Debian Codegraph @

maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ValidateMojo.java

raw
1 package org.apache.maven.scm.plugin;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 import org.apache.maven.scm.provider.svn.AbstractSvnScmProvider;
29
30 import java.util.Iterator;
31 import java.util.List;
32
33 /**
34 * Validate scm connection string.
35 *
36 * @author <a href="[email protected]">Emmanuel Venisse</a>
37 * @author Olivier Lamy
38 */
39 @Mojo( name = "validate", requiresProject = false )
40 @Execute( phase = LifecyclePhase.VALIDATE )
41 public class ValidateMojo
42 extends AbstractScmMojo
43 {
44 /**
45 * The scm connection url.
46 */
47 @Parameter( property = "scmConnection", defaultValue = "${project.scm.connection}" )
48 private String scmConnection;
49
50 @Parameter( defaultValue = "${project}", readonly = true )
51 private MavenProject project;
52
53 /**
54 * The scm connection url for developers.
55 */
56 @Parameter( property = "scmDeveloperConnection", defaultValue = "${project.scm.developerConnection}" )
57 private String scmDeveloperConnection;
58
59 /**
60 * <em>(Subversion specific)</em> Enables checking that "URL" field returned by 'svn info' matches what is
61 * specified under the scm tag.
62 * @see AbstractSvnScmProvider#CURRENT_WORKING_DIRECTORY
63 */
64 @Parameter( property = "scmCheckWorkingDirectoryUrl", defaultValue = "false" )
65 private boolean scmCheckWorkingDirectoryUrl;
66
67 /**
68 * {@inheritDoc}
69 */
70 public void execute()
71 throws MojoExecutionException
72 {
73 super.execute();
74
75 //check connectionUrl provided with cli
76 try
77 {
78 validateConnection( getConnectionUrl(), "connectionUrl" );
79 }
80 catch ( NullPointerException e )
81 {
82 // nothing to do. connectionUrl isn't defined
83 }
84
85 //check scm connection
86 if ( scmConnection != null )
87 {
88 validateConnection( scmConnection, "project.scm.connection" );
89 }
90
91 // Check scm developerConnection
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( AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY,
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 }