Example usage for org.apache.maven.plugin.descriptor PluginDescriptor setArtifactId

List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor setArtifactId

Introduction

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

Prototype

public void setArtifactId(String artifactId) 

Source Link

Usage

From source file:fr.jcgay.maven.plugin.buildplan.model.builder.MojoExecutionBuilder.java

License:Apache License

public MojoExecution build() {

    if (useMojoDescriptorConstructor) {

        MojoDescriptor descriptor = new MojoDescriptor();
        descriptor.setGoal(goal);/*from  w w w. j  av a  2 s. c  o  m*/
        descriptor.setPhase(phase);
        PluginDescriptor pluginDescriptor = new PluginDescriptor();
        pluginDescriptor.setArtifactId(artifactId);
        descriptor.setPluginDescriptor(pluginDescriptor);

        return new MojoExecution(descriptor, executionId);
    } else {

        Plugin plugin = new Plugin();
        plugin.setArtifactId(artifactId);
        return new MojoExecution(plugin, goal, executionId);
    }
}

From source file:org.jvending.masa.plugins.toolchains.ToolchainMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    PluginDescriptor pluginDescriptor = new PluginDescriptor();
    pluginDescriptor.setGroupId("org.jvending.masa.plugins");
    pluginDescriptor.setArtifactId(PluginDescriptor.getDefaultPluginArtifactId("toolchains"));

    String dependencyAndroidVersion = getAndroidVersionFromDependency();

    if (toolchains == null) {
        if (!MasaUtil.isSdkOnPath()) {
            throw new MojoExecutionException(sdkErrorMessage);
        }/*from ww  w.  ja v  a  2  s.c  om*/

        getLog().info("No toolchains.xml configured for this build.");
        if (dependencyAndroidVersion == null) {
            throw new MojoExecutionException(versionErrorMessage);
        }
        session.getPluginContext(pluginDescriptor, project).put("androidVersion", dependencyAndroidVersion);

        return;
    }

    if (toolchainsFile == null) {
        //Check if toolchains.xml exists within project directory first
        toolchainsFile = new File(project.getBasedir(), "toolchains.xml");
        //Check if toolchains.xml exists within local .m2 directory
        if (!toolchainsFile.exists()) {
            toolchainsFile = new File(new File(session.getLocalRepository().getBasedir()).getParentFile(),
                    "toolchains.xml");

        }
    }

    if (!toolchainsFile.exists()) {
        if (!MasaUtil.isSdkOnPath()) {
            throw new MojoExecutionException(sdkErrorMessage);
        }

        getLog().info("No toolchains.xml file found.");
        if (dependencyAndroidVersion == null) {
            throw new MojoExecutionException(versionErrorMessage);
        }
        session.getPluginContext(pluginDescriptor, project).put("androidVersion", dependencyAndroidVersion);
        return;

    }

    PersistedToolchains toolchainModels = null;
    Reader in = null;
    try {
        in = ReaderFactory.newXmlReader(toolchainsFile);
        toolchainModels = new MavenToolchainsXpp3Reader().read(in);
    } catch (Exception e) {
        getLog().info("Problem reading toolchains.xml. Could not process");
        if (dependencyAndroidVersion == null) {
            throw new MojoExecutionException(versionErrorMessage);
        }
        session.getPluginContext(pluginDescriptor, project).put("androidVersion", dependencyAndroidVersion);
        return;
    } finally {
        IOUtil.close(in);
    }

    Map<String, ToolchainModel> models = new HashMap<String, ToolchainModel>();

    // Capabilities
    List<List<Capability>> m = new ArrayList<List<Capability>>();
    for (ToolchainModel model : (List<ToolchainModel>) toolchainModels.getToolchains()) {
        if (!model.getType().equals("android")) {
            continue;
        }

        List<Capability> c = new ArrayList<Capability>();
        Xpp3Dom dom = (Xpp3Dom) model.getProvides();
        for (Xpp3Dom child : dom.getChildren()) {
            if (child.getName().equals("id")) {
                models.put(child.getValue(), model);
            }
            c.add(new Capability(child.getName(), child.getValue()));
        }
        m.add(c);
    }
    Matcher matcher = new Matcher(m);

    // Requirements from pom
    String capabilityId = matcher.findMatchIdFor(toolchains.android);

    if (capabilityId == null) {
        throw new MojoExecutionException("Could not match capability to toolchain requirements");
    }

    session.getPluginContext(pluginDescriptor, project).put("toolchain", models.get(capabilityId));
    session.getPluginContext(pluginDescriptor, project).put("androidVersion", getAndroidVersionFromToolchain());

    getLog().info("ID = " + capabilityId + " : " + models.get(capabilityId).getType() + " : "
            + getAndroidVersionFromToolchain());

}