Example usage for org.apache.maven.plugin.descriptor MojoDescriptor getFullGoalName

List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getFullGoalName

Introduction

In this page you can find the example usage for org.apache.maven.plugin.descriptor MojoDescriptor getFullGoalName.

Prototype

public String getFullGoalName() 

Source Link

Usage

From source file:com.cedarsoft.fish.maven.MavenCompletionGenerator.java

private void printCompletion(Plugin plugin)
        throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
        InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException,
        PluginNotFoundException, PluginVersionNotFoundException {
    PluginDescriptor pluginDescriptor = pluginManager.loadPluginDescriptor(plugin, project, session);
    List<MojoDescriptor> mojos = pluginDescriptor.getMojos();
    for (MojoDescriptor mojo : mojos) {
        StringBuilder builder = new StringBuilder();
        builder.append("complete -c mvn -a \"").append(mojo.getFullGoalName()).append("\" -d \"")
                .append(replaceSpecialChars(mojo.getDescription())).append("\"");
        System.out.println(builder.toString());
    }//from   w  w  w .  j  a v  a  2  s.c  om
}

From source file:io.fabric8.maven.core.util.GoalFinder.java

License:Apache License

private boolean checkGoalInPhase(MavenProject project, MavenSession session, String goal, String phase)
        throws MojoExecutionException {
    Lifecycle lifecycle = defaultLifeCycles.get(phase);
    if (lifecycle == null) {
        throw new MojoExecutionException("Cannot find lifecycle phase " + phase);
    }//from   w w  w.ja  va2s .  c  o m
    LifecycleMappingDelegate delegate = findDelegate(lifecycle);
    try {
        Map<String, List<MojoExecution>> executionsMap = delegate.calculateLifecycleMappings(session, project,
                lifecycle, phase);
        boolean foundPhase = false;
        boolean foundGoal = false;

        for (String p : lifecycle.getPhases()) {
            List<MojoExecution> executions = executionsMap.get(p);
            if (executions != null) {
                for (MojoExecution execution : executions) {
                    MojoDescriptor desc = execution.getMojoDescriptor();
                    if (desc != null && desc.getFullGoalName().equals(goal)) {
                        foundGoal = true;
                        break;
                    }
                }
            }
            if (phase.equals(p)) {
                foundPhase = true;
                break;
            }
        }
        return foundPhase && foundGoal;
    } catch (Exception e) {
        throw new MojoExecutionException("Interna: Cannot extract executions", e);
    }
}

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());
    }//from  w w  w .j  a  v a2s.  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);
        }
    }
}