maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohamed Talhaoui <mohamed.talha...@gmail.com>
Subject [m2] Mojo's parameters configuration
Date Thu, 22 Sep 2005 14:54:27 GMT
I wrote a simple plugin that generate java code from xml using castor.

I have 2 class:

the Mojo:
package com.mycompany.maven.plugins.castor;

import java.io.File;
import java.util.List;
import java.util.logging.Logger;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.exolab.castor.builder.SourceGenerator;

/**
 * A Maven2 plugin which generates java sources from xsd files.
 *
 * @phase=generate-sources
 * @goal castor2java
 * @version $Id$
 */
public class Castor2JavaPlugin extends AbstractMojo {

 Logger logger = Logger.getLogger("Castor2JavaPlugin");

 /**
 * @parameter
 * @required
 */
 private List castorParams;

 /**
 * @parameter default-value="${project.build.directory}/generated-sources"
 * @required
 */
 private String outputDirectory;


 public void execute() throws MojoExecutionException {
 try {
 for (int i = 0; i < castorParams.size(); i++) {
 CastorParam param= (CastorParam)castorParams.get(i);
 logger.info("Processing castor file " + param.getSchema() + "...");
 File schemaFile = new File(param.getSchema());
 String args[] = new String[4];
 args[0]="-i" + param.getSchema();
 args[1]="-f";
 args[2]="-package" + param.getPackaging();
 args[3]="-dest" + outputDirectory;
 SourceGenerator sourceGenerator = new SourceGenerator();
 sourceGenerator.main(args);

 }
 } catch (Throwable ex) {
 ex.printStackTrace();
 throw new MojoExecutionException("exception occured, message is : " +
ex.getMessage());
 }
 logger.info("End castor processing.");
 }

}

and the CastorParam that holds parameters to pass to castor:
package com.mycompany.maven.plugins.castor;

public class CastorParam {

 private String schema;
 private String packaging;

 public String getPackaging() {
 return packaging;
 }
 public void setPackaging(String packaging) {
 this.packaging = packaging;
 }
 public String getSchema() {
 return schema;
 }
 public void setSchema(String schema) {
 this.schema = schema;
 }
}

 I have the following lugin node in my project pom:
 <plugins>
<plugin>
<groupId>com.mycompany.maven.plugins</groupId>
<artifactId>maven-castor-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<goals>
<goal>castor2java</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<castorParams>
<castorParam implementation="com.mycompany.maven.plugins.castor.CastorParam
">
<schema>schemas/eRisk/risk_request.xsd</schema>
<packaging>com.netfinca.risk.castorxml.request</packaging>
</castorParam>
<castorParam implementation="com.mycompany.maven.plugins.castor.CastorParam
">
<schema>schemas/eRisk/risk_response_cpronline.xsd</schema>
<packaging>com.netfinca.risk.cpronline.castorxml</packaging>
</castorParam>
</castorParams>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

When I run the m2 install on my project I have the following:
[ERROR] BUILD ERROR
[INFO]
----------------------------------------------------------------------------
[INFO] Diagnosis: Error configuring plugin for execution of
'castor:castor2java'.
[INFO]
----------------------------------------------------------------------------
[ERROR] Cause:
org.apache.maven.plugin.MojoExecutionException: Error configuring plugin for
execution of 'castor:castor2java'.
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
DefaultPluginManager.java:378)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(
DefaultLifecycleExecutor.java:169)
 at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle
(DefaultLifecycleExecutor.java:14
3)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(
DefaultLifecycleExecutor.java:129)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(
DefaultLifecycleExecutor.java:103)
 at org.apache.maven.DefaultMaven.processProject(DefaultMaven.java:261)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:180)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:269)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:324)
 at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:303)
 at org.codehaus.classworlds.Launcher.launch(Launcher.java:243)
 at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:416)
 at org.codehaus.classworlds.Launcher.main(Launcher.java:363)
Caused by: org.apache.maven.plugin.PluginParameterException: Invalid or
missing parameters: [Mojo parameter [name: 'cast
orParams'; alias: 'null']] for mojo:
com.mycompany.maven.plugins:maven-castor-plugin:1.0-alpha-1:castor2java
 at org.apache.maven.plugin.DefaultPluginManager.checkRequiredParameters(
DefaultPluginManager.java:764)
 at org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(
DefaultPluginManager.java:527)
 at org.apache.maven.plugin.DefaultPluginManager.executeMojo(
DefaultPluginManager.java:373)
 ... 15 more

I should have missed something, but what ??

Thx for your help.

PS: I'm using maven 2 alpha 3.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message