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

com.lewisd.maven.lint.rules.opensource.MissingDeveloperInformationRule 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.rules.opensource;

import com.lewisd.maven.lint.ResultCollector;
import com.lewisd.maven.lint.rules.AbstractRule;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.routines.EmailValidator;
import org.apache.maven.model.Developer;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputSource;
import org.apache.maven.project.MavenProject;

import java.util.List;
import java.util.Map;

public class MissingDeveloperInformationRule extends AbstractRule {
    @Override
    public String getIdentifier() {
        return "OSSDevelopersSectionRule";
    }

    @Override
    public String getDescription() {
        return "The users/developers need to know where to get active bugs and to report new ones to.";
    }

    @Override
    public void invoke(MavenProject mavenProject, Map models, ResultCollector resultCollector) {
        List developers = mavenProject.getDevelopers();

        if (developers.isEmpty()) {
            InputLocation location = getEmptyLocation(mavenProject);
            resultCollector.addViolation(mavenProject, this, "missing  section", location);
        } else {
            for (Developer developer : developers) {
                if (StringUtils.isEmpty(developer.getId())) {
                    resultCollector.addViolation(mavenProject, this, "missing  entry in  section", developer.getLocation(""));
                }
                if (StringUtils.isEmpty(developer.getName())) {
                    resultCollector.addViolation(mavenProject, this, "missing  entry in  section", developer.getLocation(""));
                }
                if (!StringUtils.isEmpty(developer.getEmail()) && !EmailValidator.getInstance().isValid(developer.getEmail())) {
                    resultCollector.addViolation(mavenProject, this, "not valid  entry in  section", developer.getLocation(""));
                }
            }
        }
    }

    private InputLocation getEmptyLocation(MavenProject mavenProject) {
        final InputSource source = new InputSource();
        source.setLocation(mavenProject.getOriginalModel().getPomFile() + "");
        return new InputLocation(0, 0, source);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy