Example usage for org.apache.maven.execution ProjectExecutionEvent getProject

List of usage examples for org.apache.maven.execution ProjectExecutionEvent getProject

Introduction

In this page you can find the example usage for org.apache.maven.execution ProjectExecutionEvent getProject.

Prototype

public MavenProject getProject() 

Source Link

Usage

From source file:org.srcdeps.mvn.enforcer.SrcdepsEnforcer.java

License:Apache License

@Override
public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException {
    final MavenProject project = event.getProject();
    log.info("srcdeps enforcer checks for violations in {}:{}", project.getGroupId(), project.getArtifactId());

    final Maven maven = configurationProducer.getConfiguration().getMaven();

    final List<MojoExecution> mojoExecutions = event.getExecutionPlan();
    final List<String> goals = new ArrayList<>(mojoExecutions.size());
    for (MojoExecution mojoExecution : mojoExecutions) {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
        goals.add(mojoDescriptor.getFullGoalName());
        goals.add(mojoDescriptor.getGoal());
    }/* w  w  w .j av a  2 s. c  o  m*/

    final List<String> profiles = new ArrayList<>();
    final List<Profile> activeProfiles = project.getActiveProfiles();
    for (Profile profile : activeProfiles) {
        final String id = profile.getId();
        profiles.add(id);
    }

    final Properties props = new Properties();
    props.putAll(project.getProperties());
    props.putAll(System.getProperties());

    String[] firstViolation = assertFailWithout(maven.getFailWithout(), goals, profiles, props);
    if (firstViolation == null) {
        firstViolation = assertFailWith(maven.getFailWith(), goals, profiles, props);
    }
    if (firstViolation != null) {
        /* check if there are srcdeps */
        Artifact parent = project.getParentArtifact();
        if (parent != null) {
            assertNotSrcdeps(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), firstViolation);
        }
        DependencyManagement dm;
        List<Dependency> deps;
        if ((dm = project.getDependencyManagement()) != null && (deps = dm.getDependencies()) != null) {
            assertNotSrcdeps(deps, firstViolation);
        }
        if ((deps = project.getDependencies()) != null) {
            assertNotSrcdeps(deps, firstViolation);
        }
    }
}