diff options
author | Vikas Rangarajan <vikas@vikas-linux.tva.tvworks.com> | 2010-03-22 15:48:57 -0700 |
---|---|---|
committer | Vikas Rangarajan <vikas@vikas-linux.tva.tvworks.com> | 2010-03-22 15:48:57 -0700 |
commit | e8c35d105cf227a9a781ac4aac79dcd0c5024a6b (patch) | |
tree | ed979c6ccf8c0a9a5a6ec6ed67ff47242acfeeea /src/main/java | |
parent | 2bb8e535ca23632a4df9ba291709cd1c536d39cd (diff) | |
download | maven-nar-plugin-e8c35d105cf227a9a781ac4aac79dcd0c5024a6b.tar.gz maven-nar-plugin-e8c35d105cf227a9a781ac4aac79dcd0c5024a6b.tar.bz2 maven-nar-plugin-e8c35d105cf227a9a781ac4aac79dcd0c5024a6b.tar.xz maven-nar-plugin-e8c35d105cf227a9a781ac4aac79dcd0c5024a6b.zip |
Initial merge of local changes with master, main changes :
- New mojo for vcproj generation
- Fixed aol to be url-friendly for maven deployments (g++->gpp)
- Fail build early if specified include paths do not exist
- Only add "include" subdirs of sourcedirs if they exist, to the include path
- Removed duplication of source dirs in source path
Diffstat (limited to 'src/main/java')
8 files changed, 363 insertions, 303 deletions
diff --git a/src/main/java/org/apache/maven/plugin/nar/AOL.java b/src/main/java/org/apache/maven/plugin/nar/AOL.java index e519026..b1edb10 100644 --- a/src/main/java/org/apache/maven/plugin/nar/AOL.java +++ b/src/main/java/org/apache/maven/plugin/nar/AOL.java @@ -48,9 +48,9 @@ public class AOL os = aolString[osIndex]; case architectureIndex+1: architecture = aolString[architectureIndex]; - break; + break; - default: + default: throw new IllegalArgumentException( "AOL '" + aol + "' cannot be parsed." ); } } @@ -68,24 +68,46 @@ public class AOL */ public final String toString() { - return architecture + ( ( os == null ) ? "" : "-" + os + ( ( linkerName == null ) ? "" : "-" + linkerName ) ); + String tempLinkerName = null; + if ( linkerName == null ) { + tempLinkerName = ""; + } else if ( linkerName.equals("g++") ) { + tempLinkerName = "-gpp"; + } else { + tempLinkerName = "-" + linkerName; + } + + return architecture + + ((os == null) ? "" : "-" + os + + tempLinkerName); } // FIXME, maybe change to something like isCompatible (AOL). public final boolean hasLinker( String linker ) { - return linkerName.equals( linker ); + return linkerName.equals(linker); } /** * Returns an AOL key (arch.os.linker) to search in the properties files. * @return dot separated AOL */ - public final String getKey() + public final String getKey() { - return architecture + ( ( os == null ) ? "" : "." + os + ( ( linkerName == null ) ? "" : "." + linkerName ) ); - } - + String tempLinkerName = null; + if ( linkerName == null ) { + tempLinkerName = ""; + } else if ( linkerName.equals("g++") ) { + tempLinkerName = ".gpp"; + } else { + tempLinkerName = "." + linkerName; + } + + return architecture + + ((os == null) ? "" : "." + os + + tempLinkerName); + } + final String getOS() { return os; } diff --git a/src/main/java/org/apache/maven/plugin/nar/Compiler.java b/src/main/java/org/apache/maven/plugin/nar/Compiler.java index 33c0a8f..59cdee2 100644 --- a/src/main/java/org/apache/maven/plugin/nar/Compiler.java +++ b/src/main/java/org/apache/maven/plugin/nar/Compiler.java @@ -326,7 +326,11 @@ public abstract class Compiler includeList = new ArrayList(); for ( Iterator i = getSourceDirectories( type ).iterator(); i.hasNext(); ) { - includeList.add( new File( (File) i.next(), "include" ).getPath() ); + //VR 20100318 only add include directories that exist - we now fail the build fast if an include directory does not exist + File includePath = new File( (File) i.next(), "include" ); + if(includePath.isDirectory()) { + includeList.add( includePath.getPath() ); + } } } return includeList; @@ -555,6 +559,10 @@ public abstract class Compiler for ( Iterator i = getIncludePaths( type ).iterator(); i.hasNext(); ) { String path = (String) i.next(); + // Darren Sargent, 30Jan2008 - fail build if invalid include path(s) specified. + if ( ! new File(path).exists() ) { + throw new MojoFailureException("NAR: Include path not found: " + path); + } compiler.createIncludePath().setPath( path ); } @@ -603,24 +611,6 @@ public abstract class Compiler } } - // add other sources, FIXME seems - if ( !type.equals( TEST ) ) - { - for ( Iterator i = mojo.getMavenProject().getCompileSourceRoots().iterator(); i.hasNext(); ) - { - File dir = new File( (String) i.next() ); - mojo.getLog().debug( "Checking for existence of " + getLanguage() + " sourceCompileRoot: " + dir ); - if ( dir.exists() ) - { - ConditionalFileSet otherFileSet = new ConditionalFileSet(); - otherFileSet.setProject( mojo.getAntProject() ); - otherFileSet.setIncludes( StringUtils.join( includeSet.iterator(), "," ) ); - otherFileSet.setExcludes( StringUtils.join( excludeSet.iterator(), "," ) ); - otherFileSet.setDir( dir ); - compiler.addFileset( otherFileSet ); - } - } - } return compiler; } diff --git a/src/main/java/org/apache/maven/plugin/nar/Lib.java b/src/main/java/org/apache/maven/plugin/nar/Lib.java index e970a69..db879dc 100644 --- a/src/main/java/org/apache/maven/plugin/nar/Lib.java +++ b/src/main/java/org/apache/maven/plugin/nar/Lib.java @@ -41,43 +41,43 @@ import org.apache.tools.ant.Project; public class Lib { - /** + /** * Name of the library, or a dependency groupId:artifactId if this library contains sublibraries - * - * @parameter expression="" - * @required - */ - private String name; + * + * @parameter expression="" + * @required + */ + private String name; - /** - * Type of linking for this library - * - * @parameter expression="" default-value="shared" - * @required - */ - private String type = Library.SHARED; + /** + * Type of linking for this library + * + * @parameter expression="" default-value="shared" + * @required + */ + private String type = Library.SHARED; - /** - * Location for this library - * - * @parameter expression="" - * @required - */ - private File directory; + /** + * Location for this library + * + * @parameter expression="" + * @required + */ + private File directory; - /** - * Sub libraries for this library - * - * @parameter expression="" - */ - private List/* <Lib> */libs; + /** + * Sub libraries for this library + * + * @parameter expression="" + */ + private List/* <Lib> */libs; public final void addLibSet( AbstractDependencyMojo mojo, LinkerDef linker, Project antProject ) throws MojoFailureException, MojoExecutionException { if ( name == null ) { - throw new MojoFailureException( "NAR: Please specify <Name> as part of <Lib>" ); + throw new MojoFailureException( "NAR: Please specify <Name> as part of <Lib> for library \"" + name + "\""); } addLibSet( mojo, linker, antProject, name, directory ); } @@ -97,47 +97,47 @@ public class Lib private void addSingleLibSet( LinkerDef linker, Project antProject, String name, File dir ) throws MojoFailureException, MojoExecutionException - { - if ( !type.equals( "framework" ) && ( dir == null ) ) + { + if (!type.equals("framework") && (dir == null)) { - throw new MojoFailureException( "NAR: Please specify <Directory> as part of <Lib>" ); - } - LibrarySet libSet = new LibrarySet(); - libSet.setProject( antProject ); - libSet.setLibs( new CUtil.StringArrayBuilder( name ) ); - LibraryTypeEnum libType = new LibraryTypeEnum(); - libType.setValue( type ); - libSet.setType( libType ); - libSet.setDir( dir ); - linker.addLibset( libSet ); - } + throw new MojoFailureException("NAR: Please specify <Directory> as part of <Lib> for library \"" + name + "\""); + } + LibrarySet libSet = new LibrarySet(); + libSet.setProject(antProject); + libSet.setLibs(new CUtil.StringArrayBuilder(name)); + LibraryTypeEnum libType = new LibraryTypeEnum(); + libType.setValue(type); + libSet.setType(libType); + libSet.setDir(dir); + linker.addLibset(libSet); + } private void addMultipleLibSets( AbstractDependencyMojo mojo, LinkerDef linker, Project antProject, String name ) throws MojoFailureException, MojoExecutionException { - List dependencies = mojo.getNarManager().getNarDependencies( "compile" ); + List dependencies = mojo.getNarManager().getNarDependencies("compile"); for ( Iterator i = libs.iterator(); i.hasNext(); ) { - Lib lib = (Lib) i.next(); - String[] ids = name.split( ":", 2 ); + Lib lib = (Lib) i.next(); + String[] ids = name.split(":", 2); if ( ids.length != 2 ) { - throw new MojoFailureException( - "NAR: Please specify <Name> as part of <Lib> in format 'groupId:artifactId'" ); - } + throw new MojoFailureException( + "NAR: Please specify <Name> as part of <Lib> in format 'groupId:artifactId'"); + } for ( Iterator j = dependencies.iterator(); j.hasNext(); ) { - Artifact dependency = (Artifact) j.next(); + Artifact dependency = (Artifact) j.next(); if ( dependency.getGroupId().equals( ids[0] ) && dependency.getArtifactId().equals( ids[1] ) ) { - // FIXME NAR-90 + // FIXME NAR-90 File narDir = new File( dependency.getFile().getParentFile(), "nar/lib/" - + mojo.getAOL() + "/" + lib.type ); + + mojo.getAOL() + "/" + lib.type); String narName = dependency.getArtifactId() + "-" + lib.name + "-" + dependency.getVersion(); - lib.addLibSet( mojo, linker, antProject, narName, narDir ); - } - } - } - } + lib.addLibSet(mojo, linker, antProject, narName, narDir); + } + } + } + } } 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 811ce70..42e5a33 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java @@ -79,15 +79,15 @@ public class NarCompileMojo // check for source files int noOfSources = 0; - noOfSources += getSourcesFor( getCpp() ).size(); - noOfSources += getSourcesFor( getC() ).size(); - noOfSources += getSourcesFor( getFortran() ).size(); + noOfSources += getSourcesFor(getCpp()).size(); + noOfSources += getSourcesFor(getC()).size(); + noOfSources += getSourcesFor(getFortran()).size(); if ( noOfSources > 0 ) { getLog().info( "Compiling " + noOfSources + " native files" ); for ( Iterator i = getLibraries().iterator(); i.hasNext(); ) { - createLibrary( getAntProject(), (Library) i.next() ); + createLibrary(getAntProject(), (Library) i.next()); } } else @@ -134,33 +134,33 @@ public class NarCompileMojo } } - private void createLibrary( Project antProject, Library library ) - throws MojoExecutionException, MojoFailureException + private void createLibrary(Project antProject, Library library) + throws MojoExecutionException, MojoFailureException { getLog().debug( "Creating Library " + library ); // configure task CCTask task = new CCTask(); - task.setProject( antProject ); - + task.setProject(antProject); + // subsystem SubsystemEnum subSystem = new SubsystemEnum(); subSystem.setValue( library.getSubSystem() ); task.setSubsystem( subSystem ); // set max cores - task.setMaxCores( getMaxCores( getAOL() ) ); + task.setMaxCores(getMaxCores(getAOL())); // outtype OutputTypeEnum outTypeEnum = new OutputTypeEnum(); String type = library.getType(); - outTypeEnum.setValue( type ); - task.setOuttype( outTypeEnum ); + outTypeEnum.setValue(type); + task.setOuttype(outTypeEnum); // stdc++ - task.setLinkCPP( library.linkCPP() ); + task.setLinkCPP(library.linkCPP()); // fortran - task.setLinkFortran( library.linkFortran() ); + task.setLinkFortran(library.linkFortran()); task.setLinkFortranMain( library.linkFortranMain() ); // outDir @@ -185,69 +185,72 @@ public class NarCompileMojo if ( type.equals( Library.EXECUTABLE ) ) { // executable has no version number - outFile = new File( outDir, getMavenProject().getArtifactId() ); + outFile = new File(outDir, getMavenProject().getArtifactId()); } else { - outFile = new File( outDir, getOutput( getAOL() ) ); + outFile = new File(outDir, getOutput(getAOL())); } - getLog().debug( "NAR - output: '" + outFile + "'" ); - task.setOutfile( outFile ); + getLog().debug("NAR - output: '" + outFile + "'"); + task.setOutfile(outFile); // object directory - File objDir = new File( getTargetDirectory(), "obj" ); - objDir = new File( objDir, getAOL().toString() ); + File objDir = new File(getTargetDirectory(), "obj"); + objDir = new File(objDir, getAOL().toString()); objDir.mkdirs(); - task.setObjdir( objDir ); + task.setObjdir(objDir); // failOnError, libtool - task.setFailonerror( failOnError( getAOL() ) ); - task.setLibtool( useLibtool( getAOL() ) ); + task.setFailonerror(failOnError(getAOL())); + task.setLibtool(useLibtool(getAOL())); // runtime RuntimeType runtimeType = new RuntimeType(); - runtimeType.setValue( getRuntime( getAOL() ) ); - task.setRuntime( runtimeType ); + runtimeType.setValue(getRuntime(getAOL())); + task.setRuntime(runtimeType); + // Darren Sargent Feb 11 2010: Use Compiler.MAIN for "type"...appears the wrong "type" variable was being used + // since getCompiler() expects "main" or "test", whereas the "type" variable here is "executable", "shared" etc. // add C++ compiler - CompilerDef cpp = getCpp().getCompiler( type, getOutput( getAOL() ) ); + CompilerDef cpp = getCpp().getCompiler( Compiler.MAIN, getOutput( getAOL() ) ); if ( cpp != null ) { task.addConfiguredCompiler( cpp ); } // add C compiler - CompilerDef c = getC().getCompiler( type, getOutput( getAOL() ) ); + CompilerDef c = getC().getCompiler( Compiler.MAIN, getOutput( getAOL() ) ); if ( c != null ) { task.addConfiguredCompiler( c ); } // add Fortran compiler - CompilerDef fortran = getFortran().getCompiler( type, getOutput( getAOL() ) ); + CompilerDef fortran = getFortran().getCompiler( Compiler.MAIN, getOutput( getAOL() ) ); if ( fortran != null ) { task.addConfiguredCompiler( fortran ); } + // end Darren // add javah include path File jniDirectory = getJavah().getJniDirectory(); - if ( jniDirectory.exists() ) + if (jniDirectory.exists()) { - task.createIncludePath().setPath( jniDirectory.getPath() ); + task.createIncludePath().setPath(jniDirectory.getPath()); } // add java include paths - getJava().addIncludePaths( task, type ); + getJava().addIncludePaths(task, type); // add dependency include paths for ( Iterator i = getNarManager().getNarDependencies( "compile" ).iterator(); i.hasNext(); ) { // FIXME, handle multiple includes from one NAR NarArtifact narDependency = (NarArtifact) i.next(); - String binding = narDependency.getNarInfo().getBinding( getAOL(), Library.STATIC ); - getLog().debug( "Looking for " + narDependency + " found binding " + binding ); - if ( !binding.equals( Library.JNI ) ) + String binding = narDependency.getNarInfo().getBinding(getAOL(), Library.STATIC); + getLog().debug( "Looking for " + narDependency + " found binding " + binding); + if ( !binding.equals(Library.JNI ) ) { File unpackDirectory = getUnpackDirectory(); File include = @@ -256,7 +259,10 @@ public class NarCompileMojo getLog().debug( "Looking for include directory: " + include ); if ( include.exists() ) { - task.createIncludePath().setPath( include.getPath() ); + task.createIncludePath().setPath(include.getPath()); + } else { + throw new MojoExecutionException( + "NAR: unable to locate include path: " + include); } } } @@ -264,7 +270,7 @@ public class NarCompileMojo // add linker LinkerDef linkerDefinition = getLinker().getLinker( this, antProject, getOS(), getAOL().getKey() + ".linker.", type ); - task.addConfiguredLinker( linkerDefinition ); + task.addConfiguredLinker(linkerDefinition); // add dependency libraries // FIXME: what about PLUGIN and STATIC, depending on STATIC, should we @@ -273,7 +279,7 @@ public class NarCompileMojo { List depLibOrder = getDependencyLibOrder(); - List depLibs = getNarManager().getNarDependencies( "compile" ); + List depLibs = getNarManager().getNarDependencies("compile"); // reorder the libraries that come from the nar dependencies // to comply with the order specified by the user @@ -290,15 +296,15 @@ public class NarCompileMojo NarArtifact dep = (NarArtifact) j.next(); String depName = dep.getGroupId() + ":" + dep.getArtifactId(); - if ( depName.equals( depToOrderName ) ) + if (depName.equals(depToOrderName)) { - tmp.add( dep ); + tmp.add(dep); j.remove(); } } } - tmp.addAll( depLibs ); + tmp.addAll(depLibs); depLibs = tmp; } @@ -310,12 +316,12 @@ public class NarCompileMojo // FIXME, no way to override this at this stage String binding = dependency.getNarInfo().getBinding( getAOL(), Library.NONE ); - getLog().debug( "Using Binding: " + binding ); + getLog().debug("Using Binding: " + binding); AOL aol = getAOL(); - aol = dependency.getNarInfo().getAOL( getAOL() ); - getLog().debug( "Using Library AOL: " + aol.toString() ); + aol = dependency.getNarInfo().getAOL(getAOL()); + getLog().debug("Using Library AOL: " + aol.toString()); - if ( !binding.equals( Library.JNI ) && !binding.equals( Library.NONE ) ) + if ( !binding.equals( Library.JNI ) && !binding.equals( Library.NONE ) && !binding.equals( Library.EXECUTABLE) ) { File unpackDirectory = getUnpackDirectory(); @@ -323,20 +329,20 @@ public class NarCompileMojo getLayout().getLibDirectory( unpackDirectory, dependency.getArtifactId(), dependency.getVersion(), aol.toString(), binding ); - getLog().debug( "Looking for Library Directory: " + dir ); + getLog().debug("Looking for Library Directory: " + dir); if ( dir.exists() ) { LibrarySet libSet = new LibrarySet(); - libSet.setProject( antProject ); + libSet.setProject(antProject); // FIXME, no way to override - String libs = dependency.getNarInfo().getLibs( getAOL() ); + String libs = dependency.getNarInfo().getLibs(getAOL()); if ( ( libs != null ) && !libs.equals( "" ) ) { - getLog().debug( "Using LIBS = " + libs ); - libSet.setLibs( new CUtil.StringArrayBuilder( libs ) ); - libSet.setDir( dir ); - task.addLibset( libSet ); + getLog().debug("Using LIBS = " + libs); + libSet.setLibs(new CUtil.StringArrayBuilder(libs)); + libSet.setDir(dir); + task.addLibset(libSet); } } else @@ -348,21 +354,21 @@ public class NarCompileMojo String options = dependency.getNarInfo().getOptions( getAOL() ); if ( ( options != null ) && !options.equals( "" ) ) { - getLog().debug( "Using OPTIONS = " + options ); + getLog().debug("Using OPTIONS = " + options); LinkerArgument arg = new LinkerArgument(); - arg.setValue( options ); - linkerDefinition.addConfiguredLinkerArg( arg ); + arg.setValue(options); + linkerDefinition.addConfiguredLinkerArg(arg); } String sysLibs = dependency.getNarInfo().getSysLibs( getAOL() ); if ( ( sysLibs != null ) && !sysLibs.equals( "" ) ) { - getLog().debug( "Using SYSLIBS = " + sysLibs ); + getLog().debug("Using SYSLIBS = " + sysLibs); SystemLibrarySet sysLibSet = new SystemLibrarySet(); - sysLibSet.setProject( antProject ); + sysLibSet.setProject(antProject); sysLibSet.setLibs( new CUtil.StringArrayBuilder( sysLibs ) ); - task.addSyslibset( sysLibSet ); + task.addSyslibset(sysLibSet); } } } @@ -378,7 +384,7 @@ public class NarCompileMojo } catch ( BuildException e ) { - throw new MojoExecutionException( "NAR: Compile failed", e ); + throw new MojoExecutionException("NAR: Compile failed", e); } // FIXME, this should be done in CPPTasks at some point @@ -393,10 +399,19 @@ public class NarCompileMojo int result = NarUtil.runCommand( "mt.exe", new String[] { "/manifest", manifest, "/outputresource:" + dll + ";#2" }, null, null, getLog() ); - if ( result != 0 ) + if (result != 0) { - throw new MojoFailureException( "MT.EXE failed with exit code: " + result ); + throw new MojoFailureException("MT.EXE failed with exit code: " + result); } + } else if (libType.equals(Library.EXECUTABLE)) { + String exe = outFile.getPath() + ".exe"; + String manifest = exe + ".manifest"; + int result = NarUtil.runCommand("mt.exe", + new String[] { "/manifest", manifest, + "/outputresource:" + exe + ";#1" }, null, null, getLog()); + if (result != 0) + throw new MojoFailureException( + "MT.EXE failed with exit code: " + result); } } } diff --git a/src/main/java/org/apache/maven/plugin/nar/NarGnuConfigureMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarGnuConfigureMojo.java index 924bda3..4e15f48 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarGnuConfigureMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarGnuConfigureMojo.java @@ -104,7 +104,7 @@ public class NarGnuConfigureMojo getLog().info( "Running GNU " + CONFIGURE ); NarUtil.makeExecutable( configure, getLog() ); int result = - NarUtil.runCommand( "./" + configure.getName(), new String[] { + NarUtil.runCommand( "./" + configure.getName(), new String[] { "--disable-ccache", "--prefix=" + getGnuAOLTargetDirectory().getAbsolutePath() }, targetDir, null, getLog() ); if ( result != 0 ) { diff --git a/src/main/java/org/apache/maven/plugin/nar/NarManager.java b/src/main/java/org/apache/maven/plugin/nar/NarManager.java index 5cbcd10..fd77645 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarManager.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarManager.java @@ -47,15 +47,15 @@ import org.codehaus.plexus.archiver.manager.ArchiverManager; public class NarManager { - private Log log; + private Log log; - private MavenProject project; + private MavenProject project; - private ArtifactRepository repository; + private ArtifactRepository repository; - private AOL defaultAOL; + private AOL defaultAOL; - private String linkerName; + private String linkerName; private String[] narTypes = { NarConstants.NAR_NO_ARCH, Library.STATIC, Library.SHARED, Library.JNI, Library.PLUGIN }; @@ -64,99 +64,99 @@ public class NarManager Linker linker ) throws MojoFailureException, MojoExecutionException { - this.log = log; - this.repository = repository; - this.project = project; - this.defaultAOL = NarUtil.getAOL( architecture, os, linker, null ); - this.linkerName = NarUtil.getLinkerName( architecture, os, linker ); - } - - /** + this.log = log; + this.repository = repository; + this.project = project; + this.defaultAOL = NarUtil.getAOL(architecture, os, linker, null); + this.linkerName = NarUtil.getLinkerName(architecture, os, linker); + } + + /** * Returns dependencies which are dependent on NAR files (i.e. contain NarInfo) - */ - public final List/* <NarArtifact> */getNarDependencies( String scope ) + */ + public final List/* <NarArtifact> */getNarDependencies(String scope) throws MojoExecutionException { - List narDependencies = new LinkedList(); + List narDependencies = new LinkedList(); for ( Iterator i = getDependencies( scope ).iterator(); i.hasNext(); ) { - Artifact dependency = (Artifact) i.next(); - log.debug( "Examining artifact for NarInfo: " + dependency ); + Artifact dependency = (Artifact) i.next(); + log.debug("Examining artifact for NarInfo: " + dependency); - NarInfo narInfo = getNarInfo( dependency ); + NarInfo narInfo = getNarInfo(dependency); if ( narInfo != null ) { - log.debug( " - added as NarDependency" ); - narDependencies.add( new NarArtifact( dependency, narInfo ) ); - } - } - return narDependencies; - } - - /** + log.debug(" - added as NarDependency"); + narDependencies.add(new NarArtifact(dependency, narInfo)); + } + } + return narDependencies; + } + + /** * Returns all NAR dependencies by type: noarch, static, dynamic, jni, plugin. - * - * @throws MojoFailureException - */ + * + * @throws MojoFailureException + */ public final Map/* <String, List<AttachedNarArtifact>> */getAttachedNarDependencyMap( String scope ) throws MojoExecutionException, MojoFailureException { - Map attachedNarDependencies = new HashMap(); + Map attachedNarDependencies = new HashMap(); for ( Iterator i = getNarDependencies( scope ).iterator(); i.hasNext(); ) { - Artifact dependency = (Artifact) i.next(); + Artifact dependency = (Artifact) i.next(); for ( int j = 0; j < narTypes.length; j++ ) { List artifactList = getAttachedNarDependencies( dependency, defaultAOL, narTypes[j] ); if ( artifactList != null ) { - attachedNarDependencies.put( narTypes[j], artifactList ); - } - } - } - return attachedNarDependencies; - } + attachedNarDependencies.put(narTypes[j], artifactList); + } + } + } + return attachedNarDependencies; + } public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts ) throws MojoExecutionException, MojoFailureException { - return getAttachedNarDependencies( narArtifacts, ( String )null ); - } + return getAttachedNarDependencies(narArtifacts, (String) null); + } public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts, String classifier ) throws MojoExecutionException, MojoFailureException { - AOL aol = null; - String type = null; + AOL aol = null; + String type = null; if ( classifier != null ) { - int dash = classifier.lastIndexOf( '-' ); + int dash = classifier.lastIndexOf('-'); if ( dash < 0 ) { - aol = new AOL( classifier ); - type = null; + aol = new AOL(classifier); + type = null; } else { - aol = new AOL( classifier.substring( 0, dash ) ); - type = classifier.substring( dash + 1 ); - } - } - return getAttachedNarDependencies( narArtifacts, aol, type ); - } - - public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( - List/* <NarArtifacts> */narArtifacts, List classifiers) + aol = new AOL(classifier.substring(0, dash)); + type = classifier.substring(dash + 1); + } + } + return getAttachedNarDependencies(narArtifacts, aol, type); + } + + public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( + List/* <NarArtifacts> */narArtifacts, List classifiers) throws MojoExecutionException, MojoFailureException { - String[] types; - - List artifactList = new ArrayList(); + String[] types; + + List artifactList = new ArrayList(); if( classifiers != null && !classifiers.isEmpty() ) { - types = (String[]) classifiers.toArray(); + types = (String[]) classifiers.toArray(); for ( int j = 0; j < types.length; j++ ) { @@ -169,92 +169,92 @@ public class NarManager else { artifactList.addAll( getAttachedNarDependencies( narArtifacts, ( String )null )); - } + } - return artifactList; - } + return artifactList; + } - /** + /** * Returns a list of all attached nar dependencies for a specific binding and "noarch", but not where "local" is * specified - * + * * @param scope compile, test, runtime, .... * @param aol either a valid aol, noarch or null. In case of null both the default getAOL() and noarch dependencies * are returned. * @param type noarch, static, shared, jni, or null. In case of null the default binding found in narInfo is used. - * @return - * @throws MojoExecutionException - * @throws MojoFailureException - */ + * @return + * @throws MojoExecutionException + * @throws MojoFailureException + */ public final List/* <AttachedNarArtifact> */getAttachedNarDependencies( List/* <NarArtifacts> */narArtifacts, AOL archOsLinker, String type ) throws MojoExecutionException, MojoFailureException { - boolean noarch = false; - AOL aol = archOsLinker; + boolean noarch = false; + AOL aol = archOsLinker; if ( aol == null ) { - noarch = true; - aol = defaultAOL; - } + noarch = true; + aol = defaultAOL; + } - List artifactList = new ArrayList(); + List artifactList = new ArrayList(); for ( Iterator i = narArtifacts.iterator(); i.hasNext(); ) { - Artifact dependency = (Artifact) i.next(); - NarInfo narInfo = getNarInfo( dependency ); + Artifact dependency = (Artifact) i.next(); + NarInfo narInfo = getNarInfo(dependency); if ( noarch ) { artifactList.addAll( getAttachedNarDependencies( dependency, null, NarConstants.NAR_NO_ARCH ) ); - } + } - // use preferred binding, unless non existing. + // use preferred binding, unless non existing. String binding = narInfo.getBinding( aol, type != null ? type : Library.STATIC ); - // FIXME kludge, but does not work anymore since AOL is now a class + // FIXME kludge, but does not work anymore since AOL is now a class if ( aol.equals( NarConstants.NAR_NO_ARCH ) ) { - // FIXME no handling of local + // FIXME no handling of local artifactList.addAll( getAttachedNarDependencies( dependency, null, NarConstants.NAR_NO_ARCH ) ); } else { artifactList.addAll( getAttachedNarDependencies( dependency, aol, binding ) ); - } - } - return artifactList; - } + } + } + return artifactList; + } private List/* <AttachedNarArtifact> */getAttachedNarDependencies( Artifact dependency, AOL archOsLinker, String type ) throws MojoExecutionException, MojoFailureException { - AOL aol = archOsLinker; + AOL aol = archOsLinker; log.debug( "GetNarDependencies for " + dependency + ", aol: " + aol + ", type: " + type ); - List artifactList = new ArrayList(); - NarInfo narInfo = getNarInfo( dependency ); - String[] nars = narInfo.getAttachedNars( aol, type ); - // FIXME Move this to NarInfo.... + List artifactList = new ArrayList(); + NarInfo narInfo = getNarInfo(dependency); + String[] nars = narInfo.getAttachedNars(aol, type); + // FIXME Move this to NarInfo.... if ( nars != null ) { for ( int j = 0; j < nars.length; j++ ) { - log.debug( " Checking: " + nars[j] ); + log.debug(" Checking: " + nars[j]); if ( nars[j].equals( "" ) ) { - continue; - } - String[] nar = nars[j].split( ":", 5 ); + continue; + } + String[] nar = nars[j].split(":", 5); if ( nar.length >= 4 ) { try { - String groupId = nar[0].trim(); - String artifactId = nar[1].trim(); - String ext = nar[2].trim(); - String classifier = nar[3].trim(); - // translate for instance g++ to gcc... - aol = narInfo.getAOL( aol ); + String groupId = nar[0].trim(); + String artifactId = nar[1].trim(); + String ext = nar[2].trim(); + String classifier = nar[3].trim(); + // translate for instance g++ to gcc... + aol = narInfo.getAOL(aol); if ( aol != null ) { classifier = NarUtil.replace( "${aol}", aol.toString(), classifier ); @@ -272,42 +272,42 @@ public class NarManager else { log.warn( "nars property in " + dependency.getArtifactId() + " contains invalid field: '" + nars[j] - + "' for type: " + type ); - } - } - } - return artifactList; - } - - public final NarInfo getNarInfo( Artifact dependency ) + + "' for type: " + type); + } + } + } + return artifactList; + } + + public final NarInfo getNarInfo(Artifact dependency) throws MojoExecutionException { - // FIXME reported to maven developer list, isSnapshot changes behaviour - // of getBaseVersion, called in pathOf. - dependency.isSnapshot(); + // FIXME reported to maven developer list, isSnapshot changes behaviour + // of getBaseVersion, called in pathOf. + dependency.isSnapshot(); File file = new File( repository.getBasedir(), repository.pathOf( dependency ) ); if ( !file.exists() ) { - return null; - } + return null; + } - JarFile jar = null; + JarFile jar = null; try { - jar = new JarFile( file ); + jar = new JarFile(file); NarInfo info = new NarInfo( dependency.getGroupId(), dependency.getArtifactId(), dependency.getBaseVersion(), log ); if ( !info.exists( jar ) ) { - return null; - } - info.read( jar ); - return info; + return null; + } + info.read(jar); + return info; } catch ( IOException e ) { - throw new MojoExecutionException( "Error while reading " + file, e ); + throw new MojoExecutionException("Error while reading " + file, e); } finally { @@ -315,74 +315,74 @@ public class NarManager { try { - jar.close(); + jar.close(); } catch ( IOException e ) { - // ignore - } - } - } - } + // ignore + } + } + } + } - public final File getNarFile( Artifact dependency ) + public final File getNarFile(Artifact dependency) throws MojoFailureException { - // FIXME reported to maven developer list, isSnapshot changes behaviour - // of getBaseVersion, called in pathOf. - dependency.isSnapshot(); + // FIXME reported to maven developer list, isSnapshot changes behaviour + // of getBaseVersion, called in pathOf. + dependency.isSnapshot(); return new File( repository.getBasedir(), NarUtil.replace( "${aol}", defaultAOL.toString(), repository.pathOf( dependency ) ) ); - } + } private List getDependencies( String scope ) { if ( scope.equals( Artifact.SCOPE_TEST ) ) { - return project.getTestArtifacts(); + return project.getTestArtifacts(); } else if ( scope.equals( Artifact.SCOPE_RUNTIME ) ) { - return project.getRuntimeArtifacts(); - } - return project.getCompileArtifacts(); - } + return project.getRuntimeArtifacts(); + } + return project.getCompileArtifacts(); + } public final void downloadAttachedNars( List/* <NarArtifacts> */narArtifacts, List remoteRepositories, - ArtifactResolver resolver, String classifier ) + ArtifactResolver resolver, String classifier) throws MojoExecutionException, MojoFailureException { - // FIXME this may not be the right way to do this.... -U ignored and - // also SNAPSHOT not used - List dependencies = getAttachedNarDependencies( narArtifacts, classifier ); + // FIXME this may not be the right way to do this.... -U ignored and + // also SNAPSHOT not used + List dependencies = getAttachedNarDependencies(narArtifacts, classifier); log.debug( "Download called with classifier: " + classifier + " for NarDependencies {" ); for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { - log.debug( " - " + ( i.next() ) ); - } - log.debug( "}" ); + log.debug(" - " + (i.next())); + } + log.debug("}"); for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { - Artifact dependency = (Artifact) i.next(); + Artifact dependency = (Artifact) i.next(); try { - log.debug( "Resolving " + dependency ); - resolver.resolve( dependency, remoteRepositories, repository ); + log.debug("Resolving " + dependency); + resolver.resolve(dependency, remoteRepositories, repository); } catch ( ArtifactNotFoundException e ) { - String message = "nar not found " + dependency.getId(); - throw new MojoExecutionException( message, e ); + String message = "nar not found " + dependency.getId(); + throw new MojoExecutionException(message, e); } catch ( ArtifactResolutionException e ) { - String message = "nar cannot resolve " + dependency.getId(); - throw new MojoExecutionException( message, e ); - } - } - } + String message = "nar cannot resolve " + dependency.getId(); + throw new MojoExecutionException(message, e); + } + } + } public final void unpackAttachedNars( List/* <NarArtifacts> */narArtifacts, ArchiverManager archiverManager, String classifier, String os, NarLayout layout, File unpackDir ) @@ -391,18 +391,18 @@ public class NarManager log.debug( "Unpack called for OS: " + os + ", classifier: " + classifier + " for NarArtifacts {" ); for ( Iterator i = narArtifacts.iterator(); i.hasNext(); ) { - log.debug( " - " + ( i.next() ) ); - } - log.debug( "}" ); - // FIXME, kludge to get to download the -noarch, based on classifier - List dependencies = getAttachedNarDependencies( narArtifacts, classifier ); + log.debug(" - " + (i.next())); + } + log.debug("}"); + // FIXME, kludge to get to download the -noarch, based on classifier + List dependencies = getAttachedNarDependencies(narArtifacts, classifier); for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { - Artifact dependency = (Artifact) i.next(); - log.debug( "Unpack " + dependency ); - File file = getNarFile( dependency ); + Artifact dependency = (Artifact) i.next(); + log.debug("Unpack " + dependency + " to " + unpackDir); + File file = getNarFile(dependency); layout.unpackNar(unpackDir, archiverManager, file, os, linkerName, defaultAOL); - } - } + } + } } diff --git a/src/main/java/org/apache/maven/plugin/nar/NarSystemMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarSystemMojo.java index 24443c3..758eb74 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarSystemMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarSystemMojo.java @@ -53,7 +53,8 @@ public class NarSystemMojo for ( Iterator i = getLibraries().iterator(); !jniFound && i.hasNext(); ) { Library library = (Library) i.next(); - if ( library.getType().equals( Library.JNI ) ) + if ( library.getType().equals( Library.JNI ) + || library.getType().equals( Library.SHARED )) { packageName = library.getNarSystemPackage(); narSystemName = library.getNarSystemName(); @@ -64,6 +65,12 @@ public class NarSystemMojo if ( !jniFound || packageName == null) { + if ( !jniFound ) { + getLog().debug("NAR: not building a shared or JNI library, so not generating NarSystem class."); + } else { + getLog().warn( + "NAR: no system package specified; unable to generate NarSystem class."); + } return; } @@ -108,6 +115,12 @@ public class NarSystemMojo p.println( " System.loadLibrary(\"" + artifactId + "-" + version + "\");" ); p.println( " }" ); + p.println(""); + p.println(" public static int runUnitTests() {"); + p.println(" return new NarSystem().runUnitTestsNative();"); + p.println("}"); + p.println(""); + p.println(" public native int runUnitTestsNative();"); p.println( "}" ); p.close(); fos.close(); diff --git a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java index 751cce0..cb77355 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java @@ -39,6 +39,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.PropertyUtils; import org.codehaus.plexus.util.cli.Commandline; @@ -714,4 +715,23 @@ public final class NarUtil } } + + /** + * (Darren) this code lifted from mvn help:active-profiles plugin Recurses + * into the project's parent poms to find the active profiles of the + * specified project and all its parents. + * + * @param project + * The project to start with + * @return A list of active profiles + */ + static List collectActiveProfiles(MavenProject project) { + List profiles = project.getActiveProfiles(); + + if (project.hasParent()) { + profiles.addAll(collectActiveProfiles(project.getParent())); + } + + return profiles; + } } |