I have the following situation where I have a plugin that starts
another java process and I want to allow the user to configure it to
fork or not fork. If the process is forked, the user has some
optional attributes they are allowed to also specify. So, I have the
following bits in my Mojo:
public class StartMojo extends AbstractMojo {
private static final ForkConfiguration NON_FORKING = new
ForkConfiguration(false, null, null, "");
/**
* Determines if the framework is started in a separate process or
in the same process Maven is running in and
* the extra configuration options available. If not specified
the default is to not fork.
*
* @parameter
* @optional
*/
private ForkConfiguration fork = NON_FORKING;
public static class ForkConfiguration {
/**
* Whether the framework should be run in a forked process.
*
* @parameter default-value="true"
* @optional
*/
boolean fork;
/**
* File to send all the frameworks standard output to.
*
* @parameter
default-value="${project.build.directory}/bunches/output.log"
* @optional
*/
File outputFile;
/**
* File to send all the frameworks standard error to.
*
* @parameter
default-value="${project.build.directory}/bunches/error.log"
* @optional
*/
File errorFile;
/**
* Arguments to be passed to the jvm
*
* @parameter default-value=""
* @optional
*/
String jvmArgs;
/**
* Parameterless ctor for Maven.
*/
public ForkConfiguration() {}
/**
* Ctor that allows all parameters to be set.
*/
ForkConfiguration(boolean fork, File outputFile, File
errorFile, String jvmArgs) {
this.fork = fork;
this.outputFile = outputFile;
this.errorFile = errorFile;
this.jvmArgs = jvmArgs;
}
}
}
If the user wants to configure the thing to fork but doesn't want to
specify any other information, it would be nice if they could just use
this configuration
<configuration>
<fork/>
</configuration>
But that doesn't seem to inject a ForkConfiguration object configured
by maven into the fork member. I was expecting to create a
ForkConfiguration object with the default-values from the @parameter
annotations. Instead, it doesn't seem to set it at all. But, if I
add an element to <fork> </fork> configuration, it creates the
ForkConfiguration object with the default values for all but the user
set property. Is there anyway I can force the creation of a
ForkConfiguration object when just a <fork/> is provided? If not, is
there a way to lookup the whole <configuration> DOM element and check
for it's presence? Any other way I might be able to check the value?
Thanks,
Rich
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]