diff options
Diffstat (limited to 'src/main')
13 files changed, 476 insertions, 135 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 de643ae..a5d5c50 100644 --- a/src/main/java/org/apache/maven/plugin/nar/AOL.java +++ b/src/main/java/org/apache/maven/plugin/nar/AOL.java @@ -58,6 +58,10 @@ public class AOL this.linkerName = linkerName; } + /** + * Returns an AOL string (arch-os-linker) to use as directory or file. + * @return dash separated AOL + */ public String toString() { return architecture + ( ( os == null ) ? "" : "-" + os + ( ( linkerName == null ) ? "" : "-" + linkerName ) ); @@ -69,6 +73,10 @@ public class AOL return linkerName.equals( linker ); } + /** + * Returns an AOL key (arch.os.linker) to search in the properties files. + * @return dot separated AOL + */ public String getKey() { return architecture + ( ( os == null ) ? "" : "." + os + ( ( linkerName == null ) ? "" : "." + linkerName ) ); diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractGnuMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractGnuMojo.java new file mode 100644 index 0000000..639dda2 --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/nar/AbstractGnuMojo.java @@ -0,0 +1,78 @@ +package org.apache.maven.plugin.nar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.plugin.MojoFailureException; + +/** + * Abstract GNU Mojo keeps configuration + * + * @author Mark Donszelmann + */ +public abstract class AbstractGnuMojo + extends AbstractResourcesMojo +{ + /** + * Source directory for GNU style project + * + * @parameter expression="${basedir}/src/gnu" + * @required + */ + protected File gnuSourceDirectory; + + /** + * @parameter expression="${project.build.directory}/gnu" + * @required + */ + private File gnuTargetDirectory; + + /** + * @return + * @throws MojoFailureException + */ + protected File getGnuAOLSourceDirectory() + throws MojoFailureException + { + return new File( getGnuAOLDirectory(), "src" ); + } + + /** + * @return + * @throws MojoFailureException + */ + protected File getGnuAOLTargetDirectory() + throws MojoFailureException + { + return new File( getGnuAOLDirectory(), "target" ); + } + + /** + * @return + * @throws MojoFailureException + */ + private File getGnuAOLDirectory() + throws MojoFailureException + { + return new File( gnuTargetDirectory, getAOL().toString() ); + } + +} diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java new file mode 100644 index 0000000..31d9960 --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/nar/AbstractResourcesMojo.java @@ -0,0 +1,150 @@ +package org.apache.maven.plugin.nar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.archiver.ArchiverException; +import org.codehaus.plexus.archiver.UnArchiver; +import org.codehaus.plexus.archiver.manager.ArchiverManager; +import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; +import org.codehaus.plexus.util.FileUtils; + +/** + * Keeps track of resources + * + * @author Mark Donszelmann + */ +public abstract class AbstractResourcesMojo + extends AbstractCompileMojo +{ + /** + * Binary directory + * + * @parameter expression="bin" + * @required + */ + private String resourceBinDir; + + /** + * Include directory + * + * @parameter expression="include" + * @required + */ + private String resourceIncludeDir; + + /** + * Library directory + * + * @parameter expression="lib" + * @required + */ + private String resourceLibDir; + + /** + * To look up Archiver/UnArchiver implementations + * + * @component role="org.codehaus.plexus.archiver.manager.ArchiverManager" + * @required + */ + private ArchiverManager archiverManager; + + protected void copyResources( File srcDir, String aol) + throws MojoExecutionException, MojoFailureException + { + int copied = 0; + try + { + // copy headers + File includeDir = new File( srcDir, resourceIncludeDir ); + if ( includeDir.exists() ) + { + File includeDstDir = new File( getTargetDirectory(), "include" ); + copied += NarUtil.copyDirectoryStructure( includeDir, includeDstDir, null, NarUtil.DEFAULT_EXCLUDES ); + } + + // copy binaries + File binDir = new File( srcDir, resourceBinDir ); + if ( binDir.exists() ) + { + File binDstDir = new File( getTargetDirectory(), "bin" ); + binDstDir = new File( binDstDir, aol ); + + copied += NarUtil.copyDirectoryStructure( binDir, binDstDir, null, NarUtil.DEFAULT_EXCLUDES ); + } + + // copy libraries + File libDir = new File( srcDir, resourceLibDir ); + if ( libDir.exists() ) + { + // create all types of libs + for ( Iterator i = getLibraries().iterator(); i.hasNext(); ) + { + Library library = (Library) i.next(); + String type = library.getType(); + File libDstDir = new File( getTargetDirectory(), "lib" ); + libDstDir = new File( libDstDir, aol ); + libDstDir = new File( libDstDir, type ); + + // filter files for lib + String includes = + "**/*." + + NarUtil.getDefaults().getProperty( NarUtil.getAOLKey( aol ) + "." + type + ".extension" ); + copied += NarUtil.copyDirectoryStructure( libDir, libDstDir, includes, NarUtil.DEFAULT_EXCLUDES ); + } + } + + // unpack jar files + File classesDirectory = new File( getOutputDirectory(), "classes" ); + classesDirectory.mkdirs(); + List jars = FileUtils.getFiles( srcDir, "**/*.jar", null ); + for ( Iterator i = jars.iterator(); i.hasNext(); ) + { + File jar = (File) i.next(); + getLog().debug( "Unpacking jar " + jar ); + UnArchiver unArchiver; + unArchiver = archiverManager.getUnArchiver( AbstractNarMojo.NAR_ROLE_HINT ); + unArchiver.setSourceFile( jar ); + unArchiver.setDestDirectory( classesDirectory ); + unArchiver.extract(); + } + } + catch ( IOException e ) + { + throw new MojoExecutionException( "NAR: Could not copy resources", e ); + } + catch ( NoSuchArchiverException e ) + { + throw new MojoExecutionException( "NAR: Could not find archiver", e ); + } + catch ( ArchiverException e ) + { + throw new MojoExecutionException( "NAR: Could not unarchive jar file", e ); + } + getLog().info( "Copied " + copied + " resources for " + aol ); + } + +} diff --git a/src/main/java/org/apache/maven/plugin/nar/Javah.java b/src/main/java/org/apache/maven/plugin/nar/Javah.java index a563093..33e6b1c 100644 --- a/src/main/java/org/apache/maven/plugin/nar/Javah.java +++ b/src/main/java/org/apache/maven/plugin/nar/Javah.java @@ -235,7 +235,7 @@ public class Javah getTimestampDirectory().mkdirs(); mojo.getLog().info( "Running " + name + " compiler on " + files.size() + " classes..." ); - int result = NarUtil.runCommand( name, generateArgs( files ), null, mojo.getLog() ); + int result = NarUtil.runCommand( name, generateArgs( files ), null, null, mojo.getLog() ); if ( result != 0 ) { throw new MojoFailureException( name + " failed with exit code " + result + " 0x" 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 5a5d246..7cab1de 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarCompileMojo.java @@ -330,7 +330,7 @@ public class NarCompileMojo String manifest = dll + ".manifest"; int result = NarUtil.runCommand( "mt.exe", new String[] { "/manifest", manifest, - "/outputresource:" + dll + ";#2" }, null, getLog() ); + "/outputresource:" + dll + ";#2" }, 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 new file mode 100644 index 0000000..2f32094 --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/nar/NarGnuConfigureMojo.java @@ -0,0 +1,81 @@ +package org.apache.maven.plugin.nar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.util.FileUtils; + +/** + * Copies the GNU style source files to a target area, autogens and configures them. + * + * @goal nar-gnu-configure + * @phase process-sources + * @requiresProject + * @author Mark Donszelmann + */ +public class NarGnuConfigureMojo + extends AbstractGnuMojo +{ + /** + * Skip running of autogen.sh. + * + * @parameter expression="${nar.gnu.autogen.skip}" default-value="false" + */ + private boolean gnuAutogenSkip; + + private static String autogen = "autogen.sh"; + private static String configure = "configure"; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( shouldSkip() ) + return; + + if ( gnuSourceDirectory.exists() ) + { + getLog().info( "Copying GNU sources" ); + + File targetDir = getGnuAOLSourceDirectory(); + try + { + FileUtils.mkdir( targetDir.getPath() ); + NarUtil.copyDirectoryStructure( gnuSourceDirectory, targetDir, null, null ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Failed to copy GNU sources", e ); + } + + if ((!gnuAutogenSkip) && new File(targetDir, "autogen.sh").exists()) { + getLog().info( "Running GNU "+autogen ); + NarUtil.runCommand( "sh ./"+autogen, null, targetDir, null, getLog() ); + } + + getLog().info( "Running GNU "+configure ); + NarUtil.runCommand( "sh ./"+configure, new String[] { "--disable-ccache", "--prefix=" + + getGnuAOLTargetDirectory().getAbsolutePath() }, targetDir, null, getLog() ); + } + } +} diff --git a/src/main/java/org/apache/maven/plugin/nar/NarGnuMakeMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarGnuMakeMojo.java new file mode 100644 index 0000000..e04e3a9 --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/nar/NarGnuMakeMojo.java @@ -0,0 +1,52 @@ +package org.apache.maven.plugin.nar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * Runs make on the GNU style generated Makefile + * + * @goal nar-gnu-make + * @phase compile + * @requiresProject + * @author Mark Donszelmann + */ +public class NarGnuMakeMojo + extends AbstractGnuMojo +{ + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( shouldSkip() ) + return; + + File srcDir = getGnuAOLSourceDirectory(); + if ( srcDir.exists() ) + { + getLog().info( "Running GNU make" ); + NarUtil.runCommand( "make", null, srcDir, null, getLog() ); + NarUtil.runCommand( "make", new String[] { "install" }, srcDir, null, getLog() ); + } + } +} diff --git a/src/main/java/org/apache/maven/plugin/nar/NarGnuProcess.java b/src/main/java/org/apache/maven/plugin/nar/NarGnuProcess.java new file mode 100644 index 0000000..5f2eb5b --- /dev/null +++ b/src/main/java/org/apache/maven/plugin/nar/NarGnuProcess.java @@ -0,0 +1,61 @@ +package org.apache.maven.plugin.nar; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.archiver.manager.ArchiverManager; + +/** + * Move the GNU style output in the correct directories for nar-package + * + * @goal nar-gnu-process + * @phase process-classes + * @requiresProject + * @author Mark Donszelmann + */ +public class NarGnuProcess + extends AbstractGnuMojo +{ + /** + * To look up Archiver/UnArchiver implementations + * + * @component role="org.codehaus.plexus.archiver.manager.ArchiverManager" + * @required + */ + private ArchiverManager archiverManager; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + if ( shouldSkip() ) + return; + + File srcDir = getGnuAOLTargetDirectory(); + if ( srcDir.exists() ) + { + getLog().info( "Running GNU process" ); + + copyResources( srcDir, getAOL().toString() ); + } + } +} 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 13a464f..f1df3c9 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarManager.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarManager.java @@ -318,6 +318,14 @@ public class NarManager // 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( " - " + ( (Artifact) i.next() ) ); + } + log.debug( "}" ); + for ( Iterator i = dependencies.iterator(); i.hasNext(); ) { Artifact dependency = (Artifact) i.next(); @@ -423,10 +431,6 @@ public class NarManager unArchiver.setDestDirectory( location ); unArchiver.extract(); } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error unpacking file: " + file + " to: " + location, e ); - } catch ( NoSuchArchiverException e ) { throw new MojoExecutionException( "Error unpacking file: " + file + " to: " + location, e ); diff --git a/src/main/java/org/apache/maven/plugin/nar/NarResourcesMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarResourcesMojo.java index a23bef4..927ba3c 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarResourcesMojo.java @@ -20,16 +20,10 @@ package org.apache.maven.plugin.nar; */ import java.io.File; -import java.io.IOException; import java.util.Iterator; -import java.util.List; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.archiver.ArchiverException; -import org.codehaus.plexus.archiver.UnArchiver; -import org.codehaus.plexus.archiver.manager.ArchiverManager; -import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.SelectorUtils; @@ -42,7 +36,7 @@ import org.codehaus.plexus.util.SelectorUtils; * @author Mark Donszelmann */ public class NarResourcesMojo - extends AbstractCompileMojo + extends AbstractResourcesMojo { /** @@ -53,38 +47,6 @@ public class NarResourcesMojo */ private File resourceDirectory; - /** - * Binary directory (relative to ${resourceDirectory}/aol/${aol} - * - * @parameter expression="bin" - * @required - */ - private String resourceBinDir; - - /** - * Include directory (relative to ${resourceDirectory}/aol/${aol} - * - * @parameter expression="include" - * @required - */ - private String resourceIncludeDir; - - /** - * Library directory (relative to ${resourceDirectory}/aol/${aol} - * - * @parameter expression="lib" - * @required - */ - private String resourceLibDir; - - /** - * To look up Archiver/UnArchiver implementations - * - * @component role="org.codehaus.plexus.archiver.manager.ArchiverManager" - * @required - */ - private ArchiverManager archiverManager; - public void execute() throws MojoExecutionException, MojoFailureException { @@ -110,86 +72,10 @@ public class NarResourcesMojo } if ( !ignore ) { - copyResources( new File( aolDir, aols[i] ) ); - } - } - } - } - - private void copyResources( File aolDir ) - throws MojoExecutionException, MojoFailureException - { - String aol = aolDir.getName(); - int copied = 0; - try - { - // copy headers - File includeDir = new File( aolDir, resourceIncludeDir ); - if ( includeDir.exists() ) - { - File includeDstDir = new File( getTargetDirectory(), "include" ); - copied += NarUtil.copyDirectoryStructure( includeDir, includeDstDir, null, NarUtil.DEFAULT_EXCLUDES ); - } - - // copy binaries - File binDir = new File( aolDir, resourceBinDir ); - if ( binDir.exists() ) - { - File binDstDir = new File( getTargetDirectory(), "bin" ); - binDstDir = new File( binDstDir, aol ); - - copied += NarUtil.copyDirectoryStructure( binDir, binDstDir, null, NarUtil.DEFAULT_EXCLUDES ); - } - - // copy libraries - File libDir = new File( aolDir, resourceLibDir ); - if ( libDir.exists() ) - { - // create all types of libs - for ( Iterator i = getLibraries().iterator(); i.hasNext(); ) - { - Library library = (Library) i.next(); - String type = library.getType(); - File libDstDir = new File( getTargetDirectory(), "lib" ); - libDstDir = new File( libDstDir, aol ); - libDstDir = new File( libDstDir, type ); - - // filter files for lib - String includes = - "**/*." - + NarUtil.getDefaults().getProperty( NarUtil.getAOLKey( aol ) + "." + type + ".extension" ); - copied += NarUtil.copyDirectoryStructure( libDir, libDstDir, includes, NarUtil.DEFAULT_EXCLUDES ); + File aol = new File( aolDir, aols[i] ); + copyResources( aol, aol.getName() ); } } - - // unpack jar files - File classesDirectory = new File( getOutputDirectory(), "classes" ); - classesDirectory.mkdirs(); - List jars = FileUtils.getFiles( aolDir, "**/*.jar", null ); - for ( Iterator i = jars.iterator(); i.hasNext(); ) - { - File jar = (File) i.next(); - getLog().debug( "Unpacking jar " + jar ); - UnArchiver unArchiver; - unArchiver = archiverManager.getUnArchiver( AbstractNarMojo.NAR_ROLE_HINT ); - unArchiver.setSourceFile( jar ); - unArchiver.setDestDirectory( classesDirectory ); - unArchiver.extract(); - } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "NAR: Could not copy resources", e ); - } - catch ( NoSuchArchiverException e ) - { - throw new MojoExecutionException( "NAR: Could not find archiver", e ); } - catch ( ArchiverException e ) - { - throw new MojoExecutionException( "NAR: Could not unarchive jar file", e ); - } - getLog().info( "Copied " + copied + " resources for " + aol ); } - } diff --git a/src/main/java/org/apache/maven/plugin/nar/NarTestMojo.java b/src/main/java/org/apache/maven/plugin/nar/NarTestMojo.java index bb99242..46b7dae 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarTestMojo.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarTestMojo.java @@ -79,11 +79,11 @@ public class NarTestMojo if ( test.shouldRun() ) { String name = "target/test-nar/bin/" + getAOL() + "/" + test.getName(); - getLog().info( "Running " + name ); + getLog().info( "Running test " + name ); List args = test.getArgs(); int result = NarUtil.runCommand( getMavenProject().getBasedir() + "/" + name, - (String[]) args.toArray( new String[args.size()] ), + (String[]) args.toArray( new String[args.size()] ), null, generateEnvironment( test, getLog() ), getLog() ); if ( result != 0 ) throw new MojoFailureException( "Test " + name + " failed with exit code: " + result + " 0x" @@ -98,11 +98,11 @@ public class NarTestMojo { MavenProject project = getMavenProject(); String name = "target/nar/bin/" + getAOL() + "/" + project.getArtifactId(); - getLog().info( "Running " + name ); + getLog().info( "Running executable " + name ); List args = library.getArgs(); int result = NarUtil.runCommand( project.getBasedir() + "/" + name, - (String[]) args.toArray( new String[args.size()] ), + (String[]) args.toArray( new String[args.size()] ), null, generateEnvironment( library, getLog() ), getLog() ); if ( result != 0 ) throw new MojoFailureException( "Test " + name + " failed with exit code: " + result + " 0x" 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 4012db6..c65f3e6 100644 --- a/src/main/java/org/apache/maven/plugin/nar/NarUtil.java +++ b/src/main/java/org/apache/maven/plugin/nar/NarUtil.java @@ -38,6 +38,7 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.PropertyUtils; +import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.Commandline; /** @@ -154,7 +155,7 @@ public class NarUtil if ( file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() ) { // chmod +x file - int result = runCommand( "chmod", new String[] { "+x", file.getPath() }, null, log ); + int result = runCommand( "chmod", new String[] { "+x", file.getPath() }, null, null, log ); if ( result != 0 ) { throw new MojoExecutionException( "Failed to execute 'chmod +x " + file.getPath() + "'" @@ -182,7 +183,7 @@ public class NarUtil if ( file.isFile() && file.canRead() && file.canWrite() && !file.isHidden() && file.getName().endsWith( ".a" ) ) { // ranlib file - int result = runCommand( "ranlib", new String[] { file.getPath() }, null, log ); + int result = runCommand( "ranlib", new String[] { file.getPath() }, null, null, log ); if ( result != 0 ) { throw new MojoExecutionException( "Failed to execute 'ranlib " + file.getPath() + "'" @@ -406,11 +407,11 @@ public class NarUtil return pathName + "=" + value; } - public static int runCommand( String cmd, String[] args, String[] env, Log log ) + public static int runCommand( String cmd, String[] args, File workingDirectory, String[] env, Log log ) throws MojoExecutionException, MojoFailureException { log.debug( "RunCommand: " + cmd ); - Commandline cmdLine = new Commandline(); + NarCommandLine cmdLine = new NarCommandLine(); cmdLine.setExecutable( cmd ); if ( args != null ) { @@ -420,6 +421,11 @@ public class NarUtil } cmdLine.addArguments( args ); } + if ( workingDirectory != null ) + { + log.debug( "in: " + workingDirectory.getPath() ); + cmdLine.setWorkingDirectory( workingDirectory ); + } if ( env != null ) { @@ -429,7 +435,7 @@ public class NarUtil String[] nameValue = env[i].split( "=", 2 ); if ( nameValue.length < 2 ) throw new MojoFailureException( " Misformed env: '" + env[i] + "'" ); - log.debug( " '" + env[i] + "'" ); + log.debug( " '" + nameValue[0] + "=" + nameValue[1] + "'" ); cmdLine.addEnvironment( nameValue[0], nameValue[1] ); } } @@ -451,6 +457,18 @@ public class NarUtil } } + private static class NarCommandLine + extends Commandline + { + // Override this method to prevent addition (and obstruction) of system env variables + public String[] getEnvironmentVariables() + throws CommandLineException + { + return (String[]) envVars.toArray( new String[envVars.size()] ); + } + + } + static class StreamGobbler extends Thread { diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml index 58d09b1..51afa51 100644 --- a/src/main/resources/META-INF/plexus/components.xml +++ b/src/main/resources/META-INF/plexus/components.xml @@ -29,13 +29,16 @@ under the License. <initialize></initialize> <generate-sources>org.apache.maven.plugins:maven-nar-plugin:nar-download, org.apache.maven.plugins:maven-nar-plugin:nar-system-generate</generate-sources> - <process-sources>org.apache.maven.plugins:maven-nar-plugin:nar-unpack</process-sources> + <process-sources>org.apache.maven.plugins:maven-nar-plugin:nar-unpack, + org.apache.maven.plugins:maven-nar-plugin:nar-gnu-configure</process-sources> <generate-resources></generate-resources> <process-resources>org.apache.maven.plugins:maven-resources-plugin:resources, org.apache.maven.plugins:maven-nar-plugin:nar-resources</process-resources> <compile>org.apache.maven.plugins:maven-compiler-plugin:compile, - org.apache.maven.plugins:maven-nar-plugin:nar-javah</compile> - <process-classes>org.apache.maven.plugins:maven-nar-plugin:nar-compile</process-classes> + org.apache.maven.plugins:maven-nar-plugin:nar-javah, + org.apache.maven.plugins:maven-nar-plugin:nar-gnu-make</compile> + <process-classes>org.apache.maven.plugins:maven-nar-plugin:nar-compile, + org.apache.maven.plugins:maven-nar-plugin:nar-gnu-process</process-classes> <generate-test-sources></generate-test-sources> <process-test-sources></process-test-sources> <generate-test-resources></generate-test-resources> |