use of org.apache.maven.plugin.descriptor.MojoDescriptor in project intellij-plugins by JetBrains.
the class Maven method createMojoExecution.
public MojoExecution createMojoExecution(Plugin plugin, String goal, MavenProject project) throws Exception {
if (plugin.getVersion() == null) {
plugin.setVersion(plexusContainer.lookup(PluginVersionResolver.class).resolve(new DefaultPluginVersionRequest(plugin, session)).getVersion());
}
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor(plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
List<PluginExecution> executions = plugin.getExecutions();
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, executions.isEmpty() ? null : executions.get(executions.size() - 1).getId(), MojoExecution.Source.CLI);
plexusContainer.lookup(LifecycleExecutionPlanCalculator.class).setupMojoExecution(session, project, mojoExecution);
return mojoExecution;
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class DescribeMojoTest method testValidExpression.
public void testValidExpression() throws Exception {
StringBuilder sb = new StringBuilder();
MojoDescriptor md = new MojoDescriptor();
Parameter parameter = new Parameter();
parameter.setName("name");
parameter.setExpression("${valid.expression}");
md.addParameter(parameter);
String ls = System.getProperty("line.separator");
try {
PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
assertEquals(" Available parameters:" + ls + ls + " name" + ls + " User property: valid.expression" + ls + " (no description available)" + ls, sb.toString());
} catch (Throwable e) {
fail(e.getMessage());
}
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class DescribeMojo method describeCommand.
/**
* Describe the <code>cmd</code> parameter
*
* @param descriptionBuffer not null
* @return <code>true</code> if it implies to describe a plugin, <code>false</code> otherwise.
* @throws MojoFailureException if any reflection exceptions occur or missing components.
* @throws MojoExecutionException if any
*/
private boolean describeCommand(StringBuilder descriptionBuffer) throws MojoFailureException, MojoExecutionException {
if (cmd.indexOf(':') == -1) {
// phase
Lifecycle lifecycle = defaultLifecycles.getPhaseToLifecycleMap().get(cmd);
if (lifecycle == null) {
throw new MojoExecutionException("The given phase '" + cmd + "' is an unknown phase.");
}
Map<String, String> defaultLifecyclePhases = lifecycleMappings.get(project.getPackaging()).getLifecycles().get("default").getPhases();
List<String> phases = lifecycle.getPhases();
if (lifecycle.getDefaultPhases() == null) {
descriptionBuffer.append("'").append(cmd);
descriptionBuffer.append("' is a phase corresponding to this plugin:").append(LS);
for (String key : phases) {
if (!key.equals(cmd)) {
continue;
}
if (defaultLifecyclePhases.get(key) != null) {
descriptionBuffer.append(defaultLifecyclePhases.get(key));
descriptionBuffer.append(LS);
}
}
descriptionBuffer.append(LS);
descriptionBuffer.append("It is a part of the lifecycle for the POM packaging '");
descriptionBuffer.append(project.getPackaging());
descriptionBuffer.append("'. This lifecycle includes the following phases:");
descriptionBuffer.append(LS);
for (String key : phases) {
descriptionBuffer.append("* ").append(key).append(": ");
String value = defaultLifecyclePhases.get(key);
if (StringUtils.isNotEmpty(value)) {
for (StringTokenizer tok = new StringTokenizer(value, ","); tok.hasMoreTokens(); ) {
descriptionBuffer.append(tok.nextToken().trim());
if (!tok.hasMoreTokens()) {
descriptionBuffer.append(LS);
} else {
descriptionBuffer.append(", ");
}
}
} else {
descriptionBuffer.append(NOT_DEFINED).append(LS);
}
}
} else {
descriptionBuffer.append("'").append(cmd);
descriptionBuffer.append("' is a lifecycle with the following phases: ");
descriptionBuffer.append(LS);
for (String key : phases) {
descriptionBuffer.append("* ").append(key).append(": ");
if (lifecycle.getDefaultPhases().get(key) != null) {
descriptionBuffer.append(lifecycle.getDefaultPhases().get(key)).append(LS);
} else {
descriptionBuffer.append(NOT_DEFINED).append(LS);
}
}
}
return false;
}
// goals
MojoDescriptor mojoDescriptor;
try {
mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor(cmd, session, project);
} catch (Exception e) {
throw new MojoExecutionException("Unable to get descriptor for " + cmd, e);
}
descriptionBuffer.append("'").append(cmd).append("' is a plugin goal (aka mojo)").append(".");
descriptionBuffer.append(LS);
plugin = mojoDescriptor.getPluginDescriptor().getId();
goal = mojoDescriptor.getGoal();
return true;
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class DescribeMojoTest method testInvalidExpression.
public void testInvalidExpression() throws Exception {
StringBuilder sb = new StringBuilder();
MojoDescriptor md = new MojoDescriptor();
Parameter parameter = new Parameter();
parameter.setName("name");
//this is a defaultValue
parameter.setExpression("${project.build.directory}/generated-sources/foobar");
md.addParameter(parameter);
String ls = System.getProperty("line.separator");
try {
PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
assertEquals(" Available parameters:" + ls + ls + " name" + ls + " Expression: ${project.build.directory}/generated-sources/foobar" + ls + " (no description available)" + ls, sb.toString());
} catch (Throwable e) {
fail(e.getMessage());
}
}
use of org.apache.maven.plugin.descriptor.MojoDescriptor in project maven-plugins by apache.
the class CompilerMojoTestCase method getMockMojoExecution.
private MojoExecution getMockMojoExecution() {
MojoDescriptor md = new MojoDescriptor();
md.setGoal("compile");
MojoExecution me = new MojoExecution(md);
PluginDescriptor pd = new PluginDescriptor();
pd.setArtifactId("maven-compiler-plugin");
md.setPluginDescriptor(pd);
return me;
}
Aggregations