From 8c046e79b56e71bd0a9f3787712963bc2523d8f1 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Thu, 10 Dec 2009 09:32:49 +0100 Subject: Progress on NAR-21 --- src/it/it0014-multi-module/pom.xml | 3 ++ .../apache/maven/plugin/nar/NarCompileMojo.java | 48 ++++++++++++++++++++++ .../org/apache/maven/plugin/nar/NarJavahMojo.java | 1 + .../apache/maven/plugin/nar/NarValidateMojo.java | 42 +++++++++++-------- 4 files changed, 76 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/it/it0014-multi-module/pom.xml b/src/it/it0014-multi-module/pom.xml index a87aad6..1b349dc 100644 --- a/src/it/it0014-multi-module/pom.xml +++ b/src/it/it0014-multi-module/pom.xml @@ -40,6 +40,9 @@ under the License. http://maven.apache.org/ + install diff --git a/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java index 47f6dd4..fe5f7cc 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java @@ -38,8 +38,11 @@ import net.sf.antcontrib.cpptasks.types.LibrarySet; import net.sf.antcontrib.cpptasks.types.LinkerArgument; import net.sf.antcontrib.cpptasks.types.SystemLibrarySet; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.codehaus.plexus.util.FileUtils; @@ -50,15 +53,60 @@ import org.codehaus.plexus.util.StringUtils; * * @goal nar-compile * @phase compile + * @requiresSession + * @requiresProject * @requiresDependencyResolution compile * @author Mark Donszelmann */ public class NarCompileMojo extends AbstractCompileMojo { + /** + * The current build session instance. + * + * @parameter expression="${session}" + * @required + * @readonly + */ + private MavenSession session; + public final void narExecute() throws MojoExecutionException, MojoFailureException { + for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); ) + { + MavenProject project = (MavenProject) i.next(); + if ( !project.getPackaging().equals( NarConstants.NAR ) ) + { + continue; + } + if ( project.isExecutionRoot() ) + { + continue; + } + + // is this me ? bail out, the list was sorted + MavenProject me = getMavenProject(); + if ( project.getArtifact().equals( me.getArtifact() ) ) + { + break; + } + + // search the dependency list + for ( Iterator it = me.getArtifacts().iterator(); it.hasNext(); ) + { + Artifact dependency = (Artifact) it.next(); + // equals will not work here as the project type is "nar" while the dependencies type is "jar" + // + if ( dependency.getArtifactId().equals( project.getArtifactId() ) + && dependency.getGroupId().equals( project.getGroupId() ) + && dependency.getVersion().equals( project.getVersion() ) && dependency.getType().equals( "jar" ) ) + { + getLog().info( "Added intermodule dependency to " + project.getArtifact()+" in "+project.getBuild().getDirectory() ); + } + } + } + // make sure destination is there getTargetDirectory().mkdirs(); diff --git a/src/main/java/org/apache/maven/plugin/nar/NarJavahMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarJavahMojo.java index 9edc963..14d69df 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarJavahMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarJavahMojo.java @@ -30,6 +30,7 @@ import org.apache.maven.toolchain.ToolchainManager; * * @goal nar-javah * @phase compile + * @requiresSession * @author Mark Donszelmann */ public class NarJavahMojo diff --git a/src/main/java/org/apache/maven/plugin/nar/NarValidateMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarValidateMojo.java index e299dfb..b303b38 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarValidateMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarValidateMojo.java @@ -27,7 +27,6 @@ import org.apache.maven.plugin.MojoFailureException; * * @goal nar-validate * @phase validate - * @requiresProject * @author Mark Donszelmann */ public class NarValidateMojo @@ -35,45 +34,52 @@ public class NarValidateMojo { public final void narExecute() throws MojoExecutionException, MojoFailureException - { + { // check aol - AOL aol = getAOL(); + AOL aol = getAOL(); getLog().info( "Using AOL: " + aol ); - + // check linker exists in retrieving the version number - Linker linker = getLinker(); - getLog().debug( "Using linker version: "+linker.getVersion()); - + Linker linker = getLinker(); + getLog().debug( "Using linker version: " + linker.getVersion() ); + // check compilers int noOfCompilers = 0; Compiler cpp = getCpp(); - if (cpp.getName() != null) { + if ( cpp.getName() != null ) + { noOfCompilers++; // need includes - if (cpp.getIncludes( Compiler.MAIN ).isEmpty()) { - throw new MojoExecutionException( "No includes defined for compiler "+cpp.getName() ); + if ( cpp.getIncludes( Compiler.MAIN ).isEmpty() ) + { + throw new MojoExecutionException( "No includes defined for compiler " + cpp.getName() ); } } Compiler c = getC(); - if (c.getName() != null) { + if ( c.getName() != null ) + { noOfCompilers++; // need includes - if (c.getIncludes( Compiler.MAIN ).isEmpty()) { - throw new MojoExecutionException( "No includes defined for compiler "+c.getName() ); + if ( c.getIncludes( Compiler.MAIN ).isEmpty() ) + { + throw new MojoExecutionException( "No includes defined for compiler " + c.getName() ); } } Compiler fortran = getCpp(); - if (fortran.getName() != null) { + if ( fortran.getName() != null ) + { noOfCompilers++; // need includes - if (fortran.getIncludes( Compiler.MAIN ).isEmpty()) { - throw new MojoExecutionException( "No includes defined for compiler "+fortran.getName() ); + if ( fortran.getIncludes( Compiler.MAIN ).isEmpty() ) + { + throw new MojoExecutionException( "No includes defined for compiler " + fortran.getName() ); } } // at least one compiler has to be defined - if (noOfCompilers == 0) { - throw new MojoExecutionException( "No compilers defined for linker "+linker.getName() ); + if ( noOfCompilers == 0 ) + { + throw new MojoExecutionException( "No compilers defined for linker " + linker.getName() ); } } } -- cgit v1.2.3