Author: kmorin Date: 2009-07-23 12:52:07 +0200 (Thu, 23 Jul 2009) New Revision: 1516 Modified: trunk/maven-guix-plugin/pom.xml trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java Log: Add the target directory to the classpath Modified: trunk/maven-guix-plugin/pom.xml =================================================================== --- trunk/maven-guix-plugin/pom.xml 2009-07-23 10:51:30 UTC (rev 1515) +++ trunk/maven-guix-plugin/pom.xml 2009-07-23 10:52:07 UTC (rev 1516) @@ -42,13 +42,11 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> - <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> - <scope>provided</scope> </dependency> <!-- other dependencies --> Modified: trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java =================================================================== --- trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-07-23 10:51:30 UTC (rev 1515) +++ trunk/maven-guix-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-07-23 10:52:07 UTC (rev 1516) @@ -23,6 +23,7 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; import org.nuiton.guix.generator.GwtGenerator; import org.nuiton.guix.generator.SwingGenerator; @@ -30,32 +31,39 @@ * Launches the program * * @author morin - * @goal testMojo + * @goal generate + * @phase process-sources + * @requiresDependencyResolution compile + * @requiresProject */ -public class GuixMojo extends AbstractMojo -{ - +public class GuixMojo extends AbstractMojo { + /** - * Directory of the files to compile. - * @parameter expression="${guix.guixFilesDir}" default-value="${maven.src.dir}/main/java" - * @since 0.0.1 - */ + * Project dependencies. + * + * @parameter default-value="${project}" + * @required + * @readonly + */ + protected MavenProject project; + /** + * Directory of the files to compile. + * @parameter expression="${guix.guixFilesDir}" default-value="${maven.src.dir}/main/java" + * @since 0.0.1 + */ private String guixFilesDir; - /** * Directory of the generated files. - * @parameter expression="${guix.targetDirectory}" default-value="generatedFiles" + * @parameter expression="${guix.targetDirectory}" default-value="${basedir}/target/generatedFiles" * @since 0.0.1 */ private String targetDirectory; - /** * Directory of the generated files. * @parameter expression="${guix.rootPackage}" default-value="" * @since 0.0.1 */ private String rootPackage; - /** * Main class of the application to generate. * @parameter expression="${guix.mainClass}" @@ -63,14 +71,12 @@ * @since 0.0.1 */ private String mainClass; - /** * Generation language * @parameter expression="${guix.generationLanguage}" default-value="Swing" * @since 0.0.1 */ private String generationLanguage; - /** * Generation language * @parameter expression="${guix.launcherName}" default-value="Main" @@ -79,32 +85,36 @@ private String launcherName; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + public void execute() throws MojoExecutionException, MojoFailureException { File guixFilesDir = new File(this.guixFilesDir); File targetDirectory = new File(this.targetDirectory); Class generatorClass = null; - if(generationLanguage.equalsIgnoreCase("Swing")) { + if (generationLanguage.equalsIgnoreCase("Swing")) { generatorClass = SwingGenerator.class; SwingGuixInitializer.initialize(); } - else if(generationLanguage.equalsIgnoreCase("GWT")) { + else if (generationLanguage.equalsIgnoreCase("GWT")) { generatorClass = GwtGenerator.class; GwtGuixInitializer.initialize(); } - if(!targetDirectory.exists()) + if (!targetDirectory.exists()) { targetDirectory.mkdirs(); - - if(guixFilesDir.exists() && guixFilesDir.isDirectory()) { + } + fixCompileSourceRoots(targetDirectory); + + if (guixFilesDir.exists() && guixFilesDir.isDirectory()) { ArrayList<File> guixFiles = goDeeperInto(guixFilesDir); GuixLauncher gcl = new GuixLauncher(guixFiles.toArray( - new File[guixFiles.size()]),targetDirectory,rootPackage, - guixFilesDir,mainClass,generatorClass,launcherName); + new File[guixFiles.size()]), targetDirectory, rootPackage, + guixFilesDir, mainClass, generatorClass, launcherName); boolean result = gcl.compile(); -// if(result) -// getLog().info("Compilation succeeded !"); -// else -// getLog().error("Compilation failed..."); + if (result) { + getLog().info("Compilation succeeded !"); + } + else { + getLog().error("Compilation failed..."); + } getLog().info("Compilation over"); } else { @@ -115,11 +125,11 @@ private ArrayList<File> goDeeperInto(File dir) { getLog().debug("goind deeper into " + dir.getPath()); ArrayList<File> result = new ArrayList<File>(); - for(File f : dir.listFiles()) { - if(f.isDirectory() && !f.isHidden()) { + for (File f : dir.listFiles()) { + if (f.isDirectory() && !f.isHidden()) { result.addAll(goDeeperInto(f)); } - else if(f.getName().endsWith(".guix")) { + else if (f.getName().endsWith(".guix")) { getLog().debug("found " + f.getName()); result.add(f); } @@ -127,4 +137,12 @@ return result; } + protected void fixCompileSourceRoots(File targetDirectory) { + //fixme should remove this silly test when we will make real maven plugin tests :) + if (project != null) { + if (!project.getCompileSourceRoots().contains(targetDirectory.getPath())) { + project.addCompileSourceRoot(targetDirectory.getPath()); + } + } + } }