I needed to do a bit of compiling after the process-classes phase for a
couple of custom plugins...so I pulled out the interesting parts of the
compiler mojo and used that...not sure if there is a better way, but this
certainly works..

jesse



private Compiler compiler = new JavacCompiler();



private void compile(String file) throws MojoExecutionException {

getLog().debug("outputDir " + outputDirectory);
getLog().debug("file " + file);
getLog().debug("build to " + buildDirectory);

try {

CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.setOutputLocation( buildDirectory + "/classes" );
ArrayList list = new ArrayList();
list.add(outputDirectory);
compilerConfiguration.setSourceLocations( list );

compilerConfiguration.setClasspathEntries(
project.getCompileClasspathElements() );

HashSet set = new HashSet();
set.add(new File(file));

compilerConfiguration.setSourceFiles( set );


compilerConfiguration.setDebug( true );

List messages = null;
messages = compiler.compile( compilerConfiguration );
}
catch ( Exception e )
{
e.printStackTrace();
// TODO: don't catch Exception
throw new MojoExecutionException( "Fatal error compiling", e );
}

}

On 11/15/05, Pablo <[EMAIL PROTECTED]> wrote:
>
> Hello there
>
> I'm writting a plugin which is supposed to do a few things:
> 1) Compile test classes to be run in integration-test phase
> 2) Start tomcat
> 3) Run tests
> 4) Stop tomcat
>
> Steps 2, 3 and 4 are almost done. The main problem is step 1.
> I thought it would be too much to do by implementing compilation from
> scratch therefore I simply created a class extending TestCompilerMojo
> class.
> Unfortunatelly it doesn't work, throws exception because CompilerManager
> is not initialized. I tried to make it by myself by setting necessary
> field in execute() method (compilerManager, compilerId) and now it
> doesn't throw any exceptions.
>
> In plugin configuration I've placed 'compileSourceRoots' and
> ''outputDirectory' but it seems that these values are not set because I
> got a message:
> '[INFO] No sources to compile'
>
> Can someone point me to some tutorial or HOWTO describing all necessary
> steps to make it work?
>
> I don't want to place integration tests in the same directory as normal
> junit tests because these tests are supposed to be run after tomcat is
> started with web application running in the *integration-test* phase not
> the *test* phase. If they were placed in src/tests the *package* phase
> would return error since there would be no webapp running *(test* is
> before *package* phase).
>
> Thanks in advance.
> Pablo
>
>


--
jesse mcconnell
jesseDOTmcconnellATgmailDOTcom

Reply via email to