View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.maven.plugins.externals;
17  
18  import java.io.File;
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.swing.tree.DefaultMutableTreeNode;
23  
24  import org.apache.maven.plugin.AbstractMojo;
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.project.MavenProject;
27  
28  /**
29   * Make sure the aggregate checkout is "self-contained". Make sure the parent versions of the svn:externals modules point back to the correct root pom. Make sure the properties
30   * used to figure out which version of the child modules to use, actually match up with the versions declared in the child modules.
31   * 
32   * @goal validatepoms
33   */
34  public class ValidatePomsMojo extends AbstractMojo {
35  
36  	SVNUtils svnUtils = SVNUtils.getInstance();
37  	MojoHelper helper = MojoHelper.getInstance();
38  
39  	/**
40  	 * Filename pattern used to discover Maven pom's
41  	 * 
42  	 * @parameter expression="${externals.pom}" default-value="pom.xml"
43  	 */
44  	private String pom;
45  
46  	/**
47  	 * Directories to ignore when examining the file system for Maven pom's
48  	 * 
49  	 * @parameter expression="${externals.ignoreDirectories}" default-value="src,target,overlays,.svn,.git"
50  	 */
51  	private String ignoreDirectories;
52  
53  	/**
54  	 * The Maven project object
55  	 * 
56  	 * @parameter expression="${project}"
57  	 * @readonly
58  	 */
59  	private MavenProject project;
60  
61  	/**
62  	 * These mappings connect the svn:externals definitions with a property inside the root pom that controls what version each external is set to
63  	 * 
64  	 * @parameter
65  	 */
66  	private List<Mapping> mappings;
67  
68  	@Override
69  	public void execute() throws MojoExecutionException {
70  		List<File> files = helper.getPoms(project.getBasedir(), pom, ignoreDirectories);
71  		List<DefaultMutableTreeNode> nodes = helper.getNodes(files);
72  		// Since this tree is based on the file system directory structure, it should always be a perfect tree
73  		DefaultMutableTreeNode node = helper.getTree(project.getBasedir(), nodes, pom);
74  		// Make sure each GAV is fully populated
75  		helper.fillInGavs(node);
76  		// Populate a map keyed by the GAV id
77  		Map<String, DefaultMutableTreeNode> map = helper.getGavMap(node);
78  		// Validate that all of the parents are contained in the map
79  		helper.validateParents(node, map);
80  		helper.validateMappings(project.getProperties(), mappings, node);
81  		int depth = node.getDepth();
82  		int size = nodes.size();
83  		getLog().info("Validated " + size + " POM's.  Multi-module Maven project depth: " + depth);
84  	}
85  
86  	public String getPom() {
87  		return pom;
88  	}
89  
90  	public void setPom(String pom) {
91  		this.pom = pom;
92  	}
93  
94  	public String getIgnoreDirectories() {
95  		return ignoreDirectories;
96  	}
97  
98  	public void setIgnoreDirectories(String ignoreDirectories) {
99  		this.ignoreDirectories = ignoreDirectories;
100 	}
101 
102 	public MavenProject getProject() {
103 		return project;
104 	}
105 
106 	public void setProject(MavenProject project) {
107 		this.project = project;
108 	}
109 
110 	public List<Mapping> getMappings() {
111 		return mappings;
112 	}
113 
114 	public void setMappings(List<Mapping> mappings) {
115 		this.mappings = mappings;
116 	}
117 }