All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.maven.plugins.externals.ValidatePomsMojo Maven / Gradle / Ivy

/**
 * Copyright 2011-2012 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.maven.plugins.externals;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.swing.tree.DefaultMutableTreeNode;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

/**
 * 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
 * used to figure out which version of the child modules to use, actually match up with the versions declared in the child modules.
 * 
 * @goal validatepoms
 */
public class ValidatePomsMojo extends AbstractMojo {

	SVNUtils svnUtils = SVNUtils.getInstance();
	MojoHelper helper = MojoHelper.getInstance();

	/**
	 * Filename pattern used to discover Maven pom's
	 * 
	 * @parameter expression="${externals.pom}" default-value="pom.xml"
	 */
	private String pom;

	/**
	 * Directories to ignore when examining the file system for Maven pom's
	 * 
	 * @parameter expression="${externals.ignoreDirectories}" default-value="src,target,.svn,.git"
	 */
	private String ignoreDirectories;

	/**
	 * The Maven project object
	 * 
	 * @parameter expression="${project}"
	 * @readonly
	 */
	private MavenProject project;

	/**
	 * These mappings connect the svn:externals definitions with a property inside the root pom that controls what version each external is set to
	 * 
	 * @parameter
	 */
	private List mappings;

	@Override
	public void execute() throws MojoExecutionException {
		List files = helper.getPoms(project.getBasedir(), pom, ignoreDirectories);
		List nodes = helper.getNodes(files);
		// Since this tree is based on the file system directory structure, it should always be a perfect tree
		DefaultMutableTreeNode node = helper.getTree(project.getBasedir(), nodes, pom);
		// Make sure each GAV is fully populated
		helper.fillInGavs(node);
		// Populate a map keyed by the GAV id
		Map map = helper.getGavMap(node);
		// Validate that all of the parents are contained in the map
		helper.validateParents(node, map);
		helper.validateMappings(project.getProperties(), mappings, node);
		int depth = node.getDepth();
		int size = nodes.size();
		getLog().info("Validated " + size + " POM's.  Multi-module Maven project depth: " + depth);
	}

	public String getPom() {
		return pom;
	}

	public void setPom(String pom) {
		this.pom = pom;
	}

	public String getIgnoreDirectories() {
		return ignoreDirectories;
	}

	public void setIgnoreDirectories(String ignoreDirectories) {
		this.ignoreDirectories = ignoreDirectories;
	}

	public MavenProject getProject() {
		return project;
	}

	public void setProject(MavenProject project) {
		this.project = project;
	}

	public List getMappings() {
		return mappings;
	}

	public void setMappings(List mappings) {
		this.mappings = mappings;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy