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

com.lewisd.maven.lint.model.VersionPropertiesModelBuilder Maven / Gradle / Ivy

Go to download

Generates a report of suspicious/inconsistent POM elements, and optionally fails the build if violations are found.

The newest version!
package com.lewisd.maven.lint.model;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.maven.project.MavenProject;
import org.springframework.beans.factory.annotation.Autowired;

import com.lewisd.maven.lint.ModelFactory;
import com.lewisd.maven.lint.util.ModelUtil;

public class VersionPropertiesModelBuilder extends AbstractModelBuilder {

	private final ModelUtil modelUtil;

	@Autowired
	public VersionPropertiesModelBuilder(final ModelUtil modelUtil, final ModelFactory modelFactory) {
		super(modelFactory);
		this.modelUtil = modelUtil;
	}
	
	public Set getRequiredModels() {
		return Collections.singleton(MAVEN_PROJECT);
	}

	public Object buildModel(final Map models) {
		final Map versionPropertyByObject = new HashMap();
		
		final MavenProject mavenProject = (MavenProject) models.get(MAVEN_PROJECT);
		
		final Collection objectsToCheck = modelUtil.findGAVObjects(mavenProject);
		
		for (final Object object: objectsToCheck) {
			final String version = modelUtil.getVersion(object);

			if (version != null && version.contains("${")) {
				versionPropertyByObject.put(object, new VersionProperty(version));
			}
		}

		return versionPropertyByObject;
	}

	public String getModelId() {
		return "versionProperties";
	}

}