diff --git a/.gitignore b/.gitignore index b535040f..a65bde18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,28 @@ -# Eclipse -.classpath -.project -.settings/ - -# Intellij -.idea/ -*.iml -*.iws - -# Mac -.DS_Store -.DS_Store? -._* -.Spotlight-V100 -.Trashes -Icon? -ehthumbs.db -Thumbs.db - -# Maven -log/ -target/ +# Eclipse +.classpath +.project +.settings/ +.metadata/ +.recommenders/ + +# Intellij +.idea/ +*.iml +*.iws + +# Mac +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +Icon? +ehthumbs.db +Thumbs.db + +# Maven +log/ +target/ + +# Vim +*~ diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CobolParser.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CobolParser.java new file mode 100644 index 00000000..98d4c4d7 --- /dev/null +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CobolParser.java @@ -0,0 +1,82 @@ +/* + * + * Copyright 2002-2004 The Ant-Contrib project + * + * Licensed 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. + */ +package org.codehaus.mojo.natives.parser; + +import java.io.IOException; +import java.io.Reader; +import java.util.Vector; + +/** + * A parser that extracts #include statements from a Reader. + * + * @author Adam Murdoch + * @author Curt Arnold + */ +public final class CobolParser + extends AbstractParser + implements Parser +{ + private final Vector includes = new Vector<>(); + + private AbstractParserState newLineState; + + public CobolParser() + { + AbstractParserState quote = new FilenameState( this, new char[] { '"' } ); + AbstractParserState bracket = new FilenameState( this, new char[] { '>' } ); + AbstractParserState postE = new PostE( this, bracket, quote ); + // + // opy + // + AbstractParserState y = new LetterState( this, 'y', postE, null ); + AbstractParserState p = new LetterState( this, 'p', y, null ); + AbstractParserState o = new LetterState( this, 'o', p, null ); + newLineState = new LetterState( this, 'o', o, null ); + } + + @Override + public void addFilename( String include ) + { + includes.addElement( include ); + } + + @Override + public String[] getIncludes() + { + String[] retval = new String[includes.size()]; + + includes.copyInto( retval ); + + return retval; + } + + @Override + public AbstractParserState getNewLineState() + { + return newLineState; + } + + @Override + public void parse( Reader reader ) + throws IOException + { + includes.setSize( 0 ); + + super.parse( reader ); + } + +} diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/PostE.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/PostE.java index 151f6456..f4977ac5 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/PostE.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/PostE.java @@ -30,7 +30,13 @@ public PostE( CParser parser, AbstractParserState bracket, AbstractParserState q this.quote = quote; } - public AbstractParserState consume( char ch ) + public PostE(CobolParser parser, AbstractParserState bracket, AbstractParserState quote) { + super( parser ); + this.bracket = bracket; + this.quote = quote; + } + + public AbstractParserState consume( char ch ) { switch ( ch ) { diff --git a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerClassicTest.java b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerClassicTest.java index c5264b89..be14f948 100644 --- a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerClassicTest.java +++ b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerClassicTest.java @@ -1,11 +1,12 @@ package org.codehaus.mojo.natives.c; +import static org.junit.Assert.assertArrayEquals; + import java.io.File; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; -import static org.junit.Assert.assertArrayEquals; public class CCompilerClassicTest extends PlexusTestCase @@ -22,6 +23,7 @@ public void testSimpleCompilation() CompilerConfiguration config = new CompilerConfiguration(); CCompilerClassic compiler = new CCompilerClassic(); Commandline cl = compiler.getCommandLine( new File( "source.c" ), new File( "object.o" ), config ); - assertArrayEquals( new String[] { "gcc", "-oobject.o", "-c", "source.c" }, cl.getCommandline() ); + String[] commandLine = cl.getRawCommandline(); + assertArrayEquals( new String[] { "gcc", "-oobject.o", "-c", "source.c" }, commandLine ); } } diff --git a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerTest.java b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerTest.java index 2273f66a..d8e69cbb 100644 --- a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerTest.java +++ b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CCompilerTest.java @@ -1,10 +1,13 @@ package org.codehaus.mojo.natives.c; +import static org.junit.Assert.assertArrayEquals; + import java.io.File; + import org.codehaus.mojo.natives.compiler.CompilerConfiguration; import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.cli.Commandline; -import static org.junit.Assert.*; public class CCompilerTest extends PlexusTestCase @@ -33,7 +36,7 @@ public void testSimpleCompilation() { Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testNonDefaultExecutable() @@ -42,7 +45,7 @@ public void testNonDefaultExecutable() this.config.setExecutable( "cc" ); Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testStartOptions() @@ -54,8 +57,8 @@ public void testStartOptions() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( - new String[] { "gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + new String[] { "gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, + cl.getRawCommandline() ); } public void testIncludePaths() @@ -69,7 +72,7 @@ public void testIncludePaths() assertArrayEquals( new String[] { "gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testSystemIncludePaths() @@ -86,7 +89,7 @@ public void testSystemIncludePaths() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], - simpleArgv[2], simpleArgv[3] }, cl.getCommandline() ); + simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); } public void testMiddleOptions() @@ -103,7 +106,7 @@ public void testMiddleOptions() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3] }, cl.getCommandline() ); + simpleArgv[1], simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); } public void testEndOptions() @@ -122,6 +125,6 @@ public void testEndOptions() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }, cl.getCommandline() ); + simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }, cl.getRawCommandline() ); } } diff --git a/maven-native-components/maven-native-gnucobol/LICENSE.txt b/maven-native-components/maven-native-gnucobol/LICENSE.txt new file mode 100644 index 00000000..218e18a8 --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/LICENSE.txt @@ -0,0 +1,22 @@ + +The MIT License + +Copyright (c) 2004, The Codehaus + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/maven-native-components/maven-native-gnucobol/pom.xml b/maven-native-components/maven-native-gnucobol/pom.xml new file mode 100644 index 00000000..5870379e --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.codehaus.mojo.natives + maven-native-components + 1.0-alpha-12-SNAPSHOT + .. + + maven-native-gnucobol + Maven Native Cobol + + + org.codehaus.plexus + plexus-container-default + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-component-annotations + provided + + + diff --git a/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/AbstractCobolCompiler.java b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/AbstractCobolCompiler.java new file mode 100644 index 00000000..478f2674 --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/AbstractCobolCompiler.java @@ -0,0 +1,146 @@ +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.mojo.natives.gnucobol; + +import java.io.File; + +import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.mojo.natives.compiler.AbstractCompiler; +import org.codehaus.mojo.natives.compiler.CompilerConfiguration; +import org.codehaus.mojo.natives.parser.CobolParser; +import org.codehaus.mojo.natives.parser.Parser; +import org.codehaus.plexus.util.cli.Commandline; + +public abstract class AbstractCobolCompiler + extends AbstractCompiler +{ + /** + * resuable parser in one Compilation session + */ + + private Parser parser = new CobolParser(); + + protected abstract String getOutputFileOption(); + + protected Parser getParser() + { + return this.parser; + } + + /** + * Setup Compiler Command line + */ + protected Commandline getCommandLine( File srcFile, File destFile, CompilerConfiguration config ) + throws NativeBuildException + { + + if ( config.getExecutable() == null ) + { + config.setExecutable( "cobc" ); + } + + Commandline cl = new Commandline(); + + cl.setExecutable( config.getExecutable() ); + + if ( config.getWorkingDirectory() != null ) + { + cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + } + + this.setStartOptions( cl, config ); + + this.setIncludePaths( cl, config.getIncludePaths() ); + + this.setIncludePaths( cl, config.getSystemIncludePaths() ); + + this.setMiddleOptions( cl, config ); + + this.setOutputArgs( cl, destFile ); + + this.setSourceArgs( cl, srcFile ); + + this.setEndOptions( cl, config ); + + return cl; + } + + private void setOptions( Commandline cl, String[] options ) + { + if ( options != null ) + { + for ( int i = 0; i < options.length; ++i ) + { + cl.createArg().setValue( options[i] ); + } + } + } + + private void setStartOptions( Commandline cl, CompilerConfiguration config ) + { + this.setOptions( cl, config.getStartOptions() ); + } + + private void setMiddleOptions( Commandline cl, CompilerConfiguration config ) + { + this.setOptions( cl, config.getMiddleOptions() ); + } + + private void setEndOptions( Commandline cl, CompilerConfiguration config ) + { + this.setOptions( cl, config.getEndOptions() ); + } + + private void setIncludePaths( Commandline cl, File[] includePaths ) + { + if ( includePaths != null ) + { + for ( int i = 0; i < includePaths.length; ++i ) + { + cl.createArg().setValue( "-I" + includePaths[i].getPath() ); + } + } + } + + private void setOutputArgs( Commandline cl, File outputFile ) + { + String outputFileOption = this.getOutputFileOption(); + + if ( outputFileOption.endsWith( " " ) ) + { + cl.createArg().setValue( outputFileOption.trim() ); + cl.createArg().setValue( outputFile.getPath() ); + } + else + { + cl.createArg().setValue( outputFileOption + outputFile.getPath() ); + } + } + + private void setSourceArgs( Commandline cl, File srcFile ) + { + cl.createArg().setValue( "-c" ); + cl.createArg().setValue( srcFile.getPath() ); + } +} diff --git a/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLCompiler.java b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLCompiler.java new file mode 100644 index 00000000..f66e6d46 --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLCompiler.java @@ -0,0 +1,42 @@ +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.mojo.natives.gnucobol; + +import org.codehaus.mojo.natives.compiler.Compiler; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Generic C/CPP compiler with "-o " as its output option + */ +@Component(role = Compiler.class, hint = "gnucobol", instantiationStrategy = "per-lookup", description="GNU Cobol compiler") +public class GNUCOBOLCompiler + extends AbstractCobolCompiler +{ + + protected String getOutputFileOption() + { + return "-o "; + } + +} diff --git a/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLLinker.java b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLLinker.java new file mode 100644 index 00000000..5c5bda61 --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/src/main/java/org/codehaus/mojo/natives/gnucobol/GNUCOBOLLinker.java @@ -0,0 +1,202 @@ +/* + * The MIT License + * + * Copyright (c) 2004, The Codehaus + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.mojo.natives.gnucobol; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.mojo.natives.linker.AbstractLinker; +import org.codehaus.mojo.natives.linker.Linker; +import org.codehaus.mojo.natives.linker.LinkerConfiguration; +import org.codehaus.mojo.natives.util.FileUtil; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.cli.Commandline; + +/** + * Generic C/CPP linker with "-o " as its output option + */ +@Component(role = Linker.class, hint = "gnucobol", instantiationStrategy = "per-lookup") +public class GNUCOBOLLinker + extends AbstractLinker +{ + + /** + * @return Commandline of a linker base on its configuration and object files + */ + @Override + protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) + throws NativeBuildException + { + if ( config.getExecutable() == null ) + { + config.setExecutable( "cobc" ); + } + + Commandline cl = new Commandline(); + + cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + + cl.setExecutable( config.getExecutable() ); + + if ( config.getStartOptions() != null ) + { + cl.addArguments( config.getStartOptions() ); + } + + String linkerOutputOption = this.getLinkerOutputOption(); + if ( linkerOutputOption.endsWith( " " ) ) + { + cl.createArg().setValue( linkerOutputOption.substring( 0, linkerOutputOption.length() - 1 ) ); + cl.createArg().setFile( config.getOutputFile() ); + } + else + { + cl.createArg().setValue( linkerOutputOption + config.getOutputFile() ); + } + + // On windows to avoid command lines too long we have to use a linker response file. + if ( config.isUsingLinkerResponseFile() ) + { + try + { + File linkerFile = new File( config.getWorkingDirectory(), "objectsFile" ); + FileWriter linkerFileWriter = new FileWriter( linkerFile, false /* Don't append */ ); + for ( int i = 0; i < objectFiles.size(); ++i ) + { + File objFile = objectFiles.get( i ); + linkerFileWriter.write( objFile.getPath() + "\n" ); + } + linkerFileWriter.close(); + } + catch ( IOException error ) + { + throw new NativeBuildException( "Error creating linker response file", error ); + } + + cl.createArg().setValue( "@objectsFile" ); + } + else + { // Normal behavior. + + for ( int i = 0; i < objectFiles.size(); ++i ) + { + File objFile = objectFiles.get( i ); + + // we need to shorten the command line since windows has limited command line length + String objFilePath = FileUtil.truncatePath( objFile.getPath(), config.getWorkingDirectory().getPath() ); + + cl.createArg().setValue( objFilePath ); + } + } + + if ( config.getMiddleOptions() != null ) + { + cl.addArguments( config.getMiddleOptions() ); + } + + setCommandLineForExternalLibraries( cl, config ); + + if ( config.getEndOptions() != null ) + { + cl.addArguments( config.getEndOptions() ); + } + + return cl; + + } + + /** + * @return output option flag of a generic C linker + */ + protected String getLinkerOutputOption() + { + return "-o "; + } + + /** + * Setup Commandline to handle external library depending on extention type + * + * @param cl Commandline + * @param config LinkerConfiguration + * @throws NativeBuildException + */ + protected void setCommandLineForExternalLibraries( Commandline cl, LinkerConfiguration config ) + throws NativeBuildException + { + if ( config.getExternalLibFileNames().size() == 0 ) + { + return; + } + + boolean hasUnixLinkage = false; + + for ( Iterator iter = config.getExternalLibFileNames().iterator(); iter.hasNext(); ) + { + String libFileName = iter.next(); + + String ext = FileUtils.getExtension( libFileName ); + + if ( "o".equals( ext ) || "obj".equals( ext ) || "lib".equals( ext ) || "dylib".equals( ext ) ) + { + File libFile = new File( config.getExternalLibDirectory(), libFileName ); + String relativeLibFile = + FileUtil.truncatePath( libFile.getPath(), config.getWorkingDirectory().getPath() ); + cl.createArg().setValue( relativeLibFile ); + } + else if ( "a".equals( ext ) || "so".equals( ext ) || "sl".equals( ext ) ) + { + hasUnixLinkage = true; + } + } + + if ( hasUnixLinkage ) + { + cl.createArg().setValue( "-L" + config.getExternalLibDirectory() ); + } + + for ( Iterator iter = config.getExternalLibFileNames().iterator(); iter.hasNext(); ) + { + String libFileName = iter.next(); + + String ext = FileUtils.getExtension( libFileName ); + + if ( "a".equals( ext ) || "so".equals( ext ) || "sl".equals( ext ) ) + { + String libName = FileUtils.removeExtension( libFileName ); + + if ( libFileName.startsWith( "lib" ) ) + { + libName = libName.substring( "lib".length() ); + } + + cl.createArg().setValue( "-l" + libName ); + } + } + } +} diff --git a/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CLinkerTest.java b/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CLinkerTest.java new file mode 100644 index 00000000..1f946916 --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CLinkerTest.java @@ -0,0 +1,161 @@ +package org.codehaus.mojo.natives.gnucobol; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.mojo.natives.gnucobol.GNUCOBOLLinker; +import org.codehaus.mojo.natives.linker.LinkerConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.cli.Commandline; + +public class CLinkerTest + extends PlexusTestCase +{ + private GNUCOBOLLinker linker; + + private LinkerConfiguration config; + + private static final File objectFile0 = new File( "source1.o" ); + + private static final File objectFile1 = new File( "source2.o" ); + + private List defautlObjectFiles; + + private String basedir; + + @Override + public void setUp() + throws Exception + { + super.setUp(); + + this.defautlObjectFiles = new ArrayList<>(); + this.defautlObjectFiles.add( objectFile0 ); + this.defautlObjectFiles.add( objectFile1 ); + + this.linker = new GNUCOBOLLinker(); + this.config = new LinkerConfiguration(); + this.basedir = getBasedir(); + config.setWorkingDirectory( new File( basedir ) ); + config.setOutputDirectory( new File( basedir, "target" ) ); + config.setOutputFileExtension( "exe" ); + config.setOutputFileName( "test" ); + } + + public void testDefaultLinkerExecutable() + throws Exception + { + Commandline cl = this.getCommandline(); + + assertEquals( "cobc", cl.getLiteralExecutable() ); + assertEquals( basedir, cl.getWorkingDirectory().getPath() ); + + } + + public void testOverrideLinkerExecutable() + throws Exception + { + config.setExecutable( "ld" ); + + Commandline cl = this.getCommandline(); + + assertEquals( "ld", cl.getLiteralExecutable() ); + + } + + public void testObjectFileList() + throws Exception + { + Commandline cl = this.getCommandline(); + + int index = Arrays.asList( cl.getArguments() ).indexOf( "source1.o" ); + assertTrue( index >= 0 ); + assertEquals( "source2.o", cl.getArguments()[index + 1] ); + } + + public void testLinkerResponseFile() + throws Exception + { + this.config.setUsingLinkerResponseFile( true ); + this.config.setWorkingDirectory( new File( getBasedir(), "target" ) ); + Commandline cl = this.getCommandline(); + + assertTrue( Arrays.asList( cl.getArguments() ).indexOf( "@objectsFile" ) >= 0 ); + } + + public void testRelativeObjectFileList() + throws Exception + { + ArrayList objectFiles = new ArrayList<>( 2 ); + objectFiles.add( new File( config.getOutputDirectory(), "file1.o" ) ); + objectFiles.add( new File( config.getOutputDirectory(), "file2.o" ) ); + + Commandline cl = this.getCommandline( objectFiles ); + + int index = Arrays.asList( cl.getArguments() ).indexOf( "target" + File.separator + "file1.o" ); + assertTrue( index >= 0 ); + assertEquals( "target" + File.separator + "file2.o", cl.getArguments()[index + 1] ); + + } + + public void testOptions() + throws Exception + { + String[] options = { "-o1", "-o2", "-o3" }; + config.setStartOptions( options ); + + Commandline cl = this.getCommandline(); + + int index = Arrays.asList( cl.getArguments() ).indexOf( "-o1" ); + assertTrue( index >= 0 ); + assertEquals( "-o2", cl.getArguments()[index + 1] ); + assertEquals( "-o3", cl.getArguments()[index + 2] ); + + } + + public void testExternalUnixLibraries() + throws Exception + { + config.setExternalLibDirectory( new File( "theLib" ) ); + + List externalLibFileNames = new ArrayList<>(); + + externalLibFileNames.add( "file0.lib" ); + + externalLibFileNames.add( "file0.o" ); + + externalLibFileNames.add( "file1.obj" ); + + externalLibFileNames.add( "file1.so" ); + + externalLibFileNames.add( "libfile2.so" ); + + externalLibFileNames.add( "libfile3.a" ); + + config.setExternalLibFileNames( externalLibFileNames ); + + Commandline cl = this.getCommandline( new ArrayList( 0 ) ); + + int index = Arrays.asList( cl.getArguments() ).indexOf( "-LtheLib" ); + assertTrue( index >= 0 ); + assertEquals( "-lfile1", cl.getArguments()[index + 1] ); + assertEquals( "-lfile2", cl.getArguments()[index + 2] ); + assertEquals( "-lfile3", cl.getArguments()[index + 3] ); + } + + // ///////////////////////// HELPERS ////////////////////////////////////// + private Commandline getCommandline() + throws NativeBuildException + { + return this.linker.createLinkerCommandLine( defautlObjectFiles, config ); + } + + private Commandline getCommandline( List objectFiles ) + throws NativeBuildException + { + return this.linker.createLinkerCommandLine( objectFiles, config ); + } + +} diff --git a/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CobolCompilerTest.java b/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CobolCompilerTest.java new file mode 100644 index 00000000..4f67dd3c --- /dev/null +++ b/maven-native-components/maven-native-gnucobol/src/test/java/org/codehaus/mojo/natives/gnucobol/CobolCompilerTest.java @@ -0,0 +1,129 @@ +package org.codehaus.mojo.natives.gnucobol; + +import static org.junit.Assert.assertArrayEquals; + +import java.io.File; + +import org.codehaus.mojo.natives.compiler.CompilerConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.cli.Commandline; + +public class CobolCompilerTest + extends PlexusTestCase +{ + private GNUCOBOLCompiler compiler; + + private CompilerConfiguration config; + + private static File sourceFile = new File( "source.cob" ); + + private static File objectFile = new File( "object.o" ); + + private static String[] simpleArgv = { "-o", "object.o", "-c", "source.cob" }; + + public void setUp() + throws Exception + { + super.setUp(); + + this.compiler = new GNUCOBOLCompiler(); + this.config = new CompilerConfiguration(); + } + + public void testSimpleCompilation() + throws Exception + { + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + assertArrayEquals( new String[] { "cobc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, + cl.getRawCommandline() ); + } + + public void testNonDefaultExecutable() + throws Exception + { + this.config.setExecutable( "cobol" ); + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + assertArrayEquals( new String[] { "cobol", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, + cl.getRawCommandline() ); + } + + public void testStartOptions() + throws Exception + { + String[] startOptions = { "-s1", "-s2" }; + config.setStartOptions( startOptions ); + + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + + assertArrayEquals( + new String[] { "cobc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, + cl.getRawCommandline() ); + } + + public void testIncludePaths() + throws Exception + { + File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + + config.setIncludePaths( includePaths ); + + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + + assertArrayEquals( + new String[] { "cobc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, + cl.getRawCommandline() ); + } + + public void testSystemIncludePaths() + throws Exception + { + File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + + File[] systemIncludePaths = { new File( "sp1" ), new File( "sp2" ) }; + + config.setIncludePaths( includePaths ); + + config.setSystemIncludePaths( systemIncludePaths ); + + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + + assertArrayEquals( new String[] { "cobc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], + simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); + } + + public void testMiddleOptions() + throws Exception + { + File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + config.setIncludePaths( includePaths ); + + String[] startOptions = { "-s1", "-s2" }; + String[] middleOptions = { "-m1", "-m2" }; + config.setStartOptions( startOptions ); + config.setMiddleOptions( middleOptions ); + + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + + assertArrayEquals( new String[] { "cobc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], + simpleArgv[1], simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); + } + + public void testEndOptions() + throws Exception + { + File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + config.setIncludePaths( includePaths ); + + String[] startOptions = { "-s1", "-s2" }; + String[] middleOptions = { "-m1", "-m2" }; + String[] endOptions = { "-e1", "-e2" }; + config.setStartOptions( startOptions ); + config.setMiddleOptions( middleOptions ); + config.setEndOptions( endOptions ); + + Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + + assertArrayEquals( new String[] { "cobc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], + simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }, cl.getRawCommandline() ); + } +} diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultCompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultCompilerManager.java index c301a5fa..1cd9f4af 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultCompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultCompilerManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.codehaus.mojo.natives.compiler.Compiler; import org.codehaus.plexus.component.annotations.Component; diff --git a/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccCompilerTest.java b/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccCompilerTest.java index d16bad01..e6ed459d 100644 --- a/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccCompilerTest.java +++ b/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccCompilerTest.java @@ -35,7 +35,7 @@ public void testSimpleCompilation() { Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testNonDefaultExecutable() @@ -44,7 +44,7 @@ public void testNonDefaultExecutable() this.config.setExecutable( "cc" ); Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testStartOptions() @@ -57,7 +57,7 @@ public void testStartOptions() assertArrayEquals( new String[] { "gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testIncludePaths() @@ -71,7 +71,7 @@ public void testIncludePaths() assertArrayEquals( new String[] { "gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } public void testSystemIncludePaths() @@ -88,7 +88,7 @@ public void testSystemIncludePaths() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], - simpleArgv[2], simpleArgv[3] }, cl.getCommandline() ); + simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); } public void testMiddleOptions() @@ -105,7 +105,7 @@ public void testMiddleOptions() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3] }, cl.getCommandline() ); + simpleArgv[1], simpleArgv[2], simpleArgv[3] }, cl.getRawCommandline() ); } public void testEndOptions() @@ -124,6 +124,6 @@ public void testEndOptions() Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }, cl.getCommandline() ); + simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }, cl.getRawCommandline() ); } } diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCCompilerTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCCompilerTest.java index 7462d33c..93fa7b15 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCCompilerTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCCompilerTest.java @@ -34,6 +34,6 @@ public void testSimpleCompilation() { Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); assertArrayEquals( new String[] { "cl.exe", simpleArgv[0], simpleArgv[1], simpleArgv[2] }, - cl.getCommandline() ); + cl.getRawCommandline() ); } } diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCLinkerTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCLinkerTest.java index d7f7ab76..486c0929 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCLinkerTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVCLinkerTest.java @@ -56,7 +56,7 @@ public void testSimpleLinkerCommand() { Commandline cl = this.getCommandline(); assertArrayEquals( new String[] { "link.exe", "/out:" + config.getOutputFile(), "source1.obj", "source2.obj" }, - cl.getCommandline() ); + cl.getRawCommandline() ); } // ///////////////////////// HELPERS ////////////////////////////////////// diff --git a/maven-native-components/pom.xml b/maven-native-components/pom.xml index e6a76b07..c47d38c6 100644 --- a/maven-native-components/pom.xml +++ b/maven-native-components/pom.xml @@ -16,6 +16,7 @@ maven-native-bcc maven-native-msvc maven-native-mingw + maven-native-gnucobol diff --git a/pom.xml b/pom.xml index 476557eb..5212cbef 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,7 @@ https://travis-ci.org/mojohaus/maven-native + none 3.2.5 ${project.build.directory}/staging/maven-native @@ -125,6 +126,11 @@ maven-native-generic-c ${project.version} + + org.codehaus.mojo.natives + maven-native-gnucobol + ${project.version} + org.codehaus.mojo.natives maven-native-javah @@ -169,7 +175,7 @@ org.codehaus.plexus plexus-utils - 3.1.0 + 3.3.0 @@ -183,6 +189,14 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + none + + org.apache.maven.plugins maven-plugin-plugin @@ -204,6 +218,13 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + + none + + com.github.ekryd.sortpom sortpom-maven-plugin @@ -230,6 +251,18 @@ + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + none + + + + m2e