From cf4c4001b43bc60bea4d58e2576bbf8a92a73b07 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 17 Mar 2024 18:32:54 +0100 Subject: [PATCH] Apply spotless plugin --- .../mojo/natives/AbstractEnvFactory.java | 15 +- .../mojo/natives/ConfigurationBase.java | 10 +- .../org/codehaus/mojo/natives/Dependency.java | 162 ++++------ .../org/codehaus/mojo/natives/EnvFactory.java | 7 +- .../mojo/natives/NativeBuildException.java | 15 +- .../codehaus/mojo/natives/NativeSources.java | 130 +++----- .../natives/SourceDependencyAnalyzer.java | 30 +- .../natives/compiler/AbstractCompiler.java | 187 ++++-------- .../compiler/AbstractMessageCompiler.java | 25 +- .../compiler/AbstractResourceCompiler.java | 62 ++-- .../mojo/natives/compiler/Compiler.java | 8 +- .../compiler/CompilerConfiguration.java | 78 ++--- .../natives/compiler/MessageCompiler.java | 7 +- .../MessageCompilerConfiguration.java | 43 +-- .../natives/compiler/ResourceCompiler.java | 7 +- .../ResourceCompilerConfiguration.java | 67 ++-- .../mojo/natives/javah/AbstractJavah.java | 7 +- .../codehaus/mojo/natives/javah/Javah.java | 6 +- .../natives/javah/JavahConfiguration.java | 51 ++-- .../mojo/natives/linker/AbstractLinker.java | 67 ++-- .../mojo/natives/linker/ArchiveLinker.java | 41 +-- .../mojo/natives/linker/DefaultRanlib.java | 15 +- .../codehaus/mojo/natives/linker/Linker.java | 8 +- .../natives/linker/LinkerConfiguration.java | 88 ++---- .../mojo/natives/linker/Manifest.java | 6 +- .../natives/linker/ManifestConfiguration.java | 23 +- .../codehaus/mojo/natives/linker/Ranlib.java | 6 +- .../mojo/natives/parser/AbstractParser.java | 47 +-- .../natives/parser/AbstractParserState.java | 16 +- .../mojo/natives/parser/BranchState.java | 33 +- .../codehaus/mojo/natives/parser/CParser.java | 65 ++-- .../parser/CaseInsensitiveLetterState.java | 27 +- .../mojo/natives/parser/FilenameState.java | 33 +- .../mojo/natives/parser/FortranParser.java | 49 ++- .../mojo/natives/parser/LetterState.java | 23 +- .../codehaus/mojo/natives/parser/Parser.java | 6 +- .../codehaus/mojo/natives/parser/PostE.java | 15 +- ...hitespaceOrCaseInsensitiveLetterState.java | 27 +- .../parser/WhitespaceOrLetterState.java | 23 +- .../mojo/natives/util/CommandLineUtil.java | 27 +- .../codehaus/mojo/natives/util/EnvUtil.java | 60 ++-- .../codehaus/mojo/natives/util/FileSet.java | 72 ++--- .../codehaus/mojo/natives/util/FileUtil.java | 146 ++++----- .../mojo/natives/AbstractDependencyTest.java | 52 ++-- .../codehaus/mojo/natives/DependencyTest.java | 84 +++-- .../mojo/natives/NativeSourcesTest.java | 168 +++++----- .../natives/compiler/CompilerUtilTest.java | 38 +-- .../natives/parser/AbstractParserTest.java | 9 +- .../mojo/natives/parser/CParserTest.java | 119 +++----- .../natives/parser/FortranParserTest.java | 50 ++- .../mojo/natives/bcc/BCCCompiler.java | 28 +- .../mojo/natives/bcc/BCCEnvFactory.java | 30 +- .../codehaus/mojo/natives/bcc/BCCLinker.java | 48 ++- .../mojo/natives/bcc/BCCResourceCompiler.java | 46 ++- .../codehaus/mojo/natives/bcc/TLibLinker.java | 30 +- .../mojo/natives/bcc/TLibLinkerTest.java | 47 +-- .../mojo/natives/c/AbstractCCompiler.java | 103 +++---- .../codehaus/mojo/natives/c/CCompiler.java | 10 +- .../mojo/natives/c/CCompilerClassic.java | 8 +- .../org/codehaus/mojo/natives/c/CLinker.java | 138 ++++----- .../mojo/natives/c/CLinkerClassic.java | 8 +- .../mojo/natives/c/CCompilerClassicTest.java | 15 +- .../mojo/natives/c/CCompilerTest.java | 175 ++++++----- .../codehaus/mojo/natives/c/CLinkerTest.java | 137 ++++----- .../mojo/natives/javah/JavahExecutable.java | 114 +++---- .../natives/javah/JavahMacOSExecutable.java | 10 +- .../natives/javah/JavahExecutableTest.java | 108 ++++--- .../mojo/natives/manager/CompilerManager.java | 6 +- .../manager/DefaultCompilerManager.java | 27 +- .../manager/DefaultEnvFactoryManager.java | 29 +- .../natives/manager/DefaultJavahManager.java | 27 +- .../natives/manager/DefaultLinkerManager.java | 28 +- .../manager/DefaultManifestManager.java | 28 +- .../DefaultMessageCompilerManager.java | 28 +- .../natives/manager/DefaultRanlibManager.java | 28 +- .../DefaultResourceCompilerManager.java | 29 +- .../natives/manager/EnvFactoryManager.java | 6 +- .../mojo/natives/manager/JavahManager.java | 6 +- .../mojo/natives/manager/LinkerManager.java | 6 +- .../mojo/natives/manager/ManifestManager.java | 6 +- .../manager/MessageCompilerManager.java | 6 +- .../NoSuchNativeProviderException.java | 13 +- .../mojo/natives/manager/RanlibManager.java | 6 +- .../manager/ResourceCompilerManager.java | 6 +- .../natives/mingw/AbstractGccCompiler.java | 103 +++---- .../mojo/natives/mingw/GccCompiler.java | 8 +- .../mojo/natives/mingw/GccLinker.java | 139 ++++----- .../mingw/WindresResourceCompiler.java | 50 ++- .../mojo/natives/mingw/GccCompilerTest.java | 171 ++++++----- .../mojo/natives/mingw/GccLinkerTest.java | 138 ++++----- .../msvc/AbstractCommunityEnvFactory.java | 70 ++--- .../msvc/AbstractMSVC2005EnvFactory.java | 6 +- ...AbstractMSVC2017CircaEnvFactoryHelper.java | 113 +++---- .../msvc/AbstractMSVC2019EnvFactory.java | 9 +- .../natives/msvc/AbstractMSVCEnvFactory.java | 93 +++--- .../msvc/Community2017x64EnvFactory.java | 13 +- .../msvc/Community2017x86AMD64EnvFactory.java | 13 +- .../msvc/Community2017x86EnvFactory.java | 13 +- .../mojo/natives/msvc/EnvStreamConsumer.java | 32 +- .../mojo/natives/msvc/MSVC2003EnvFactory.java | 45 ++- .../msvc/MSVC2003ToolkitEnvFactory.java | 37 +-- .../natives/msvc/MSVC2005AMD64EnvFactory.java | 57 ++-- .../msvc/MSVC2005x86AMD64EnvFactory.java | 57 ++-- .../natives/msvc/MSVC2005x86EnvFactory.java | 57 ++-- .../msvc/MSVC2008x86AMD64EnvFactory.java | 97 +++--- .../natives/msvc/MSVC2008x86EnvFactory.java | 97 +++--- .../msvc/MSVC2010x86AMD64EnvFactory.java | 12 +- .../natives/msvc/MSVC2010x86EnvFactory.java | 12 +- .../msvc/MSVC2012x86AMD64EnvFactory.java | 12 +- .../natives/msvc/MSVC2012x86EnvFactory.java | 12 +- .../msvc/MSVC2013x86AMD64EnvFactory.java | 12 +- .../natives/msvc/MSVC2013x86EnvFactory.java | 12 +- .../msvc/MSVC2019AMD64x86EnvFactory.java | 23 +- .../natives/msvc/MSVC2019x64EnvFactory.java | 21 +- .../msvc/MSVC2019x86AMD64EnvFactory.java | 23 +- .../natives/msvc/MSVC2019x86EnvFactory.java | 23 +- .../mojo/natives/msvc/MSVC6EnvFactory.java | 46 ++- .../mojo/natives/msvc/MSVCCompiler.java | 30 +- .../mojo/natives/msvc/MSVCLinker.java | 21 +- .../mojo/natives/msvc/MSVCManifest.java | 36 +-- .../natives/msvc/MSVCMessageCompiler.java | 59 ++-- .../natives/msvc/MSVCResourceCompiler.java | 46 ++- .../codehaus/mojo/natives/msvc/RegQuery.java | 38 +-- .../msvc/AbstractCommunityEnvFactoryTest.java | 159 ++++------ .../natives/msvc/MSVC2012EnvFactoryTest.java | 19 +- .../natives/msvc/MSVC2019EnvFactoryTest.java | 121 ++++---- .../mojo/natives/msvc/MSVCCompilerTest.java | 25 +- .../mojo/natives/msvc/MSVCLinkerTest.java | 51 ++-- .../mojo/natives/msvc/RegQueryTest.java | 16 +- .../codehaus/mojo/natives/test/TestUtils.java | 204 ++++++------- .../natives/plugin/AbstractNativeMojo.java | 52 ++-- .../mojo/natives/plugin/JavahInclude.java | 16 +- .../plugin/NativeBundleIncludeFilesMojo.java | 47 ++- .../natives/plugin/NativeCompileMojo.java | 128 ++++---- .../natives/plugin/NativeInitializeMojo.java | 23 +- .../mojo/natives/plugin/NativeJavahMojo.java | 194 +++++------- .../mojo/natives/plugin/NativeLinkMojo.java | 288 ++++++++---------- .../natives/plugin/NativeManifestMojo.java | 54 ++-- .../plugin/NativeMessageCompileMojo.java | 51 ++-- .../mojo/natives/plugin/NativeMojoUtils.java | 29 +- .../mojo/natives/plugin/NativeRanlibMojo.java | 38 +-- .../plugin/NativeResourceCompileMojo.java | 55 ++-- .../natives/plugin/NativeUnZipIncMojo.java | 92 +++--- .../mojo/natives/noop/NoopCompiler.java | 32 +- .../codehaus/mojo/natives/noop/NoopJavah.java | 11 +- .../mojo/natives/noop/NoopLinker.java | 15 +- .../mojo/natives/noop/NoopRanlib.java | 11 +- .../natives/plugin/NativeCompileMojoTest.java | 113 ++++--- .../plugin/NativeInitializeMojoTest.java | 32 +- .../natives/plugin/NativeJavahMojoTest.java | 33 +- .../natives/plugin/NativeLinkerMojoTest.java | 89 +++--- .../natives/plugin/NativeRanlibMojoTest.java | 27 +- .../mojo/natives/plugin/stubs/BuildStub.java | 16 +- .../natives/plugin/stubs/ProjectStub.java | 40 +-- pom.xml | 6 +- 155 files changed, 3042 insertions(+), 4601 deletions(-) diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/AbstractEnvFactory.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/AbstractEnvFactory.java index 8658e956..4b56736a 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/AbstractEnvFactory.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/AbstractEnvFactory.java @@ -2,25 +2,18 @@ import java.util.Map; -public abstract class AbstractEnvFactory - implements EnvFactory -{ +public abstract class AbstractEnvFactory implements EnvFactory { private static Map envs; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs == null) { envs = createEnvs(); } return envs; } - protected abstract Map createEnvs() - throws NativeBuildException; - + protected abstract Map createEnvs() throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/ConfigurationBase.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/ConfigurationBase.java index 3125b4e6..848db93a 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/ConfigurationBase.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/ConfigurationBase.java @@ -23,18 +23,14 @@ */ package org.codehaus.mojo.natives; -public class ConfigurationBase -{ +public class ConfigurationBase { private EnvFactory envFactory; - public EnvFactory getEnvFactory() - { + public EnvFactory getEnvFactory() { return envFactory; } - public void setEnvFactory( EnvFactory envFactory ) - { + public void setEnvFactory(EnvFactory envFactory) { this.envFactory = envFactory; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/Dependency.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/Dependency.java index 5717085e..104370bb 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/Dependency.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/Dependency.java @@ -38,9 +38,7 @@ * @author Dan Tran * @version $Id$ */ - -public class Dependency -{ +public class Dependency { /** * Field source */ @@ -62,18 +60,15 @@ public class Dependency Dependency parent; - public Dependency( Dependency parent, File source, Parser parser, File[] includePaths ) - { - init( parent, source, parser, includePaths ); + public Dependency(Dependency parent, File source, Parser parser, File[] includePaths) { + init(parent, source, parser, includePaths); } - public Dependency( File source, Parser parser, File[] includePaths ) - { - init( null, source, parser, includePaths ); + public Dependency(File source, Parser parser, File[] includePaths) { + init(null, source, parser, includePaths); } - private void init( Dependency parent, File source, Parser parser, File[] includePaths ) - { + private void init(Dependency parent, File source, Parser parser, File[] includePaths) { this.parent = parent; this.source = source.getPath(); @@ -82,68 +77,53 @@ private void init( Dependency parent, File source, Parser parser, File[] include this.parser = parser; - if ( includePaths == null ) - { + if (includePaths == null) { this.includePaths = new File[0]; - } - else - { + } else { this.includePaths = includePaths; } } - public void analyze() - throws IOException - { + public void analyze() throws IOException { String[] includeNames = getIncludeNames(); - File[] resolvedIncludeFiles = resolveIncludeNames( includeNames ); + File[] resolvedIncludeFiles = resolveIncludeNames(includeNames); - for ( File fileName : resolvedIncludeFiles ) - { - Dependency depend = new Dependency( this, fileName, this.parser, this.includePaths ); + for (File fileName : resolvedIncludeFiles) { + Dependency depend = new Dependency(this, fileName, this.parser, this.includePaths); - if ( !this.getRoot().contains( depend ) ) - { - this.addDependency( depend ); + if (!this.getRoot().contains(depend)) { + this.addDependency(depend); } } - for ( int i = 0; i < this.getDependencies().size(); ++i ) - { - Dependency depend = this.getDependencies().get( i ); + for (int i = 0; i < this.getDependencies().size(); ++i) { + Dependency depend = this.getDependencies().get(i); depend.analyze(); } - } - private Dependency getRoot() - { + private Dependency getRoot() { Dependency root = this; - while ( root.getParent() != null ) - { + while (root.getParent() != null) { root = root.getParent(); } return root; } - public Dependency getParent() - { + public Dependency getParent() { return this.parent; } - public long getCompositeLastModified() - { + public long getCompositeLastModified() { long currentLastModify = this.lastModified; - for ( Dependency dependency : this.getDependencies() ) - { + for (Dependency dependency : this.getDependencies()) { long lastModified = dependency.getCompositeLastModified(); - if ( lastModified > currentLastModify ) - { + if (lastModified > currentLastModify) { currentLastModify = lastModified; } } @@ -151,12 +131,9 @@ public long getCompositeLastModified() return currentLastModify; } - private String[] getIncludeNames() - throws IOException - { - try ( Reader reader = new BufferedReader( new FileReader( this.source ) ) ) - { - parser.parse( reader ); + private String[] getIncludeNames() throws IOException { + try (Reader reader = new BufferedReader(new FileReader(this.source))) { + parser.parse(reader); return parser.getIncludes(); } } @@ -166,26 +143,21 @@ private String[] getIncludeNames() * @return * @throws IOException */ - private File[] resolveIncludeNames( String[] includeNames ) - throws IOException - { - ArrayList resolvedIncludeFiles = new ArrayList<>( includeNames.length ); - - for ( String includeName : includeNames ) - { - File resolvedFile = resolveSingleIncludeName( includeName ); - - if ( resolvedFile != null ) - { - resolvedIncludeFiles.add( resolvedFile ); + private File[] resolveIncludeNames(String[] includeNames) throws IOException { + ArrayList resolvedIncludeFiles = new ArrayList<>(includeNames.length); + + for (String includeName : includeNames) { + File resolvedFile = resolveSingleIncludeName(includeName); + + if (resolvedFile != null) { + resolvedIncludeFiles.add(resolvedFile); } } File[] arrayResolvedIncludeFiles = new File[resolvedIncludeFiles.size()]; - for ( int j = 0; j < arrayResolvedIncludeFiles.length; ++j ) - { - arrayResolvedIncludeFiles[j] = resolvedIncludeFiles.get( j ); + for (int j = 0; j < arrayResolvedIncludeFiles.length; ++j) { + arrayResolvedIncludeFiles[j] = resolvedIncludeFiles.get(j); } return arrayResolvedIncludeFiles; @@ -198,21 +170,17 @@ private File[] resolveIncludeNames( String[] includeNames ) * @return an file or null when it is not found in user include path * @throws IOException */ - - private File resolveSingleIncludeName( String includeName ) - throws IOException - { + private File resolveSingleIncludeName(String includeName) throws IOException { File includeFile = null; File[] sourcePath = new File[1]; - sourcePath[0] = new File( new File( this.source ).getParent() ); // TODO + sourcePath[0] = new File(new File(this.source).getParent()); // TODO - includeFile = this.resolveSingleIncludeNameFromPaths( includeName, sourcePath ); + includeFile = this.resolveSingleIncludeNameFromPaths(includeName, sourcePath); - if ( includeFile == null ) - { - includeFile = this.resolveSingleIncludeNameFromPaths( includeName, this.includePaths ); + if (includeFile == null) { + includeFile = this.resolveSingleIncludeNameFromPaths(includeName, this.includePaths); } return includeFile; @@ -225,17 +193,14 @@ private File resolveSingleIncludeName( String includeName ) * @param includePath * @return */ - private File resolveSingleIncludeNameFromPaths( String includeName, File[] includePath ) - { + private File resolveSingleIncludeNameFromPaths(String includeName, File[] includePath) { File includeFile = null; - for ( File file : includePath ) - { - File tmpFile = new File( file, includeName ); + for (File file : includePath) { + File tmpFile = new File(file, includeName); // make sure we dont pickup directory like STL which has no extension - if ( tmpFile.exists() && tmpFile.isFile() ) - { + if (tmpFile.exists() && tmpFile.isFile()) { includeFile = tmpFile; break; @@ -250,18 +215,15 @@ private File resolveSingleIncludeNameFromPaths( String includeName, File[] inclu * * @param dependency */ - public void addDependency( Dependency dependency ) - { - getDependencies().add( dependency ); + public void addDependency(Dependency dependency) { + getDependencies().add(dependency); } /** * Method getDependencies */ - public java.util.List getDependencies() - { - if ( this.dependencies == null ) - { + public java.util.List getDependencies() { + if (this.dependencies == null) { this.dependencies = new java.util.ArrayList<>(); } @@ -271,32 +233,26 @@ public java.util.List getDependencies() /** * Method getLastModified */ - public long getLastModified() - { + public long getLastModified() { return this.lastModified; } /** * Method getSource */ - public String getSource() - { + public String getSource() { return this.source; } // helper for testing only - boolean contains( Dependency dependent ) - { - if ( this.source.equals( dependent.getSource() ) ) - { + boolean contains(Dependency dependent) { + if (this.source.equals(dependent.getSource())) { return true; } - for ( int i = 0; i < this.getDependencies().size(); ++i ) - { - Dependency node = this.getDependencies().get( i ); - if ( node.contains( dependent ) ) - { + for (int i = 0; i < this.getDependencies().size(); ++i) { + Dependency node = this.getDependencies().get(i); + if (node.contains(dependent)) { return true; } } @@ -304,12 +260,10 @@ boolean contains( Dependency dependent ) return false; } - int getDeepDependencyCount() - { + int getDeepDependencyCount() { int ret = this.getDependencies().size(); - for ( int i = 0; i < this.getDependencies().size(); ++i ) - { - Dependency node = this.getDependencies().get( i ); + for (int i = 0; i < this.getDependencies().size(); ++i) { + Dependency node = this.getDependencies().get(i); ret += node.getDeepDependencyCount(); } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/EnvFactory.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/EnvFactory.java index 8d9cab4f..539a6694 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/EnvFactory.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/EnvFactory.java @@ -28,13 +28,10 @@ /** * @author dtran */ -public interface EnvFactory -{ +public interface EnvFactory { /** * @return a map of environment variable/value pairs * @throws NativeBuildException */ - Map getEnvironmentVariables() - throws NativeBuildException; - + Map getEnvironmentVariables() throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeBuildException.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeBuildException.java index 24de365b..8895bcad 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeBuildException.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeBuildException.java @@ -29,26 +29,21 @@ * @author Dan Tran * @version $Id$ */ - -public class NativeBuildException - extends RuntimeException -{ +public class NativeBuildException extends RuntimeException { private static final long serialVersionUID = 1L; /** * @param msg */ - public NativeBuildException( String msg ) - { - super( msg ); + public NativeBuildException(String msg) { + super(msg); } /** * @param msg * @param cause */ - public NativeBuildException( String msg, Throwable cause ) - { - super( msg, cause ); + public NativeBuildException(String msg, Throwable cause) { + super(msg, cause); } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeSources.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeSources.java index dbf511f0..87dc4e38 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeSources.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/NativeSources.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; + import org.codehaus.plexus.util.DirectoryScanner; /** @@ -32,8 +33,7 @@ * @description * @version $Id$ */ -public class NativeSources -{ +public class NativeSources { private File directory; private String[] fileNames = new String[0]; @@ -55,42 +55,34 @@ public class NativeSources */ private String[] excludes; - public NativeSources() - { - - } + public NativeSources() {} /** * @return */ - public File getDirectory() - { + public File getDirectory() { return this.directory; } /** * @param directory */ - public void setDirectory( File directory ) - { + public void setDirectory(File directory) { this.directory = directory; } /** * @return */ - public String[] getFileNames() - { + public String[] getFileNames() { return this.fileNames; } /** * @param fileNames */ - public void setFileNames( String[] fileNames ) - { - if ( fileNames == null ) - { + public void setFileNames(String[] fileNames) { + if (fileNames == null) { this.fileNames = new String[0]; } @@ -100,73 +92,63 @@ public void setFileNames( String[] fileNames ) /** * @return */ - public String[] getIncludes() - { + public String[] getIncludes() { return this.includes; } /** * @param includes */ - public void setIncludes( String[] includes ) - { + public void setIncludes(String[] includes) { this.includes = includes; } /** * @return */ - public String[] getExcludes() - { + public String[] getExcludes() { return this.excludes; } /** * @param excludes */ - public void setExcludes( String[] excludes ) - { + public void setExcludes(String[] excludes) { this.excludes = excludes; } /** * @return */ - public boolean getDependencyAnalysisParticipation() - { + public boolean getDependencyAnalysisParticipation() { return this.dependencyAnalysisParticipation; } /** * @param flag */ - public void setDependencyAnalysisParticipation( boolean flag ) - { + public void setDependencyAnalysisParticipation(boolean flag) { this.dependencyAnalysisParticipation = flag; } - public boolean isDeployable() - { + public boolean isDeployable() { return deployable; } - public void setDeployable( boolean deployable ) - { + public void setDeployable(boolean deployable) { this.deployable = deployable; } // ////////////////////////////////////////////////////////////////////////// - public List getFiles() - { + public List getFiles() { String[] filePaths = new String[0]; - if ( includes != null || excludes != null ) - { + if (includes != null || excludes != null) { DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir( this.directory ); - scanner.setIncludes( includes ); - scanner.setExcludes( excludes ); + scanner.setBasedir(this.directory); + scanner.setIncludes(includes); + scanner.setExcludes(excludes); scanner.addDefaultExcludes(); scanner.scan(); @@ -174,36 +156,30 @@ public List getFiles() filePaths = scanner.getIncludedFiles(); } - List files = new ArrayList<>( filePaths.length + this.fileNames.length ); - for ( String filePath : filePaths ) - { - files.add( new File( this.directory, filePath ) ); + List files = new ArrayList<>(filePaths.length + this.fileNames.length); + for (String filePath : filePaths) { + files.add(new File(this.directory, filePath)); } // remove duplicate files - for ( String fileName : this.fileNames ) - { - File file = new File( this.directory, fileName ); + for (String fileName : this.fileNames) { + File file = new File(this.directory, fileName); boolean found = false; - for ( int k = 0; k < filePaths.length; ++k ) - { - if ( files.get( k ).equals( file ) ) - { + for (int k = 0; k < filePaths.length; ++k) { + if (files.get(k).equals(file)) { found = true; break; } } - if ( !found ) - { - files.add( file ); + if (!found) { + files.add(file); } } return files; - } // /////////////////////////////////////////////////////////////////////// @@ -216,61 +192,49 @@ public List getFiles() * @param sources * @return */ - public static File[] getAllSourceFiles( NativeSources[] sources ) - { - if ( sources == null ) - { + public static File[] getAllSourceFiles(NativeSources[] sources) { + if (sources == null) { return new File[0]; } List sourceFiles = new ArrayList<>(); - for ( NativeSources source : sources ) - { - sourceFiles.addAll( source.getFiles() ); + for (NativeSources source : sources) { + sourceFiles.addAll(source.getFiles()); } - return sourceFiles.toArray( new File[sourceFiles.size()] ); + return sourceFiles.toArray(new File[sourceFiles.size()]); } - public static File[] getIncludePaths( NativeSources[] sources ) - { - if ( sources == null ) - { + public static File[] getIncludePaths(NativeSources[] sources) { + if (sources == null) { return new File[0]; } List list = new ArrayList<>(); - for ( NativeSources source : sources ) - { - if ( source.getDependencyAnalysisParticipation() ) - { - list.add( source.getDirectory() ); + for (NativeSources source : sources) { + if (source.getDependencyAnalysisParticipation()) { + list.add(source.getDirectory()); } } - return list.toArray( new File[0] ); + return list.toArray(new File[0]); } - public static File[] getSystemIncludePaths( NativeSources[] sources ) - { - if ( sources == null ) - { + public static File[] getSystemIncludePaths(NativeSources[] sources) { + if (sources == null) { return new File[0]; } List list = new ArrayList<>(); - for ( NativeSources source : sources ) - { - if ( !source.getDependencyAnalysisParticipation() ) - { - list.add( source.getDirectory() ); + for (NativeSources source : sources) { + if (!source.getDependencyAnalysisParticipation()) { + list.add(source.getDirectory()); } } - return list.toArray( new File[0] ); + return list.toArray(new File[0]); } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/SourceDependencyAnalyzer.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/SourceDependencyAnalyzer.java index d232036f..1ce423e5 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/SourceDependencyAnalyzer.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/SourceDependencyAnalyzer.java @@ -32,37 +32,27 @@ * @author Dan Tran * @version $Id$ */ - -public class SourceDependencyAnalyzer -{ - public static boolean isStaled( File source, File dest, Parser parser, File[] includePaths ) - throws NativeBuildException - { - if ( !source.exists() ) - { - throw new NativeBuildException( source.getPath() + " not found." ); +public class SourceDependencyAnalyzer { + public static boolean isStaled(File source, File dest, Parser parser, File[] includePaths) + throws NativeBuildException { + if (!source.exists()) { + throw new NativeBuildException(source.getPath() + " not found."); } // quick compare with the source where the user likely to change first - if ( ( !dest.exists() ) || ( dest.lastModified() < source.lastModified() ) ) - { + if ((!dest.exists()) || (dest.lastModified() < source.lastModified())) { return true; } // analyze the depenencies of the source file to detect any new changes - Dependency dependency = new Dependency( null, source, parser, includePaths ); + Dependency dependency = new Dependency(null, source, parser, includePaths); - try - { + try { dependency.analyze(); - } - catch ( IOException ioe ) - { - throw new NativeBuildException( "Error analysing " + source.getPath() + ". Reason: " + ioe.getMessage() ); + } catch (IOException ioe) { + throw new NativeBuildException("Error analysing " + source.getPath() + ". Reason: " + ioe.getMessage()); } return dest.lastModified() < dependency.getCompositeLastModified(); - } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractCompiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractCompiler.java index b5ba2e9c..0ad85235 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractCompiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractCompiler.java @@ -40,93 +40,69 @@ import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractCompiler - extends AbstractLogEnabled - implements Compiler -{ +public abstract class AbstractCompiler extends AbstractLogEnabled implements Compiler { protected abstract Parser getParser(); - protected abstract Commandline getCommandLine( File src, File dest, CompilerConfiguration config ) - throws NativeBuildException; + protected abstract Commandline getCommandLine(File src, File dest, CompilerConfiguration config) + throws NativeBuildException; @Override - public List compile( CompilerConfiguration config, File[] sourceFiles ) - throws NativeBuildException - { - if ( !config.getOutputDirectory().exists() ) - { + public List compile(CompilerConfiguration config, File[] sourceFiles) throws NativeBuildException { + if (!config.getOutputDirectory().exists()) { config.getOutputDirectory().mkdirs(); } - List compilerOutputFiles = new ArrayList<>( sourceFiles.length ); + List compilerOutputFiles = new ArrayList<>(sourceFiles.length); CompilerThreadPoolExecutor compilerThreadPoolExecutor = null; - if ( config.getNumberOfConcurrentCompilation() > 1 ) - { - compilerThreadPoolExecutor = new CompilerThreadPoolExecutor( config.getNumberOfConcurrentCompilation() ); + if (config.getNumberOfConcurrentCompilation() > 1) { + compilerThreadPoolExecutor = new CompilerThreadPoolExecutor(config.getNumberOfConcurrentCompilation()); } - for ( File source : sourceFiles ) - { - File objectFile = getObjectFile( source, config.getOutputDirectory(), config.getObjectFileExtension() ); + for (File source : sourceFiles) { + File objectFile = getObjectFile(source, config.getOutputDirectory(), config.getObjectFileExtension()); - compilerOutputFiles.add( objectFile ); + compilerOutputFiles.add(objectFile); Parser parser = this.getParser(); - if ( SourceDependencyAnalyzer.isStaled( source, objectFile, parser, config.getIncludePaths() ) ) - { - if ( compilerThreadPoolExecutor != null && compilerThreadPoolExecutor.isErrorFound() ) - { + if (SourceDependencyAnalyzer.isStaled(source, objectFile, parser, config.getIncludePaths())) { + if (compilerThreadPoolExecutor != null && compilerThreadPoolExecutor.isErrorFound()) { break; } - Commandline cl = getCommandLine( source, objectFile, config ); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + Commandline cl = getCommandLine(source, objectFile, config); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - if ( compilerThreadPoolExecutor != null ) - { - try - { - compilerThreadPoolExecutor.execute( new CompilerRunnable( cl, this.getLogger() ) ); + if (compilerThreadPoolExecutor != null) { + try { + compilerThreadPoolExecutor.execute(new CompilerRunnable(cl, this.getLogger())); + } catch (RejectedExecutionException e) { + CommandLineUtil.execute(cl, this.getLogger()); } - catch ( RejectedExecutionException e ) - { - CommandLineUtil.execute( cl, this.getLogger() ); - } - } - else - { - CommandLineUtil.execute( cl, this.getLogger() ); + } else { + CommandLineUtil.execute(cl, this.getLogger()); } - } - else - { - this.getLogger().debug( ( objectFile + " is up to date." ) ); + } else { + this.getLogger().debug((objectFile + " is up to date.")); } } - if ( compilerThreadPoolExecutor != null ) - { - if ( !compilerThreadPoolExecutor.isErrorFound() ) - { + if (compilerThreadPoolExecutor != null) { + if (!compilerThreadPoolExecutor.isErrorFound()) { compilerThreadPoolExecutor.shutdown(); } - try - { - compilerThreadPoolExecutor.awaitTermination( Integer.MAX_VALUE, TimeUnit.SECONDS ); - } - catch ( InterruptedException e ) - { + try { + compilerThreadPoolExecutor.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); + } catch (InterruptedException e) { } - if ( compilerThreadPoolExecutor.isErrorFound() ) - { - throw new NativeBuildException( "Compilation failure detected." ); + if (compilerThreadPoolExecutor.isErrorFound()) { + throw new NativeBuildException("Compilation failure detected."); } } @@ -138,20 +114,13 @@ public List compile( CompilerConfiguration config, File[] sourceFiles ) * * @return */ - protected static String getObjectFileExtension( String fileExtension ) - { - if ( fileExtension != null ) - { + protected static String getObjectFileExtension(String fileExtension) { + if (fileExtension != null) { return fileExtension; - } - else - { - if ( Os.isFamily( "windows" ) ) - { + } else { + if (Os.isFamily("windows")) { return "obj"; - } - else - { + } else { return "o"; } } @@ -166,119 +135,93 @@ protected static String getObjectFileExtension( String fileExtension ) * @param config * @return */ - protected static File getObjectFile( File sourceFile, File outputDirectory, String objectFileExtension ) - throws NativeBuildException - { + protected static File getObjectFile(File sourceFile, File outputDirectory, String objectFileExtension) + throws NativeBuildException { String objectFileName; - try - { - objectFileExtension = AbstractCompiler.getObjectFileExtension( objectFileExtension ); + try { + objectFileExtension = AbstractCompiler.getObjectFileExtension(objectFileExtension); // plexus-util requires that we remove all ".." in the the file source, so getCanonicalPath is required // other filename with .. and no extension will throw StringIndexOutOfBoundsException - objectFileName = FileUtils.basename( sourceFile.getCanonicalPath() ); + objectFileName = FileUtils.basename(sourceFile.getCanonicalPath()); - if ( objectFileName.charAt( objectFileName.length() - 1 ) != '.' ) - { + if (objectFileName.charAt(objectFileName.length() - 1) != '.') { objectFileName += "." + objectFileExtension; - } - else - { + } else { objectFileName += objectFileExtension; } - } - catch ( IOException e ) - { + } catch (IOException e) { throw new NativeBuildException( - "Failed to figure out object file name for " + sourceFile + ": " + e.getMessage(), e ); + "Failed to figure out object file name for " + sourceFile + ": " + e.getMessage(), e); } - File objectFile = new File( outputDirectory, objectFileName ); + File objectFile = new File(outputDirectory, objectFileName); return objectFile; - } - private class CompilerThreadPoolExecutor - extends ThreadPoolExecutor - { + private class CompilerThreadPoolExecutor extends ThreadPoolExecutor { private boolean errorFound = false; - public synchronized void setErrorFound( boolean errorFound ) - { + public synchronized void setErrorFound(boolean errorFound) { this.errorFound = errorFound; } - public synchronized boolean isErrorFound() - { + public synchronized boolean isErrorFound() { return errorFound; } - public CompilerThreadPoolExecutor( int corePoolSize ) - { - super( corePoolSize, corePoolSize, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>( corePoolSize * 2 ) ); + public CompilerThreadPoolExecutor(int corePoolSize) { + super(corePoolSize, corePoolSize, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(corePoolSize * 2)); } @Override - protected void afterExecute( Runnable r, Throwable t ) - { - super.afterExecute( r, t ); + protected void afterExecute(Runnable r, Throwable t) { + super.afterExecute(r, t); - if ( t != null ) - { - this.setErrorFound( true ); + if (t != null) { + this.setErrorFound(true); this.shutdown(); } } @Override - protected void beforeExecute( Thread t, Runnable r ) - { - super.beforeExecute( t, r ); + protected void beforeExecute(Thread t, Runnable r) { + super.beforeExecute(t, r); // fail fast - if ( this.isErrorFound() ) - { - ( (CompilerRunnable) r ).setSkip( true ); + if (this.isErrorFound()) { + ((CompilerRunnable) r).setSkip(true); } } } - public class CompilerRunnable - implements Runnable - { + public class CompilerRunnable implements Runnable { private Commandline cl; private Logger logger; private boolean skip = false; - public void setSkip( boolean skip ) - { + public void setSkip(boolean skip) { this.skip = skip; } - public CompilerRunnable( Commandline cl, Logger logger ) - { + public CompilerRunnable(Commandline cl, Logger logger) { this.cl = cl; this.logger = logger; } @Override - public void run() - throws NativeBuildException - { - if ( skip ) - { + public void run() throws NativeBuildException { + if (skip) { return; } - CommandLineUtil.execute( cl, logger ); + CommandLineUtil.execute(cl, logger); } - } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractMessageCompiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractMessageCompiler.java index 514f39cf..81b2853e 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractMessageCompiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractMessageCompiler.java @@ -28,31 +28,22 @@ import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.CommandLineUtil; import org.codehaus.mojo.natives.util.EnvUtil; - import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractMessageCompiler - extends AbstractLogEnabled - implements MessageCompiler -{ +public abstract class AbstractMessageCompiler extends AbstractLogEnabled implements MessageCompiler { - protected abstract Commandline getCommandLine( MessageCompilerConfiguration config, File source ) - throws NativeBuildException; + protected abstract Commandline getCommandLine(MessageCompilerConfiguration config, File source) + throws NativeBuildException; - public void compile( MessageCompilerConfiguration config, File[] sourceFiles ) - throws NativeBuildException - { + public void compile(MessageCompilerConfiguration config, File[] sourceFiles) throws NativeBuildException { - for ( File sourceFile : sourceFiles ) - { - Commandline cl = getCommandLine( config, sourceFile ); + for (File sourceFile : sourceFiles) { + Commandline cl = getCommandLine(config, sourceFile); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - CommandLineUtil.execute( cl, this.getLogger() ); + CommandLineUtil.execute(cl, this.getLogger()); } - } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractResourceCompiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractResourceCompiler.java index 81fa44f0..01440d4d 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractResourceCompiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/AbstractResourceCompiler.java @@ -26,6 +26,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.NativeSources; import org.codehaus.mojo.natives.SourceDependencyAnalyzer; @@ -37,70 +38,55 @@ import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractResourceCompiler - extends AbstractLogEnabled - implements ResourceCompiler -{ +public abstract class AbstractResourceCompiler extends AbstractLogEnabled implements ResourceCompiler { - protected abstract Commandline getCommandLine( ResourceCompilerConfiguration config, File source ) - throws NativeBuildException; + protected abstract Commandline getCommandLine(ResourceCompilerConfiguration config, File source) + throws NativeBuildException; @Override - public List compile( ResourceCompilerConfiguration config, NativeSources[] sources ) - throws NativeBuildException - { - File[] sourceFiles = NativeSources.getAllSourceFiles( sources ); + public List compile(ResourceCompilerConfiguration config, NativeSources[] sources) + throws NativeBuildException { + File[] sourceFiles = NativeSources.getAllSourceFiles(sources); - config.setIncludePaths( NativeSources.getIncludePaths( sources ) ); + config.setIncludePaths(NativeSources.getIncludePaths(sources)); - config.setSystemIncludePaths( NativeSources.getSystemIncludePaths( sources ) ); + config.setSystemIncludePaths(NativeSources.getSystemIncludePaths(sources)); - List compilerOutputFiles = new ArrayList<>( sourceFiles.length ); + List compilerOutputFiles = new ArrayList<>(sourceFiles.length); - for ( File src : sourceFiles ) - { - if ( !"rc".equals( FileUtils.getExtension( src.getPath() ) ) ) - { + for (File src : sourceFiles) { + if (!"rc".equals(FileUtils.getExtension(src.getPath()))) { continue; } - File outputFile = config.getOutputFile( src ); + File outputFile = config.getOutputFile(src); - compilerOutputFiles.add( outputFile ); + compilerOutputFiles.add(outputFile); - if ( isResourceFileStaled( src, outputFile, config.getIncludePaths() ) ) - { - Commandline cl = getCommandLine( config, src ); + if (isResourceFileStaled(src, outputFile, config.getIncludePaths())) { + Commandline cl = getCommandLine(config, src); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - CommandLineUtil.execute( cl, this.getLogger() ); + CommandLineUtil.execute(cl, this.getLogger()); } } return compilerOutputFiles; - } - private boolean isResourceFileStaled( File src, File dest, File[] includePaths ) - throws NativeBuildException - { + private boolean isResourceFileStaled(File src, File dest, File[] includePaths) throws NativeBuildException { Parser parser = new CParser(); - try - { - if ( !SourceDependencyAnalyzer.isStaled( src, dest, parser, includePaths ) ) - { - this.getLogger().info( src.getPath() + " is up to date." ); + try { + if (!SourceDependencyAnalyzer.isStaled(src, dest, parser, includePaths)) { + this.getLogger().info(src.getPath() + " is up to date."); return false; } - } - catch ( NativeBuildException ioe ) - { - throw new NativeBuildException( "Error analyzing " + src.getPath() + " dependencies.", ioe ); + } catch (NativeBuildException ioe) { + throw new NativeBuildException("Error analyzing " + src.getPath() + " dependencies.", ioe); } return true; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/Compiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/Compiler.java index 575c4bfa..e6a7dcbd 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/Compiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/Compiler.java @@ -25,10 +25,10 @@ import java.io.File; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; -public interface Compiler -{ +public interface Compiler { String ROLE = Compiler.class.getName(); /** @@ -37,7 +37,5 @@ public interface Compiler * @return List of compiler ouput files (ie, .o, .obj ) * @throws NativeBuildException */ - List compile( CompilerConfiguration config, File[] sourceFiles ) - throws NativeBuildException; - + List compile(CompilerConfiguration config, File[] sourceFiles) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/CompilerConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/CompilerConfiguration.java index 280cc39b..accc9f64 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/CompilerConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/CompilerConfiguration.java @@ -30,9 +30,7 @@ /** * CompilerConfiguration contains inputs by the user + DependencyMangement for dependencies analysis */ -public class CompilerConfiguration - extends ConfigurationBase -{ +public class CompilerConfiguration extends ConfigurationBase { private File workingDirectory; @@ -63,122 +61,96 @@ public class CompilerConfiguration private int numberOfConcurrentCompilation = 4; - public CompilerConfiguration() - { - } + public CompilerConfiguration() {} - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } - public String getExecutable() - { + public String getExecutable() { return this.executable; } - public void setExecutable( String executable ) - { + public void setExecutable(String executable) { this.executable = executable; } - public String getObjectFileExtension() - { + public String getObjectFileExtension() { return this.objectFileExtension; } - public void setObjectFileExtension( String ofe ) - { + public void setObjectFileExtension(String ofe) { this.objectFileExtension = ofe; } - public void setSystemIncludePaths( File[] paths ) - { + public void setSystemIncludePaths(File[] paths) { this.systemIncludePaths = paths; } - public File[] getSystemIncludePaths() - { - if ( this.systemIncludePaths == null ) - { + public File[] getSystemIncludePaths() { + if (this.systemIncludePaths == null) { return new File[0]; } return this.systemIncludePaths; } - public void setIncludePaths( File[] paths ) - { + public void setIncludePaths(File[] paths) { this.includePaths = paths; } - public File[] getIncludePaths() - { - if ( this.includePaths == null ) - { + public File[] getIncludePaths() { + if (this.includePaths == null) { return new File[0]; } return this.includePaths; } - public File getOutputDirectory() - { + public File getOutputDirectory() { return this.outputDirectory; } - public void setOutputDirectory( File dir ) - { + public void setOutputDirectory(File dir) { this.outputDirectory = dir; } - public String[] getStartOptions() - { - if ( this.startOptions == null ) - { + public String[] getStartOptions() { + if (this.startOptions == null) { return new String[0]; } return this.startOptions; } - public void setStartOptions( String[] options ) - { + public void setStartOptions(String[] options) { this.startOptions = options; } - public String[] getMiddleOptions() - { + public String[] getMiddleOptions() { return this.middleOptions; } - public void setMiddleOptions( String[] options ) - { + public void setMiddleOptions(String[] options) { this.middleOptions = options; } - public String[] getEndOptions() - { + public String[] getEndOptions() { return this.endOptions; } - public void setEndOptions( String[] options ) - { + public void setEndOptions(String[] options) { this.endOptions = options; } - public int getNumberOfConcurrentCompilation() - { + public int getNumberOfConcurrentCompilation() { return numberOfConcurrentCompilation; } - public void setNumberOfConcurrentCompilation( int numberOfConcurrentCompilation ) - { + public void setNumberOfConcurrentCompilation(int numberOfConcurrentCompilation) { this.numberOfConcurrentCompilation = numberOfConcurrentCompilation; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompiler.java index 4c10bc38..4bbf1b68 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompiler.java @@ -27,11 +27,8 @@ import org.codehaus.mojo.natives.NativeBuildException; -public interface MessageCompiler -{ +public interface MessageCompiler { String ROLE = MessageCompiler.class.getName(); - void compile( MessageCompilerConfiguration config, File[] sourceFiles ) - throws NativeBuildException; - + void compile(MessageCompilerConfiguration config, File[] sourceFiles) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompilerConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompilerConfiguration.java index 54d4c274..3b50ee6e 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompilerConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/MessageCompilerConfiguration.java @@ -27,9 +27,7 @@ import org.codehaus.mojo.natives.ConfigurationBase; -public class MessageCompilerConfiguration - extends ConfigurationBase -{ +public class MessageCompilerConfiguration extends ConfigurationBase { /** * Must be in your path */ @@ -43,64 +41,49 @@ public class MessageCompilerConfiguration private String[] options = new String[0]; - public MessageCompilerConfiguration() - { - } + public MessageCompilerConfiguration() {} - public String getExecutable() - { + public String getExecutable() { return this.executable; } - public void setExecutable( String executable ) - { + public void setExecutable(String executable) { this.executable = executable; } - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } - public String[] getOptions() - { + public String[] getOptions() { return this.options; } - public void setOptions( String[] options ) - { + public void setOptions(String[] options) { this.options = options; - if ( this.options == null ) - { + if (this.options == null) { this.options = new String[0]; - } } - public File getOutputDirectory() - { + public File getOutputDirectory() { return this.outputDirectory; } - public void setOutputDirectory( File dir ) - { + public void setOutputDirectory(File dir) { this.outputDirectory = dir; } - public File getDebugOutputDirectory() - { + public File getDebugOutputDirectory() { return this.debugOutputDirectory; } - public void setDebugOutputDirectory( File dir ) - { + public void setDebugOutputDirectory(File dir) { this.debugOutputDirectory = dir; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompiler.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompiler.java index a52bddf2..8dcefccf 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompiler.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompiler.java @@ -29,8 +29,7 @@ import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.NativeSources; -public interface ResourceCompiler -{ +public interface ResourceCompiler { String ROLE = ResourceCompiler.class.getName(); /** @@ -39,7 +38,5 @@ public interface ResourceCompiler * @return List of resource ouput files * @throws NativeBuildException */ - List compile( ResourceCompilerConfiguration config, NativeSources[] sources ) - throws NativeBuildException; - + List compile(ResourceCompilerConfiguration config, NativeSources[] sources) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompilerConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompilerConfiguration.java index d5154189..63c3d29a 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompilerConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/compiler/ResourceCompilerConfiguration.java @@ -28,9 +28,7 @@ import org.codehaus.mojo.natives.ConfigurationBase; import org.codehaus.plexus.util.FileUtils; -public class ResourceCompilerConfiguration - extends ConfigurationBase -{ +public class ResourceCompilerConfiguration extends ConfigurationBase { private static final File[] EMPTY_FILE_ARRAY = new File[0]; private static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -52,91 +50,72 @@ public class ResourceCompilerConfiguration private File[] systemIncludePaths = EMPTY_FILE_ARRAY; - public ResourceCompilerConfiguration() - { - } + public ResourceCompilerConfiguration() {} - public String getExecutable() - { + public String getExecutable() { return this.executable; } - public void setExecutable( String executable ) - { + public void setExecutable(String executable) { this.executable = executable; } - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } - public String[] getOptions() - { + public String[] getOptions() { return this.options; } - public void setOptions( String[] options ) - { + public void setOptions(String[] options) { this.options = options; - if ( this.options == null ) - { + if (this.options == null) { this.options = EMPTY_STRING_ARRAY; } } - public File getOutputDirectory() - { + public File getOutputDirectory() { return this.outputDirectory; } - public void setOutputDirectory( File dir ) - { + public void setOutputDirectory(File dir) { this.outputDirectory = dir; } - public File getDebugOutputDirectory() - { + public File getDebugOutputDirectory() { return this.debugOutputDirectory; } - public void setDebugOutputDirectory( File dir ) - { + public void setDebugOutputDirectory(File dir) { this.debugOutputDirectory = dir; } - public File[] getIncludePaths() - { + public File[] getIncludePaths() { return this.includePaths; } - public void setIncludePaths( File[] paths ) - { + public void setIncludePaths(File[] paths) { this.includePaths = paths; - if ( this.includePaths == null ) - { + if (this.includePaths == null) { this.includePaths = EMPTY_FILE_ARRAY; } } - public File[] getSystemIncludePaths() - { + public File[] getSystemIncludePaths() { return this.systemIncludePaths; } - public void setSystemIncludePaths( File[] paths ) - { + public void setSystemIncludePaths(File[] paths) { this.systemIncludePaths = paths; - if ( this.systemIncludePaths == null ) - { + if (this.systemIncludePaths == null) { this.systemIncludePaths = EMPTY_FILE_ARRAY; } } @@ -144,13 +123,11 @@ public void setSystemIncludePaths( File[] paths ) // ////////////////////////////////////////////////////////// // HELPER // ///////////////////////////////////////////////////////// - public File getOutputFile( File src ) - { + public File getOutputFile(File src) { String srcPath = src.getPath(); - String destPath = this.getOutputDirectory().getPath() + "/" + FileUtils.basename( srcPath ) + "res"; + String destPath = this.getOutputDirectory().getPath() + "/" + FileUtils.basename(srcPath) + "res"; - return new File( destPath ); + return new File(destPath); } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/AbstractJavah.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/AbstractJavah.java index b9da139c..47ff5b8f 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/AbstractJavah.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/AbstractJavah.java @@ -25,9 +25,4 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; -public abstract class AbstractJavah - extends AbstractLogEnabled - implements Javah -{ - -} +public abstract class AbstractJavah extends AbstractLogEnabled implements Javah {} diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/Javah.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/Javah.java index 7c5f71e0..89ad88bf 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/Javah.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/Javah.java @@ -28,10 +28,8 @@ /** * Generates JNI header files using javah */ -public interface Javah -{ +public interface Javah { String ROLE = Javah.class.getName(); - void compile( JavahConfiguration configuration ) - throws NativeBuildException; + void compile(JavahConfiguration configuration) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/JavahConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/JavahConfiguration.java index ff98f4fe..d91d56c8 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/JavahConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/javah/JavahConfiguration.java @@ -22,8 +22,7 @@ import java.io.File; -public class JavahConfiguration -{ +public class JavahConfiguration { /** * Working directory where javah command will run */ @@ -59,83 +58,67 @@ public class JavahConfiguration private boolean verbose = false; - public void setOutputDirectory( File dir ) - { + public void setOutputDirectory(File dir) { this.outputDirectory = dir; } - public File getOutputDirectory() - { + public File getOutputDirectory() { return this.outputDirectory; } - public String[] getClassPaths() - { + public String[] getClassPaths() { return this.classPaths; } - public void setJavahPath( File javahPath ) - { + public void setJavahPath(File javahPath) { this.javahPath = javahPath; } - public void setClassPaths( String[] paths ) - { + public void setClassPaths(String[] paths) { this.classPaths = paths; } - public void setUseEnvClasspath( boolean flag ) - { + public void setUseEnvClasspath(boolean flag) { this.useEnvClasspath = flag; } - public boolean getUseEnvClasspath() - { + public boolean getUseEnvClasspath() { return this.useEnvClasspath; } - public void setVerbose( boolean flag ) - { + public void setVerbose(boolean flag) { this.verbose = flag; } - public File getJavahPath() - { + public File getJavahPath() { return this.javahPath; } - public boolean getVerbose() - { + public boolean getVerbose() { return this.verbose; } - public void setClassNames( String[] names ) - { + public void setClassNames(String[] names) { this.classNames = names; } - public String[] getClassNames() - { + public String[] getClassNames() { return this.classNames; } - public void setFileName( String name ) - { + public void setFileName(String name) { this.fileName = name; } - public String getFileName() - { + public String getFileName() { return this.fileName; } - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/AbstractLinker.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/AbstractLinker.java index ac375032..d480440e 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/AbstractLinker.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/AbstractLinker.java @@ -26,76 +26,64 @@ import java.io.File; import java.io.IOException; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.CommandLineUtil; import org.codehaus.mojo.natives.util.EnvUtil; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractLinker - extends AbstractLogEnabled - implements Linker -{ +public abstract class AbstractLinker extends AbstractLogEnabled implements Linker { - protected abstract Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) - throws NativeBuildException; + protected abstract Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException; @Override - public File link( LinkerConfiguration config, List compilerOutputFiles ) - throws NativeBuildException, IOException - { - if ( isStaled( config, compilerOutputFiles ) ) - { + public File link(LinkerConfiguration config, List compilerOutputFiles) + throws NativeBuildException, IOException { + if (isStaled(config, compilerOutputFiles)) { // TODO validate config to make sure required fields are available - Commandline cl = this.createLinkerCommandLine( compilerOutputFiles, config ); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); - CommandLineUtil.execute( cl, this.getLogger() ); + Commandline cl = this.createLinkerCommandLine(compilerOutputFiles, config); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); + CommandLineUtil.execute(cl, this.getLogger()); } return config.getOutputFile(); } - private boolean isStaled( LinkerConfiguration config, List compilerOutputFiles ) - { - if ( !config.isCheckStaleLinkage() ) - { + private boolean isStaled(LinkerConfiguration config, List compilerOutputFiles) { + if (!config.isCheckStaleLinkage()) { // user dont care return true; } File previousDestination = config.getOutputFile(); - if ( !previousDestination.exists() ) - { + if (!previousDestination.exists()) { return true; } - if ( previousDestination.exists() ) - { - for ( File compilerOutputFile : compilerOutputFiles ) - { - if ( previousDestination.lastModified() < compilerOutputFile.lastModified() ) - { - if ( this.getLogger().isDebugEnabled() ) - { - getLogger().debug( "Stale relative to compilerOutputFiles: " - + compilerOutputFile.getAbsolutePath() ); + if (previousDestination.exists()) { + for (File compilerOutputFile : compilerOutputFiles) { + if (previousDestination.lastModified() < compilerOutputFile.lastModified()) { + if (this.getLogger().isDebugEnabled()) { + getLogger() + .debug("Stale relative to compilerOutputFiles: " + + compilerOutputFile.getAbsolutePath()); } return true; } } - for ( int i = 0; i < config.getExternalLibFileNames().size(); ++i ) - { - File extLib = new File( config.getExternalLibDirectory(), - config.getExternalLibFileNames().get( i ) ); + for (int i = 0; i < config.getExternalLibFileNames().size(); ++i) { + File extLib = new File( + config.getExternalLibDirectory(), + config.getExternalLibFileNames().get(i)); - if ( previousDestination.lastModified() < extLib.lastModified() ) - { - if ( this.getLogger().isDebugEnabled() ) - { - getLogger().debug( "Stale relative to extLib: " + extLib.getAbsolutePath() ); + if (previousDestination.lastModified() < extLib.lastModified()) { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug("Stale relative to extLib: " + extLib.getAbsolutePath()); } return true; @@ -105,5 +93,4 @@ private boolean isStaled( LinkerConfiguration config, List compilerOutputF return false; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ArchiveLinker.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ArchiveLinker.java index d8acfb5f..a80a78ac 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ArchiveLinker.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ArchiveLinker.java @@ -26,56 +26,45 @@ import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.Commandline; -public class ArchiveLinker - extends AbstractLinker -{ +public class ArchiveLinker extends AbstractLinker { public static final String EXECUTABLE = "ar"; - public ArchiveLinker() - { - } + public ArchiveLinker() {} @Override - protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) - { + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) { Commandline cl = new Commandline(); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); String executable = EXECUTABLE; - if ( !StringUtils.isBlank( config.getExecutable() ) ) - { + if (!StringUtils.isBlank(config.getExecutable())) { executable = config.getExecutable(); } - cl.setExecutable( executable ); + cl.setExecutable(executable); - for ( int i = 0; i < config.getStartOptions().length; ++i ) - { - cl.createArg().setValue( config.getStartOptions()[i] ); + for (int i = 0; i < config.getStartOptions().length; ++i) { + cl.createArg().setValue(config.getStartOptions()[i]); } // the next 2 are for completeness, the start options should be good enough - for ( int i = 0; i < config.getMiddleOptions().length; ++i ) - { - cl.createArg().setValue( config.getMiddleOptions()[i] ); + for (int i = 0; i < config.getMiddleOptions().length; ++i) { + cl.createArg().setValue(config.getMiddleOptions()[i]); } - for ( int i = 0; i < config.getEndOptions().length; ++i ) - { - cl.createArg().setValue( config.getEndOptions()[i] ); + for (int i = 0; i < config.getEndOptions().length; ++i) { + cl.createArg().setValue(config.getEndOptions()[i]); } - cl.createArg().setFile( config.getOutputFile() ); + cl.createArg().setFile(config.getOutputFile()); - for ( File objFile : objectFiles ) - { - cl.createArg().setValue( objFile.getPath() ); + for (File objFile : objectFiles) { + cl.createArg().setValue(objFile.getPath()); } return cl; - } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/DefaultRanlib.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/DefaultRanlib.java index cd1bdeda..a2634661 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/DefaultRanlib.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/DefaultRanlib.java @@ -7,19 +7,14 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.cli.Commandline; -public class DefaultRanlib - extends AbstractLogEnabled - implements Ranlib -{ - public void run( File file ) - throws NativeBuildException - { +public class DefaultRanlib extends AbstractLogEnabled implements Ranlib { + public void run(File file) throws NativeBuildException { Commandline cl = new Commandline(); - cl.setExecutable( "ranlib" ); + cl.setExecutable("ranlib"); - cl.createArg().setValue( file.getAbsolutePath() ); + cl.createArg().setValue(file.getAbsolutePath()); - CommandLineUtil.execute( cl, this.getLogger() ); + CommandLineUtil.execute(cl, this.getLogger()); } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Linker.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Linker.java index eaeedd03..053f3fa3 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Linker.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Linker.java @@ -26,13 +26,11 @@ import java.io.File; import java.io.IOException; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; -public interface Linker -{ +public interface Linker { String ROLE = Linker.class.getName(); - File link( LinkerConfiguration config, List compilerOutputFiles ) - throws NativeBuildException, IOException; - + File link(LinkerConfiguration config, List compilerOutputFiles) throws NativeBuildException, IOException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/LinkerConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/LinkerConfiguration.java index 799b19b2..248b2217 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/LinkerConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/LinkerConfiguration.java @@ -26,15 +26,14 @@ import java.io.File; import java.util.ArrayList; import java.util.List; + import org.codehaus.mojo.natives.ConfigurationBase; /* * CompilerConfiguration contains inputs by the user + * DependencyMangement for dependecies analysis */ -public class LinkerConfiguration - extends ConfigurationBase -{ +public class LinkerConfiguration extends ConfigurationBase { private File workingDirectory; @@ -80,83 +79,67 @@ public class LinkerConfiguration */ private boolean checkStaleLinkage; - public File getOutputDirectory() - { + public File getOutputDirectory() { return this.outputDirectory; } - public void setOutputDirectory( File dir ) - { + public void setOutputDirectory(File dir) { this.outputDirectory = dir; } - public String getOutputFileExtension() - { + public String getOutputFileExtension() { return this.outputFileExtension; } - public void setOutputFileExtension( String ext ) - { + public void setOutputFileExtension(String ext) { this.outputFileExtension = ext; } - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } - public String[] getStartOptions() - { + public String[] getStartOptions() { return this.startOptions; } - public void setStartOptions( String[] options ) - { + public void setStartOptions(String[] options) { this.startOptions = options; } - public String[] getMiddleOptions() - { + public String[] getMiddleOptions() { return this.middleOptions; } - public void setMiddleOptions( String[] options ) - { + public void setMiddleOptions(String[] options) { this.middleOptions = options; } - public String[] getEndOptions() - { + public String[] getEndOptions() { return this.endOptions; } - public void setEndOptions( String[] options ) - { + public void setEndOptions(String[] options) { this.endOptions = options; } - public String getExecutable() - { + public String getExecutable() { return this.executable; } - public void setExecutable( String executable ) - { + public void setExecutable(String executable) { this.executable = executable; } - public String getOutputFileName() - { + public String getOutputFileName() { return this.outputFileName; } - public void setOutputFileName( String name ) - { + public void setOutputFileName(String name) { this.outputFileName = name; } @@ -165,56 +148,45 @@ public void setOutputFileName( String name ) * * @return */ - public File getOutputFile() - { - File out = new File( this.outputDirectory, this.outputFileName + "." + this.outputFileExtension ); + public File getOutputFile() { + File out = new File(this.outputDirectory, this.outputFileName + "." + this.outputFileExtension); return out; } - public List getExternalLibFileNames() - { - if ( this.externalLibFileNames == null ) - { - return new ArrayList<>( 0 ); + public List getExternalLibFileNames() { + if (this.externalLibFileNames == null) { + return new ArrayList<>(0); } return this.externalLibFileNames; } - public void setExternalLibFileNames( List list ) - { + public void setExternalLibFileNames(List list) { this.externalLibFileNames = list; } - public void setExternalLibDirectory( File dir ) - { + public void setExternalLibDirectory(File dir) { this.externalLibDirectory = dir; } - public File getExternalLibDirectory() - { + public File getExternalLibDirectory() { return this.externalLibDirectory; } - public boolean isUsingLinkerResponseFile() - { + public boolean isUsingLinkerResponseFile() { return usingLinkerResponseFile; } - public void setUsingLinkerResponseFile( boolean useObjectsFile ) - { + public void setUsingLinkerResponseFile(boolean useObjectsFile) { this.usingLinkerResponseFile = useObjectsFile; } - public boolean isCheckStaleLinkage() - { + public boolean isCheckStaleLinkage() { return checkStaleLinkage; } - public void setCheckStaleLinkage( boolean checkStaleLinkage ) - { + public void setCheckStaleLinkage(boolean checkStaleLinkage) { this.checkStaleLinkage = checkStaleLinkage; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Manifest.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Manifest.java index a5f32a4c..08656df7 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Manifest.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Manifest.java @@ -22,10 +22,8 @@ import org.codehaus.mojo.natives.NativeBuildException; -public interface Manifest -{ +public interface Manifest { String ROLE = Manifest.class.getName(); - void run( ManifestConfiguration config ) - throws NativeBuildException; + void run(ManifestConfiguration config) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ManifestConfiguration.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ManifestConfiguration.java index 901be5b3..a699d824 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ManifestConfiguration.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/ManifestConfiguration.java @@ -30,9 +30,7 @@ /* * ManifestConfiguration contains inputs by the user */ -public class ManifestConfiguration - extends ConfigurationBase -{ +public class ManifestConfiguration extends ConfigurationBase { private File workingDirectory; @@ -40,34 +38,27 @@ public class ManifestConfiguration private File manifestFile; - public File getInputFile() - { + public File getInputFile() { return inputFile; } - public void setInputFile( File inputFile ) - { + public void setInputFile(File inputFile) { this.inputFile = inputFile; } - public File getManifestFile() - { + public File getManifestFile() { return manifestFile; } - public void setManifestFile( File manifestFile ) - { + public void setManifestFile(File manifestFile) { this.manifestFile = manifestFile; } - public File getWorkingDirectory() - { + public File getWorkingDirectory() { return this.workingDirectory; } - public void setWorkingDirectory( File dir ) - { + public void setWorkingDirectory(File dir) { this.workingDirectory = dir; } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Ranlib.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Ranlib.java index 500bdbc3..a0cf5947 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Ranlib.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/linker/Ranlib.java @@ -4,10 +4,8 @@ import org.codehaus.mojo.natives.NativeBuildException; -public interface Ranlib -{ +public interface Ranlib { String ROLE = Ranlib.class.getName(); - void run( File file ) - throws NativeBuildException; + void run(File file) throws NativeBuildException; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParser.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParser.java index b9b9bc20..d109b7fd 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParser.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParser.java @@ -25,54 +25,40 @@ * * @author Curt Arnold */ -public abstract class AbstractParser -{ +public abstract class AbstractParser { - protected AbstractParser() - { - } + protected AbstractParser() {} - protected abstract void addFilename( String filename ); + protected abstract void addFilename(String filename); public abstract AbstractParserState getNewLineState(); - protected void parse( Reader reader ) - throws IOException - { + protected void parse(Reader reader) throws IOException { char[] buf = new char[4096]; AbstractParserState newLineState = getNewLineState(); AbstractParserState state = newLineState; int charsRead = -1; - do - { - charsRead = reader.read( buf, 0, buf.length ); - if ( state == null ) - { - for ( int i = 0; i < charsRead; i++ ) - { - if ( buf[i] == '\n' ) - { + do { + charsRead = reader.read(buf, 0, buf.length); + if (state == null) { + for (int i = 0; i < charsRead; i++) { + if (buf[i] == '\n') { state = newLineState; break; } } } - if ( state != null ) - { - for ( int i = 0; i < charsRead; i++ ) - { - state = state.consume( buf[i] ); + if (state != null) { + for (int i = 0; i < charsRead; i++) { + state = state.consume(buf[i]); // // didn't match a production, skip to a new line // - if ( state == null ) - { - for ( ; i < charsRead; i++ ) - { - if ( buf[i] == '\n' ) - { + if (state == null) { + for (; i < charsRead; i++) { + if (buf[i] == '\n') { state = newLineState; break; } @@ -81,7 +67,6 @@ protected void parse( Reader reader ) } } - } - while ( charsRead >= 0 ); + } while (charsRead >= 0); } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParserState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParserState.java index 67b56c61..e8b65ba4 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParserState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/AbstractParserState.java @@ -22,15 +22,12 @@ * @author CurtArnold * @see AbstractParser */ -public abstract class AbstractParserState -{ +public abstract class AbstractParserState { private AbstractParser parser; - protected AbstractParserState( AbstractParser parser ) - { - if ( parser == null ) - { - throw new NullPointerException( "parser" ); + protected AbstractParserState(AbstractParser parser) { + if (parser == null) { + throw new NullPointerException("parser"); } this.parser = parser; } @@ -40,10 +37,9 @@ protected AbstractParserState( AbstractParser parser ) * * @return new state, may be null to ignore the rest of the line */ - public abstract AbstractParserState consume( char ch ); + public abstract AbstractParserState consume(char ch); - protected AbstractParser getParser() - { + protected AbstractParser getParser() { return parser; } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/BranchState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/BranchState.java index d5574709..e1d24f77 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/BranchState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/BranchState.java @@ -16,45 +16,40 @@ */ package org.codehaus.mojo.natives.parser; -public class BranchState - extends AbstractParserState -{ +public class BranchState extends AbstractParserState { private char[] branchChars; private AbstractParserState[] branchStates; private AbstractParserState noMatchState; - public BranchState( AbstractParser parser, char[] branchChars, AbstractParserState[] branchStates, - AbstractParserState noMatchState ) - { - super( parser ); + public BranchState( + AbstractParser parser, + char[] branchChars, + AbstractParserState[] branchStates, + AbstractParserState noMatchState) { + super(parser); this.branchChars = branchChars.clone(); this.branchStates = branchStates.clone(); this.noMatchState = noMatchState; } - public AbstractParserState consume( char ch ) - { + public AbstractParserState consume(char ch) { AbstractParserState state; - for ( int i = 0; i < branchChars.length; i++ ) - { - if ( ch == branchChars[i] ) - { + for (int i = 0; i < branchChars.length; i++) { + if (ch == branchChars[i]) { state = branchStates[i]; - return state.consume( ch ); + return state.consume(ch); } } state = getNoMatchState(); - if ( state != null ) - { - return state.consume( ch ); + if (state != null) { + return state.consume(ch); } return state; } - protected AbstractParserState getNoMatchState() - { + protected AbstractParserState getNoMatchState() { return noMatchState; } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CParser.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CParser.java index 3e7b9371..b0191dc5 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CParser.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CParser.java @@ -26,74 +26,63 @@ * @author Adam Murdoch * @author Curt Arnold */ -public final class CParser - extends AbstractParser - implements Parser -{ +public final class CParser extends AbstractParser implements Parser { private final Vector includes = new Vector<>(); private AbstractParserState newLineState; - public CParser() - { - AbstractParserState quote = new FilenameState( this, new char[] { '"' } ); - AbstractParserState bracket = new FilenameState( this, new char[] { '>' } ); - AbstractParserState postE = new PostE( this, bracket, quote ); + public CParser() { + AbstractParserState quote = new FilenameState(this, new char[] {'"'}); + AbstractParserState bracket = new FilenameState(this, new char[] {'>'}); + AbstractParserState postE = new PostE(this, bracket, quote); // // nclude // - AbstractParserState e = new LetterState( this, 'e', postE, null ); - AbstractParserState d = new LetterState( this, 'd', e, null ); - AbstractParserState u = new LetterState( this, 'u', d, null ); - AbstractParserState l = new LetterState( this, 'l', u, null ); - AbstractParserState c = new LetterState( this, 'c', l, null ); - AbstractParserState n = new LetterState( this, 'n', c, null ); + AbstractParserState e = new LetterState(this, 'e', postE, null); + AbstractParserState d = new LetterState(this, 'd', e, null); + AbstractParserState u = new LetterState(this, 'u', d, null); + AbstractParserState l = new LetterState(this, 'l', u, null); + AbstractParserState c = new LetterState(this, 'c', l, null); + AbstractParserState n = new LetterState(this, 'n', c, null); // // mport is equivalent to nclude // - AbstractParserState t = new LetterState( this, 't', postE, null ); - AbstractParserState r = new LetterState( this, 'r', t, null ); - AbstractParserState o = new LetterState( this, 'o', r, null ); - AbstractParserState p = new LetterState( this, 'p', o, null ); - AbstractParserState m = new LetterState( this, 'm', p, null ); + AbstractParserState t = new LetterState(this, 't', postE, null); + AbstractParserState r = new LetterState(this, 'r', t, null); + AbstractParserState o = new LetterState(this, 'o', r, null); + AbstractParserState p = new LetterState(this, 'p', o, null); + AbstractParserState m = new LetterState(this, 'm', p, null); // // switch between // - AbstractParserState n_m = - new BranchState( this, new char[] { 'n', 'm' }, new AbstractParserState[] { n, m }, null ); - AbstractParserState i = new WhitespaceOrLetterState( this, 'i', n_m ); - newLineState = new LetterState( this, '#', i, null ); + AbstractParserState n_m = new BranchState(this, new char[] {'n', 'm'}, new AbstractParserState[] {n, m}, null); + AbstractParserState i = new WhitespaceOrLetterState(this, 'i', n_m); + newLineState = new LetterState(this, '#', i, null); } @Override - public void addFilename( String include ) - { - includes.addElement( include ); + public void addFilename(String include) { + includes.addElement(include); } @Override - public String[] getIncludes() - { + public String[] getIncludes() { String[] retval = new String[includes.size()]; - includes.copyInto( retval ); + includes.copyInto(retval); return retval; } @Override - public AbstractParserState getNewLineState() - { + public AbstractParserState getNewLineState() { return newLineState; } @Override - public void parse( Reader reader ) - throws IOException - { - includes.setSize( 0 ); + public void parse(Reader reader) throws IOException { + includes.setSize(0); - super.parse( reader ); + super.parse(reader); } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CaseInsensitiveLetterState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CaseInsensitiveLetterState.java index 11413299..6876eff3 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CaseInsensitiveLetterState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/CaseInsensitiveLetterState.java @@ -21,9 +21,7 @@ * * @author Curt Arnold */ -public final class CaseInsensitiveLetterState - extends AbstractParserState -{ +public final class CaseInsensitiveLetterState extends AbstractParserState { /** * Next state if a match is found. */ @@ -52,12 +50,14 @@ public final class CaseInsensitiveLetterState * @param nextStateArg next state if a match on the letter * @param noMatchStateArg state if no match on letter */ - public CaseInsensitiveLetterState( final AbstractParser parser, final char matchLetter, - final AbstractParserState nextStateArg, final AbstractParserState noMatchStateArg ) - { - super( parser ); - this.lowerLetter = Character.toLowerCase( matchLetter ); - this.upperLetter = Character.toUpperCase( matchLetter ); + public CaseInsensitiveLetterState( + final AbstractParser parser, + final char matchLetter, + final AbstractParserState nextStateArg, + final AbstractParserState noMatchStateArg) { + super(parser); + this.lowerLetter = Character.toLowerCase(matchLetter); + this.upperLetter = Character.toUpperCase(matchLetter); this.nextState = nextStateArg; this.noMatchState = noMatchStateArg; } @@ -68,14 +68,11 @@ public CaseInsensitiveLetterState( final AbstractParser parser, final char match * @param ch next character * @return the configured nextState if ch is the expected character or the configure noMatchState otherwise. */ - public AbstractParserState consume( final char ch ) - { - if ( ch == lowerLetter || ch == upperLetter ) - { + public AbstractParserState consume(final char ch) { + if (ch == lowerLetter || ch == upperLetter) { return nextState; } - if ( ch == '\n' ) - { + if (ch == '\n') { getParser().getNewLineState(); } return noMatchState; diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FilenameState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FilenameState.java index 46608c74..9b9abde2 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FilenameState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FilenameState.java @@ -16,38 +16,29 @@ */ package org.codehaus.mojo.natives.parser; -public class FilenameState - extends AbstractParserState -{ +public class FilenameState extends AbstractParserState { private final StringBuffer buf = new StringBuffer(); private final char[] terminators; - public FilenameState( AbstractParser parser, char[] terminators ) - { - super( parser ); + public FilenameState(AbstractParser parser, char[] terminators) { + super(parser); this.terminators = terminators.clone(); } - public AbstractParserState consume( char ch ) - { - for ( char terminator : terminators ) - { - if ( ch == terminator ) - { - getParser().addFilename( buf.toString() ); - buf.setLength( 0 ); + public AbstractParserState consume(char ch) { + for (char terminator : terminators) { + if (ch == terminator) { + getParser().addFilename(buf.toString()); + buf.setLength(0); return null; } } - if ( ch == '\n' ) - { - buf.setLength( 0 ); + if (ch == '\n') { + buf.setLength(0); return getParser().getNewLineState(); - } - else - { - buf.append( ch ); + } else { + buf.append(ch); } return this; } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FortranParser.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FortranParser.java index 440d6a62..0113acdc 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FortranParser.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/FortranParser.java @@ -25,10 +25,7 @@ * * @author Curt Arnold */ -public final class FortranParser - extends AbstractParser - implements Parser -{ +public final class FortranParser extends AbstractParser implements Parser { /** * List of included filenames. */ @@ -42,18 +39,17 @@ public final class FortranParser /** * Default constructor. */ - public FortranParser() - { - AbstractParserState filename = new FilenameState( this, new char[] { '\'', '/' } ); - AbstractParserState apos = new WhitespaceOrLetterState( this, '\'', filename ); - AbstractParserState blank = new LetterState( this, ' ', apos, null ); - AbstractParserState e = new CaseInsensitiveLetterState( this, 'E', blank, null ); - AbstractParserState d = new CaseInsensitiveLetterState( this, 'D', e, null ); - AbstractParserState u = new CaseInsensitiveLetterState( this, 'U', d, null ); - AbstractParserState l = new CaseInsensitiveLetterState( this, 'L', u, null ); - AbstractParserState c = new CaseInsensitiveLetterState( this, 'C', l, null ); - AbstractParserState n = new CaseInsensitiveLetterState( this, 'N', c, null ); - newLineState = new WhitespaceOrCaseInsensitiveLetterState( this, 'I', n ); + public FortranParser() { + AbstractParserState filename = new FilenameState(this, new char[] {'\'', '/'}); + AbstractParserState apos = new WhitespaceOrLetterState(this, '\'', filename); + AbstractParserState blank = new LetterState(this, ' ', apos, null); + AbstractParserState e = new CaseInsensitiveLetterState(this, 'E', blank, null); + AbstractParserState d = new CaseInsensitiveLetterState(this, 'D', e, null); + AbstractParserState u = new CaseInsensitiveLetterState(this, 'U', d, null); + AbstractParserState l = new CaseInsensitiveLetterState(this, 'L', u, null); + AbstractParserState c = new CaseInsensitiveLetterState(this, 'C', l, null); + AbstractParserState n = new CaseInsensitiveLetterState(this, 'N', c, null); + newLineState = new WhitespaceOrCaseInsensitiveLetterState(this, 'I', n); } /** @@ -62,9 +58,8 @@ public FortranParser() * @param include include file name */ @Override - public void addFilename( final String include ) - { - includes.addElement( include ); + public void addFilename(final String include) { + includes.addElement(include); } /** @@ -73,10 +68,9 @@ public void addFilename( final String include ) * @return include file names */ @Override - public String[] getIncludes() - { + public String[] getIncludes() { String[] retval = new String[includes.size()]; - includes.copyInto( retval ); + includes.copyInto(retval); return retval; } @@ -86,8 +80,7 @@ public String[] getIncludes() * @return start of line state */ @Override - public AbstractParserState getNewLineState() - { + public AbstractParserState getNewLineState() { return newLineState; } @@ -98,10 +91,8 @@ public AbstractParserState getNewLineState() * @throws IOException throw if I/O error during parse */ @Override - public void parse( final Reader reader ) - throws IOException - { - includes.setSize( 0 ); - super.parse( reader ); + public void parse(final Reader reader) throws IOException { + includes.setSize(0); + super.parse(reader); } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/LetterState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/LetterState.java index a287301c..8318e507 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/LetterState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/LetterState.java @@ -21,9 +21,7 @@ * * @author Curt Arnold */ -public final class LetterState - extends AbstractParserState -{ +public final class LetterState extends AbstractParserState { /** * Next state if a match is found. */ @@ -47,10 +45,12 @@ public final class LetterState * @param nextStateArg next state if a match on the letter * @param noMatchStateArg state if no match on letter */ - public LetterState( final AbstractParser parser, final char matchLetter, final AbstractParserState nextStateArg, - final AbstractParserState noMatchStateArg ) - { - super( parser ); + public LetterState( + final AbstractParser parser, + final char matchLetter, + final AbstractParserState nextStateArg, + final AbstractParserState noMatchStateArg) { + super(parser); this.thisLetter = matchLetter; this.nextState = nextStateArg; this.noMatchState = noMatchStateArg; @@ -62,14 +62,11 @@ public LetterState( final AbstractParser parser, final char matchLetter, final A * @param ch next character * @return the configured nextState if ch is the expected character or the configure noMatchState otherwise. */ - public AbstractParserState consume( final char ch ) - { - if ( ch == thisLetter ) - { + public AbstractParserState consume(final char ch) { + if (ch == thisLetter) { return nextState; } - if ( ch == '\n' ) - { + if (ch == '\n') { getParser().getNewLineState(); } return noMatchState; diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/Parser.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/Parser.java index 35052895..4ff4e1ef 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/Parser.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/Parser.java @@ -25,10 +25,8 @@ * * @author Curt Arnold */ -public interface Parser -{ +public interface Parser { String[] getIncludes(); - void parse( Reader reader ) - throws IOException; + void parse(Reader reader) throws IOException; } 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..7ba6ba3d 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 @@ -16,24 +16,19 @@ */ package org.codehaus.mojo.natives.parser; -public class PostE - extends AbstractParserState -{ +public class PostE extends AbstractParserState { private AbstractParserState bracket; private AbstractParserState quote; - public PostE( CParser parser, AbstractParserState bracket, AbstractParserState quote ) - { - super( parser ); + public PostE(CParser parser, AbstractParserState bracket, AbstractParserState quote) { + super(parser); this.bracket = bracket; this.quote = quote; } - public AbstractParserState consume( char ch ) - { - switch ( ch ) - { + public AbstractParserState consume(char ch) { + switch (ch) { case ' ': case '\t': return this; diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrCaseInsensitiveLetterState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrCaseInsensitiveLetterState.java index 7c81eb8f..900f4172 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrCaseInsensitiveLetterState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrCaseInsensitiveLetterState.java @@ -21,9 +21,7 @@ * * @author Curt Arnold */ -public final class WhitespaceOrCaseInsensitiveLetterState - extends AbstractParserState -{ +public final class WhitespaceOrCaseInsensitiveLetterState extends AbstractParserState { /** * Next state if the character is found. */ @@ -46,12 +44,11 @@ public final class WhitespaceOrCaseInsensitiveLetterState * @param matchLetter letter to match * @param nextStateArg next state if a match on the letter */ - public WhitespaceOrCaseInsensitiveLetterState( final AbstractParser parser, final char matchLetter, - final AbstractParserState nextStateArg ) - { - super( parser ); - this.lowerLetter = Character.toLowerCase( matchLetter ); - this.upperLetter = Character.toUpperCase( matchLetter ); + public WhitespaceOrCaseInsensitiveLetterState( + final AbstractParser parser, final char matchLetter, final AbstractParserState nextStateArg) { + super(parser); + this.lowerLetter = Character.toLowerCase(matchLetter); + this.upperLetter = Character.toUpperCase(matchLetter); this.nextState = nextStateArg; } @@ -61,18 +58,14 @@ public WhitespaceOrCaseInsensitiveLetterState( final AbstractParser parser, fina * @param ch next character * @return the configured nextState if ch is the expected character or the configure noMatchState otherwise. */ - public AbstractParserState consume( final char ch ) - { - if ( ch == lowerLetter || ch == upperLetter ) - { + public AbstractParserState consume(final char ch) { + if (ch == lowerLetter || ch == upperLetter) { return nextState; } - if ( ch == ' ' || ch == '\t' ) - { + if (ch == ' ' || ch == '\t') { return this; } - if ( ch == '\n' ) - { + if (ch == '\n') { getParser().getNewLineState(); } return null; diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrLetterState.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrLetterState.java index 9d0cc27a..c68cca5c 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrLetterState.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/parser/WhitespaceOrLetterState.java @@ -21,9 +21,7 @@ * * @author Curt Arnold */ -public final class WhitespaceOrLetterState - extends AbstractParserState -{ +public final class WhitespaceOrLetterState extends AbstractParserState { /** * Next state if the character is found. */ @@ -41,10 +39,9 @@ public final class WhitespaceOrLetterState * @param matchLetter letter to match * @param nextStateArg next state if a match on the letter */ - public WhitespaceOrLetterState( final AbstractParser parser, final char matchLetter, - final AbstractParserState nextStateArg ) - { - super( parser ); + public WhitespaceOrLetterState( + final AbstractParser parser, final char matchLetter, final AbstractParserState nextStateArg) { + super(parser); this.thisLetter = matchLetter; this.nextState = nextStateArg; } @@ -56,18 +53,14 @@ public WhitespaceOrLetterState( final AbstractParser parser, final char matchLet * noMatchState otherwise. * @return next state */ - public AbstractParserState consume( final char ch ) - { - if ( ch == thisLetter ) - { + public AbstractParserState consume(final char ch) { + if (ch == thisLetter) { return nextState; } - if ( ch == ' ' || ch == '\t' ) - { + if (ch == ' ' || ch == '\t') { return this; } - if ( ch == '\n' ) - { + if (ch == '\n') { getParser().getNewLineState(); } return null; diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/CommandLineUtil.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/CommandLineUtil.java index 412ba25f..4169acd3 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/CommandLineUtil.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/CommandLineUtil.java @@ -1,37 +1,30 @@ package org.codehaus.mojo.natives.util; import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.DefaultConsumer; -import org.codehaus.plexus.logging.Logger; -public class CommandLineUtil -{ - public static void execute( Commandline cl, Logger logger ) - throws NativeBuildException - { +public class CommandLineUtil { + public static void execute(Commandline cl, Logger logger) throws NativeBuildException { int ok; - try - { + try { DefaultConsumer stdout = new DefaultConsumer(); DefaultConsumer stderr = stdout; - logger.info( cl.toString() ); + logger.info(cl.toString()); - ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr ); - } - catch ( CommandLineException ecx ) - { - throw new NativeBuildException( "Error executing command line", ecx ); + ok = CommandLineUtils.executeCommandLine(cl, stdout, stderr); + } catch (CommandLineException ecx) { + throw new NativeBuildException("Error executing command line", ecx); } - if ( ok != 0 ) - { - throw new NativeBuildException( "Error executing command line. Exit code:" + ok ); + if (ok != 0) { + throw new NativeBuildException("Error executing command line. Exit code:" + ok); } } } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/EnvUtil.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/EnvUtil.java index 05154a62..a3fd142b 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/EnvUtil.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/EnvUtil.java @@ -1,75 +1,59 @@ package org.codehaus.mojo.natives.util; import java.util.Map; + import org.codehaus.mojo.natives.EnvFactory; import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.plexus.util.cli.Commandline; -public class EnvUtil -{ - public static String getEnv( String envKey ) - { - return getEnv( envKey, "" ); +public class EnvUtil { + public static String getEnv(String envKey) { + return getEnv(envKey, ""); } - public static String getEnv( String envKey, String defaultValue ) - { - return getEnv( envKey, null, defaultValue ); + public static String getEnv(String envKey, String defaultValue) { + return getEnv(envKey, null, defaultValue); } - public static String getEnv( String envKey, String alternateSystemProperty, String defaultValue ) - { + public static String getEnv(String envKey, String alternateSystemProperty, String defaultValue) { String envValue = null; - try - { + try { // TODO move this to an env object similar to Ant Environment - envValue = System.getenv( envKey ); + envValue = System.getenv(envKey); - if ( envValue == null && alternateSystemProperty != null ) - { - envValue = System.getProperty( alternateSystemProperty ); + if (envValue == null && alternateSystemProperty != null) { + envValue = System.getProperty(alternateSystemProperty); } - } - catch ( Error e ) - { + } catch (Error e) { // JDK 1.4? - if ( alternateSystemProperty != null ) - { - envValue = getProperty( alternateSystemProperty ); + if (alternateSystemProperty != null) { + envValue = getProperty(alternateSystemProperty); } } - if ( envValue == null ) - { + if (envValue == null) { envValue = defaultValue; } return envValue; } - private static String getProperty( String key ) - { - if ( key != null ) - { - return System.getProperty( key ); + private static String getProperty(String key) { + if (key != null) { + return System.getProperty(key); } return null; } - public static void setupCommandlineEnv( Commandline cl, EnvFactory envFactory ) - throws NativeBuildException - { - if ( envFactory != null ) - { + public static void setupCommandlineEnv(Commandline cl, EnvFactory envFactory) throws NativeBuildException { + if (envFactory != null) { Map envs = envFactory.getEnvironmentVariables(); - for ( String key : envs.keySet() ) - { - cl.addEnvironment( key, envs.get( key ) ); + for (String key : envs.keySet()) { + cl.addEnvironment(key, envs.get(key)); } } } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileSet.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileSet.java index 27c85ca3..551fb39f 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileSet.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileSet.java @@ -1,12 +1,12 @@ package org.codehaus.mojo.natives.util; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.StringUtils; - import java.io.File; import java.io.IOException; import java.util.Arrays; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + /* * Copyright 2001-2004 The Apache Software Foundation. * @@ -23,8 +23,7 @@ * limitations under the License. */ -public class FileSet -{ +public class FileSet { private File basedir; /** List of files, all relative to the basedir. */ @@ -32,81 +31,66 @@ public class FileSet private static final File[] EMPTY_FILE_ARRAY = new File[0]; - public FileSet( File basedir ) - { - this( basedir, EMPTY_FILE_ARRAY ); + public FileSet(File basedir) { + this(basedir, EMPTY_FILE_ARRAY); } - public FileSet( File basedir, File file ) - { - this( basedir, new File[] { file } ); + public FileSet(File basedir, File file) { + this(basedir, new File[] {file}); } - public FileSet( File basedir, String includes, String excludes ) - throws IOException - { + public FileSet(File basedir, String includes, String excludes) throws IOException { this.basedir = basedir; - excludes = this.trimCommaSeparateString( excludes ); + excludes = this.trimCommaSeparateString(excludes); - includes = this.trimCommaSeparateString( includes ); + includes = this.trimCommaSeparateString(includes); - files = FileUtils.getFiles( basedir, includes, excludes ).toArray( EMPTY_FILE_ARRAY ); + files = FileUtils.getFiles(basedir, includes, excludes).toArray(EMPTY_FILE_ARRAY); } - public FileSet( File basedir, File[] files ) - { - if ( basedir == null ) - { - throw new NullPointerException( "basedir must not be null" ); + public FileSet(File basedir, File[] files) { + if (basedir == null) { + throw new NullPointerException("basedir must not be null"); } - if ( files == null ) - { - throw new NullPointerException( "files must not be null" ); + if (files == null) { + throw new NullPointerException("files must not be null"); } this.basedir = basedir; this.files = files; } - public File getBasedir() - { + public File getBasedir() { return basedir; } - public File[] getFiles() - { + public File[] getFiles() { return this.files; } - public String toString() - { - return "basedir = " + basedir + "; files = " + Arrays.asList( files ); + public String toString() { + return "basedir = " + basedir + "; files = " + Arrays.asList(files); } // temp solution until plexus-util is fix - private String trimCommaSeparateString( String in ) - { - if ( in == null || in.trim().length() == 0 ) - { + private String trimCommaSeparateString(String in) { + if (in == null || in.trim().length() == 0) { return ""; } StringBuilder out = new StringBuilder(); - String[] tokens = StringUtils.split( in, "," ); - for ( int i = 0; i < tokens.length; ++i ) - { - if ( i != 0 ) - { - out.append( "," ); + String[] tokens = StringUtils.split(in, ","); + for (int i = 0; i < tokens.length; ++i) { + if (i != 0) { + out.append(","); } - out.append( tokens[i].trim() ); + out.append(tokens[i].trim()); } return out.toString(); } - } diff --git a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileUtil.java b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileUtil.java index b21b24cd..e5991c5c 100644 --- a/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileUtil.java +++ b/maven-native-api/src/main/java/org/codehaus/mojo/natives/util/FileUtil.java @@ -5,8 +5,7 @@ import org.codehaus.plexus.util.StringUtils; -public class FileUtil -{ +public class FileUtil { /** * Returns a relative path for the targetFile relative to the base directory. @@ -17,18 +16,15 @@ public class FileUtil * target * @author Curt Arnold */ - public static File getRelativeFile( File workingDirectory, File targetFile ) - { - try - { + public static File getRelativeFile(File workingDirectory, File targetFile) { + try { // // remove trailing file separator // String canonicalBase = workingDirectory.getCanonicalFile().getAbsolutePath(); - if ( canonicalBase.charAt( canonicalBase.length() - 1 ) == File.separatorChar ) - { - canonicalBase = canonicalBase.substring( 0, canonicalBase.length() - 1 ); + if (canonicalBase.charAt(canonicalBase.length() - 1) == File.separatorChar) { + canonicalBase = canonicalBase.substring(0, canonicalBase.length() - 1); } // @@ -37,60 +33,45 @@ public static File getRelativeFile( File workingDirectory, File targetFile ) String canonicalTarget; - if ( System.getProperty( "os.name" ).equals( "OS/400" ) ) - { + if (System.getProperty("os.name").equals("OS/400")) { canonicalTarget = targetFile.getPath(); - } - else - { + } else { canonicalTarget = targetFile.getCanonicalPath(); } - if ( canonicalTarget.charAt( canonicalTarget.length() - 1 ) == File.separatorChar ) - { - canonicalTarget = canonicalTarget.substring( 0, canonicalTarget.length() - 1 ); + if (canonicalTarget.charAt(canonicalTarget.length() - 1) == File.separatorChar) { + canonicalTarget = canonicalTarget.substring(0, canonicalTarget.length() - 1); } - if ( canonicalTarget.equals( canonicalBase ) ) - { - return new File( "." ); + if (canonicalTarget.equals(canonicalBase)) { + return new File("."); } // // see if the prefixes are the same // - if ( canonicalBase.startsWith( "\\\\" ) ) - { + if (canonicalBase.startsWith("\\\\")) { // // UNC file name, if target file doesn't also start with same // server name, don't go there - int endPrefix = canonicalBase.indexOf( '\\', 2 ); - String prefix1 = canonicalBase.substring( 0, endPrefix ); - String prefix2 = canonicalTarget.substring( 0, endPrefix ); - if ( !prefix1.equals( prefix2 ) ) - { - return new File( canonicalTarget ); + int endPrefix = canonicalBase.indexOf('\\', 2); + String prefix1 = canonicalBase.substring(0, endPrefix); + String prefix2 = canonicalTarget.substring(0, endPrefix); + if (!prefix1.equals(prefix2)) { + return new File(canonicalTarget); } - } - else - { - if ( canonicalBase.startsWith( ":\\", 1 ) ) - { + } else { + if (canonicalBase.startsWith(":\\", 1)) { int endPrefix = 2; - String prefix1 = canonicalBase.substring( 0, endPrefix ); - String prefix2 = canonicalTarget.substring( 0, endPrefix ); - if ( !prefix1.equals( prefix2 ) ) - { - return new File( canonicalTarget ); + String prefix1 = canonicalBase.substring(0, endPrefix); + String prefix2 = canonicalTarget.substring(0, endPrefix); + if (!prefix1.equals(prefix2)) { + return new File(canonicalTarget); } - } - else - { - if ( canonicalBase.charAt( 0 ) == '/' ) - { - if ( canonicalTarget.charAt( 0 ) != '/' ) - { - return new File( canonicalTarget ); + } else { + if (canonicalBase.charAt(0) == '/') { + if (canonicalTarget.charAt(0) != '/') { + return new File(canonicalTarget); } } } @@ -100,8 +81,7 @@ public static File getRelativeFile( File workingDirectory, File targetFile ) int lastSeparator = -1; int minLength = canonicalBase.length(); - if ( canonicalTarget.length() < minLength ) - { + if (canonicalTarget.length() < minLength) { minLength = canonicalTarget.length(); } @@ -110,76 +90,61 @@ public static File getRelativeFile( File workingDirectory, File targetFile ) // // walk to the shorter of the two paths // finding the last separator they have in common - for ( int i = 0; i < minLength; i++ ) - { - if ( canonicalTarget.charAt( i ) == canonicalBase.charAt( i ) ) - { - if ( canonicalTarget.charAt( i ) == separator ) - { + for (int i = 0; i < minLength; i++) { + if (canonicalTarget.charAt(i) == canonicalBase.charAt(i)) { + if (canonicalTarget.charAt(i) == separator) { lastSeparator = i; } - } - else - { + } else { firstDifference = lastSeparator + 1; break; } } - StringBuilder relativePath = new StringBuilder( 50 ); + StringBuilder relativePath = new StringBuilder(50); // // walk from the first difference to the end of the base // adding "../" for each separator encountered // - if ( canonicalBase.length() > firstDifference ) - { - relativePath.append( ".." ); - for ( int i = firstDifference; i < canonicalBase.length(); i++ ) - { - if ( canonicalBase.charAt( i ) == separator ) - { - relativePath.append( separator ); - relativePath.append( ".." ); + if (canonicalBase.length() > firstDifference) { + relativePath.append(".."); + for (int i = firstDifference; i < canonicalBase.length(); i++) { + if (canonicalBase.charAt(i) == separator) { + relativePath.append(separator); + relativePath.append(".."); } } } - if ( canonicalTarget.length() > firstDifference ) - { + if (canonicalTarget.length() > firstDifference) { // // append the rest of the target // - if ( relativePath.length() > 0 ) - { - relativePath.append( separator ); + if (relativePath.length() > 0) { + relativePath.append(separator); } - relativePath.append( canonicalTarget.substring( firstDifference ) ); + relativePath.append(canonicalTarget.substring(firstDifference)); } - return new File( relativePath.toString() ); + return new File(relativePath.toString()); - } - catch ( IOException ex ) - { + } catch (IOException ex) { // TODO more handling } return targetFile; - } - public static File[] breakPaths( String paths ) - { - String[] tokens = StringUtils.split( paths, "," ); + public static File[] breakPaths(String paths) { + String[] tokens = StringUtils.split(paths, ","); File[] files = new File[tokens.length]; - for ( int i = 0; i < tokens.length; ++i ) - { - files[i] = new File( tokens[i] ); + for (int i = 0; i < tokens.length; ++i) { + files[i] = new File(tokens[i]); } return files; @@ -190,14 +155,11 @@ public static File[] breakPaths( String paths ) * @param baseDirectory String * @return relative path to a base directory if possible */ - public static String truncatePath( String path, String baseDirectory ) - { - if ( path.contains( baseDirectory ) ) - { - path = path.substring( path.indexOf( baseDirectory ) + baseDirectory.length() ); - if ( path.startsWith( File.separator ) ) - { - path = path.substring( File.separator.length() ); + public static String truncatePath(String path, String baseDirectory) { + if (path.contains(baseDirectory)) { + path = path.substring(path.indexOf(baseDirectory) + baseDirectory.length()); + if (path.startsWith(File.separator)) { + path = path.substring(File.separator.length()); } } return path; diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/AbstractDependencyTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/AbstractDependencyTest.java index fd5b273c..9e2a65c8 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/AbstractDependencyTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/AbstractDependencyTest.java @@ -23,56 +23,40 @@ */ package org.codehaus.mojo.natives; -import junit.framework.TestCase; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import org.codehaus.plexus.util.IOUtil; +import junit.framework.TestCase; import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; -public abstract class AbstractDependencyTest - extends TestCase -{ +public abstract class AbstractDependencyTest extends TestCase { - public AbstractDependencyTest( String name ) - { - super( name ); + public AbstractDependencyTest(String name) { + super(name); } - protected void mkDir( String dirPath ) - throws IOException - { - FileUtils.forceMkdir( new File( dirPath ) ); + protected void mkDir(String dirPath) throws IOException { + FileUtils.forceMkdir(new File(dirPath)); } - protected void rmDir( String dirPath ) - throws IOException - { - FileUtils.deleteDirectory( dirPath ); + protected void rmDir(String dirPath) throws IOException { + FileUtils.deleteDirectory(dirPath); } - protected void writeFile( String filePath, String content ) - throws IOException - { - FileOutputStream fs = new FileOutputStream( filePath ); - try - { - IOUtil.copy( content, fs ); - } - finally - { - if ( fs != null ) - { - IOUtil.close( fs ); + protected void writeFile(String filePath, String content) throws IOException { + FileOutputStream fs = new FileOutputStream(filePath); + try { + IOUtil.copy(content, fs); + } finally { + if (fs != null) { + IOUtil.close(fs); } } } - protected void removeFile( String filePath ) - { - new File( filePath ).delete(); + protected void removeFile(String filePath) { + new File(filePath).delete(); } - } diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/DependencyTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/DependencyTest.java index 712fc518..fe7058b9 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/DependencyTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/DependencyTest.java @@ -26,119 +26,105 @@ import java.io.File; import java.io.IOException; -import org.codehaus.mojo.natives.Dependency; import org.codehaus.mojo.natives.parser.CParser; import org.codehaus.mojo.natives.parser.Parser; -public class DependencyTest - extends AbstractDependencyTest -{ +public class DependencyTest extends AbstractDependencyTest { - public DependencyTest( String name ) - { - super( name ); + public DependencyTest(String name) { + super(name); } /** * Source has includes, but include path is not given **/ - public void testNoneParticipateDepedencyAnalysisInclude() - throws IOException - { + public void testNoneParticipateDepedencyAnalysisInclude() throws IOException { String testSrcDir = "target/test/testNoneParticipateDepedencyAnalysisInclude/c/"; String testSource = testSrcDir + "test1.c"; - this.rmDir( testSrcDir ); - this.mkDir( testSrcDir ); + this.rmDir(testSrcDir); + this.mkDir(testSrcDir); - this.writeFile( testSource, "#include \"test1.h\"\n \"test2.h\"\n" ); + this.writeFile(testSource, "#include \"test1.h\"\n \"test2.h\"\n"); File[] includePaths = new File[0]; - File srcFile = new File( testSource ); + File srcFile = new File(testSource); Parser parser = new CParser(); - Dependency dependency = new Dependency( srcFile, parser, includePaths ); + Dependency dependency = new Dependency(srcFile, parser, includePaths); dependency.analyze(); - assertEquals( 0, dependency.getDependencies().size() ); - + assertEquals(0, dependency.getDependencies().size()); } - public void testCyclicOnTheSameSource() - throws IOException - { + public void testCyclicOnTheSameSource() throws IOException { String testIncDir = "target/test/testCyclicOnTheSameSource/h/"; String testSource = testIncDir + "test1.h"; - this.rmDir( testIncDir ); - this.mkDir( testIncDir ); + this.rmDir(testIncDir); + this.mkDir(testIncDir); - this.writeFile( testSource, "#include \"test1.h\"" ); + this.writeFile(testSource, "#include \"test1.h\""); File[] includePaths = new File[0]; - File srcFile = new File( testSource ); + File srcFile = new File(testSource); Parser parser = new CParser(); - Dependency dependency = new Dependency( srcFile, parser, includePaths ); + Dependency dependency = new Dependency(srcFile, parser, includePaths); dependency.analyze(); - assertEquals( 0, dependency.getDependencies().size() ); - + assertEquals(0, dependency.getDependencies().size()); } /* * Makesure depedencies tree does not contain duplicate node */ - public void testCyclicDependencyAnalysis() - throws IOException, InterruptedException - { + public void testCyclicDependencyAnalysis() throws IOException, InterruptedException { String testSrcDir = "target/test/testCyclicDependencyAnalysis/c/"; String testIncDir = "target/test/testCyclicDependencyAnalysis/h/"; - this.rmDir( testSrcDir ); - this.rmDir( testIncDir ); + this.rmDir(testSrcDir); + this.rmDir(testIncDir); - this.mkDir( testSrcDir ); - this.mkDir( testIncDir ); + this.mkDir(testSrcDir); + this.mkDir(testIncDir); - this.writeFile( testSrcDir + "test1.h", "#include \"test2.h\"" ); + this.writeFile(testSrcDir + "test1.h", "#include \"test2.h\""); - Thread.sleep( 100 ); + Thread.sleep(100); // force a cyclic condiction - this.writeFile( testIncDir + "test2.h", "#include \"test1.h\"" ); + this.writeFile(testIncDir + "test2.h", "#include \"test1.h\""); - this.writeFile( testIncDir + "test3.h", "#include \"test1.h\"" ); + this.writeFile(testIncDir + "test3.h", "#include \"test1.h\""); - Thread.sleep( 100 ); + Thread.sleep(100); - this.writeFile( testSrcDir + "test1.c", "#include \"test1.h\"\n#include \"test3.h\"" ); + this.writeFile(testSrcDir + "test1.c", "#include \"test1.h\"\n#include \"test3.h\""); - File srcFile = new File( testSrcDir + "test1.c" ); + File srcFile = new File(testSrcDir + "test1.c"); File[] includePaths = new File[2]; - includePaths[0] = new File( testSrcDir ); - includePaths[1] = new File( testIncDir ); + includePaths[0] = new File(testSrcDir); + includePaths[1] = new File(testIncDir); Parser parser = new CParser(); - Dependency dependency = new Dependency( srcFile, parser, includePaths ); + Dependency dependency = new Dependency(srcFile, parser, includePaths); dependency.analyze(); - assertEquals( 2, dependency.getDependencies().size() ); + assertEquals(2, dependency.getDependencies().size()); - assertEquals( 3, dependency.getDeepDependencyCount() ); - - assertEquals( srcFile.lastModified(), dependency.getCompositeLastModified() ); + assertEquals(3, dependency.getDeepDependencyCount()); + assertEquals(srcFile.lastModified(), dependency.getCompositeLastModified()); } - } diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/NativeSourcesTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/NativeSourcesTest.java index 54b5e4fb..7d22f9b6 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/NativeSourcesTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/NativeSourcesTest.java @@ -2,185 +2,165 @@ import java.io.File; import java.util.List; + import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; -public class NativeSourcesTest - extends PlexusTestCase -{ +public class NativeSourcesTest extends PlexusTestCase { File workDirectory; @Override - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - workDirectory = new File( getBasedir(), "/target/NativeSourceTest" ); - if ( workDirectory.exists() ) - { - FileUtils.deleteDirectory( workDirectory ); + workDirectory = new File(getBasedir(), "/target/NativeSourceTest"); + if (workDirectory.exists()) { + FileUtils.deleteDirectory(workDirectory); } workDirectory.mkdirs(); } - public void testFileNamesOnly() - { + public void testFileNamesOnly() { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); - String[] fileNames = { "file1.c", "file2.c" }; - source.setFileNames( fileNames ); + source.setDirectory(this.workDirectory); + String[] fileNames = {"file1.c", "file2.c"}; + source.setFileNames(fileNames); List files = source.getFiles(); - assertEquals( 2, files.size() ); + assertEquals(2, files.size()); } - public void testEmptyIncludes() - { + public void testEmptyIncludes() { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); - String[] fileNames = { "file1.c", "file2.c" }; - source.setFileNames( fileNames ); + source.setDirectory(this.workDirectory); + String[] fileNames = {"file1.c", "file2.c"}; + source.setFileNames(fileNames); - String[] includes = { "*.c", "*.cpp" }; + String[] includes = {"*.c", "*.cpp"}; - source.setIncludes( includes ); + source.setIncludes(includes); List files = source.getFiles(); - assertEquals( 2, files.size() ); + assertEquals(2, files.size()); } // merge include wild card list with fileNames array - public void testMerge() - throws Exception - { + public void testMerge() throws Exception { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); - String[] fileNames = { "file1.c", "file2.c" }; - source.setFileNames( fileNames ); + source.setDirectory(this.workDirectory); + String[] fileNames = {"file1.c", "file2.c"}; + source.setFileNames(fileNames); - String[] includes = { "*.c", "*.cpp" }; + String[] includes = {"*.c", "*.cpp"}; // this file is unique comparing to above list - File nodupFile = new File( this.workDirectory, "file3.c" ); + File nodupFile = new File(this.workDirectory, "file3.c"); nodupFile.createNewFile(); - source.setIncludes( includes ); + source.setIncludes(includes); List files = source.getFiles(); - assertEquals( 3, files.size() ); + assertEquals(3, files.size()); } - public void testDuplicateFiles() - throws Exception - { + public void testDuplicateFiles() throws Exception { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); - String[] fileNames = { "file1.c", "file2.c" }; - source.setFileNames( fileNames ); + source.setDirectory(this.workDirectory); + String[] fileNames = {"file1.c", "file2.c"}; + source.setFileNames(fileNames); - String[] includes = { "*.c", "*.cpp" }; + String[] includes = {"*.c", "*.cpp"}; - File dupFile = new File( this.workDirectory, "file1.c" ); + File dupFile = new File(this.workDirectory, "file1.c"); dupFile.createNewFile(); - source.setIncludes( includes ); + source.setIncludes(includes); List files = source.getFiles(); - assertEquals( 2, files.size() ); + assertEquals(2, files.size()); } - public void testEmpty() - { + public void testEmpty() { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); - String[] includes = { "*.*" }; - source.setIncludes( includes ); + source.setDirectory(this.workDirectory); + String[] includes = {"*.*"}; + source.setIncludes(includes); List files = source.getFiles(); - assertEquals( 0, files.size() ); + assertEquals(0, files.size()); } - public void testGetAllSourceFiles() - throws Exception - { + public void testGetAllSourceFiles() throws Exception { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); + source.setDirectory(this.workDirectory); - String[] includes = { "*.c", "*.cpp" }; - source.setIncludes( includes ); + String[] includes = {"*.c", "*.cpp"}; + source.setIncludes(includes); - String[] fileNames = { "file1.c", "file2.c" }; - source.setFileNames( fileNames ); + String[] fileNames = {"file1.c", "file2.c"}; + source.setFileNames(fileNames); // this file is unique comparing to above list - File nodupFile = new File( this.workDirectory, "file3.c" ); + File nodupFile = new File(this.workDirectory, "file3.c"); nodupFile.createNewFile(); - NativeSources[] sources = { source, source }; + NativeSources[] sources = {source, source}; - File[] files = NativeSources.getAllSourceFiles( sources ); + File[] files = NativeSources.getAllSourceFiles(sources); - assertEquals( 6, files.length ); + assertEquals(6, files.length); } - public void testEmptyFileNames() - throws Exception - { + public void testEmptyFileNames() throws Exception { NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); + source.setDirectory(this.workDirectory); - String[] includes = { "*.c", "*.cpp" }; - source.setIncludes( includes ); + String[] includes = {"*.c", "*.cpp"}; + source.setIncludes(includes); - File someFile = new File( this.workDirectory, "someFile.c" ); + File someFile = new File(this.workDirectory, "someFile.c"); someFile.createNewFile(); List files = source.getFiles(); - assertEquals( 1, files.size() ); - + assertEquals(1, files.size()); } - public void testExcludes() - throws Exception - { + public void testExcludes() throws Exception { - new File( this.workDirectory, "someFile.c" ).createNewFile(); - new File( this.workDirectory, "someFile.cpp" ).createNewFile(); + new File(this.workDirectory, "someFile.c").createNewFile(); + new File(this.workDirectory, "someFile.cpp").createNewFile(); NativeSources source = new NativeSources(); - source.setDirectory( this.workDirectory ); + source.setDirectory(this.workDirectory); - String[] includes = { "*.*" }; - source.setIncludes( includes ); - assertEquals( 2, source.getFiles().size() ); + String[] includes = {"*.*"}; + source.setIncludes(includes); + assertEquals(2, source.getFiles().size()); - String[] excludes = { "*.cpp" }; - source.setExcludes( excludes ); - assertEquals( 1, source.getFiles().size() ); + String[] excludes = {"*.cpp"}; + source.setExcludes(excludes); + assertEquals(1, source.getFiles().size()); - String[] excludes2 = { "*.c" }; - source.setExcludes( excludes2 ); - assertEquals( 1, source.getFiles().size() ); + String[] excludes2 = {"*.c"}; + source.setExcludes(excludes2); + assertEquals(1, source.getFiles().size()); - String[] excludes3 = { "someFile.c" }; - source.setExcludes( excludes3 ); - assertEquals( 1, source.getFiles().size() ); - - String[] excludes4 = { "someFile.c", "someFile.cpp" }; - source.setExcludes( excludes4 ); - assertEquals( 0, source.getFiles().size() ); + String[] excludes3 = {"someFile.c"}; + source.setExcludes(excludes3); + assertEquals(1, source.getFiles().size()); + String[] excludes4 = {"someFile.c", "someFile.cpp"}; + source.setExcludes(excludes4); + assertEquals(0, source.getFiles().size()); } - } diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/compiler/CompilerUtilTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/compiler/CompilerUtilTest.java index 3ee01e7b..147001b7 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/compiler/CompilerUtilTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/compiler/CompilerUtilTest.java @@ -5,40 +5,32 @@ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.Os; -public class CompilerUtilTest - extends PlexusTestCase -{ +public class CompilerUtilTest extends PlexusTestCase { - public void testGetObjectFileFromSourceWithNoExtension() - { + public void testGetObjectFileFromSourceWithNoExtension() { File source; - if ( Os.isFamily( "windows" ) ) - { - source = new File( "..\\dir1\\dir2\\fileWithoutExtenstion" ); - } - else - { - source = new File( "../dir1/dir2/fileWithoutExtenstion" ); + if (Os.isFamily("windows")) { + source = new File("..\\dir1\\dir2\\fileWithoutExtenstion"); + } else { + source = new File("../dir1/dir2/fileWithoutExtenstion"); } - File outputDirectory = new File( "outputDirectory" ); - File objectFile = AbstractCompiler.getObjectFile( source, outputDirectory, null ); + File outputDirectory = new File("outputDirectory"); + File objectFile = AbstractCompiler.getObjectFile(source, outputDirectory, null); assertEquals( - new File( outputDirectory, "fileWithoutExtenstion." + AbstractCompiler.getObjectFileExtension( null ) ), - objectFile ); + new File(outputDirectory, "fileWithoutExtenstion." + AbstractCompiler.getObjectFileExtension(null)), + objectFile); } - public void testGetObjectFileWithKnownExtension() - { + public void testGetObjectFileWithKnownExtension() { - File source = new File( "target/somefile.c" ); + File source = new File("target/somefile.c"); - File outputDirectory = new File( "outputDirectory" ); - File objectFile = AbstractCompiler.getObjectFile( source, outputDirectory, "someext" ); + File outputDirectory = new File("outputDirectory"); + File objectFile = AbstractCompiler.getObjectFile(source, outputDirectory, "someext"); - assertEquals( new File( outputDirectory, "somefile." + "someext" ), objectFile ); + assertEquals(new File(outputDirectory, "somefile." + "someext"), objectFile); } - } diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/AbstractParserTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/AbstractParserTest.java index 2d1b602c..23040dc0 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/AbstractParserTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/AbstractParserTest.java @@ -21,11 +21,8 @@ /** * Tests for the CParser class */ -public abstract class AbstractParserTest - extends TestCase -{ - public AbstractParserTest( String name ) - { - super( name ); +public abstract class AbstractParserTest extends TestCase { + public AbstractParserTest(String name) { + super(name); } } diff --git a/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/CParserTest.java b/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/CParserTest.java index 18ec7ca1..5186b3fa 100644 --- a/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/CParserTest.java +++ b/maven-native-api/src/test/java/org/codehaus/mojo/natives/parser/CParserTest.java @@ -19,22 +19,17 @@ import java.io.CharArrayReader; import java.io.IOException; -import org.codehaus.mojo.natives.parser.CParser; - /** * Tests for the CParser class. */ -public final class CParserTest - extends AbstractParserTest -{ +public final class CParserTest extends AbstractParserTest { /** * Constructor. * * @param name String test name */ - public CParserTest( final String name ) - { - super( name ); + public CParserTest(final String name) { + super(name); } /** @@ -42,15 +37,13 @@ public CParserTest( final String name ) * * @throws IOException test fails on IOException */ - public void testImmediateImportBracket() - throws IOException - { - CharArrayReader reader = new CharArrayReader( "#import nowhatever ".toCharArray() ); + public void testImmediateImportBracket() throws IOException { + CharArrayReader reader = new CharArrayReader("#import nowhatever ".toCharArray()); CParser parser = new CParser(); - parser.parse( reader ); + parser.parse(reader); String[] includes = parser.getIncludes(); - assertEquals( includes.length, 1 ); - assertEquals( "foo.h", includes[0] ); + assertEquals(includes.length, 1); + assertEquals("foo.h", includes[0]); } /** @@ -58,15 +51,13 @@ public void testImmediateImportBracket() * * @throws IOException test fails on IOException */ - public void testImmediateImportQuote() - throws IOException - { - CharArrayReader reader = new CharArrayReader( "#import \"foo.h\" ".toCharArray() ); + public void testImmediateImportQuote() throws IOException { + CharArrayReader reader = new CharArrayReader("#import \"foo.h\" ".toCharArray()); CParser parser = new CParser(); - parser.parse( reader ); + parser.parse(reader); String[] includes = parser.getIncludes(); - assertEquals( includes.length, 1 ); - assertEquals( "foo.h", includes[0] ); + assertEquals(includes.length, 1); + assertEquals("foo.h", includes[0]); } /** @@ -74,15 +65,13 @@ public void testImmediateImportQuote() * * @throws IOException test fails on IOException */ - public void testImmediateIncludeBracket() - throws IOException - { - CharArrayReader reader = new CharArrayReader( "#include ".toCharArray() ); + public void testImmediateIncludeBracket() throws IOException { + CharArrayReader reader = new CharArrayReader("#include ".toCharArray()); CParser parser = new CParser(); - parser.parse( reader ); + parser.parse(reader); String[] includes = parser.getIncludes(); - assertEquals( includes.length, 1 ); - assertEquals( "foo.h", includes[0] ); + assertEquals(includes.length, 1); + assertEquals("foo.h", includes[0]); } /** @@ -90,15 +79,13 @@ public void testImmediateIncludeBracket() * * @throws IOException test fails on IOException. */ - public void testImmediateIncludeQuote() - throws IOException - { - CharArrayReader reader = new CharArrayReader( "#include \"foo.h\" ".toCharArray() ); + public void testImmediateIncludeQuote() throws IOException { + CharArrayReader reader = new CharArrayReader("#include \"foo.h\" ".toCharArray()); CParser parser = new CParser(); - parser.parse( reader ); + parser.parse(reader); String[] includes = parser.getIncludes(); - assertEquals( includes.length, 1 ); - assertEquals( "foo.h", includes[0] ); + assertEquals(includes.length, 1); + assertEquals("foo.h", includes[0]); } /** @@ -106,14 +93,12 @@ public void testImmediateIncludeQuote() * * @throws IOException test fails on IOException */ - public void testIncompleteImmediateImportBracket() - throws IOException - { - CharArrayReader reader = new CharArrayReader( "#import envs; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs == null) { envs = createEnvs(); } return envs; } - private Map createEnvs() - throws NativeBuildException - { - File bccDir = new File( EnvUtil.getEnv( BCC_INSTALL_ENV_KEY, BCC_INSTALL_ENV_KEY, DEFAULT_BCC_INSTALL_DIR ) ); + private Map createEnvs() throws NativeBuildException { + File bccDir = new File(EnvUtil.getEnv(BCC_INSTALL_ENV_KEY, BCC_INSTALL_ENV_KEY, DEFAULT_BCC_INSTALL_DIR)); - if ( !bccDir.isDirectory() ) - { - throw new NativeBuildException( bccDir.getPath() + " is not a directory." ); + if (!bccDir.isDirectory()) { + throw new NativeBuildException(bccDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = bccDir.getPath() + "\\BIN;" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); return envs; - } - } diff --git a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCLinker.java b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCLinker.java index cb8a7ce6..486c09fc 100644 --- a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCLinker.java +++ b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCLinker.java @@ -25,6 +25,7 @@ import java.io.File; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.c.CLinker; import org.codehaus.mojo.natives.linker.Linker; @@ -34,19 +35,16 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = Linker.class, hint = "bcc", instantiationStrategy = "per-lookup") -public class BCCLinker - extends CLinker -{ +public class BCCLinker extends CLinker { public static final String DEFAULT_EXECUTABLE = "ilink32"; @Override - protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) - throws NativeBuildException - { + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException { Commandline cl = new Commandline(); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); String executable = DEFAULT_EXECUTABLE; @@ -54,44 +52,38 @@ protected Commandline createLinkerCommandLine( List objectFiles, LinkerCon * Turbo Incremental Link 5.68 Copyright (c) 1997-2005 Borland Syntax: ILINK32 options objfiles, exefile, * mapfile, libfiles, deffile, resfiles */ - if ( config.getExecutable() != null && config.getExecutable().trim().length() != 0 ) - { + if (config.getExecutable() != null && config.getExecutable().trim().length() != 0) { executable = config.getExecutable(); } - cl.createArg().setValue( executable ); + cl.createArg().setValue(executable); - cl.addArguments( config.getStartOptions() ); + cl.addArguments(config.getStartOptions()); // objfiles - for ( File objFile : objectFiles ) - { - cl.createArg().setValue( objFile.getPath() ); + for (File objFile : objectFiles) { + cl.createArg().setValue(objFile.getPath()); } - for ( String fileName : config.getExternalLibFileNames() ) - { - if ( !FileUtils.getExtension( fileName ).equalsIgnoreCase( "res" ) ) - { - cl.createArg().setFile( new File( config.getExternalLibDirectory(), fileName ) ); + for (String fileName : config.getExternalLibFileNames()) { + if (!FileUtils.getExtension(fileName).equalsIgnoreCase("res")) { + cl.createArg().setFile(new File(config.getExternalLibDirectory(), fileName)); } } // ouput file - cl.createArg().setValue( "," + config.getOutputFile() ); + cl.createArg().setValue("," + config.getOutputFile()); // map files + system lib, and def file to be given by user in middle options // a comma is required between map, lib, and def - cl.createArg().setValue( "," ); - cl.addArguments( config.getMiddleOptions() ); + cl.createArg().setValue(","); + cl.addArguments(config.getMiddleOptions()); // res file - cl.createArg().setValue( "," ); - for ( String fileName : config.getExternalLibFileNames() ) - { - if ( FileUtils.getExtension( fileName ).equalsIgnoreCase( "res" ) ) - { - cl.createArg().setFile( new File( config.getExternalLibDirectory(), fileName ) ); + cl.createArg().setValue(","); + for (String fileName : config.getExternalLibFileNames()) { + if (FileUtils.getExtension(fileName).equalsIgnoreCase("res")) { + cl.createArg().setFile(new File(config.getExternalLibDirectory(), fileName)); } } diff --git a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCResourceCompiler.java b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCResourceCompiler.java index 715de1f3..0b3f15f1 100644 --- a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCResourceCompiler.java +++ b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/BCCResourceCompiler.java @@ -34,56 +34,48 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = ResourceCompiler.class, hint = "bcc") -public class BCCResourceCompiler - extends AbstractResourceCompiler -{ +public class BCCResourceCompiler extends AbstractResourceCompiler { - protected Commandline getCommandLine( ResourceCompilerConfiguration config, File source ) - throws NativeBuildException - { + protected Commandline getCommandLine(ResourceCompilerConfiguration config, File source) + throws NativeBuildException { Commandline cl = new Commandline(); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "brcc32.exe" ); + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("brcc32.exe"); } - cl.setExecutable( config.getExecutable().trim() ); + cl.setExecutable(config.getExecutable().trim()); - cl.addArguments( config.getOptions() ); + cl.addArguments(config.getOptions()); - for ( int i = 0; i < config.getIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getIncludePaths().length; ++i) { String includePath = config.getIncludePaths()[i].getPath(); - cl.createArg().setValue( "-i" ); + cl.createArg().setValue("-i"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - for ( int i = 0; i < config.getSystemIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getSystemIncludePaths().length; ++i) { String includePath = config.getSystemIncludePaths()[i].getPath(); - cl.createArg().setValue( "-i" ); + cl.createArg().setValue("-i"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - cl.createArg().setValue( "-fo" ); + cl.createArg().setValue("-fo"); - cl.createArg().setValue( config.getOutputFile( source ).getPath() ); + cl.createArg().setValue(config.getOutputFile(source).getPath()); - cl.createArg().setValue( source.getPath() ); + cl.createArg().setValue(source.getPath()); return cl; } - } diff --git a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/TLibLinker.java b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/TLibLinker.java index 3eb1a74c..b6315ba9 100644 --- a/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/TLibLinker.java +++ b/maven-native-components/maven-native-bcc/src/main/java/org/codehaus/mojo/natives/bcc/TLibLinker.java @@ -34,43 +34,35 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = Linker.class, hint = "tlib", instantiationStrategy = "per-lookup") -public class TLibLinker - extends AbstractLinker -{ +public class TLibLinker extends AbstractLinker { public static final String EXECUTABLE = "tlib"; @Override - protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) - throws NativeBuildException - { + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException { Commandline cl = new Commandline(); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); String executable = EXECUTABLE; - if ( config.getExecutable() != null && config.getExecutable().trim().length() != 0 ) - { + if (config.getExecutable() != null && config.getExecutable().trim().length() != 0) { executable = config.getExecutable(); } - cl.createArg().setValue( executable ); + cl.createArg().setValue(executable); - cl.createArg().setValue( "\"" + config.getOutputFile() + "\"" ); + cl.createArg().setValue("\"" + config.getOutputFile() + "\""); - for ( int i = 0; i < config.getStartOptions().length; ++i ) - { - cl.createArg().setValue( config.getStartOptions()[i] ); + for (int i = 0; i < config.getStartOptions().length; ++i) { + cl.createArg().setValue(config.getStartOptions()[i]); } - for ( File objFile : objectFiles ) - { - cl.createArg().setValue( "+\"" + objFile.getPath() + "\"" ); + for (File objFile : objectFiles) { + cl.createArg().setValue("+\"" + objFile.getPath() + "\""); } return cl; - } - } diff --git a/maven-native-components/maven-native-bcc/src/test/java/org/codehaus/mojo/natives/bcc/TLibLinkerTest.java b/maven-native-components/maven-native-bcc/src/test/java/org/codehaus/mojo/natives/bcc/TLibLinkerTest.java index aa9a7262..ad2b9e95 100644 --- a/maven-native-components/maven-native-bcc/src/test/java/org/codehaus/mojo/natives/bcc/TLibLinkerTest.java +++ b/maven-native-components/maven-native-bcc/src/test/java/org/codehaus/mojo/natives/bcc/TLibLinkerTest.java @@ -23,46 +23,47 @@ */ package org.codehaus.mojo.natives.bcc; -import static org.junit.Assert.assertArrayEquals; - import java.io.File; import java.util.ArrayList; import java.util.List; +import junit.framework.TestCase; import org.codehaus.mojo.natives.linker.LinkerConfiguration; import org.codehaus.plexus.util.cli.Commandline; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; -public class TLibLinkerTest - extends TestCase -{ +public class TLibLinkerTest extends TestCase { - public void testCommandLine() - { + public void testCommandLine() { TLibLinker linker = new TLibLinker(); LinkerConfiguration config = new LinkerConfiguration(); - config.setWorkingDirectory( new File( "." ) ); + config.setWorkingDirectory(new File(".")); - String[] options = { "/C" }; - config.setStartOptions( options ); - config.setOutputFileName( "tlib" ); - config.setOutputFileExtension( "lib" ); - config.setOutputDirectory( new File( "target" ) ); + String[] options = {"/C"}; + config.setStartOptions(options); + config.setOutputFileName("tlib"); + config.setOutputFileExtension("lib"); + config.setOutputDirectory(new File("target")); List objectFiles = new ArrayList<>(); - objectFiles.add( new File( "target" + File.separator + "a.obj" ) ); - objectFiles.add( new File( "target" + File.separator + "b.obj" ) ); - objectFiles.add( new File( "target" + File.separator + "c.obj" ) ); - - Commandline cl = linker.createLinkerCommandLine( objectFiles, config ); + objectFiles.add(new File("target" + File.separator + "a.obj")); + objectFiles.add(new File("target" + File.separator + "b.obj")); + objectFiles.add(new File("target" + File.separator + "c.obj")); - assertArrayEquals( new String[] { "tlib", "\"target" + File.separator + "tlib.lib\"", "/C", - "+\"target" + File.separator + "a.obj\"", "+\"target" + File.separator + "b.obj\"", - "+\"target" + File.separator + "c.obj\"" }, cl.getArguments() ); + Commandline cl = linker.createLinkerCommandLine(objectFiles, config); + assertArrayEquals( + new String[] { + "tlib", + "\"target" + File.separator + "tlib.lib\"", + "/C", + "+\"target" + File.separator + "a.obj\"", + "+\"target" + File.separator + "b.obj\"", + "+\"target" + File.separator + "c.obj\"" + }, + cl.getArguments()); } - } diff --git a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/AbstractCCompiler.java b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/AbstractCCompiler.java index 2ac3bd92..9c508fbf 100644 --- a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/AbstractCCompiler.java +++ b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/AbstractCCompiler.java @@ -24,123 +24,102 @@ package org.codehaus.mojo.natives.c; import java.io.File; -import org.codehaus.plexus.util.cli.Commandline; 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.Parser; import org.codehaus.mojo.natives.parser.CParser; +import org.codehaus.mojo.natives.parser.Parser; +import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractCCompiler - extends AbstractCompiler -{ +public abstract class AbstractCCompiler extends AbstractCompiler { /** * resuable parser in one Compilation session */ - private Parser parser = new CParser(); protected abstract String getOutputFileOption(); - protected Parser getParser() - { + protected Parser getParser() { return this.parser; } /** * Setup Compiler Command line */ - protected Commandline getCommandLine( File srcFile, File destFile, CompilerConfiguration config ) - throws NativeBuildException - { + protected Commandline getCommandLine(File srcFile, File destFile, CompilerConfiguration config) + throws NativeBuildException { - if ( config.getExecutable() == null ) - { - config.setExecutable( "gcc" ); + if (config.getExecutable() == null) { + config.setExecutable("gcc"); } Commandline cl = new Commandline(); - cl.setExecutable( config.getExecutable() ); + cl.setExecutable(config.getExecutable()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - this.setStartOptions( cl, config ); + this.setStartOptions(cl, config); - this.setIncludePaths( cl, config.getIncludePaths() ); + this.setIncludePaths(cl, config.getIncludePaths()); - this.setIncludePaths( cl, config.getSystemIncludePaths() ); + this.setIncludePaths(cl, config.getSystemIncludePaths()); - this.setMiddleOptions( cl, config ); + this.setMiddleOptions(cl, config); - this.setOutputArgs( cl, destFile ); + this.setOutputArgs(cl, destFile); - this.setSourceArgs( cl, srcFile ); + this.setSourceArgs(cl, srcFile); - this.setEndOptions( cl, config ); + this.setEndOptions(cl, config); return cl; } - private void setOptions( Commandline cl, String[] options ) - { - if ( options != null ) - { - for ( String option : options ) - { - cl.createArg().setValue( option ); + private void setOptions(Commandline cl, String[] options) { + if (options != null) { + for (String option : options) { + cl.createArg().setValue(option); } } } - private void setStartOptions( Commandline cl, CompilerConfiguration config ) - { - this.setOptions( cl, config.getStartOptions() ); + 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 setMiddleOptions(Commandline cl, CompilerConfiguration config) { + this.setOptions(cl, config.getMiddleOptions()); } - private void setEndOptions( Commandline cl, CompilerConfiguration config ) - { - this.setOptions( cl, config.getEndOptions() ); + private void setEndOptions(Commandline cl, CompilerConfiguration config) { + this.setOptions(cl, config.getEndOptions()); } - private void setIncludePaths( Commandline cl, File[] includePaths ) - { - if ( includePaths != null ) - { - for ( File includePath : includePaths ) - { - cl.createArg().setValue( "-I" + includePath.getPath() ); + private void setIncludePaths(Commandline cl, File[] includePaths) { + if (includePaths != null) { + for (File includePath : includePaths) { + cl.createArg().setValue("-I" + includePath.getPath()); } } } - private void setOutputArgs( Commandline cl, File outputFile ) - { + 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() ); + 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() ); + private void setSourceArgs(Commandline cl, File srcFile) { + cl.createArg().setValue("-c"); + cl.createArg().setValue(srcFile.getPath()); } } diff --git a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompiler.java b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompiler.java index e74f1636..5eb7e37c 100644 --- a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompiler.java +++ b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompiler.java @@ -23,20 +23,16 @@ */ package org.codehaus.mojo.natives.c; -import org.codehaus.plexus.component.annotations.Component; 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 = "generic", instantiationStrategy = "per-lookup") -public class CCompiler - extends AbstractCCompiler -{ +public class CCompiler extends AbstractCCompiler { - protected String getOutputFileOption() - { + protected String getOutputFileOption() { return "-o "; } - } diff --git a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompilerClassic.java b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompilerClassic.java index 6593645e..9e37a12c 100644 --- a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompilerClassic.java +++ b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CCompilerClassic.java @@ -30,13 +30,9 @@ * Generic C/CPP compiler with "-o" as its output option */ @Component(role = Compiler.class, hint = "generic-classic", instantiationStrategy = "per-lookup") -public class CCompilerClassic - extends AbstractCCompiler -{ +public class CCompilerClassic extends AbstractCCompiler { - protected String getOutputFileOption() - { + protected String getOutputFileOption() { return "-o"; } - } diff --git a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinker.java b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinker.java index 62843620..d8681d55 100644 --- a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinker.java +++ b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinker.java @@ -41,97 +41,78 @@ * Generic C/CPP linker with "-o " as its output option */ @Component(role = Linker.class, hint = "generic", instantiationStrategy = "per-lookup") -public class CLinker - extends AbstractLinker -{ +public class CLinker 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( "gcc" ); + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException { + if (config.getExecutable() == null) { + config.setExecutable("gcc"); } Commandline cl = new Commandline(); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); - cl.setExecutable( config.getExecutable() ); + cl.setExecutable(config.getExecutable()); - if ( config.getStartOptions() != null ) - { - cl.addArguments( config.getStartOptions() ); + 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() ); + 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 ( File objFile : objectFiles ) - { - linkerFileWriter.write( objFile.getPath() + "\n" ); + if (config.isUsingLinkerResponseFile()) { + try { + File linkerFile = new File(config.getWorkingDirectory(), "objectsFile"); + FileWriter linkerFileWriter = new FileWriter(linkerFile, false /* Don't append */); + for (File objFile : objectFiles) { + linkerFileWriter.write(objFile.getPath() + "\n"); } linkerFileWriter.close(); - } - catch ( IOException error ) - { - throw new NativeBuildException( "Error creating linker response file", error ); + } catch (IOException error) { + throw new NativeBuildException("Error creating linker response file", error); } - cl.createArg().setValue( "@objectsFile" ); - } - else - { // Normal behavior. + cl.createArg().setValue("@objectsFile"); + } else { // Normal behavior. - for ( File objFile : objectFiles ) - { + for (File objFile : objectFiles) { // we need to shorten the command line since windows has limited command line length - String objFilePath = FileUtil.truncatePath( objFile.getPath(), config.getWorkingDirectory().getPath() ); + String objFilePath = FileUtil.truncatePath( + objFile.getPath(), config.getWorkingDirectory().getPath()); - cl.createArg().setValue( objFilePath ); + cl.createArg().setValue(objFilePath); } } - if ( config.getMiddleOptions() != null ) - { - cl.addArguments( config.getMiddleOptions() ); + if (config.getMiddleOptions() != null) { + cl.addArguments(config.getMiddleOptions()); } - setCommandLineForExternalLibraries( cl, config ); + setCommandLineForExternalLibraries(cl, config); - if ( config.getEndOptions() != null ) - { - cl.addArguments( config.getEndOptions() ); + if (config.getEndOptions() != null) { + cl.addArguments(config.getEndOptions()); } return cl; - } /** * @return output option flag of a generic C linker */ - protected String getLinkerOutputOption() - { + protected String getLinkerOutputOption() { return "-o "; } @@ -142,54 +123,43 @@ protected String getLinkerOutputOption() * @param config LinkerConfiguration * @throws NativeBuildException */ - protected void setCommandLineForExternalLibraries( Commandline cl, LinkerConfiguration config ) - throws NativeBuildException - { - if ( config.getExternalLibFileNames().size() == 0 ) - { + protected void setCommandLineForExternalLibraries(Commandline cl, LinkerConfiguration config) + throws NativeBuildException { + if (config.getExternalLibFileNames().size() == 0) { return; } boolean hasUnixLinkage = false; - for ( String libFileName : config.getExternalLibFileNames() ) - { - String ext = FileUtils.getExtension( libFileName ); + for (String libFileName : config.getExternalLibFileNames()) { + 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 ) ) - { + 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() ); + if (hasUnixLinkage) { + cl.createArg().setValue("-L" + config.getExternalLibDirectory()); } - for ( String libFileName : config.getExternalLibFileNames() ) - { - String ext = FileUtils.getExtension( libFileName ); + for (String libFileName : config.getExternalLibFileNames()) { + String ext = FileUtils.getExtension(libFileName); - if ( "a".equals( ext ) || "so".equals( ext ) || "sl".equals( ext ) ) - { - String libName = FileUtils.removeExtension( 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() ); + if (libFileName.startsWith("lib")) { + libName = libName.substring("lib".length()); } - cl.createArg().setValue( "-l" + libName ); + cl.createArg().setValue("-l" + libName); } } } - } diff --git a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinkerClassic.java b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinkerClassic.java index 5d012aa2..d689fa06 100644 --- a/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinkerClassic.java +++ b/maven-native-components/maven-native-generic-c/src/main/java/org/codehaus/mojo/natives/c/CLinkerClassic.java @@ -30,12 +30,8 @@ * Generic C/CPP linker with "-o" as its output option */ @Component(role = Linker.class, hint = "generic-classic", instantiationStrategy = "per-lookup") -public class CLinkerClassic - extends CLinker -{ - protected String getLinkerOutputOption() - { +public class CLinkerClassic extends CLinker { + protected String getLinkerOutputOption() { return "-o"; } - } 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 97f094b1..0960d825 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 @@ -3,26 +3,23 @@ import java.io.File; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; -import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; +import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import static org.junit.Assert.assertArrayEquals; -public class CCompilerClassicTest - extends PlexusTestCase -{ +public class CCompilerClassicTest extends PlexusTestCase { /** * Simple test, note: -o option has no space * */ - public void testSimpleCompilation() - { + public void testSimpleCompilation() { CompilerConfiguration config = new CompilerConfiguration(); CCompilerClassic compiler = new CCompilerClassic(); - Commandline cl = compiler.getCommandLine( new File( "source.c" ), new File( "object.o" ), config ); - String[] expected = new String[] { "gcc", "-oobject.o", "-c", "source.c" }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + Commandline cl = compiler.getCommandLine(new File("source.c"), new File("object.o"), config); + String[] expected = new String[] {"gcc", "-oobject.o", "-c", "source.c"}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } } 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 9069e576..1168d636 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,126 +1,141 @@ package org.codehaus.mojo.natives.c; import java.io.File; + import org.codehaus.mojo.natives.compiler.CompilerConfiguration; -import static org.codehaus.mojo.natives.test.TestUtils.*; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; -import static org.junit.Assert.*; +import static org.codehaus.mojo.natives.test.TestUtils.*; +import static org.junit.Assert.*; -public class CCompilerTest - extends PlexusTestCase -{ +public class CCompilerTest extends PlexusTestCase { private CCompiler compiler; private CompilerConfiguration config; - private static File sourceFile = new File( "source.c" ); + private static File sourceFile = new File("source.c"); - private static File objectFile = new File( "object.o" ); + private static File objectFile = new File("object.o"); - private static String[] simpleArgv = { "-o", "object.o", "-c", "source.c" }; + private static String[] simpleArgv = {"-o", "object.o", "-c", "source.c"}; - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.compiler = new CCompiler(); this.config = new CompilerConfiguration(); } - public void testSimpleCompilation() - { - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); - - String[] expected = new String[] { "gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testSimpleCompilation() { + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); + String[] expected = new String[] {"gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testNonDefaultExecutable() - { - this.config.setExecutable( "cc" ); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); - String[] expected = new String[] { "cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testNonDefaultExecutable() { + this.config.setExecutable("cc"); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); + String[] expected = new String[] {"cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testStartOptions() - { - String[] startOptions = { "-s1", "-s2" }; - config.setStartOptions( startOptions ); + public void testStartOptions() { + String[] startOptions = {"-s1", "-s2"}; + config.setStartOptions(startOptions); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = + new String[] {"gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testIncludePaths() - { - File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + public void testIncludePaths() { + File[] includePaths = {new File("p1"), new File("p2")}; - config.setIncludePaths( includePaths ); + config.setIncludePaths(includePaths); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = + new String[] {"gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testSystemIncludePaths() - { - File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + public void testSystemIncludePaths() { + File[] includePaths = {new File("p1"), new File("p2")}; - File[] systemIncludePaths = { new File( "sp1" ), new File( "sp2" ) }; + File[] systemIncludePaths = {new File("sp1"), new File("sp2")}; - config.setIncludePaths( includePaths ); + config.setIncludePaths(includePaths); - config.setSystemIncludePaths( systemIncludePaths ); + config.setSystemIncludePaths(systemIncludePaths); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], - simpleArgv[2], simpleArgv[3] } ; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = new String[] { + "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testMiddleOptions() - { - 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 ); - - String[] expected = new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); - + public void testMiddleOptions() { + 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); + + String[] expected = new String[] { + "gcc", + "-s1", + "-s2", + "-Ip1", + "-Ip2", + "-m1", + "-m2", + simpleArgv[0], + simpleArgv[1], + simpleArgv[2], + simpleArgv[3] + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testEndOptions() - { - 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 ); - - String[] expected = new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testEndOptions() { + 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); + + String[] expected = new String[] { + "gcc", + "-s1", + "-s2", + "-Ip1", + "-Ip2", + "-m1", + "-m2", + simpleArgv[0], + simpleArgv[1], + simpleArgv[2], + simpleArgv[3], + "-e1", + "-e2" + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } } diff --git a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CLinkerTest.java b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CLinkerTest.java index 70e7f3b5..7cdc3be2 100644 --- a/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CLinkerTest.java +++ b/maven-native-components/maven-native-generic-c/src/test/java/org/codehaus/mojo/natives/c/CLinkerTest.java @@ -4,150 +4,131 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.linker.LinkerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; -public class CLinkerTest - extends PlexusTestCase -{ +public class CLinkerTest extends PlexusTestCase { private CLinker linker; private LinkerConfiguration config; - private static final File objectFile0 = new File( "source1.o" ); + private static final File objectFile0 = new File("source1.o"); - private static final File objectFile1 = new File( "source2.o" ); + private static final File objectFile1 = new File("source2.o"); private List defautlObjectFiles; private String basedir; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.defautlObjectFiles = new ArrayList<>(); - this.defautlObjectFiles.add( objectFile0 ); - this.defautlObjectFiles.add( objectFile1 ); + this.defautlObjectFiles.add(objectFile0); + this.defautlObjectFiles.add(objectFile1); this.linker = new CLinker(); this.config = new LinkerConfiguration(); this.basedir = getBasedir(); - config.setWorkingDirectory( new File( basedir ) ); - config.setOutputDirectory( new File( basedir, "target" ) ); - config.setOutputFileExtension( "exe" ); - config.setOutputFileName( "test" ); + config.setWorkingDirectory(new File(basedir)); + config.setOutputDirectory(new File(basedir, "target")); + config.setOutputFileExtension("exe"); + config.setOutputFileName("test"); } - public void testDefaultLinkerExecutable() - { + public void testDefaultLinkerExecutable() { Commandline cl = this.getCommandline(); - assertEquals( "gcc", cl.getLiteralExecutable() ); - assertEquals( basedir, cl.getWorkingDirectory().getPath() ); - + assertEquals("gcc", cl.getLiteralExecutable()); + assertEquals(basedir, cl.getWorkingDirectory().getPath()); } - public void testOverrideLinkerExecutable() - { - config.setExecutable( "ld" ); + public void testOverrideLinkerExecutable() { + config.setExecutable("ld"); Commandline cl = this.getCommandline(); - assertEquals( "ld", cl.getLiteralExecutable() ); - + assertEquals("ld", cl.getLiteralExecutable()); } - public void testObjectFileList() - { + public void testObjectFileList() { Commandline cl = this.getCommandline(); - int index = Arrays.asList( cl.getArguments() ).indexOf( "source1.o" ); - assertTrue( index >= 0 ); - assertEquals( "source2.o", cl.getArguments()[index + 1] ); + int index = Arrays.asList(cl.getArguments()).indexOf("source1.o"); + assertTrue(index >= 0); + assertEquals("source2.o", cl.getArguments()[index + 1]); } - public void testLinkerResponseFile() - { - this.config.setUsingLinkerResponseFile( true ); - this.config.setWorkingDirectory( new File( getBasedir(), "target" ) ); + public void testLinkerResponseFile() { + this.config.setUsingLinkerResponseFile(true); + this.config.setWorkingDirectory(new File(getBasedir(), "target")); Commandline cl = this.getCommandline(); - assertTrue( Arrays.asList( cl.getArguments() ).contains( "@objectsFile" ) ); + assertTrue(Arrays.asList(cl.getArguments()).contains("@objectsFile")); } - public void testRelativeObjectFileList() - { - ArrayList objectFiles = new ArrayList<>( 2 ); - objectFiles.add( new File( config.getOutputDirectory(), "file1.o" ) ); - objectFiles.add( new File( config.getOutputDirectory(), "file2.o" ) ); + public void testRelativeObjectFileList() { + 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] ); + 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() - { - String[] options = { "-o1", "-o2", "-o3" }; - config.setStartOptions( options ); + public void testOptions() { + 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] ); - + 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() - { - config.setExternalLibDirectory( new File( "theLib" ) ); + public void testExternalUnixLibraries() { + config.setExternalLibDirectory(new File("theLib")); List externalLibFileNames = new ArrayList<>(); - externalLibFileNames.add( "file0.lib" ); + externalLibFileNames.add("file0.lib"); - externalLibFileNames.add( "file0.o" ); + externalLibFileNames.add("file0.o"); - externalLibFileNames.add( "file1.obj" ); + externalLibFileNames.add("file1.obj"); - externalLibFileNames.add( "file1.so" ); + externalLibFileNames.add("file1.so"); - externalLibFileNames.add( "libfile2.so" ); + externalLibFileNames.add("libfile2.so"); - externalLibFileNames.add( "libfile3.a" ); + externalLibFileNames.add("libfile3.a"); - config.setExternalLibFileNames( externalLibFileNames ); + config.setExternalLibFileNames(externalLibFileNames); - Commandline cl = this.getCommandline( new ArrayList<>( 0 ) ); + 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] ); + 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() throws NativeBuildException { + return this.linker.createLinkerCommandLine(defautlObjectFiles, config); } - private Commandline getCommandline( List objectFiles ) - throws NativeBuildException - { - return this.linker.createLinkerCommandLine( objectFiles, config ); + private Commandline getCommandline(List objectFiles) throws NativeBuildException { + return this.linker.createLinkerCommandLine(objectFiles, config); } - } diff --git a/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahExecutable.java b/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahExecutable.java index bb25630d..0d683358 100644 --- a/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahExecutable.java +++ b/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahExecutable.java @@ -20,57 +20,43 @@ */ package org.codehaus.mojo.natives.javah; +import java.io.File; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.CommandLineUtil; import org.codehaus.plexus.util.cli.Commandline; -import java.io.File; - /** * Sun's javah compatible implementation */ +public class JavahExecutable extends AbstractJavah { + public JavahExecutable() {} -public class JavahExecutable - extends AbstractJavah -{ - public JavahExecutable() - { - } - - public void compile( JavahConfiguration config ) - throws NativeBuildException - { - Commandline cl = this.createJavahCommand( config ); + public void compile(JavahConfiguration config) throws NativeBuildException { + Commandline cl = this.createJavahCommand(config); - CommandLineUtil.execute( cl, this.getLogger() ); + CommandLineUtil.execute(cl, this.getLogger()); } - protected Commandline createJavahCommand( JavahConfiguration config ) - throws NativeBuildException - { - this.validateConfiguration( config ); + protected Commandline createJavahCommand(JavahConfiguration config) throws NativeBuildException { + this.validateConfiguration(config); Commandline cl = new Commandline(); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - cl.setExecutable( this.getJavaHExecutable( config ) ); + cl.setExecutable(this.getJavaHExecutable(config)); - if ( config.getFileName() != null && config.getFileName().length() > 0 ) - { - File outputFile = new File( config.getOutputDirectory(), config.getFileName() ); - cl.createArg().setValue( "-o" ); - cl.createArg().setFile( outputFile ); - } - else - { - if ( config.getOutputDirectory() != null ) - { - cl.createArg().setValue( "-d" ); - cl.createArg().setFile( config.getOutputDirectory() ); + if (config.getFileName() != null && config.getFileName().length() > 0) { + File outputFile = new File(config.getOutputDirectory(), config.getFileName()); + cl.createArg().setValue("-o"); + cl.createArg().setFile(outputFile); + } else { + if (config.getOutputDirectory() != null) { + cl.createArg().setValue("-d"); + cl.createArg().setFile(config.getOutputDirectory()); } } @@ -78,74 +64,58 @@ protected Commandline createJavahCommand( JavahConfiguration config ) StringBuilder classPathBuffer = new StringBuilder(); - for ( int i = 0; i < classPaths.length; ++i ) - { - classPathBuffer.append( classPaths[i] ); - if ( i != classPaths.length - 1 ) - { - classPathBuffer.append( File.pathSeparatorChar ); + for (int i = 0; i < classPaths.length; ++i) { + classPathBuffer.append(classPaths[i]); + if (i != classPaths.length - 1) { + classPathBuffer.append(File.pathSeparatorChar); } } - if ( config.getUseEnvClasspath() ) - { - cl.addEnvironment( "CLASSPATH", classPathBuffer.toString() ); - } - else - { - cl.createArg().setValue( "-classpath" ); + if (config.getUseEnvClasspath()) { + cl.addEnvironment("CLASSPATH", classPathBuffer.toString()); + } else { + cl.createArg().setValue("-classpath"); - cl.createArg().setValue( classPathBuffer.toString() ); + cl.createArg().setValue(classPathBuffer.toString()); } - if ( config.getVerbose() ) - { - cl.createArg().setValue( "-verbose" ); + if (config.getVerbose()) { + cl.createArg().setValue("-verbose"); } - cl.addArguments( config.getClassNames() ); + cl.addArguments(config.getClassNames()); return cl; } - private void validateConfiguration( JavahConfiguration config ) - throws NativeBuildException - { - if ( config.getClassPaths() == null || config.getClassPaths().length == 0 ) - { - throw new NativeBuildException( "javah classpaths can not be empty." ); + private void validateConfiguration(JavahConfiguration config) throws NativeBuildException { + if (config.getClassPaths() == null || config.getClassPaths().length == 0) { + throw new NativeBuildException("javah classpaths can not be empty."); } - if ( config.getOutputDirectory() == null ) - { - throw new NativeBuildException( "javah destDir can not be empty." ); + if (config.getOutputDirectory() == null) { + throw new NativeBuildException("javah destDir can not be empty."); } - if ( !config.getOutputDirectory().exists() ) - { + if (!config.getOutputDirectory().exists()) { config.getOutputDirectory().mkdirs(); } - if ( config.getClassNames() == null || config.getClassNames().length == 0 ) - { - throw new NativeBuildException( "javah: java classes can not be empty." ); + if (config.getClassNames() == null || config.getClassNames().length == 0) { + throw new NativeBuildException("javah: java classes can not be empty."); } - } /** * @return */ - protected String getJavaHExecutable( JavahConfiguration config ) - { + protected String getJavaHExecutable(JavahConfiguration config) { String path = "javah"; - if ( config.getJavahPath() != null ) - { + if (config.getJavahPath() != null) { path = config.getJavahPath().getAbsolutePath(); } return path; } - } diff --git a/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahMacOSExecutable.java b/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahMacOSExecutable.java index a96ef1b8..6cd79326 100644 --- a/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahMacOSExecutable.java +++ b/maven-native-components/maven-native-javah/src/main/java/org/codehaus/mojo/natives/javah/JavahMacOSExecutable.java @@ -5,12 +5,8 @@ /** * @deprecated use the JavahExecutable instead since its invokes javah on system path */ -public class JavahMacOSExecutable - extends JavahExecutable -{ - protected String getJavaHExecutable() - { - return new File( System.getProperty( "java.home" ), "bin/javah" ).getAbsolutePath(); +public class JavahMacOSExecutable extends JavahExecutable { + protected String getJavaHExecutable() { + return new File(System.getProperty("java.home"), "bin/javah").getAbsolutePath(); } - } diff --git a/maven-native-components/maven-native-javah/src/test/java/org/codehaus/mojo/natives/javah/JavahExecutableTest.java b/maven-native-components/maven-native-javah/src/test/java/org/codehaus/mojo/natives/javah/JavahExecutableTest.java index b0d5f622..0dc2a94c 100644 --- a/maven-native-components/maven-native-javah/src/test/java/org/codehaus/mojo/natives/javah/JavahExecutableTest.java +++ b/maven-native-components/maven-native-javah/src/test/java/org/codehaus/mojo/natives/javah/JavahExecutableTest.java @@ -4,77 +4,93 @@ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; + import static org.junit.Assert.*; -public class JavahExecutableTest - extends PlexusTestCase -{ +public class JavahExecutableTest extends PlexusTestCase { private JavahConfiguration config; - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.config = new JavahConfiguration(); - String[] classPaths = { "path1", "path2" }; - config.setClassPaths( classPaths ); - - String[] classNames = { "className1", "className2" }; - config.setClassNames( classNames ); + String[] classPaths = {"path1", "path2"}; + config.setClassPaths(classPaths); - config.setOutputDirectory( new File( getBasedir(), "target/native" ) ); + String[] classNames = {"className1", "className2"}; + config.setClassNames(classNames); + config.setOutputDirectory(new File(getBasedir(), "target/native")); } - public void testDefaultJavahExecutable() - { + public void testDefaultJavahExecutable() { JavahExecutable javah = new JavahExecutable(); - Commandline cl = javah.createJavahCommand( config ); - - File outputDir = new File( getBasedir(), "target/native" ); - - assertEquals( "javah", cl.getLiteralExecutable() ); - assertArrayEquals( new String[] { "-d", outputDir.getAbsolutePath(), "-classpath", - "path1" + File.pathSeparator + "path2", "className1", "className2" }, cl.getArguments() ); + Commandline cl = javah.createJavahCommand(config); + + File outputDir = new File(getBasedir(), "target/native"); + + assertEquals("javah", cl.getLiteralExecutable()); + assertArrayEquals( + new String[] { + "-d", + outputDir.getAbsolutePath(), + "-classpath", + "path1" + File.pathSeparator + "path2", + "className1", + "className2" + }, + cl.getArguments()); } - public void testConfiguredJavahExecutable() - { - File javaBin = new File( "/java/home/bin" ); + public void testConfiguredJavahExecutable() { + File javaBin = new File("/java/home/bin"); JavahExecutable javah = new JavahExecutable(); - config.setJavahPath( javaBin ); - Commandline cl = javah.createJavahCommand( config ); - - File outputDir = new File( getBasedir(), "target/native" ); - - assertEquals( javaBin.getAbsolutePath(), cl.getLiteralExecutable() ); - assertArrayEquals( new String[] { "-d", outputDir.getAbsolutePath(), "-classpath", - "path1" + File.pathSeparator + "path2", "className1", "className2" }, cl.getArguments() ); + config.setJavahPath(javaBin); + Commandline cl = javah.createJavahCommand(config); + + File outputDir = new File(getBasedir(), "target/native"); + + assertEquals(javaBin.getAbsolutePath(), cl.getLiteralExecutable()); + assertArrayEquals( + new String[] { + "-d", + outputDir.getAbsolutePath(), + "-classpath", + "path1" + File.pathSeparator + "path2", + "className1", + "className2" + }, + cl.getArguments()); } - public void testJavahExecutableDashoOption() - { - config.setFileName( "fileName" ); + public void testJavahExecutableDashoOption() { + config.setFileName("fileName"); JavahExecutable javah = new JavahExecutable(); - Commandline cl = javah.createJavahCommand( config ); - - File outputFile = new File( getBasedir(), "target/native/" + "fileName" ); - assertArrayEquals( new String[] { "-o", outputFile.getAbsolutePath(), "-classpath", - "path1" + File.pathSeparator + "path2", "className1", "className2" }, cl.getArguments() ); + Commandline cl = javah.createJavahCommand(config); + + File outputFile = new File(getBasedir(), "target/native/" + "fileName"); + assertArrayEquals( + new String[] { + "-o", + outputFile.getAbsolutePath(), + "-classpath", + "path1" + File.pathSeparator + "path2", + "className1", + "className2" + }, + cl.getArguments()); } - public void testWorkingDirectory() - { + public void testWorkingDirectory() { JavahExecutable javah = new JavahExecutable(); - File workingDirectory = new File( getBasedir() ); - config.setWorkingDirectory( workingDirectory ); + File workingDirectory = new File(getBasedir()); + config.setWorkingDirectory(workingDirectory); - Commandline cl = javah.createJavahCommand( config ); + Commandline cl = javah.createJavahCommand(config); - assertEquals( workingDirectory, cl.getWorkingDirectory() ); + assertEquals(workingDirectory, cl.getWorkingDirectory()); } } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/CompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/CompilerManager.java index 2dfc5ae7..80df9b17 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/CompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/CompilerManager.java @@ -25,8 +25,6 @@ import org.codehaus.mojo.natives.compiler.Compiler; -public interface CompilerManager -{ - Compiler getCompiler( String roleHint ) - throws NoSuchNativeProviderException; +public interface CompilerManager { + Compiler getCompiler(String roleHint) throws NoSuchNativeProviderException; } 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..510e19b2 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 @@ -33,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = CompilerManager.class, hint = "native-compiler-provider-manager") -public class DefaultCompilerManager - extends AbstractLogEnabled - implements CompilerManager, Initializable -{ +public class DefaultCompilerManager extends AbstractLogEnabled implements CompilerManager, Initializable { @Requirement(role = Compiler.class) private Map providers; @@ -45,28 +42,22 @@ public class DefaultCompilerManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No compiler providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No compiler providers configured."); } } @Override - public Compiler getCompiler( String providerType ) - throws NoSuchNativeProviderException - { - Compiler provider = providers.get( providerType ); + public Compiler getCompiler(String providerType) throws NoSuchNativeProviderException { + Compiler provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultEnvFactoryManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultEnvFactoryManager.java index 13eabb44..2af44d21 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultEnvFactoryManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultEnvFactoryManager.java @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.EnvFactory; import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.plexus.component.annotations.Component; @@ -10,32 +11,22 @@ * Construct EnvFactory */ @Component(role = EnvFactoryManager.class, hint = "default", instantiationStrategy = "singleton") -public class DefaultEnvFactoryManager - implements EnvFactoryManager -{ +public class DefaultEnvFactoryManager implements EnvFactoryManager { private Map envFactoryCache = new HashMap<>(); @Override - public EnvFactory getEnvFactory( String className ) - throws NativeBuildException - { - EnvFactory envFactory = envFactoryCache.get( className ); + public EnvFactory getEnvFactory(String className) throws NativeBuildException { + EnvFactory envFactory = envFactoryCache.get(className); - if ( envFactory == null ) - { - try - { - envFactory = (EnvFactory) Class.forName( className ).newInstance(); - envFactoryCache.put( className, envFactory ); - } - catch ( Exception e ) - { - throw new NativeBuildException( "Unable to find EnvFactory: " + className ); + if (envFactory == null) { + try { + envFactory = (EnvFactory) Class.forName(className).newInstance(); + envFactoryCache.put(className, envFactory); + } catch (Exception e) { + throw new NativeBuildException("Unable to find EnvFactory: " + className); } } return envFactory; - } - } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultJavahManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultJavahManager.java index a8b9c79c..0c4107d7 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultJavahManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultJavahManager.java @@ -33,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = JavahManager.class, hint = "native-javah-provider-manager") -public class DefaultJavahManager - extends AbstractLogEnabled - implements JavahManager, Initializable -{ +public class DefaultJavahManager extends AbstractLogEnabled implements JavahManager, Initializable { @Requirement(role = Javah.class) private Map providers; @@ -45,28 +42,22 @@ public class DefaultJavahManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No linker providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No linker providers configured."); } } @Override - public Javah getJavah( String providerType ) - throws NoSuchNativeProviderException - { - Javah provider = providers.get( providerType ); + public Javah getJavah(String providerType) throws NoSuchNativeProviderException { + Javah provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultLinkerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultLinkerManager.java index d659c1d0..451e5323 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultLinkerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultLinkerManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.linker.Linker; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -32,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = LinkerManager.class, hint = "native-linker-provider-manager") -public class DefaultLinkerManager - extends AbstractLogEnabled - implements LinkerManager, Initializable -{ +public class DefaultLinkerManager extends AbstractLogEnabled implements LinkerManager, Initializable { @Requirement(role = Linker.class) private Map providers; @@ -44,28 +42,22 @@ public class DefaultLinkerManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No linker providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No linker providers configured."); } } @Override - public Linker getLinker( String providerType ) - throws NoSuchNativeProviderException - { - Linker provider = providers.get( providerType ); + public Linker getLinker(String providerType) throws NoSuchNativeProviderException { + Linker provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultManifestManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultManifestManager.java index 1c29cdc9..fd8d2d52 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultManifestManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultManifestManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.linker.Manifest; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -32,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = ManifestManager.class, hint = "native-manifest-provider-manager") -public class DefaultManifestManager - extends AbstractLogEnabled - implements ManifestManager, Initializable -{ +public class DefaultManifestManager extends AbstractLogEnabled implements ManifestManager, Initializable { @Requirement(role = Manifest.class) private Map providers; @@ -44,28 +42,22 @@ public class DefaultManifestManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No manifest providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No manifest providers configured."); } } @Override - public Manifest getManifest( String providerType ) - throws NoSuchNativeProviderException - { - Manifest provider = providers.get( providerType ); + public Manifest getManifest(String providerType) throws NoSuchNativeProviderException { + Manifest provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultMessageCompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultMessageCompilerManager.java index 647ac07d..96cc1062 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultMessageCompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultMessageCompilerManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.compiler.MessageCompiler; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -32,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = MessageCompilerManager.class, hint = "native-message-compiler-provider-manager") -public class DefaultMessageCompilerManager - extends AbstractLogEnabled - implements MessageCompilerManager, Initializable -{ +public class DefaultMessageCompilerManager extends AbstractLogEnabled implements MessageCompilerManager, Initializable { @Requirement(role = MessageCompiler.class) private Map providers; @@ -44,29 +42,23 @@ public class DefaultMessageCompilerManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No compiler providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No compiler providers configured."); } } @Override - public MessageCompiler getMessageCompiler( String providerType ) - throws NoSuchNativeProviderException - { + public MessageCompiler getMessageCompiler(String providerType) throws NoSuchNativeProviderException { - MessageCompiler provider = providers.get( providerType ); + MessageCompiler provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultRanlibManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultRanlibManager.java index 5a5785c5..4892890d 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultRanlibManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultRanlibManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.linker.Ranlib; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -32,10 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = RanlibManager.class, hint = "native-ranlib-provider-manager") -public class DefaultRanlibManager - extends AbstractLogEnabled - implements RanlibManager, Initializable -{ +public class DefaultRanlibManager extends AbstractLogEnabled implements RanlibManager, Initializable { @Requirement(role = Ranlib.class) private Map providers; @@ -44,28 +42,22 @@ public class DefaultRanlibManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No ranlib providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No ranlib providers configured."); } } @Override - public Ranlib getRanlib( String providerType ) - throws NoSuchNativeProviderException - { - Ranlib provider = providers.get( providerType ); + public Ranlib getRanlib(String providerType) throws NoSuchNativeProviderException { + Ranlib provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultResourceCompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultResourceCompilerManager.java index 977fb8ff..2c8ca439 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultResourceCompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/DefaultResourceCompilerManager.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.compiler.ResourceCompiler; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -32,10 +33,8 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; @Component(role = ResourceCompilerManager.class, hint = "native-resource-compiler-provider-manager") -public class DefaultResourceCompilerManager - extends AbstractLogEnabled - implements ResourceCompilerManager, Initializable -{ +public class DefaultResourceCompilerManager extends AbstractLogEnabled + implements ResourceCompilerManager, Initializable { @Requirement(role = ResourceCompiler.class) private Map providers; @@ -44,29 +43,23 @@ public class DefaultResourceCompilerManager // ---------------------------------------------------------------------- @Override - public void initialize() - { - if ( providers == null ) - { + public void initialize() { + if (providers == null) { providers = new HashMap<>(); } - if ( providers.size() == 0 ) - { - getLogger().warn( "No compiler providers configured." ); + if (providers.size() == 0) { + getLogger().warn("No compiler providers configured."); } } @Override - public ResourceCompiler getResourceCompiler( String providerType ) - throws NoSuchNativeProviderException - { + public ResourceCompiler getResourceCompiler(String providerType) throws NoSuchNativeProviderException { - ResourceCompiler provider = providers.get( providerType ); + ResourceCompiler provider = providers.get(providerType); - if ( provider == null ) - { - throw new NoSuchNativeProviderException( providerType ); + if (provider == null) { + throw new NoSuchNativeProviderException(providerType); } return provider; diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/EnvFactoryManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/EnvFactoryManager.java index a342b3af..835c8d69 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/EnvFactoryManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/EnvFactoryManager.java @@ -3,8 +3,6 @@ import org.codehaus.mojo.natives.EnvFactory; import org.codehaus.mojo.natives.NativeBuildException; -public interface EnvFactoryManager -{ - EnvFactory getEnvFactory( String className ) - throws NativeBuildException; +public interface EnvFactoryManager { + EnvFactory getEnvFactory(String className) throws NativeBuildException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/JavahManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/JavahManager.java index 6320f793..e693517c 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/JavahManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/JavahManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.javah.Javah; -public interface JavahManager -{ +public interface JavahManager { String ROLE = JavahManager.class.getName(); - Javah getJavah( String roleHint ) - throws NoSuchNativeProviderException; + Javah getJavah(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/LinkerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/LinkerManager.java index 1a673e96..b62439d6 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/LinkerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/LinkerManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.linker.Linker; -public interface LinkerManager -{ +public interface LinkerManager { String ROLE = LinkerManager.class.getName(); - Linker getLinker( String roleHint ) - throws NoSuchNativeProviderException; + Linker getLinker(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ManifestManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ManifestManager.java index 29766ae8..824906e1 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ManifestManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ManifestManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.linker.Manifest; -public interface ManifestManager -{ +public interface ManifestManager { String ROLE = ManifestManager.class.getName(); - Manifest getManifest( String roleHint ) - throws NoSuchNativeProviderException; + Manifest getManifest(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/MessageCompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/MessageCompilerManager.java index 1e790454..5a986bb4 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/MessageCompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/MessageCompilerManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.compiler.MessageCompiler; -public interface MessageCompilerManager -{ +public interface MessageCompilerManager { String ROLE = MessageCompilerManager.class.getName(); - MessageCompiler getMessageCompiler( String roleHint ) - throws NoSuchNativeProviderException; + MessageCompiler getMessageCompiler(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/NoSuchNativeProviderException.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/NoSuchNativeProviderException.java index 9dd96672..af894ec6 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/NoSuchNativeProviderException.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/NoSuchNativeProviderException.java @@ -23,23 +23,18 @@ */ package org.codehaus.mojo.natives.manager; -public class NoSuchNativeProviderException - extends Exception -{ +public class NoSuchNativeProviderException extends Exception { private static final long serialVersionUID = 1L; private String providerName; - public NoSuchNativeProviderException( String providerName ) - { - super( "No such provider: '" + providerName + "'." ); + public NoSuchNativeProviderException(String providerName) { + super("No such provider: '" + providerName + "'."); this.providerName = providerName; } - public String getProviderName() - { + public String getProviderName() { return providerName; } - } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/RanlibManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/RanlibManager.java index 069e67ae..7228ce09 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/RanlibManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/RanlibManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.linker.Ranlib; -public interface RanlibManager -{ +public interface RanlibManager { String ROLE = RanlibManager.class.getName(); - Ranlib getRanlib( String roleHint ) - throws NoSuchNativeProviderException; + Ranlib getRanlib(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ResourceCompilerManager.java b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ResourceCompilerManager.java index 7be3e105..4c1e35ca 100644 --- a/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ResourceCompilerManager.java +++ b/maven-native-components/maven-native-manager/src/main/java/org/codehaus/mojo/natives/manager/ResourceCompilerManager.java @@ -25,10 +25,8 @@ import org.codehaus.mojo.natives.compiler.ResourceCompiler; -public interface ResourceCompilerManager -{ +public interface ResourceCompilerManager { String ROLE = ResourceCompilerManager.class.getName(); - ResourceCompiler getResourceCompiler( String roleHint ) - throws NoSuchNativeProviderException; + ResourceCompiler getResourceCompiler(String roleHint) throws NoSuchNativeProviderException; } diff --git a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/AbstractGccCompiler.java b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/AbstractGccCompiler.java index 83f130f2..ea73da06 100644 --- a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/AbstractGccCompiler.java +++ b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/AbstractGccCompiler.java @@ -24,124 +24,103 @@ package org.codehaus.mojo.natives.mingw; import java.io.File; -import org.codehaus.plexus.util.cli.Commandline; 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.Parser; import org.codehaus.mojo.natives.parser.CParser; +import org.codehaus.mojo.natives.parser.Parser; +import org.codehaus.plexus.util.cli.Commandline; -public abstract class AbstractGccCompiler - extends AbstractCompiler -{ +public abstract class AbstractGccCompiler extends AbstractCompiler { /** * resuable parser in one Compilation session */ - private Parser parser = new CParser(); protected abstract String getOutputFileOption(); - protected Parser getParser() - { + protected Parser getParser() { return this.parser; } /** * Setup Compiler Command line */ - protected Commandline getCommandLine( File srcFile, File destFile, CompilerConfiguration config ) - throws NativeBuildException - { + protected Commandline getCommandLine(File srcFile, File destFile, CompilerConfiguration config) + throws NativeBuildException { - if ( config.getExecutable() == null ) - { - config.setExecutable( "gcc" ); + if (config.getExecutable() == null) { + config.setExecutable("gcc"); } Commandline cl = new Commandline(); - cl.setExecutable( config.getExecutable() ); + cl.setExecutable(config.getExecutable()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - this.setStartOptions( cl, config ); + this.setStartOptions(cl, config); - this.setIncludePaths( cl, config.getIncludePaths() ); + this.setIncludePaths(cl, config.getIncludePaths()); - this.setIncludePaths( cl, config.getSystemIncludePaths() ); + this.setIncludePaths(cl, config.getSystemIncludePaths()); - this.setMiddleOptions( cl, config ); + this.setMiddleOptions(cl, config); - this.setOutputArgs( cl, destFile ); + this.setOutputArgs(cl, destFile); - this.setSourceArgs( cl, srcFile ); + this.setSourceArgs(cl, srcFile); - this.setEndOptions( cl, config ); + this.setEndOptions(cl, config); return cl; } - private void setOptions( Commandline cl, String[] options ) - { - if ( options != null ) - { - for ( String option : options ) - { - cl.createArg().setValue( option ); + private void setOptions(Commandline cl, String[] options) { + if (options != null) { + for (String option : options) { + cl.createArg().setValue(option); } } } - private void setStartOptions( Commandline cl, CompilerConfiguration config ) - { - this.setOptions( cl, config.getStartOptions() ); + 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 setMiddleOptions(Commandline cl, CompilerConfiguration config) { + this.setOptions(cl, config.getMiddleOptions()); } - private void setEndOptions( Commandline cl, CompilerConfiguration config ) - { - this.setOptions( cl, config.getEndOptions() ); + private void setEndOptions(Commandline cl, CompilerConfiguration config) { + this.setOptions(cl, config.getEndOptions()); } - private void setIncludePaths( Commandline cl, File[] includePaths ) - { - if ( includePaths != null ) - { - for ( File includePath : includePaths ) - { - cl.createArg().setValue( "-I" + includePath.getPath() ); + private void setIncludePaths(Commandline cl, File[] includePaths) { + if (includePaths != null) { + for (File includePath : includePaths) { + cl.createArg().setValue("-I" + includePath.getPath()); } } } - private void setOutputArgs( Commandline cl, File outputFile ) - { + 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() ); + 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() ); + private void setSourceArgs(Commandline cl, File srcFile) { + cl.createArg().setValue("-c"); + cl.createArg().setValue(srcFile.getPath()); } } diff --git a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccCompiler.java b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccCompiler.java index ab270957..00bee908 100644 --- a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccCompiler.java +++ b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccCompiler.java @@ -30,13 +30,9 @@ * Generic MinGW compiler with "-o " as its output option */ @Component(role = Compiler.class, hint = "mingw", instantiationStrategy = "per-lookup") -public class GccCompiler - extends AbstractGccCompiler -{ +public class GccCompiler extends AbstractGccCompiler { - protected String getOutputFileOption() - { + protected String getOutputFileOption() { return "-o "; } - } diff --git a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccLinker.java b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccLinker.java index 1c8a014a..d530c8dd 100644 --- a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccLinker.java +++ b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/GccLinker.java @@ -27,6 +27,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.linker.AbstractLinker; import org.codehaus.mojo.natives.linker.Linker; @@ -40,99 +41,80 @@ * Generic MinGW linker with "-o " as its output option */ @Component(role = Linker.class, hint = "mingw", instantiationStrategy = "per-lookup") -public final class GccLinker - extends AbstractLinker -{ +public final class GccLinker 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( "gcc" ); + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException { + if (config.getExecutable() == null) { + config.setExecutable("gcc"); } Commandline cl = new Commandline(); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); - cl.setExecutable( config.getExecutable() ); + cl.setExecutable(config.getExecutable()); - if ( config.getStartOptions() != null ) - { - cl.addArguments( config.getStartOptions() ); + 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() ); + 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 ( File objFile : objectFiles ) - { - linkerFileWriter.write( objFile.getPath() + "\n" ); + if (config.isUsingLinkerResponseFile()) { + try { + File linkerFile = new File(config.getWorkingDirectory(), "objectsFile"); + FileWriter linkerFileWriter = new FileWriter(linkerFile, false /* Don't append */); + for (File objFile : objectFiles) { + linkerFileWriter.write(objFile.getPath() + "\n"); } linkerFileWriter.close(); - } - catch ( IOException error ) - { - throw new NativeBuildException( "Error creating linker response file", error ); + } catch (IOException error) { + throw new NativeBuildException("Error creating linker response file", error); } - cl.createArg().setValue( "@objectsFile" ); - } - else - { // Normal behavior. + cl.createArg().setValue("@objectsFile"); + } else { // Normal behavior. - for ( File objFile : objectFiles ) - { + for (File objFile : objectFiles) { // we need to shorten the command line since windows has limited command line // length - String objFilePath = FileUtil.truncatePath( objFile.getPath(), config.getWorkingDirectory().getPath() ); + String objFilePath = FileUtil.truncatePath( + objFile.getPath(), config.getWorkingDirectory().getPath()); - cl.createArg().setValue( objFilePath ); + cl.createArg().setValue(objFilePath); } } - if ( config.getMiddleOptions() != null ) - { - cl.addArguments( config.getMiddleOptions() ); + if (config.getMiddleOptions() != null) { + cl.addArguments(config.getMiddleOptions()); } - setCommandLineForExternalLibraries( cl, config ); + setCommandLineForExternalLibraries(cl, config); - if ( config.getEndOptions() != null ) - { - cl.addArguments( config.getEndOptions() ); + if (config.getEndOptions() != null) { + cl.addArguments(config.getEndOptions()); } return cl; - } /** * @return output option flag of a generic C linker */ - protected String getLinkerOutputOption() - { + protected String getLinkerOutputOption() { return "-o "; } @@ -143,54 +125,43 @@ protected String getLinkerOutputOption() * @param config LinkerConfiguration * @throws NativeBuildException */ - protected void setCommandLineForExternalLibraries( Commandline cl, LinkerConfiguration config ) - throws NativeBuildException - { - if ( config.getExternalLibFileNames().size() == 0 ) - { + protected void setCommandLineForExternalLibraries(Commandline cl, LinkerConfiguration config) + throws NativeBuildException { + if (config.getExternalLibFileNames().size() == 0) { return; } boolean hasUnixLinkage = false; - for ( String libFileName : config.getExternalLibFileNames() ) - { - String ext = FileUtils.getExtension( libFileName ); + for (String libFileName : config.getExternalLibFileNames()) { + 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 ) ) - { + 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() ); + if (hasUnixLinkage) { + cl.createArg().setValue("-L" + config.getExternalLibDirectory()); } - for ( String libFileName : config.getExternalLibFileNames() ) - { - String ext = FileUtils.getExtension( libFileName ); + for (String libFileName : config.getExternalLibFileNames()) { + String ext = FileUtils.getExtension(libFileName); - if ( "a".equals( ext ) || "so".equals( ext ) || "sl".equals( ext ) ) - { - String libName = FileUtils.removeExtension( 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() ); + if (libFileName.startsWith("lib")) { + libName = libName.substring("lib".length()); } - cl.createArg().setValue( "-l" + libName ); + cl.createArg().setValue("-l" + libName); } } } - } diff --git a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/WindresResourceCompiler.java b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/WindresResourceCompiler.java index ddc9102f..5b3894dc 100644 --- a/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/WindresResourceCompiler.java +++ b/maven-native-components/maven-native-mingw/src/main/java/org/codehaus/mojo/natives/mingw/WindresResourceCompiler.java @@ -34,60 +34,52 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = ResourceCompiler.class, hint = "mingw", instantiationStrategy = "per-lookup") -public final class WindresResourceCompiler - extends AbstractResourceCompiler -{ +public final class WindresResourceCompiler extends AbstractResourceCompiler { - protected Commandline getCommandLine( ResourceCompilerConfiguration config, File source ) - throws NativeBuildException - { + protected Commandline getCommandLine(ResourceCompilerConfiguration config, File source) + throws NativeBuildException { Commandline cl = new Commandline(); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "windres.exe" ); + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("windres.exe"); } - cl.setExecutable( config.getExecutable().trim() ); + cl.setExecutable(config.getExecutable().trim()); - cl.addArguments( config.getOptions() ); + cl.addArguments(config.getOptions()); - for ( int i = 0; i < config.getIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getIncludePaths().length; ++i) { String includePath = config.getIncludePaths()[i].getPath(); - cl.createArg().setValue( "-I" ); + cl.createArg().setValue("-I"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - for ( int i = 0; i < config.getSystemIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getSystemIncludePaths().length; ++i) { String includePath = config.getSystemIncludePaths()[i].getPath(); - cl.createArg().setValue( "-I" ); + cl.createArg().setValue("-I"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - cl.createArg().setValue( "-O" ); + cl.createArg().setValue("-O"); - cl.createArg().setValue( "coff" ); + cl.createArg().setValue("coff"); - cl.createArg().setValue( "-o" ); + cl.createArg().setValue("-o"); - cl.createArg().setValue( config.getOutputFile( source ).getPath() ); + cl.createArg().setValue(config.getOutputFile(source).getPath()); - cl.createArg().setValue( source.getPath() ); + cl.createArg().setValue(source.getPath()); return cl; } - } 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 058ae32a..0ad08551 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 @@ -3,122 +3,139 @@ import java.io.File; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; -import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; + +import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import static org.junit.Assert.*; -public class GccCompilerTest - extends PlexusTestCase -{ +public class GccCompilerTest extends PlexusTestCase { private GccCompiler compiler; private CompilerConfiguration config; - private static File sourceFile = new File( "source.c" ); + private static File sourceFile = new File("source.c"); - private static File objectFile = new File( "object.o" ); + private static File objectFile = new File("object.o"); - private static String[] simpleArgv = { "-o", "object.o", "-c", "source.c" }; + private static String[] simpleArgv = {"-o", "object.o", "-c", "source.c"}; - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.compiler = new GccCompiler(); this.config = new CompilerConfiguration(); } - public void testSimpleCompilation() - { - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); - String[] expected = new String[] { "gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testSimpleCompilation() { + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); + String[] expected = new String[] {"gcc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testNonDefaultExecutable() - { - this.config.setExecutable( "cc" ); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); - String[] expected = new String[] { "cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testNonDefaultExecutable() { + this.config.setExecutable("cc"); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); + String[] expected = new String[] {"cc", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testStartOptions() - { - String[] startOptions = { "-s1", "-s2" }; - config.setStartOptions( startOptions ); + public void testStartOptions() { + String[] startOptions = {"-s1", "-s2"}; + config.setStartOptions(startOptions); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = + new String[] {"gcc", "-s1", "-s2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testIncludePaths() - { - File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + public void testIncludePaths() { + File[] includePaths = {new File("p1"), new File("p2")}; - config.setIncludePaths( includePaths ); + config.setIncludePaths(includePaths); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = + new String[] {"gcc", "-Ip1", "-Ip2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testSystemIncludePaths() - { - File[] includePaths = { new File( "p1" ), new File( "p2" ) }; + public void testSystemIncludePaths() { + File[] includePaths = {new File("p1"), new File("p2")}; - File[] systemIncludePaths = { new File( "sp1" ), new File( "sp2" ) }; + File[] systemIncludePaths = {new File("sp1"), new File("sp2")}; - config.setIncludePaths( includePaths ); + config.setIncludePaths(includePaths); - config.setSystemIncludePaths( systemIncludePaths ); + config.setSystemIncludePaths(systemIncludePaths); - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); - String[] expected = new String[] { "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], - simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = new String[] { + "gcc", "-Ip1", "-Ip2", "-Isp1", "-Isp2", simpleArgv[0], simpleArgv[1], simpleArgv[2], simpleArgv[3] + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testMiddleOptions() - { - 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 ); - - String[] expected = new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testMiddleOptions() { + 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); + + String[] expected = new String[] { + "gcc", + "-s1", + "-s2", + "-Ip1", + "-Ip2", + "-m1", + "-m2", + simpleArgv[0], + simpleArgv[1], + simpleArgv[2], + simpleArgv[3] + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } - public void testEndOptions() - { - 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 ); - - String[] expected = new String[] { "gcc", "-s1", "-s2", "-Ip1", "-Ip2", "-m1", "-m2", simpleArgv[0], - simpleArgv[1], simpleArgv[2], simpleArgv[3], "-e1", "-e2" }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testEndOptions() { + 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); + + String[] expected = new String[] { + "gcc", + "-s1", + "-s2", + "-Ip1", + "-Ip2", + "-m1", + "-m2", + simpleArgv[0], + simpleArgv[1], + simpleArgv[2], + simpleArgv[3], + "-e1", + "-e2" + }; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } } diff --git a/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccLinkerTest.java b/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccLinkerTest.java index 7d4acf41..4188abba 100644 --- a/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccLinkerTest.java +++ b/maven-native-components/maven-native-mingw/src/test/java/org/codehaus/mojo/natives/mingw/GccLinkerTest.java @@ -4,149 +4,129 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.linker.LinkerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; -public class GccLinkerTest - extends PlexusTestCase -{ +public class GccLinkerTest extends PlexusTestCase { private GccLinker linker; private LinkerConfiguration config; - private static final File objectFile0 = new File( "source1.o" ); + private static final File objectFile0 = new File("source1.o"); - private static final File objectFile1 = new File( "source2.o" ); + private static final File objectFile1 = new File("source2.o"); private List defautlObjectFiles; private String basedir; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.defautlObjectFiles = new ArrayList<>(); - this.defautlObjectFiles.add( objectFile0 ); - this.defautlObjectFiles.add( objectFile1 ); + this.defautlObjectFiles.add(objectFile0); + this.defautlObjectFiles.add(objectFile1); this.linker = new GccLinker(); this.config = new LinkerConfiguration(); this.basedir = getBasedir(); - config.setWorkingDirectory( new File( basedir ) ); - config.setOutputDirectory( new File( basedir, "target" ) ); - config.setOutputFileExtension( "exe" ); - config.setOutputFileName( "test" ); + config.setWorkingDirectory(new File(basedir)); + config.setOutputDirectory(new File(basedir, "target")); + config.setOutputFileExtension("exe"); + config.setOutputFileName("test"); } - public void testDefaultLinkerExecutable() - { + public void testDefaultLinkerExecutable() { Commandline cl = this.getCommandline(); - assertEquals( "gcc", cl.getLiteralExecutable() ); - assertEquals( basedir, cl.getWorkingDirectory().getPath() ); - + assertEquals("gcc", cl.getLiteralExecutable()); + assertEquals(basedir, cl.getWorkingDirectory().getPath()); } - public void testOverrideLinkerExecutable() - { - config.setExecutable( "ld" ); + public void testOverrideLinkerExecutable() { + config.setExecutable("ld"); Commandline cl = this.getCommandline(); - assertEquals( "ld", cl.getLiteralExecutable() ); + assertEquals("ld", cl.getLiteralExecutable()); } - public void testObjectFileList() - { + public void testObjectFileList() { Commandline cl = this.getCommandline(); - int index = Arrays.asList( cl.getArguments() ).indexOf( "source1.o" ); - assertTrue( index >= 0 ); - assertEquals( "source2.o", cl.getArguments()[index + 1] ); - + int index = Arrays.asList(cl.getArguments()).indexOf("source1.o"); + assertTrue(index >= 0); + assertEquals("source2.o", cl.getArguments()[index + 1]); } - public void testLinkerResponseFile() - { - this.config.setUsingLinkerResponseFile( true ); - this.config.setWorkingDirectory( new File( getBasedir(), "target" ) ); + public void testLinkerResponseFile() { + this.config.setUsingLinkerResponseFile(true); + this.config.setWorkingDirectory(new File(getBasedir(), "target")); Commandline cl = this.getCommandline(); - assertTrue( cl.toString().contains( "@objectsFile" ) ); + assertTrue(cl.toString().contains("@objectsFile")); } - public void testRelativeObjectFileList() - { - 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 ); + public void testRelativeObjectFileList() { + ArrayList objectFiles = new ArrayList<>(2); + objectFiles.add(new File(config.getOutputDirectory(), "file1.o")); + objectFiles.add(new File(config.getOutputDirectory(), "file2.o")); - 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] ); + 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() - { - String[] options = { "-o1", "-o2", "-o3" }; - config.setStartOptions( options ); + public void testOptions() { + 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] ); - + 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() - { - config.setExternalLibDirectory( new File( "theLib" ) ); + public void testExternalUnixLibraries() { + config.setExternalLibDirectory(new File("theLib")); List externalLibFileNames = new ArrayList<>(); - externalLibFileNames.add( "file0.lib" ); - - externalLibFileNames.add( "file0.o" ); + externalLibFileNames.add("file0.lib"); - externalLibFileNames.add( "file1.obj" ); + externalLibFileNames.add("file0.o"); - externalLibFileNames.add( "file1.so" ); + externalLibFileNames.add("file1.obj"); - externalLibFileNames.add( "libfile2.so" ); + externalLibFileNames.add("file1.so"); - externalLibFileNames.add( "libfile3.a" ); + externalLibFileNames.add("libfile2.so"); - config.setExternalLibFileNames( externalLibFileNames ); + externalLibFileNames.add("libfile3.a"); - Commandline cl = this.getCommandline( new ArrayList<>( 0 ) ); + config.setExternalLibFileNames(externalLibFileNames); - 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] ); + 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() throws NativeBuildException { + return this.linker.createLinkerCommandLine(defautlObjectFiles, config); } - private Commandline getCommandline( List objectFiles ) - throws NativeBuildException - { - return this.linker.createLinkerCommandLine( objectFiles, config ); + private Commandline getCommandline(List objectFiles) throws NativeBuildException { + return this.linker.createLinkerCommandLine(objectFiles, config); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactory.java index f44c018d..214c7320 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactory.java @@ -1,77 +1,55 @@ package org.codehaus.mojo.natives.msvc; +import java.io.File; +import java.util.Map; + import org.codehaus.mojo.natives.AbstractEnvFactory; import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.plexus.util.cli.Commandline; -import java.io.File; -import java.util.Map; - -public abstract class AbstractCommunityEnvFactory extends AbstractEnvFactory -{ +public abstract class AbstractCommunityEnvFactory extends AbstractEnvFactory { private AbstractMSVC2017CircaEnvFactoryHelper helper = new AbstractMSVC2017CircaEnvFactoryHelper(); - - protected Map createEnvs(String version, String platform) - throws NativeBuildException - { + protected Map createEnvs(String version, String platform) throws NativeBuildException { File tmpEnvExecFile = null; - try - { - String vsCommunityPath = queryVSInstallPath( version ); + try { + String vsCommunityPath = queryVSInstallPath(version); - if ( vsCommunityPath == null ) - { - throw new NativeBuildException( - String.format( "Can not find VS Community version '%s'", version ) - ); + if (vsCommunityPath == null) { + throw new NativeBuildException(String.format("Can not find VS Community version '%s'", version)); } - if ( !vsCommunityPath.endsWith( "Community\\" ) && !vsCommunityPath.endsWith( "Community" ) ) - { + if (!vsCommunityPath.endsWith("Community\\") && !vsCommunityPath.endsWith("Community")) { throw new NativeBuildException( - String.format( "Directory '%s' is not a VS Community directory", vsCommunityPath ) - ); + String.format("Directory '%s' is not a VS Community directory", vsCommunityPath)); } - File communityDir = new File( vsCommunityPath ); - if ( !communityDir.isDirectory() ) - { - throw new NativeBuildException( - String.format( "Path '%s' is not a directory", vsCommunityPath ) - ); + File communityDir = new File(vsCommunityPath); + if (!communityDir.isDirectory()) { + throw new NativeBuildException(String.format("Path '%s' is not a directory", vsCommunityPath)); } - tmpEnvExecFile = this.helper.createEnvWrapperFile( communityDir, platform ); + tmpEnvExecFile = this.helper.createEnvWrapperFile(communityDir, platform); Commandline cl = new Commandline(); - cl.setExecutable( tmpEnvExecFile.getAbsolutePath() ); + cl.setExecutable(tmpEnvExecFile.getAbsolutePath()); - return executeCommandLine( cl ); + return executeCommandLine(cl); - } - catch ( NativeBuildException e ) - { + } catch (NativeBuildException e) { throw e; - } - catch ( Exception e ) - { - throw new NativeBuildException( "Unable to retrieve env", e ); - } - finally - { - if ( tmpEnvExecFile != null ) - { + } catch (Exception e) { + throw new NativeBuildException("Unable to retrieve env", e); + } finally { + if (tmpEnvExecFile != null) { tmpEnvExecFile.delete(); } } } - protected String queryVSInstallPath(String version) - { + protected String queryVSInstallPath(String version) { return helper.queryVSInstallPath(version); } - protected Map executeCommandLine(Commandline command) throws NativeBuildException - { + protected Map executeCommandLine(Commandline command) throws NativeBuildException { return helper.executeCommandLine(command); } } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2005EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2005EnvFactory.java index aaf69ec6..c2c56572 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2005EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2005EnvFactory.java @@ -26,12 +26,8 @@ /** * Equivalent of MSVC2005's vcvars32.bat */ - -public abstract class AbstractMSVC2005EnvFactory - extends AbstractMSVCEnvFactory -{ +public abstract class AbstractMSVC2005EnvFactory extends AbstractMSVCEnvFactory { protected static final String MSVS2005_INSTALL_ENV_KEY = "MSVS2005_INSTALL_DIR"; protected static final String DEFAULT_MSVS2005_INSTALL_DIR = getProgramFiles() + "/Microsoft Visual Studio 8"; - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2017CircaEnvFactoryHelper.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2017CircaEnvFactoryHelper.java index a8e42e68..daf9d31d 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2017CircaEnvFactoryHelper.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2017CircaEnvFactoryHelper.java @@ -1,63 +1,50 @@ -package org.codehaus.mojo.natives.msvc; - -import java.io.File; -import java.io.IOException; -import java.util.Map; - -import org.codehaus.mojo.natives.NativeBuildException; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.cli.CommandLineException; -import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.codehaus.plexus.util.cli.Commandline; -import org.codehaus.plexus.util.cli.DefaultConsumer; -import org.codehaus.plexus.util.cli.StreamConsumer; - - -/** - * Encapsulate some behavior common to Visual Studio since 2017. - */ -class AbstractMSVC2017CircaEnvFactoryHelper { - - protected File createEnvWrapperFile(File vsInstallDir, String platform) - throws IOException - { - - File tmpFile = File.createTempFile( "msenv", ".bat" ); - - String buffer = "@echo off\r\n" - + "call \"" + vsInstallDir + "\"" - + "\\VC\\Auxiliary\\Build\\vcvarsall.bat " + platform + "\r\n" - + "echo " + EnvStreamConsumer.START_PARSING_INDICATOR + "\r\n" - + "set\r\n"; - FileUtils.fileWrite( tmpFile.getAbsolutePath(), buffer ); - - return tmpFile; - } - - protected Map executeCommandLine(Commandline command) throws NativeBuildException - { - EnvStreamConsumer stdout = new EnvStreamConsumer(); - StreamConsumer stderr = new DefaultConsumer(); - - try - { - CommandLineUtils.executeCommandLine( command, stdout, stderr ); - } - catch ( CommandLineException e ) - { - throw new NativeBuildException( "Failed to execute vcvarsall.bat" ); - } - - return stdout.getParsedEnv(); - } - - protected String queryVSInstallPath(String version) - { - return RegQuery.getValue( - "REG_SZ", - "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\SxS\\VS7", - version - ); - } - -} +package org.codehaus.mojo.natives.msvc; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.Commandline; +import org.codehaus.plexus.util.cli.DefaultConsumer; +import org.codehaus.plexus.util.cli.StreamConsumer; + +/** + * Encapsulate some behavior common to Visual Studio since 2017. + */ +class AbstractMSVC2017CircaEnvFactoryHelper { + + protected File createEnvWrapperFile(File vsInstallDir, String platform) throws IOException { + + File tmpFile = File.createTempFile("msenv", ".bat"); + + String buffer = "@echo off\r\n" + + "call \"" + vsInstallDir + "\"" + + "\\VC\\Auxiliary\\Build\\vcvarsall.bat " + platform + "\r\n" + + "echo " + EnvStreamConsumer.START_PARSING_INDICATOR + "\r\n" + + "set\r\n"; + FileUtils.fileWrite(tmpFile.getAbsolutePath(), buffer); + + return tmpFile; + } + + protected Map executeCommandLine(Commandline command) throws NativeBuildException { + EnvStreamConsumer stdout = new EnvStreamConsumer(); + StreamConsumer stderr = new DefaultConsumer(); + + try { + CommandLineUtils.executeCommandLine(command, stdout, stderr); + } catch (CommandLineException e) { + throw new NativeBuildException("Failed to execute vcvarsall.bat"); + } + + return stdout.getParsedEnv(); + } + + protected String queryVSInstallPath(String version) { + return RegQuery.getValue("REG_SZ", "HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\SxS\\VS7", version); + } +} diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2019EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2019EnvFactory.java index 8554ca86..b90997f4 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2019EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVC2019EnvFactory.java @@ -3,16 +3,11 @@ import java.io.File; import java.io.IOException; -public abstract class AbstractMSVC2019EnvFactory extends AbstractMSVCEnvFactory -{ +public abstract class AbstractMSVC2019EnvFactory extends AbstractMSVCEnvFactory { private AbstractMSVC2017CircaEnvFactoryHelper helper = new AbstractMSVC2017CircaEnvFactoryHelper(); - @Override - protected File createEnvWrapperFile( File vsInstallDir, String platform ) - throws IOException - { + protected File createEnvWrapperFile(File vsInstallDir, String platform) throws IOException { return helper.createEnvWrapperFile(vsInstallDir, platform); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVCEnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVCEnvFactory.java index 15bab5eb..e166adab 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVCEnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/AbstractMSVCEnvFactory.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.util.Map; + import org.codehaus.mojo.natives.AbstractEnvFactory; import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; @@ -12,98 +13,73 @@ import org.codehaus.plexus.util.cli.DefaultConsumer; import org.codehaus.plexus.util.cli.StreamConsumer; -public abstract class AbstractMSVCEnvFactory - extends AbstractEnvFactory -{ +public abstract class AbstractMSVCEnvFactory extends AbstractEnvFactory { - protected static String getProgramFiles() - { - return EnvUtil.getEnv( "ProgramFiles", "ProgramFiles", "C:\\Program Files" ); + protected static String getProgramFiles() { + return EnvUtil.getEnv("ProgramFiles", "ProgramFiles", "C:\\Program Files"); } - protected static String getProgramFilesX86() - { - return EnvUtil.getEnv( "ProgramFiles(x86)", "ProgramFiles", getProgramFiles() ); + protected static String getProgramFilesX86() { + return EnvUtil.getEnv("ProgramFiles(x86)", "ProgramFiles", getProgramFiles()); } - protected static String getSystemRoot() - { - return EnvUtil.getEnv( "SystemRoot", "SystemRoot", "C:\\WINDOWS" ); + protected static String getSystemRoot() { + return EnvUtil.getEnv("SystemRoot", "SystemRoot", "C:\\WINDOWS"); } - protected Map createEnvs( String commonToolEnvKey, String platform ) - throws NativeBuildException - { + protected Map createEnvs(String commonToolEnvKey, String platform) throws NativeBuildException { File tmpEnvExecFile = null; - try - { - File vsCommonToolDir = this.getCommonToolDirectory( commonToolEnvKey ); + try { + File vsCommonToolDir = this.getCommonToolDirectory(commonToolEnvKey); - File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir ); + File vsInstallDir = this.getVisualStudioInstallDirectory(vsCommonToolDir); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } - tmpEnvExecFile = this.createEnvWrapperFile( vsInstallDir, platform ); + tmpEnvExecFile = this.createEnvWrapperFile(vsInstallDir, platform); Commandline cl = new Commandline(); - cl.setExecutable( tmpEnvExecFile.getAbsolutePath() ); + cl.setExecutable(tmpEnvExecFile.getAbsolutePath()); EnvStreamConsumer stdout = new EnvStreamConsumer(); StreamConsumer stderr = new DefaultConsumer(); - CommandLineUtils.executeCommandLine( cl, stdout, stderr ); + CommandLineUtils.executeCommandLine(cl, stdout, stderr); return stdout.getParsedEnv(); - } - catch ( Exception e ) - { - throw new NativeBuildException( "Unable to retrieve env", e ); - } - finally - { - if ( tmpEnvExecFile != null ) - { + } catch (Exception e) { + throw new NativeBuildException("Unable to retrieve env", e); + } finally { + if (tmpEnvExecFile != null) { tmpEnvExecFile.delete(); } } - } - private File getCommonToolDirectory( String commonToolEnvKey ) - throws NativeBuildException - { - String envValue = System.getenv( commonToolEnvKey ); - if ( envValue == null ) - { - throw new NativeBuildException( "Environment variable: " + commonToolEnvKey + " not available." ); + private File getCommonToolDirectory(String commonToolEnvKey) throws NativeBuildException { + String envValue = System.getenv(commonToolEnvKey); + if (envValue == null) { + throw new NativeBuildException("Environment variable: " + commonToolEnvKey + " not available."); } - return new File( envValue ); + return new File(envValue); } - private File getVisualStudioInstallDirectory( File commonToolDir ) - throws NativeBuildException - { - try - { - return new File( commonToolDir, "../.." ).getCanonicalFile(); - } - catch ( IOException e ) - { + private File getVisualStudioInstallDirectory(File commonToolDir) throws NativeBuildException { + try { + return new File(commonToolDir, "../..").getCanonicalFile(); + } catch (IOException e) { throw new NativeBuildException( - "Unable to contruct Visual Studio install directory using: " + commonToolDir, e ); + "Unable to contruct Visual Studio install directory using: " + commonToolDir, e); } } - protected File createEnvWrapperFile( File vsInstallDir, String platform ) - throws IOException - { + protected File createEnvWrapperFile(File vsInstallDir, String platform) throws IOException { - File tmpFile = File.createTempFile( "msenv", ".bat" ); + File tmpFile = File.createTempFile("msenv", ".bat"); String buffer = "@echo off\r\n" + "call \"" + vsInstallDir + "\"" + "\\VC\\vcvarsall.bat " @@ -111,9 +87,8 @@ protected File createEnvWrapperFile( File vsInstallDir, String platform ) + "echo " + EnvStreamConsumer.START_PARSING_INDICATOR + "\r\n" + "set\n\r"; - FileUtils.fileWrite( tmpFile.getAbsolutePath(), buffer ); + FileUtils.fileWrite(tmpFile.getAbsolutePath(), buffer); return tmpFile; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x64EnvFactory.java index fda66efa..0bd02045 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x64EnvFactory.java @@ -1,16 +1,13 @@ package org.codehaus.mojo.natives.msvc; -import org.codehaus.mojo.natives.NativeBuildException; - import java.util.Map; -public class Community2017x64EnvFactory extends AbstractCommunityEnvFactory -{ +import org.codehaus.mojo.natives.NativeBuildException; + +public class Community2017x64EnvFactory extends AbstractCommunityEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "15.0", "x64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("15.0", "x64"); } } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86AMD64EnvFactory.java index 2dc6d8c8..b5d1af3d 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86AMD64EnvFactory.java @@ -1,16 +1,13 @@ package org.codehaus.mojo.natives.msvc; -import org.codehaus.mojo.natives.NativeBuildException; - import java.util.Map; -public class Community2017x86AMD64EnvFactory extends AbstractCommunityEnvFactory -{ +import org.codehaus.mojo.natives.NativeBuildException; + +public class Community2017x86AMD64EnvFactory extends AbstractCommunityEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "15.0", "x86_amd64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("15.0", "x86_amd64"); } } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86EnvFactory.java index 9bd5568b..3bbdf622 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/Community2017x86EnvFactory.java @@ -1,16 +1,13 @@ package org.codehaus.mojo.natives.msvc; -import org.codehaus.mojo.natives.NativeBuildException; - import java.util.Map; -public class Community2017x86EnvFactory extends AbstractCommunityEnvFactory -{ +import org.codehaus.mojo.natives.NativeBuildException; + +public class Community2017x86EnvFactory extends AbstractCommunityEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "15.0", "x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("15.0", "x86"); } } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/EnvStreamConsumer.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/EnvStreamConsumer.java index 6143c516..b0cc34c3 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/EnvStreamConsumer.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/EnvStreamConsumer.java @@ -2,12 +2,11 @@ import java.util.HashMap; import java.util.Map; + import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.StreamConsumer; -public class EnvStreamConsumer - implements StreamConsumer -{ +public class EnvStreamConsumer implements StreamConsumer { public static final String START_PARSING_INDICATOR = "================================This is the beginning of env parsing================================"; @@ -17,33 +16,24 @@ public class EnvStreamConsumer private boolean startParsing = false; @Override - public void consumeLine( String line ) - { + public void consumeLine(String line) { - if ( line.startsWith( START_PARSING_INDICATOR ) ) - { + if (line.startsWith(START_PARSING_INDICATOR)) { this.startParsing = true; return; } - if ( this.startParsing ) - { - String[] tokens = StringUtils.split( line, "=" ); - if ( tokens.length == 2 ) - { - envs.put( tokens[0], tokens[1] ); + if (this.startParsing) { + String[] tokens = StringUtils.split(line, "="); + if (tokens.length == 2) { + envs.put(tokens[0], tokens[1]); } + } else { + System.out.println(line); } - else - { - System.out.println( line ); - } - } - public Map getParsedEnv() - { + public Map getParsedEnv() { return this.envs; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003EnvFactory.java index 9b1fa6b3..51431e46 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003EnvFactory.java @@ -26,81 +26,74 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of Microsoft Visual Studio .NET 2003's vcvars32.bat */ - -public class MSVC2003EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2003EnvFactory extends AbstractMSVCEnvFactory { private static final String MSVS2003_INSTALL_ENV_KEY = "MSVS2003_INSTALL_DIR"; private static final String DEFAULT_MSVS2003_INSTALL_DIR = getProgramFiles() + "/Microsoft Visual Studio .NET 2003"; @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { File vcInstallDir = new File( - EnvUtil.getEnv( MSVS2003_INSTALL_ENV_KEY, MSVS2003_INSTALL_ENV_KEY, DEFAULT_MSVS2003_INSTALL_DIR ) ); + EnvUtil.getEnv(MSVS2003_INSTALL_ENV_KEY, MSVS2003_INSTALL_ENV_KEY, DEFAULT_MSVS2003_INSTALL_DIR)); - if ( !vcInstallDir.isDirectory() ) - { - throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." ); + if (!vcInstallDir.isDirectory()) { + throw new NativeBuildException(vcInstallDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); - File vsInstallDir = new File( vcInstallDir.getPath() + "/Common7/IDE" ); + File vsInstallDir = new File(vcInstallDir.getPath() + "/Common7/IDE"); // TODO get winhome dir - File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "/Microsoft.NET/Framework"); + envs.put("FrameworkDir", frameworkDir.getPath()); - File frameworkSDKDir = new File( vcInstallDir.getPath() + "/SDK/v1.1" ); - envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() ); + File frameworkSDKDir = new File(vcInstallDir.getPath() + "/SDK/v1.1"); + envs.put("FrameworkSDKDir", frameworkSDKDir.getPath()); String frameworkVersion = "v1.1.4322"; - envs.put( "frameworkVersion", frameworkVersion ); + envs.put("frameworkVersion", frameworkVersion); File devEnvDir = vsInstallDir; - File msvcDir = new File( vcInstallDir.getPath() + "/VC7" ); + File msvcDir = new File(vcInstallDir.getPath() + "/VC7"); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = devEnvDir.getPath() + ";" + msvcDir.getPath() + "\\BIN;" + vcInstallDir.getPath() + "\\Common7\\Tools;" + vcInstallDir.getPath() + "\\Common7\\Tools\\bin\\prerelease;" + vcInstallDir.getPath() + "\\Common7\\Tools\\bin;" + frameworkSDKDir.getPath() + "\\bin;" + frameworkDir.getPath() + "\\" + frameworkVersion + ";" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = msvcDir.getPath() + "\\ATLMFC\\INCLUDE;" + msvcDir.getPath() + "\\INCLUDE;" + msvcDir.getPath() + "\\PlatformSDK\\include\\prerelease;" + msvcDir.getPath() + "\\PlatformSDK\\include;" + frameworkSDKDir.getPath() + "\\include;" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = msvcDir.getPath() + "\\ATLMFC\\LIB;" + msvcDir.getPath() + "\\LIB;" + msvcDir.getPath() + "\\PlatformSDK\\lib\\prerelease;" + msvcDir.getPath() + "\\PlatformSDK\\lib;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003ToolkitEnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003ToolkitEnvFactory.java index 0fe8c609..193857d0 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003ToolkitEnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2003ToolkitEnvFactory.java @@ -26,60 +26,55 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of Microsoft Visual C++ Toolkit 2003's vcvars32.bat */ - -public class MSVC2003ToolkitEnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2003ToolkitEnvFactory extends AbstractMSVCEnvFactory { private static final String MSVC2003_TOOLKIT_INSTALL_ENV_KEY = "MSVC2003_TOOLKIT_INSTALL_DIR"; private static final String DEFAULT_MSVC2003_TOOLKT_INSTALL_DIR = getProgramFiles() + "/Microsoft Visual C++ Toolkit 2003"; @Override - protected Map createEnvs() - throws NativeBuildException - { - File vcInstallDir = new File( EnvUtil.getEnv( MSVC2003_TOOLKIT_INSTALL_ENV_KEY, - MSVC2003_TOOLKIT_INSTALL_ENV_KEY, DEFAULT_MSVC2003_TOOLKT_INSTALL_DIR ) ); - - if ( !vcInstallDir.isDirectory() ) - { - throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." ); + protected Map createEnvs() throws NativeBuildException { + File vcInstallDir = new File(EnvUtil.getEnv( + MSVC2003_TOOLKIT_INSTALL_ENV_KEY, + MSVC2003_TOOLKIT_INSTALL_ENV_KEY, + DEFAULT_MSVC2003_TOOLKT_INSTALL_DIR)); + + if (!vcInstallDir.isDirectory()) { + throw new NativeBuildException(vcInstallDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = vcInstallDir.getPath() + "\\BIN;" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = vcInstallDir.getPath() + "\\INCLUDE;" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = vcInstallDir.getPath() + "\\LIB;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005AMD64EnvFactory.java index d378d29f..53480517 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005AMD64EnvFactory.java @@ -26,53 +26,48 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of MSVC2005's vcvarsamd64.bat */ - -public class MSVC2005AMD64EnvFactory - extends AbstractMSVC2005EnvFactory -{ +public class MSVC2005AMD64EnvFactory extends AbstractMSVC2005EnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { File vsInstallDir = new File( - EnvUtil.getEnv( MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR ) ); + EnvUtil.getEnv(MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR)); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); - envs.put( "VSINSTALLDIR", vsInstallDir.getPath() ); + envs.put("VSINSTALLDIR", vsInstallDir.getPath()); - File vcInstallDir = new File( vsInstallDir.getPath() + "/VC" ); - envs.put( "VCINSTALLDIR", vcInstallDir.getPath() ); + File vcInstallDir = new File(vsInstallDir.getPath() + "/VC"); + envs.put("VCINSTALLDIR", vcInstallDir.getPath()); // TODO get winhome dir - File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework64" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "/Microsoft.NET/Framework64"); + envs.put("FrameworkDir", frameworkDir.getPath()); String frameworkVersion = "v2.0.50727"; - envs.put( "FrameworkVersion", frameworkVersion ); + envs.put("FrameworkVersion", frameworkVersion); - File frameworkSDKDir = new File( vsInstallDir.getPath() + "/SDK/v2.0 64bit" ); - envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() ); + File frameworkSDKDir = new File(vsInstallDir.getPath() + "/SDK/v2.0 64bit"); + envs.put("FrameworkSDKDir", frameworkSDKDir.getPath()); - File devEnvDir = new File( vsInstallDir.getPath() + "/Common7/IDE" ); - envs.put( "DevEnvDir", devEnvDir.getPath() ); + File devEnvDir = new File(vsInstallDir.getPath() + "/Common7/IDE"); + envs.put("DevEnvDir", devEnvDir.getPath()); - File platformSDKDir = new File( vcInstallDir.getPath() + "/PlatformSDK" ); + File platformSDKDir = new File(vcInstallDir.getPath() + "/PlatformSDK"); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = vcInstallDir.getPath() + "\\BIN\\amd64;" + platformSDKDir.getPath() + "\\BIN\\WIN64\\AMD64;" + platformSDKDir.getPath() + "\\BIN;" + frameworkDir.getPath() + "\\" + frameworkVersion + ";" @@ -80,40 +75,38 @@ protected Map createEnvs() + "\\Common7\\Tools;" + vcInstallDir.getPath() + "\\Common7\\Tools\\Bin;" + vcInstallDir.getPath() + "\\SDK\\v2.0\\bin;" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;" + platformSDKDir.getPath() + "\\INCLUDE;" + vcInstallDir.getPath() + "\\SDK\\v2.0\\include;" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = vcInstallDir.getPath() + "\\ATLMFC\\LIB\\AMD64;" + vcInstallDir.getPath() + "\\LIB\\AMD64;" + platformSDKDir.getPath() + "\\LIB\\AMD64;" + vsInstallDir.getPath() + "\\SDK\\v2.0\\LIB\\AMD64;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); // // setup new LIBPATH // - String currentLibPathPath = EnvUtil.getEnv( "LIBPATH" ); + String currentLibPathPath = EnvUtil.getEnv("LIBPATH"); String newLibPathPath = vcInstallDir.getPath() + "\\ATLMFC\\LIB\\AMD64" + currentLibPathPath; - envs.put( "LIBPATH", newLibPathPath ); + envs.put("LIBPATH", newLibPathPath); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86AMD64EnvFactory.java index e5e0c8c6..371ba887 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86AMD64EnvFactory.java @@ -26,53 +26,48 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of MSVC2005's vcvarsx86_amd64.bat */ - -public class MSVC2005x86AMD64EnvFactory - extends AbstractMSVC2005EnvFactory -{ +public class MSVC2005x86AMD64EnvFactory extends AbstractMSVC2005EnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { File vsInstallDir = new File( - EnvUtil.getEnv( MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR ) ); + EnvUtil.getEnv(MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR)); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); - envs.put( "VSINSTALLDIR", vsInstallDir.getPath() ); + envs.put("VSINSTALLDIR", vsInstallDir.getPath()); - File vcInstallDir = new File( vsInstallDir.getPath() + "/VC" ); - envs.put( "VCINSTALLDIR", vcInstallDir.getPath() ); + File vcInstallDir = new File(vsInstallDir.getPath() + "/VC"); + envs.put("VCINSTALLDIR", vcInstallDir.getPath()); // TODO get winhome dir - File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "/Microsoft.NET/Framework"); + envs.put("FrameworkDir", frameworkDir.getPath()); String frameworkVersion = "v2.0.50727"; - envs.put( "FrameworkVersion", frameworkVersion ); + envs.put("FrameworkVersion", frameworkVersion); - File frameworkSDKDir = new File( vsInstallDir.getPath() + "/SDK/v2.0" ); - envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() ); + File frameworkSDKDir = new File(vsInstallDir.getPath() + "/SDK/v2.0"); + envs.put("FrameworkSDKDir", frameworkSDKDir.getPath()); - File devEnvDir = new File( vsInstallDir.getPath() + "/Common7/IDE" ); - envs.put( "DevEnvDir", devEnvDir.getPath() ); + File devEnvDir = new File(vsInstallDir.getPath() + "/Common7/IDE"); + envs.put("DevEnvDir", devEnvDir.getPath()); - File platformSDKDir = new File( vcInstallDir.getPath() + "/PlatformSDK" ); + File platformSDKDir = new File(vcInstallDir.getPath() + "/PlatformSDK"); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = devEnvDir.getPath() + ";" + vcInstallDir.getPath() + "\\BIN\\x86_amd64;" + vcInstallDir.getPath() + "\\BIN;" + vcInstallDir.getPath() + "\\Common7\\Tools;" @@ -80,40 +75,38 @@ protected Map createEnvs() + frameworkSDKDir.getPath() + "\\BIN;" + frameworkDir.getPath() + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\VCPackages;" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;" + platformSDKDir.getPath() + "\\INCLUDE;" + frameworkSDKDir.getPath() + "\\INCLUDE;" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = vcInstallDir.getPath() + "\\ATLMFC\\LIB\\AMD64;" + vcInstallDir.getPath() + "\\LIB\\AMD64;" + platformSDKDir.getPath() + "\\LIB\\AMD64;" + frameworkSDKDir.getPath() + "\\LIB\\AMD64;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); // // setup new LIBPATH // - String currentLibPathPath = EnvUtil.getEnv( "LIBPATH" ); + String currentLibPathPath = EnvUtil.getEnv("LIBPATH"); String newLibPathPath = vcInstallDir.getPath() + "\\ATLMFC\\LIB\\AMD64" + currentLibPathPath; - envs.put( "LIBPATH", newLibPathPath ); + envs.put("LIBPATH", newLibPathPath); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86EnvFactory.java index e807b2cb..9a591326 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2005x86EnvFactory.java @@ -26,78 +26,73 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of MSVC2005's vcvars32.bat */ - -public class MSVC2005x86EnvFactory - extends AbstractMSVC2005EnvFactory -{ +public class MSVC2005x86EnvFactory extends AbstractMSVC2005EnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { File vsInstallDir = new File( - EnvUtil.getEnv( MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR ) ); + EnvUtil.getEnv(MSVS2005_INSTALL_ENV_KEY, MSVS2005_INSTALL_ENV_KEY, DEFAULT_MSVS2005_INSTALL_DIR)); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); - envs.put( "VSINSTALLDIR", vsInstallDir.getPath() ); + envs.put("VSINSTALLDIR", vsInstallDir.getPath()); - File vcInstallDir = new File( vsInstallDir.getPath() + "/VC" ); - envs.put( "VCINSTALLDIR", vcInstallDir.getPath() ); + File vcInstallDir = new File(vsInstallDir.getPath() + "/VC"); + envs.put("VCINSTALLDIR", vcInstallDir.getPath()); - File frameworkDir = new File( getSystemRoot() + "/Microsoft.NET/Framework" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "/Microsoft.NET/Framework"); + envs.put("FrameworkDir", frameworkDir.getPath()); String frameworkVersion = "v2.0.50727"; - envs.put( "FrameworkVersion", frameworkVersion ); + envs.put("FrameworkVersion", frameworkVersion); - File frameworkSDKDir = new File( vsInstallDir.getPath() + "/SDK/v2.0" ); - envs.put( "FrameworkSDKDir", frameworkSDKDir.getPath() ); + File frameworkSDKDir = new File(vsInstallDir.getPath() + "/SDK/v2.0"); + envs.put("FrameworkSDKDir", frameworkSDKDir.getPath()); - File devEnvDir = new File( vsInstallDir.getPath() + "/Common7/IDE" ); - envs.put( "DevEnvDir", devEnvDir.getPath() ); + File devEnvDir = new File(vsInstallDir.getPath() + "/Common7/IDE"); + envs.put("DevEnvDir", devEnvDir.getPath()); - File platformSDKDir = new File( vcInstallDir.getPath() + "/PlatformSDK" ); + File platformSDKDir = new File(vcInstallDir.getPath() + "/PlatformSDK"); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = devEnvDir.getPath() + ";" + vcInstallDir.getPath() + "\\BIN;" + vcInstallDir.getPath() + "\\Common7\\Tools;" + vcInstallDir.getPath() + "\\Common7\\Tools\\bin;" + platformSDKDir.getPath() + "\\BIN;" + frameworkSDKDir.getPath() + "\\BIN;" + frameworkDir.getPath() + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\VCPackages;" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;" + platformSDKDir.getPath() + "\\INCLUDE;" + frameworkSDKDir.getPath() + "\\INCLUDE;" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = vcInstallDir.getPath() + "\\ATLMFC\\LIB;" + vcInstallDir.getPath() + "\\LIB;" + platformSDKDir.getPath() + "\\LIB;" + frameworkSDKDir.getPath() + "\\LIB;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); // // setup new LIBPATH @@ -106,13 +101,11 @@ protected Map createEnvs() String currentLibPathPath = frameworkDir.getPath() + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\ATLMFC\\LIB"; - envs.put( "LIBPATH", currentLibPathPath ); + envs.put("LIBPATH", currentLibPathPath); // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=473294&SiteID=1 - envs.put( "SystemRoot", getSystemRoot() ); + envs.put("SystemRoot", getSystemRoot()); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86AMD64EnvFactory.java index 0fc69e21..7e7aecdb 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86AMD64EnvFactory.java @@ -24,62 +24,55 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Microsoft Visual Studio 9.0\Common7\Tools\vcvarsx86_adm64.bat environment */ - -public class MSVC2008x86AMD64EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2008x86AMD64EnvFactory extends AbstractMSVCEnvFactory { private static final String VS90COMNTOOLS_ENV_KEY = "VS90COMNTOOLS"; @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { Map envs = new HashMap<>(); File vsCommonToolDir = this.getCommonToolDirectory(); - File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir ); + File vsInstallDir = this.getVisualStudioInstallDirectory(vsCommonToolDir); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } - envs.put( "VSINSTALLDIR", vsInstallDir.getPath() ); + envs.put("VSINSTALLDIR", vsInstallDir.getPath()); - File vcInstallDir = new File( vsInstallDir.getPath() + "\\VC" ); - if ( !vcInstallDir.isDirectory() ) - { - throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." ); + File vcInstallDir = new File(vsInstallDir.getPath() + "\\VC"); + if (!vcInstallDir.isDirectory()) { + throw new NativeBuildException(vcInstallDir.getPath() + " is not a directory."); } - envs.put( "VCINSTALLDIR", vcInstallDir.getPath() ); + envs.put("VCINSTALLDIR", vcInstallDir.getPath()); - File frameworkDir = new File( getSystemRoot() + "\\Microsoft.NET\\Framework" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "\\Microsoft.NET\\Framework"); + envs.put("FrameworkDir", frameworkDir.getPath()); - File windowsSDKDir = new File( "C:\\Program Files" + "\\Microsoft SDKs\\Windows\\v6.0A" ); - String value = RegQuery.getValue( "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows", - "CurrentInstallFolder" ); - if ( value != null ) - { - windowsSDKDir = new File( value ); + File windowsSDKDir = new File("C:\\Program Files" + "\\Microsoft SDKs\\Windows\\v6.0A"); + String value = RegQuery.getValue( + "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows", "CurrentInstallFolder"); + if (value != null) { + windowsSDKDir = new File(value); } - envs.put( "WindowsSdkDir", windowsSDKDir.getPath() ); + envs.put("WindowsSdkDir", windowsSDKDir.getPath()); String frameworkVersion = "v2.0.50727"; - envs.put( "FrameworkVersion", frameworkVersion ); + envs.put("FrameworkVersion", frameworkVersion); String framework35Version = "v3.5"; - envs.put( "Framework35Version", framework35Version ); + envs.put("Framework35Version", framework35Version); String devEnvDir = vsCommonToolDir + "\\..\\IDE"; - envs.put( "DevEnvDir", devEnvDir ); + envs.put("DevEnvDir", devEnvDir); // set "PATH=%WindowsSdkDir%bin;%PATH%" // @set PATH=C:\Program Files (x86)\Microsoft Visual Studio @@ -90,14 +83,14 @@ protected Map createEnvs() // Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;%PATH% // setup new PATH - String currentPathEnv = System.getProperty( "java.library.path" ); + String currentPathEnv = System.getProperty("java.library.path"); String newPathEnv = devEnvDir + ";" + vcInstallDir.getPath() + "\\bin\\x86_amd64;" + vcInstallDir.getPath() + "\\bin" + ";" + vsCommonToolDir + ";" + frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\VCPackages" + ";" + windowsSDKDir.getPath() + "\\bin;" + currentPathEnv; - envs.put( "PATH", newPathEnv ); + envs.put("PATH", newPathEnv); // setup new INCLUDE PATH // @set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio @@ -105,22 +98,22 @@ protected Map createEnvs() // Files // (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;%INCLUDE% - String currentIncludeEnv = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludeEnv = EnvUtil.getEnv("INCLUDE"); String newIncludeEnv = vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;" + windowsSDKDir.getPath() + "\\include;" + currentIncludeEnv; - envs.put( "INCLUDE", newIncludeEnv ); + envs.put("INCLUDE", newIncludeEnv); // // setup new LIB PATH // - String currentLibEnv = EnvUtil.getEnv( "LIB" ); + String currentLibEnv = EnvUtil.getEnv("LIB"); String newLibEnv = vcInstallDir.getPath() + "\\ATLMFC\\LIB\\amd64;" + vcInstallDir.getPath() + "\\LIB\\amd64;" + windowsSDKDir.getPath() + "\\LIB\\x64;" + currentLibEnv; - envs.put( "LIB", newLibEnv ); + envs.put("LIB", newLibEnv); // @set // LIBPATH=C:\Windows\Microsoft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program @@ -129,42 +122,32 @@ protected Map createEnvs() // Studio // 9.0\VC\LIB;%LIBPATH% - String currentLibPathEnv = EnvUtil.getEnv( "LIBPATH" ); + String currentLibPathEnv = EnvUtil.getEnv("LIBPATH"); String newLibPathEnv = frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\ATLMFC\\LIB\\amd64;" + vcInstallDir.getPath() + "\\LIB\\amd64;" + currentLibPathEnv; - envs.put( "LIBPATH", newLibPathEnv ); + envs.put("LIBPATH", newLibPathEnv); return envs; - } - private File getCommonToolDirectory() - throws NativeBuildException - { - String envValue = System.getenv( VS90COMNTOOLS_ENV_KEY ); - if ( envValue == null ) - { - throw new NativeBuildException( "Environment variable: " + VS90COMNTOOLS_ENV_KEY + " not available." ); + private File getCommonToolDirectory() throws NativeBuildException { + String envValue = System.getenv(VS90COMNTOOLS_ENV_KEY); + if (envValue == null) { + throw new NativeBuildException("Environment variable: " + VS90COMNTOOLS_ENV_KEY + " not available."); } - return new File( envValue ); + return new File(envValue); } - private File getVisualStudioInstallDirectory( File commonToolDir ) - throws NativeBuildException - { - try - { - return new File( commonToolDir, "../.." ).getCanonicalFile(); - } - catch ( IOException e ) - { + private File getVisualStudioInstallDirectory(File commonToolDir) throws NativeBuildException { + try { + return new File(commonToolDir, "../..").getCanonicalFile(); + } catch (IOException e) { throw new NativeBuildException( - "Unable to contruct Visual Studio install directory using: " + commonToolDir, e ); + "Unable to contruct Visual Studio install directory using: " + commonToolDir, e); } } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86EnvFactory.java index 4fed7063..beca1610 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2008x86EnvFactory.java @@ -24,62 +24,55 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat environment */ - -public class MSVC2008x86EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2008x86EnvFactory extends AbstractMSVCEnvFactory { private static final String VS90COMNTOOLS_ENV_KEY = "VS90COMNTOOLS"; @Override - protected Map createEnvs() - throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { Map envs = new HashMap<>(); File vsCommonToolDir = this.getCommonToolDirectory(); - File vsInstallDir = this.getVisualStudioInstallDirectory( vsCommonToolDir ); + File vsInstallDir = this.getVisualStudioInstallDirectory(vsCommonToolDir); - if ( !vsInstallDir.isDirectory() ) - { - throw new NativeBuildException( vsInstallDir.getPath() + " is not a directory." ); + if (!vsInstallDir.isDirectory()) { + throw new NativeBuildException(vsInstallDir.getPath() + " is not a directory."); } - envs.put( "VSINSTALLDIR", vsInstallDir.getPath() ); + envs.put("VSINSTALLDIR", vsInstallDir.getPath()); - File vcInstallDir = new File( vsInstallDir.getPath() + "\\VC" ); - if ( !vcInstallDir.isDirectory() ) - { - throw new NativeBuildException( vcInstallDir.getPath() + " is not a directory." ); + File vcInstallDir = new File(vsInstallDir.getPath() + "\\VC"); + if (!vcInstallDir.isDirectory()) { + throw new NativeBuildException(vcInstallDir.getPath() + " is not a directory."); } - envs.put( "VCINSTALLDIR", vcInstallDir.getPath() ); + envs.put("VCINSTALLDIR", vcInstallDir.getPath()); - File frameworkDir = new File( getSystemRoot() + "\\Microsoft.NET\\Framework" ); - envs.put( "FrameworkDir", frameworkDir.getPath() ); + File frameworkDir = new File(getSystemRoot() + "\\Microsoft.NET\\Framework"); + envs.put("FrameworkDir", frameworkDir.getPath()); - File windowsSDKDir = new File( "C:\\Program Files" + "\\Microsoft SDKs\\Windows\\v6.0A" ); - String value = RegQuery.getValue( "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows", - "CurrentInstallFolder" ); - if ( value != null ) - { - windowsSDKDir = new File( value ); + File windowsSDKDir = new File("C:\\Program Files" + "\\Microsoft SDKs\\Windows\\v6.0A"); + String value = RegQuery.getValue( + "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows", "CurrentInstallFolder"); + if (value != null) { + windowsSDKDir = new File(value); } - envs.put( "WindowsSdkDir", windowsSDKDir.getPath() ); + envs.put("WindowsSdkDir", windowsSDKDir.getPath()); String frameworkVersion = "v2.0.50727"; - envs.put( "FrameworkVersion", frameworkVersion ); + envs.put("FrameworkVersion", frameworkVersion); String framework35Version = "v3.5"; - envs.put( "Framework35Version", framework35Version ); + envs.put("Framework35Version", framework35Version); String devEnvDir = vsCommonToolDir + "\\..\\IDE"; - envs.put( "DevEnvDir", devEnvDir ); + envs.put("DevEnvDir", devEnvDir); // set "PATH=%WindowsSdkDir%bin;%PATH%" // @set PATH=C:\Program Files (x86)\Microsoft Visual Studio @@ -90,13 +83,13 @@ protected Map createEnvs() // Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;%PATH% // setup new PATH - String currentPathEnv = System.getProperty( "java.library.path" ); + String currentPathEnv = System.getProperty("java.library.path"); String newPathEnv = devEnvDir + ";" + vcInstallDir.getPath() + "\\bin" + ";" + vsCommonToolDir + ";" + frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\VCPackages" + ";" + windowsSDKDir.getPath() + "\\bin;" + currentPathEnv; - envs.put( "PATH", newPathEnv ); + envs.put("PATH", newPathEnv); // setup new INCLUDE PATH // @set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio @@ -104,12 +97,12 @@ protected Map createEnvs() // Files // (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;%INCLUDE% - String currentIncludeEnv = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludeEnv = EnvUtil.getEnv("INCLUDE"); String newIncludeEnv = vcInstallDir.getPath() + "\\ATLMFC\\INCLUDE;" + vcInstallDir.getPath() + "\\INCLUDE;" + windowsSDKDir.getPath() + "\\include;" + currentIncludeEnv; - envs.put( "INCLUDE", newIncludeEnv ); + envs.put("INCLUDE", newIncludeEnv); // // setup new LIB PATH @@ -118,12 +111,12 @@ protected Map createEnvs() // (x86)\Microsoft // Visual Studio 9.0\VC\LIB;%LIB% // - String currentLibEnv = EnvUtil.getEnv( "LIB" ); + String currentLibEnv = EnvUtil.getEnv("LIB"); String newLibEnv = vcInstallDir.getPath() + "\\ATLMFC\\LIB;" + vcInstallDir.getPath() + "\\LIB;" + windowsSDKDir.getPath() + "\\LIB;" + currentLibEnv; - envs.put( "LIB", newLibEnv ); + envs.put("LIB", newLibEnv); // @set // LIBPATH=C:\Windows\Microsoft.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program @@ -132,42 +125,32 @@ protected Map createEnvs() // Studio // 9.0\VC\LIB;%LIBPATH% - String currentLibPathEnv = EnvUtil.getEnv( "LIBPATH" ); + String currentLibPathEnv = EnvUtil.getEnv("LIBPATH"); String newLibPathEnv = frameworkDir + "\\" + framework35Version + ";" + frameworkDir + "\\" + frameworkVersion + ";" + vcInstallDir.getPath() + "\\ATLMFC\\LIB;" + vcInstallDir.getPath() + "\\LIB;" + currentLibPathEnv; - envs.put( "LIBPATH", newLibPathEnv ); + envs.put("LIBPATH", newLibPathEnv); return envs; - } - private File getCommonToolDirectory() - throws NativeBuildException - { - String envValue = System.getenv( VS90COMNTOOLS_ENV_KEY ); - if ( envValue == null ) - { - throw new NativeBuildException( "Environment variable: " + VS90COMNTOOLS_ENV_KEY + " not available." ); + private File getCommonToolDirectory() throws NativeBuildException { + String envValue = System.getenv(VS90COMNTOOLS_ENV_KEY); + if (envValue == null) { + throw new NativeBuildException("Environment variable: " + VS90COMNTOOLS_ENV_KEY + " not available."); } - return new File( envValue ); + return new File(envValue); } - private File getVisualStudioInstallDirectory( File commonToolDir ) - throws NativeBuildException - { - try - { - return new File( commonToolDir, "../.." ).getCanonicalFile(); - } - catch ( IOException e ) - { + private File getVisualStudioInstallDirectory(File commonToolDir) throws NativeBuildException { + try { + return new File(commonToolDir, "../..").getCanonicalFile(); + } catch (IOException e) { throw new NativeBuildException( - "Unable to contruct Visual Studio install directory using: " + commonToolDir, e ); + "Unable to contruct Visual Studio install directory using: " + commonToolDir, e); } } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86AMD64EnvFactory.java index 87acddb3..23d3d4c0 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86AMD64EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2010x86AMD64EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2010x86AMD64EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS100COMNTOOLS", "amd64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS100COMNTOOLS", "amd64"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86EnvFactory.java index 551b8107..5937bbfc 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2010x86EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2010x86EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2010x86EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS100COMNTOOLS", "x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS100COMNTOOLS", "x86"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86AMD64EnvFactory.java index 9e695979..94e6f41d 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86AMD64EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2012x86AMD64EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2012x86AMD64EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS110COMNTOOLS", "amd64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS110COMNTOOLS", "amd64"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86EnvFactory.java index 20457524..222ac483 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2012x86EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2012x86EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2012x86EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS110COMNTOOLS", "x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS110COMNTOOLS", "x86"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86AMD64EnvFactory.java index e0344852..b4a9e2bb 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86AMD64EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2013x86AMD64EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2013x86AMD64EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS120COMNTOOLS", "amd64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS120COMNTOOLS", "amd64"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86EnvFactory.java index 5433afba..2aa1f546 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2013x86EnvFactory.java @@ -1,17 +1,13 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2013x86EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC2013x86EnvFactory extends AbstractMSVCEnvFactory { @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS120COMNTOOLS", "x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS120COMNTOOLS", "x86"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019AMD64x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019AMD64x86EnvFactory.java index 7db422b6..5d96e9a1 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019AMD64x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019AMD64x86EnvFactory.java @@ -1,35 +1,28 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2019AMD64x86EnvFactory - extends AbstractMSVC2019EnvFactory -{ +public class MSVC2019AMD64x86EnvFactory extends AbstractMSVC2019EnvFactory { /** * Each env factory needs its own static field, otherwise - * the different "vcvarsall " calls will end up + * the different "vcvarsall " calls will end up * colliding with each other. */ private static Map envs2019amd64x86; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs2019amd64x86 == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs2019amd64x86 == null) { envs2019amd64x86 = createEnvs(); } return envs2019amd64x86; } - + @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS160COMNTOOLS", "x64_x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS160COMNTOOLS", "x64_x86"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x64EnvFactory.java index 983236a7..da4d8906 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x64EnvFactory.java @@ -1,24 +1,20 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2019x64EnvFactory - extends AbstractMSVC2019EnvFactory -{ +public class MSVC2019x64EnvFactory extends AbstractMSVC2019EnvFactory { /** * Each env factory needs its own static field, otherwise - * the different "vcvarsall " calls will end up + * the different "vcvarsall " calls will end up * colliding with each other. */ private static Map envs2019x64; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs2019x64 == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs2019x64 == null) { envs2019x64 = createEnvs(); } @@ -26,10 +22,7 @@ public synchronized Map getEnvironmentVariables() } @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS160COMNTOOLS", "x64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS160COMNTOOLS", "x64"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86AMD64EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86AMD64EnvFactory.java index 9c2e50c7..d222d509 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86AMD64EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86AMD64EnvFactory.java @@ -1,36 +1,29 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2019x86AMD64EnvFactory - extends AbstractMSVC2019EnvFactory -{ +public class MSVC2019x86AMD64EnvFactory extends AbstractMSVC2019EnvFactory { /** * Each env factory needs its own static field, otherwise - * the different "vcvarsall " calls will end up + * the different "vcvarsall " calls will end up * colliding with each other. */ private static Map envs2019x86amd64; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs2019x86amd64 == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs2019x86amd64 == null) { envs2019x86amd64 = createEnvs(); } return envs2019x86amd64; } - + @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS160COMNTOOLS", "x86_x64" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS160COMNTOOLS", "x86_x64"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86EnvFactory.java index 6fba428a..a54228d5 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC2019x86EnvFactory.java @@ -1,25 +1,21 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; -public class MSVC2019x86EnvFactory - extends AbstractMSVC2019EnvFactory -{ - +public class MSVC2019x86EnvFactory extends AbstractMSVC2019EnvFactory { + /** * Each env factory needs its own static field, otherwise - * the different "vcvarsall " calls will end up + * the different "vcvarsall " calls will end up * colliding with each other. */ private static Map envs2019x86; @Override - public synchronized Map getEnvironmentVariables() - throws NativeBuildException - { - if ( envs2019x86 == null ) - { + public synchronized Map getEnvironmentVariables() throws NativeBuildException { + if (envs2019x86 == null) { envs2019x86 = createEnvs(); } @@ -27,10 +23,7 @@ public synchronized Map getEnvironmentVariables() } @Override - protected Map createEnvs() - throws NativeBuildException - { - return this.createEnvs( "VS160COMNTOOLS", "x86" ); + protected Map createEnvs() throws NativeBuildException { + return this.createEnvs("VS160COMNTOOLS", "x86"); } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC6EnvFactory.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC6EnvFactory.java index 9f5a6344..c1c06bb1 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC6EnvFactory.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVC6EnvFactory.java @@ -26,76 +26,68 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.util.EnvUtil; /** * Equivalent of MSVC6's vcvars32.bat */ - -public class MSVC6EnvFactory - extends AbstractMSVCEnvFactory -{ +public class MSVC6EnvFactory extends AbstractMSVCEnvFactory { private static final String MSVS6_INSTALL_ENV_KEY = "MSVS6_INSTALL_DIR"; private static final String DEFAULT_MSVS6_INSTALL_DIR = getProgramFilesX86() + "/Microsoft Visual Studio"; @Override - protected Map createEnvs() - throws NativeBuildException - { - File vsDir = - new File( EnvUtil.getEnv( MSVS6_INSTALL_ENV_KEY, MSVS6_INSTALL_ENV_KEY, DEFAULT_MSVS6_INSTALL_DIR ) ); - - if ( !vsDir.isDirectory() ) - { - throw new NativeBuildException( vsDir.getPath() + " is not a directory." ); + protected Map createEnvs() throws NativeBuildException { + File vsDir = new File(EnvUtil.getEnv(MSVS6_INSTALL_ENV_KEY, MSVS6_INSTALL_ENV_KEY, DEFAULT_MSVS6_INSTALL_DIR)); + + if (!vsDir.isDirectory()) { + throw new NativeBuildException(vsDir.getPath() + " is not a directory."); } Map envs = new HashMap<>(); String vcOsDir = "WINNT"; - String winDir = EnvUtil.getEnv( "windir" ); + String winDir = EnvUtil.getEnv("windir"); - File vsCommonDir = new File( vsDir + "/Common" ); + File vsCommonDir = new File(vsDir + "/Common"); - File vsCommonToolDir = new File( vsCommonDir + "/TOOLS" ); + File vsCommonToolDir = new File(vsCommonDir + "/TOOLS"); - File msDevDir = new File( vsCommonDir + "/msdev98" ); + File msDevDir = new File(vsCommonDir + "/msdev98"); - File msvcDir = new File( vsDir + "/VC98" ); + File msvcDir = new File(vsDir + "/VC98"); - envs.put( "MSVCDir", msvcDir.getPath() ); + envs.put("MSVCDir", msvcDir.getPath()); // setup new PATH - String currentPath = System.getProperty( "java.library.path" ); + String currentPath = System.getProperty("java.library.path"); String newPath = msDevDir.getPath() + "\\BIN;" + msvcDir.getPath() + "\\BIN;" + vsCommonToolDir.getPath() + "\\" + vcOsDir + ";" + vsCommonToolDir.getPath() + ";" + winDir + ";" + currentPath; - envs.put( "PATH", newPath ); + envs.put("PATH", newPath); // setup new INCLUDE PATH - String currentIncludePath = EnvUtil.getEnv( "INCLUDE" ); + String currentIncludePath = EnvUtil.getEnv("INCLUDE"); String newIncludePath = msvcDir.getPath() + "\\ATL\\INCLUDE;" + msvcDir.getPath() + "\\INCLUDE;" + msvcDir.getPath() + "\\MFC\\INCLUDE;" + vsCommonToolDir.getPath() + vcOsDir + ";" + vsCommonToolDir.getPath() + ";" + currentIncludePath; - envs.put( "INCLUDE", newIncludePath ); + envs.put("INCLUDE", newIncludePath); // // setup new LIB PATH // - String currentLibPath = EnvUtil.getEnv( "LIB" ); + String currentLibPath = EnvUtil.getEnv("LIB"); String newLibPath = msvcDir.getPath() + "\\LIB;" + msvcDir.getPath() + "\\MFC\\LIB;" + currentLibPath; - envs.put( "LIB", newLibPath ); + envs.put("LIB", newLibPath); return envs; - } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCCompiler.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCCompiler.java index 49726ed6..476de28e 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCCompiler.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCCompiler.java @@ -26,6 +26,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.c.AbstractCCompiler; import org.codehaus.mojo.natives.compiler.Compiler; @@ -34,20 +35,15 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = Compiler.class, hint = "msvc") -public class MSVCCompiler - extends AbstractCCompiler -{ +public class MSVCCompiler extends AbstractCCompiler { private Map environmentVariables; - protected void setEnvironmentVariables( Map envs ) - { + protected void setEnvironmentVariables(Map envs) { this.environmentVariables = envs; } - protected Map getEnvironmentVariables() - { - if ( this.environmentVariables == null ) - { + protected Map getEnvironmentVariables() { + if (this.environmentVariables == null) { return new HashMap<>(); } @@ -55,23 +51,19 @@ protected Map getEnvironmentVariables() } @Override - protected String getOutputFileOption() - { + protected String getOutputFileOption() { return "/Fo"; } @Override - protected Commandline getCommandLine( File src, File dest, CompilerConfiguration config ) - throws NativeBuildException - { - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "cl.exe" ); + protected Commandline getCommandLine(File src, File dest, CompilerConfiguration config) + throws NativeBuildException { + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("cl.exe"); } - Commandline cl = super.getCommandLine( src, dest, config ); + Commandline cl = super.getCommandLine(src, dest, config); return cl; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCLinker.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCLinker.java index 5ed4c14d..a2fac5e5 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCLinker.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCLinker.java @@ -25,6 +25,7 @@ import java.io.File; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.c.CLinker; import org.codehaus.mojo.natives.linker.Linker; @@ -33,27 +34,21 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = Linker.class, hint = "msvc") -public class MSVCLinker - extends CLinker -{ +public class MSVCLinker extends CLinker { - protected Commandline createLinkerCommandLine( List objectFiles, LinkerConfiguration config ) - throws NativeBuildException - { - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "link.exe" ); + protected Commandline createLinkerCommandLine(List objectFiles, LinkerConfiguration config) + throws NativeBuildException { + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("link.exe"); } - Commandline cl = super.createLinkerCommandLine( objectFiles, config ); + Commandline cl = super.createLinkerCommandLine(objectFiles, config); return cl; } @Override - protected String getLinkerOutputOption() - { + protected String getLinkerOutputOption() { return "/out:"; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCManifest.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCManifest.java index 3df3bd6f..395f7b40 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCManifest.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCManifest.java @@ -34,41 +34,33 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = Manifest.class, hint = "msvc", instantiationStrategy = "per-lookup") -public class MSVCManifest - extends AbstractLogEnabled - implements Manifest -{ - public void run( ManifestConfiguration config ) - throws NativeBuildException - { +public class MSVCManifest extends AbstractLogEnabled implements Manifest { + public void run(ManifestConfiguration config) throws NativeBuildException { Commandline cl = new Commandline(); - cl.setExecutable( "mt.exe" ); - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + cl.setExecutable("mt.exe"); + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); - cl.createArg().setValue( "-manifest" ); + cl.createArg().setValue("-manifest"); int manifestType = 0; - if ( "EXE".equalsIgnoreCase( FileUtils.getExtension( config.getInputFile().getPath() ) ) ) - { + if ("EXE".equalsIgnoreCase(FileUtils.getExtension(config.getInputFile().getPath()))) { manifestType = 1; - } - else if ( "DLL".equalsIgnoreCase( FileUtils.getExtension( config.getInputFile().getPath() ) ) ) - { + } else if ("DLL" + .equalsIgnoreCase(FileUtils.getExtension(config.getInputFile().getPath()))) { manifestType = 2; } - if ( manifestType == 0 ) - { - throw new NativeBuildException( "Unknown manifest input file type: " + config.getInputFile() ); + if (manifestType == 0) { + throw new NativeBuildException("Unknown manifest input file type: " + config.getInputFile()); } - cl.createArg().setFile( config.getManifestFile() ); - cl.createArg().setValue( "-outputresource:" + config.getInputFile() + ";" + manifestType ); + cl.createArg().setFile(config.getManifestFile()); + cl.createArg().setValue("-outputresource:" + config.getInputFile() + ";" + manifestType); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - CommandLineUtil.execute( cl, this.getLogger() ); + CommandLineUtil.execute(cl, this.getLogger()); } } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCMessageCompiler.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCMessageCompiler.java index f9f793e7..adf53b3f 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCMessageCompiler.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCMessageCompiler.java @@ -23,62 +23,53 @@ */ package org.codehaus.mojo.natives.msvc; +import java.io.File; + import org.codehaus.mojo.natives.NativeBuildException; -import org.codehaus.mojo.natives.compiler.MessageCompilerConfiguration; import org.codehaus.mojo.natives.compiler.AbstractMessageCompiler; -import org.codehaus.mojo.natives.util.EnvUtil; -import org.codehaus.plexus.util.cli.Commandline; - -import java.io.File; import org.codehaus.mojo.natives.compiler.MessageCompiler; +import org.codehaus.mojo.natives.compiler.MessageCompilerConfiguration; +import org.codehaus.mojo.natives.util.EnvUtil; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.cli.Commandline; @Component(role = MessageCompiler.class, hint = "msvc") -public class MSVCMessageCompiler - extends AbstractMessageCompiler -{ +public class MSVCMessageCompiler extends AbstractMessageCompiler { - protected Commandline getCommandLine( MessageCompilerConfiguration config, File source ) - throws NativeBuildException - { + protected Commandline getCommandLine(MessageCompilerConfiguration config, File source) throws NativeBuildException { Commandline cl = new Commandline(); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "mc.exe" ); + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("mc.exe"); } - cl.setExecutable( config.getExecutable().trim() ); - - cl.addArguments( config.getOptions() ); + cl.setExecutable(config.getExecutable().trim()); - if ( config.getOutputDirectory() != null && config.getOutputDirectory().getPath().trim().length() != 0 ) - { - cl.createArg().setValue( "-r" ); - cl.createArg().setValue( config.getOutputDirectory().getPath() ); + cl.addArguments(config.getOptions()); - cl.createArg().setValue( "-h" ); - cl.createArg().setValue( config.getOutputDirectory().getPath() ); + if (config.getOutputDirectory() != null + && config.getOutputDirectory().getPath().trim().length() != 0) { + cl.createArg().setValue("-r"); + cl.createArg().setValue(config.getOutputDirectory().getPath()); + cl.createArg().setValue("-h"); + cl.createArg().setValue(config.getOutputDirectory().getPath()); } - if ( config.getDebugOutputDirectory() != null - && config.getDebugOutputDirectory().getPath().trim().length() != 0 ) - { - cl.createArg().setValue( "-x" ); - cl.createArg().setValue( config.getDebugOutputDirectory().getPath() ); + if (config.getDebugOutputDirectory() != null + && config.getDebugOutputDirectory().getPath().trim().length() != 0) { + cl.createArg().setValue("-x"); + cl.createArg().setValue(config.getDebugOutputDirectory().getPath()); } - cl.createArg().setValue( source.getPath() ); + cl.createArg().setValue(source.getPath()); return cl; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCResourceCompiler.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCResourceCompiler.java index 47155b1b..df70483c 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCResourceCompiler.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/MSVCResourceCompiler.java @@ -34,56 +34,48 @@ import org.codehaus.plexus.util.cli.Commandline; @Component(role = ResourceCompiler.class, hint = "msvc") -public class MSVCResourceCompiler - extends AbstractResourceCompiler -{ +public class MSVCResourceCompiler extends AbstractResourceCompiler { - protected Commandline getCommandLine( ResourceCompilerConfiguration config, File source ) - throws NativeBuildException - { + protected Commandline getCommandLine(ResourceCompilerConfiguration config, File source) + throws NativeBuildException { Commandline cl = new Commandline(); - EnvUtil.setupCommandlineEnv( cl, config.getEnvFactory() ); + EnvUtil.setupCommandlineEnv(cl, config.getEnvFactory()); - if ( config.getWorkingDirectory() != null ) - { - cl.setWorkingDirectory( config.getWorkingDirectory().getPath() ); + if (config.getWorkingDirectory() != null) { + cl.setWorkingDirectory(config.getWorkingDirectory().getPath()); } - if ( config.getExecutable() == null || config.getExecutable().trim().length() == 0 ) - { - config.setExecutable( "rc.exe" ); + if (config.getExecutable() == null || config.getExecutable().trim().length() == 0) { + config.setExecutable("rc.exe"); } - cl.setExecutable( config.getExecutable().trim() ); + cl.setExecutable(config.getExecutable().trim()); - cl.addArguments( config.getOptions() ); + cl.addArguments(config.getOptions()); - for ( int i = 0; i < config.getIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getIncludePaths().length; ++i) { String includePath = config.getIncludePaths()[i].getPath(); - cl.createArg().setValue( "/i" ); + cl.createArg().setValue("/i"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - for ( int i = 0; i < config.getSystemIncludePaths().length; ++i ) - { + for (int i = 0; i < config.getSystemIncludePaths().length; ++i) { String includePath = config.getSystemIncludePaths()[i].getPath(); - cl.createArg().setValue( "/i" ); + cl.createArg().setValue("/i"); - cl.createArg().setValue( includePath ); + cl.createArg().setValue(includePath); } - cl.createArg().setValue( "/fo" ); + cl.createArg().setValue("/fo"); - cl.createArg().setValue( config.getOutputFile( source ).getPath() ); + cl.createArg().setValue(config.getOutputFile(source).getPath()); - cl.createArg().setValue( source.getPath() ); + cl.createArg().setValue(source.getPath()); return cl; } - } diff --git a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/RegQuery.java b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/RegQuery.java index 6cb13190..19719b33 100644 --- a/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/RegQuery.java +++ b/maven-native-components/maven-native-msvc/src/main/java/org/codehaus/mojo/natives/msvc/RegQuery.java @@ -5,44 +5,36 @@ import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; -public class RegQuery -{ - public static String getValue( String valueType, String folderName, String folderKey ) - throws NativeBuildException - { +public class RegQuery { + public static String getValue(String valueType, String folderName, String folderKey) throws NativeBuildException { Commandline cl = new Commandline(); - cl.setExecutable( "reg" ); - cl.createArg().setValue( "query" ); - cl.createArg().setValue( folderName ); - cl.createArg().setValue( "/v" ); - cl.createArg().setValue( folderKey ); + cl.setExecutable("reg"); + cl.createArg().setValue("query"); + cl.createArg().setValue(folderName); + cl.createArg().setValue("/v"); + cl.createArg().setValue(folderKey); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); - try - { - int ok = CommandLineUtils.executeCommandLine( cl, stdout, stderr ); + try { + int ok = CommandLineUtils.executeCommandLine(cl, stdout, stderr); - if ( ok != 0 ) - { + if (ok != 0) { return null; } - } - catch ( CommandLineException e ) - { - throw new NativeBuildException( e.getMessage(), e ); + } catch (CommandLineException e) { + throw new NativeBuildException(e.getMessage(), e); } String result = stdout.getOutput(); - int p = result.indexOf( valueType ); + int p = result.indexOf(valueType); - if ( p == -1 ) - { + if (p == -1) { return null; } - return result.substring( p + valueType.length() ).trim(); + return result.substring(p + valueType.length()).trim(); } } diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactoryTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactoryTest.java index 08e16782..981b0f1e 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactoryTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/AbstractCommunityEnvFactoryTest.java @@ -1,153 +1,110 @@ package org.codehaus.mojo.natives.msvc; -import org.codehaus.mojo.natives.NativeBuildException; -import org.codehaus.plexus.PlexusTestCase; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.cli.Commandline; - import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; -public class AbstractCommunityEnvFactoryTest - extends PlexusTestCase -{ +import org.codehaus.mojo.natives.NativeBuildException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.cli.Commandline; + +public class AbstractCommunityEnvFactoryTest extends PlexusTestCase { - public void testPathValidation() throws IOException - { + public void testPathValidation() throws IOException { CommunityEnvFactoryMock mock = new CommunityEnvFactoryMock(); - try - { - mock.setVsInstallPathMock( "C:\\Program Files\\VS 2017\\Ultimate" ); - mock.createEnvs( "17.0", "x86" ); - fail( "Path validation must fail" ); - } - catch ( NativeBuildException e ) - { + try { + mock.setVsInstallPathMock("C:\\Program Files\\VS 2017\\Ultimate"); + mock.createEnvs("17.0", "x86"); + fail("Path validation must fail"); + } catch (NativeBuildException e) { assertEquals( - e.getMessage(), - "Directory 'C:\\Program Files\\VS 2017\\Ultimate' is not a VS Community directory" - ); + e.getMessage(), "Directory 'C:\\Program Files\\VS 2017\\Ultimate' is not a VS Community directory"); } - try - { - mock.setVsInstallPathMock( null ); - mock.createEnvs( "17.0", "x86" ); - fail( "Path validation must fail" ); - } - catch ( NativeBuildException e ) - { - assertEquals( - e.getMessage(), - "Can not find VS Community version '17.0'" - ); + try { + mock.setVsInstallPathMock(null); + mock.createEnvs("17.0", "x86"); + fail("Path validation must fail"); + } catch (NativeBuildException e) { + assertEquals(e.getMessage(), "Can not find VS Community version '17.0'"); } - File tempDir = createCommunityDir( true ); - try - { - mock.setVsInstallPathMock( tempDir.getAbsolutePath() ); - mock.createEnvs( "17.0", "x86" ); - fail( "Path validation must fail" ); - } - catch ( NativeBuildException e ) - { - assertEquals( - e.getMessage(), - String.format( "Path '%s' is not a directory", tempDir.getAbsolutePath() ) - ); + File tempDir = createCommunityDir(true); + try { + mock.setVsInstallPathMock(tempDir.getAbsolutePath()); + mock.createEnvs("17.0", "x86"); + fail("Path validation must fail"); + } catch (NativeBuildException e) { + assertEquals(e.getMessage(), String.format("Path '%s' is not a directory", tempDir.getAbsolutePath())); } } - public void testCommandGeneration() throws IOException - { + public void testCommandGeneration() throws IOException { CommunityEnvFactoryMock mock = new CommunityEnvFactoryMock(); - File tempDir = createCommunityDir( false ); - try - { - mock.setVsInstallPathMock( tempDir.getAbsolutePath() ); - mock.createEnvs( "17.0", "x64" ); - assertTrue( mock.getRecordedCommandFileContent().contains( tempDir.getAbsolutePath() ) ); - } - catch ( NativeBuildException e ) - { - fail( "Must not fail" ); + File tempDir = createCommunityDir(false); + try { + mock.setVsInstallPathMock(tempDir.getAbsolutePath()); + mock.createEnvs("17.0", "x64"); + assertTrue(mock.getRecordedCommandFileContent().contains(tempDir.getAbsolutePath())); + } catch (NativeBuildException e) { + fail("Must not fail"); } } - private File createCommunityDir(boolean isFile) throws IOException - { - File tempDir = FileUtils.createTempFile( "test", "dir", null ); - if ( !tempDir.mkdir() ) - { - fail( "Failed to create temporary directory" ); + private File createCommunityDir(boolean isFile) throws IOException { + File tempDir = FileUtils.createTempFile("test", "dir", null); + if (!tempDir.mkdir()) { + fail("Failed to create temporary directory"); } - File tempCommunityFile = new File( - tempDir, - "Community" - ); - if ( isFile ) - { - if ( !tempCommunityFile.createNewFile() ) - { - fail( "Failed to create Community file" ); + File tempCommunityFile = new File(tempDir, "Community"); + if (isFile) { + if (!tempCommunityFile.createNewFile()) { + fail("Failed to create Community file"); } - } - else - { - if ( !tempCommunityFile.mkdir() ) - { - fail( "Failed to create Community directory" ); + } else { + if (!tempCommunityFile.mkdir()) { + fail("Failed to create Community directory"); } } - FileUtils.forceDeleteOnExit( tempDir ); - FileUtils.forceDeleteOnExit( tempCommunityFile ); + FileUtils.forceDeleteOnExit(tempDir); + FileUtils.forceDeleteOnExit(tempCommunityFile); return tempCommunityFile; } } -class CommunityEnvFactoryMock extends AbstractCommunityEnvFactory -{ +class CommunityEnvFactoryMock extends AbstractCommunityEnvFactory { private String vsInstallPathMock; private String recordedCommandFile; - void setVsInstallPathMock(String value) - { + void setVsInstallPathMock(String value) { vsInstallPathMock = value; } - String getRecordedCommandFileContent() - { + String getRecordedCommandFileContent() { return recordedCommandFile; } @Override - protected String queryVSInstallPath(String version) - { + protected String queryVSInstallPath(String version) { return vsInstallPathMock; } @Override - protected Map executeCommandLine(Commandline command) throws NativeBuildException - { - try - { - recordedCommandFile = FileUtils.fileRead( command.getLiteralExecutable() ); - } - catch ( IOException e ) - { - throw new NativeBuildException( "Failed to capture file output" ); + protected Map executeCommandLine(Commandline command) throws NativeBuildException { + try { + recordedCommandFile = FileUtils.fileRead(command.getLiteralExecutable()); + } catch (IOException e) { + throw new NativeBuildException("Failed to capture file output"); } return new HashMap<>(); } @Override - protected Map createEnvs() throws NativeBuildException - { + protected Map createEnvs() throws NativeBuildException { return null; } -} \ No newline at end of file +} diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2012EnvFactoryTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2012EnvFactoryTest.java index c71a88ea..4660d7cc 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2012EnvFactoryTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2012EnvFactoryTest.java @@ -1,25 +1,20 @@ package org.codehaus.mojo.natives.msvc; import java.util.Map; + import org.codehaus.plexus.PlexusTestCase; import org.junit.Assert; -public class MSVC2012EnvFactoryTest - extends PlexusTestCase -{ +public class MSVC2012EnvFactoryTest extends PlexusTestCase { - public void testMSVC2012x86Env() - { + public void testMSVC2012x86Env() { - if ( System.getenv( "VS110COMNTOOLS" ) != null ) - { + if (System.getenv("VS110COMNTOOLS") != null) { MSVC2012x86EnvFactory envFact = new MSVC2012x86EnvFactory(); Map env = envFact.getEnvironmentVariables(); - Assert.assertTrue( env.containsKey( "VSINSTALLDIR" ) ); - Assert.assertTrue( env.containsKey( "INCLUDE" ) ); - Assert.assertTrue( env.containsKey( "FrameworkVersion32" ) ); + Assert.assertTrue(env.containsKey("VSINSTALLDIR")); + Assert.assertTrue(env.containsKey("INCLUDE")); + Assert.assertTrue(env.containsKey("FrameworkVersion32")); } - } - } diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2019EnvFactoryTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2019EnvFactoryTest.java index 661c54c2..42cff533 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2019EnvFactoryTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/MSVC2019EnvFactoryTest.java @@ -1,110 +1,93 @@ package org.codehaus.mojo.natives.msvc; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.logging.LoggerManager; - import java.util.Map; import java.util.TreeMap; import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.LoggerManager; import org.junit.Assert; - -public class MSVC2019EnvFactoryTest - extends PlexusTestCase -{ +public class MSVC2019EnvFactoryTest extends PlexusTestCase { private Logger logger; - - public Logger getLogger() - { + + public Logger getLogger() { return logger; } - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - LoggerManager loggerManager = lookup( LoggerManager.class ); + LoggerManager loggerManager = lookup(LoggerManager.class); - logger = loggerManager.getLoggerForComponent( this.getClass().toString() ); + logger = loggerManager.getLoggerForComponent(this.getClass().toString()); } - - public void testMSVC2019x64Env() - { - if ( System.getenv( "VS160COMNTOOLS" ) != null ) - { + public void testMSVC2019x64Env() { + + if (System.getenv("VS160COMNTOOLS") != null) { MSVC2019x64EnvFactory envFact = new MSVC2019x64EnvFactory(); Map env = envFact.getEnvironmentVariables(); - logger.info( envFact.getClass().getName()+"env="+env ); - Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + logger.info(envFact.getClass().getName() + "env=" + env); + Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); envCaseInsenstiveKeys.putAll(env); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSINSTALLDIR" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "INCLUDE" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertEquals( "x64", envCaseInsenstiveKeys.get( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_TGT_ARCH" ) ); - Assert.assertEquals( "x64", envCaseInsenstiveKeys.get( "VSCMD_ARG_TGT_ARCH" ) ); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSINSTALLDIR")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("INCLUDE")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_HOST_ARCH")); + Assert.assertEquals("x64", envCaseInsenstiveKeys.get("VSCMD_ARG_HOST_ARCH")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_TGT_ARCH")); + Assert.assertEquals("x64", envCaseInsenstiveKeys.get("VSCMD_ARG_TGT_ARCH")); } - } - - public void testMSVC2019x86Env() - { - if ( System.getenv( "VS160COMNTOOLS" ) != null ) - { + public void testMSVC2019x86Env() { + + if (System.getenv("VS160COMNTOOLS") != null) { MSVC2019x86EnvFactory envFact = new MSVC2019x86EnvFactory(); Map env = envFact.getEnvironmentVariables(); - logger.info( envFact.getClass().getName()+":env="+env ); - Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + logger.info(envFact.getClass().getName() + ":env=" + env); + Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); envCaseInsenstiveKeys.putAll(env); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSINSTALLDIR" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "INCLUDE" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertEquals( "x86", envCaseInsenstiveKeys.get( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_TGT_ARCH" ) ); - Assert.assertEquals( "x86", envCaseInsenstiveKeys.get( "VSCMD_ARG_TGT_ARCH" ) ); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSINSTALLDIR")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("INCLUDE")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_HOST_ARCH")); + Assert.assertEquals("x86", envCaseInsenstiveKeys.get("VSCMD_ARG_HOST_ARCH")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_TGT_ARCH")); + Assert.assertEquals("x86", envCaseInsenstiveKeys.get("VSCMD_ARG_TGT_ARCH")); } } - - public void testMSVC2019x86AMD64Env() - { - if ( System.getenv( "VS160COMNTOOLS" ) != null ) - { + public void testMSVC2019x86AMD64Env() { + + if (System.getenv("VS160COMNTOOLS") != null) { MSVC2019x86AMD64EnvFactory envFact = new MSVC2019x86AMD64EnvFactory(); Map env = envFact.getEnvironmentVariables(); - logger.info( envFact.getClass().getName()+":env="+env ); - Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + logger.info(envFact.getClass().getName() + ":env=" + env); + Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); envCaseInsenstiveKeys.putAll(env); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSINSTALLDIR" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "INCLUDE" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertEquals( "x86", envCaseInsenstiveKeys.get( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_TGT_ARCH" ) ); - Assert.assertEquals( "x64", envCaseInsenstiveKeys.get( "VSCMD_ARG_TGT_ARCH" ) ); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSINSTALLDIR")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("INCLUDE")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_HOST_ARCH")); + Assert.assertEquals("x86", envCaseInsenstiveKeys.get("VSCMD_ARG_HOST_ARCH")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_TGT_ARCH")); + Assert.assertEquals("x64", envCaseInsenstiveKeys.get("VSCMD_ARG_TGT_ARCH")); } } - public void testMSVC2019AMD64x864Env() - { - - if ( System.getenv( "VS160COMNTOOLS" ) != null ) - { + public void testMSVC2019AMD64x864Env() { + + if (System.getenv("VS160COMNTOOLS") != null) { MSVC2019AMD64x86EnvFactory envFact = new MSVC2019AMD64x86EnvFactory(); Map env = envFact.getEnvironmentVariables(); - logger.info( envFact.getClass().getName()+":env="+env ); - Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + logger.info(envFact.getClass().getName() + ":env=" + env); + Map envCaseInsenstiveKeys = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); envCaseInsenstiveKeys.putAll(env); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSINSTALLDIR" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "INCLUDE" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertEquals( "x64", envCaseInsenstiveKeys.get( "VSCMD_ARG_HOST_ARCH" ) ); - Assert.assertTrue( envCaseInsenstiveKeys.containsKey( "VSCMD_ARG_TGT_ARCH" ) ); - Assert.assertEquals( "x86", envCaseInsenstiveKeys.get( "VSCMD_ARG_TGT_ARCH" ) ); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSINSTALLDIR")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("INCLUDE")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_HOST_ARCH")); + Assert.assertEquals("x64", envCaseInsenstiveKeys.get("VSCMD_ARG_HOST_ARCH")); + Assert.assertTrue(envCaseInsenstiveKeys.containsKey("VSCMD_ARG_TGT_ARCH")); + Assert.assertEquals("x86", envCaseInsenstiveKeys.get("VSCMD_ARG_TGT_ARCH")); } } - } 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 05357b0e..c2702678 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 @@ -3,38 +3,33 @@ import java.io.File; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; -import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; +import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import static org.junit.Assert.*; -public class MSVCCompilerTest - extends PlexusTestCase -{ +public class MSVCCompilerTest extends PlexusTestCase { private MSVCCompiler compiler; private CompilerConfiguration config; - private static File sourceFile = new File( "source.c" ); + private static File sourceFile = new File("source.c"); - private static File objectFile = new File( "object.obj" ); + private static File objectFile = new File("object.obj"); - private static String[] simpleArgv = { "/Foobject.obj", "-c", "source.c" }; + private static String[] simpleArgv = {"/Foobject.obj", "-c", "source.c"}; - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.compiler = new MSVCCompiler(); this.config = new CompilerConfiguration(); } - public void testSimpleCompilation() - { - Commandline cl = compiler.getCommandLine( sourceFile, objectFile, config ); - String[] expected = new String[] { "cl.exe", simpleArgv[0], simpleArgv[1], simpleArgv[2] }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + public void testSimpleCompilation() { + Commandline cl = compiler.getCommandLine(sourceFile, objectFile, config); + String[] expected = new String[] {"cl.exe", simpleArgv[0], simpleArgv[1], simpleArgv[2]}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } } 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 2617da90..20a05de6 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 @@ -1,68 +1,61 @@ package org.codehaus.mojo.natives.msvc; -import static org.junit.Assert.assertArrayEquals; import java.io.File; import java.util.ArrayList; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.linker.LinkerConfiguration; -import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.cli.Commandline; -public class MSVCLinkerTest - extends PlexusTestCase -{ +import static org.codehaus.mojo.natives.test.TestUtils.formPlatformCommandline; +import static org.junit.Assert.assertArrayEquals; + +public class MSVCLinkerTest extends PlexusTestCase { private MSVCLinker linker; private LinkerConfiguration config; - private static final File objectFile0 = new File( "source1.obj" ); + private static final File objectFile0 = new File("source1.obj"); - private static final File objectFile1 = new File( "source2.obj" ); + private static final File objectFile1 = new File("source2.obj"); private List defautlObjectFiles; private String basedir; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); this.defautlObjectFiles = new ArrayList<>(); - this.defautlObjectFiles.add( objectFile0 ); - this.defautlObjectFiles.add( objectFile1 ); + this.defautlObjectFiles.add(objectFile0); + this.defautlObjectFiles.add(objectFile1); this.linker = new MSVCLinker(); this.config = new LinkerConfiguration(); this.basedir = getBasedir(); - config.setWorkingDirectory( new File( basedir ) ); - config.setOutputDirectory( new File( basedir, "target" ) ); - config.setOutputFileExtension( "exe" ); - config.setOutputFileName( "test" ); + config.setWorkingDirectory(new File(basedir)); + config.setOutputDirectory(new File(basedir, "target")); + config.setOutputFileExtension("exe"); + config.setOutputFileName("test"); } - public void testDefaultLinkerExecutable() - { + public void testDefaultLinkerExecutable() { Commandline cl = this.getCommandline(); - assertEquals( "link.exe", cl.getLiteralExecutable() ); - assertEquals( basedir, cl.getWorkingDirectory().getPath() ); + assertEquals("link.exe", cl.getLiteralExecutable()); + assertEquals(basedir, cl.getWorkingDirectory().getPath()); } - public void testSimpleLinkerCommand() - { + public void testSimpleLinkerCommand() { Commandline cl = this.getCommandline(); - String[] expected = new String[] { "link.exe", "/out:" + config.getOutputFile(), "source1.obj", "source2.obj" }; - assertArrayEquals( formPlatformCommandline( expected ), cl.getCommandline() ); + String[] expected = new String[] {"link.exe", "/out:" + config.getOutputFile(), "source1.obj", "source2.obj"}; + assertArrayEquals(formPlatformCommandline(expected), cl.getCommandline()); } // ///////////////////////// HELPERS ////////////////////////////////////// - private Commandline getCommandline() - throws NativeBuildException - { - return this.linker.createLinkerCommandLine( defautlObjectFiles, config ); + private Commandline getCommandline() throws NativeBuildException { + return this.linker.createLinkerCommandLine(defautlObjectFiles, config); } - } diff --git a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/RegQueryTest.java b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/RegQueryTest.java index 889f3d4e..2706dc76 100644 --- a/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/RegQueryTest.java +++ b/maven-native-components/maven-native-msvc/src/test/java/org/codehaus/mojo/natives/msvc/RegQueryTest.java @@ -3,16 +3,12 @@ import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.Os; -public class RegQueryTest - extends PlexusTestCase -{ - public void testRegQuery() - { - if ( Os.isFamily( "windows" ) ) - { - String value = RegQuery.getValue( "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion", - "ProgramFilesDir" ); - assertNotNull( value ); +public class RegQueryTest extends PlexusTestCase { + public void testRegQuery() { + if (Os.isFamily("windows")) { + String value = RegQuery.getValue( + "REG_SZ", "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir"); + assertNotNull(value); } } } diff --git a/maven-native-test/src/test/java/org/codehaus/mojo/natives/test/TestUtils.java b/maven-native-test/src/test/java/org/codehaus/mojo/natives/test/TestUtils.java index 4cb99e3d..e1d9f66d 100644 --- a/maven-native-test/src/test/java/org/codehaus/mojo/natives/test/TestUtils.java +++ b/maven-native-test/src/test/java/org/codehaus/mojo/natives/test/TestUtils.java @@ -1,112 +1,92 @@ -package org.codehaus.mojo.natives.test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.codehaus.plexus.util.Os; - - -/** - * Contains utility methods used by tests. - */ -public class TestUtils -{ - - private static final String[] WINDOWS_COMMANDLINE_PARTS = {"cmd.exe", "/X", "/C"}; - - private static final List WINDOWS_COMMANDLINE_PARTS_ASLIST = new ArrayList<>(); - - static - { - WINDOWS_COMMANDLINE_PARTS_ASLIST.addAll( Arrays.asList( WINDOWS_COMMANDLINE_PARTS ) ); - } - - - /** - * Adjusts commandline based on the platform. - * - * @param origCommandline Commandline to adjust. - * @return Commandline adjusted for platform. - */ - public static String[] formPlatformCommandline( String[] origCommandline ) - { - - if ( null == origCommandline ) - { - return null; - } - - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { - return formWindowsCommandline( origCommandline ); - } - else - { - return origCommandline; - } - } - - /** - * Adjusts commandline for Windows platform. - * - * @param origCommandline Commandline to adjust. - * @return - */ - private static String[] formWindowsCommandline( String[] origCommandline ) - { - - if ( null == origCommandline ) - { - return null; - } - - List origCommandlineAsList = new ArrayList<>(); - - // combine origCommandline with spaces in between - - final int SIZE_ORIG_COMMANDLINE = origCommandline.length; - int i = 1; - if ( SIZE_ORIG_COMMANDLINE > 0 ) - { - for ( String origCommandlineArg : origCommandline ) - { - if ( i == 1 ) - { - origCommandlineAsList.add( origCommandlineArg ); - } - else - { - origCommandlineAsList.add( " " ); - origCommandlineAsList.add( origCommandlineArg ); - } - i++; - } - } - - // now generate single quoted string of origCommandline - - StringBuilder buf = new StringBuilder(); - buf.append( "\"" ); - for ( String s : origCommandlineAsList ) - { - buf.append( s ); - } - buf.append( "\"" ); - - // prefix result with win commandline parts - List result = new ArrayList<>( WINDOWS_COMMANDLINE_PARTS_ASLIST ); - // and add origCommandline to result - result.add( buf.toString() ); - - return result.toArray( new String[0] ); - } - - /** - * Utility class so hide constructor. - */ - private TestUtils() - { - } - -} +package org.codehaus.mojo.natives.test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.codehaus.plexus.util.Os; + +/** + * Contains utility methods used by tests. + */ +public class TestUtils { + + private static final String[] WINDOWS_COMMANDLINE_PARTS = {"cmd.exe", "/X", "/C"}; + + private static final List WINDOWS_COMMANDLINE_PARTS_ASLIST = new ArrayList<>(); + + static { + WINDOWS_COMMANDLINE_PARTS_ASLIST.addAll(Arrays.asList(WINDOWS_COMMANDLINE_PARTS)); + } + + /** + * Adjusts commandline based on the platform. + * + * @param origCommandline Commandline to adjust. + * @return Commandline adjusted for platform. + */ + public static String[] formPlatformCommandline(String[] origCommandline) { + + if (null == origCommandline) { + return null; + } + + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + return formWindowsCommandline(origCommandline); + } else { + return origCommandline; + } + } + + /** + * Adjusts commandline for Windows platform. + * + * @param origCommandline Commandline to adjust. + * @return + */ + private static String[] formWindowsCommandline(String[] origCommandline) { + + if (null == origCommandline) { + return null; + } + + List origCommandlineAsList = new ArrayList<>(); + + // combine origCommandline with spaces in between + + final int SIZE_ORIG_COMMANDLINE = origCommandline.length; + int i = 1; + if (SIZE_ORIG_COMMANDLINE > 0) { + for (String origCommandlineArg : origCommandline) { + if (i == 1) { + origCommandlineAsList.add(origCommandlineArg); + } else { + origCommandlineAsList.add(" "); + origCommandlineAsList.add(origCommandlineArg); + } + i++; + } + } + + // now generate single quoted string of origCommandline + + StringBuilder buf = new StringBuilder(); + buf.append("\""); + for (String s : origCommandlineAsList) { + buf.append(s); + } + buf.append("\""); + + // prefix result with win commandline parts + List result = new ArrayList<>(WINDOWS_COMMANDLINE_PARTS_ASLIST); + // and add origCommandline to result + result.add(buf.toString()); + + return result.toArray(new String[0]); + } + + /** + * Utility class so hide constructor. + */ + private TestUtils() {} +} diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/AbstractNativeMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/AbstractNativeMojo.java index c1140963..4d54e83b 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/AbstractNativeMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/AbstractNativeMojo.java @@ -26,6 +26,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -35,9 +36,7 @@ import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.manager.EnvFactoryManager; -public abstract class AbstractNativeMojo - extends AbstractMojo -{ +public abstract class AbstractNativeMojo extends AbstractMojo { public static final String LINKER_INPUT_LIST_NAME = "NativeLinkerInputListName"; public static final String LINKER_OUTPUT_PATH = "NativeLinkerOutputPath"; @@ -73,62 +72,47 @@ public abstract class AbstractNativeMojo @Parameter(defaultValue = "${project.build.directory}/native/include") protected File dependencyIncludeDirectory; - protected static String[] removeEmptyOptions( List args ) - { - return NativeMojoUtils.trimParams( args ); + protected static String[] removeEmptyOptions(List args) { + return NativeMojoUtils.trimParams(args); } - protected List getAllCompilersOutputFileList() - { + protected List getAllCompilersOutputFileList() { @SuppressWarnings("unchecked") - List list = (List) this.getPluginContext().get( AbstractNativeMojo.LINKER_INPUT_LIST_NAME ); + List list = (List) this.getPluginContext().get(AbstractNativeMojo.LINKER_INPUT_LIST_NAME); - if ( list == null ) - { + if (list == null) { list = new ArrayList<>(); - @SuppressWarnings({ "unchecked", "unused" }) - Object unchecked = this.getPluginContext().put( AbstractNativeMojo.LINKER_INPUT_LIST_NAME, list ); + @SuppressWarnings({"unchecked", "unused"}) + Object unchecked = this.getPluginContext().put(AbstractNativeMojo.LINKER_INPUT_LIST_NAME, list); } return list; - } - protected void saveCompilerOutputFilePaths( List filePaths ) - throws MojoExecutionException - { + protected void saveCompilerOutputFilePaths(List filePaths) throws MojoExecutionException { List allCompilerOutputFileList = getAllCompilersOutputFileList(); - allCompilerOutputFileList.addAll( filePaths ); + allCompilerOutputFileList.addAll(filePaths); } /** * Internal for unit test only */ - - protected MavenProject getProject() - { + protected MavenProject getProject() { return this.project; } private EnvFactory envFactory = null; - protected EnvFactory getEnvFactory() - throws MojoExecutionException - { - if ( envFactory == null && envFactoryName != null ) - { - try - { - envFactory = this.envFactoryManager.getEnvFactory( this.envFactoryName ); - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + protected EnvFactory getEnvFactory() throws MojoExecutionException { + if (envFactory == null && envFactoryName != null) { + try { + envFactory = this.envFactoryManager.getEnvFactory(this.envFactoryName); + } catch (NativeBuildException e) { + throw new MojoExecutionException(e.getMessage(), e); } } return envFactory; } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/JavahInclude.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/JavahInclude.java index 05b21ccd..84a60827 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/JavahInclude.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/JavahInclude.java @@ -20,30 +20,24 @@ */ package org.codehaus.mojo.natives.plugin; -public class JavahInclude -{ +public class JavahInclude { private String className; private String headerName; - public String getClassName() - { + public String getClassName() { return className; } - public void setClassName( String className ) - { + public void setClassName(String className) { this.className = className; } - public String getHeaderName() - { + public String getHeaderName() { return headerName; } - public void setHeaderName( String headerName ) - { + public void setHeaderName(String headerName) { this.headerName = headerName; } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeBundleIncludeFilesMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeBundleIncludeFilesMojo.java index 41c8875c..392b0489 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeBundleIncludeFilesMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeBundleIncludeFilesMojo.java @@ -38,9 +38,7 @@ * @since 1.0-alpha-4 */ @Mojo(name = "inczip", defaultPhase = LifecyclePhase.PACKAGE) -public class NativeBundleIncludeFilesMojo - extends AbstractNativeMojo -{ +public class NativeBundleIncludeFilesMojo extends AbstractNativeMojo { /** * Array of NativeSources containing include directories and source files. @@ -74,47 +72,36 @@ public class NativeBundleIncludeFilesMojo @Component private MavenProjectHelper projectHelper; - public void execute() - throws MojoExecutionException - { - if ( skipIncludeDeployment ) - { + public void execute() throws MojoExecutionException { + if (skipIncludeDeployment) { return; } - if ( this.sources.length != 0 ) - { - try - { + if (this.sources.length != 0) { + try { ZipArchiver archiver = new ZipArchiver(); boolean zipIt = false; - for ( NativeSources source : sources ) - { - if ( source.isDeployable() ) - { + for (NativeSources source : sources) { + if (source.isDeployable()) { DefaultFileSet fileSet = new DefaultFileSet(); - fileSet.setUsingDefaultExcludes( true ); - fileSet.setDirectory( source.getDirectory() ); - fileSet.setIncludes( source.getIncludes() ); - fileSet.setExcludes( source.getExcludes() ); - archiver.addFileSet( fileSet ); + fileSet.setUsingDefaultExcludes(true); + fileSet.setDirectory(source.getDirectory()); + fileSet.setIncludes(source.getIncludes()); + fileSet.setExcludes(source.getExcludes()); + archiver.addFileSet(fileSet); zipIt = true; } } - if ( zipIt ) - { - archiver.setDestFile( this.incZipFile ); + if (zipIt) { + archiver.setDestFile(this.incZipFile); archiver.createArchive(); - projectHelper.attachArtifact( this.project, INCZIP_TYPE, null, this.incZipFile ); + projectHelper.attachArtifact(this.project, INCZIP_TYPE, null, this.incZipFile); } - } - catch ( Exception e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + } catch (Exception e) { + throw new MojoExecutionException(e.getMessage(), e); } } } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeCompileMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeCompileMojo.java index 464328f5..61556372 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeCompileMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeCompileMojo.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -40,9 +41,7 @@ * Compile source files into native object files */ @Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE) -public class NativeCompileMojo - extends AbstractNativeMojo -{ +public class NativeCompileMojo extends AbstractNativeMojo { /** * Compiler Provider Type @@ -138,23 +137,17 @@ public class NativeCompileMojo private CompilerManager manager; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { Compiler compiler; - try - { - compiler = this.manager.getCompiler( this.compilerProvider ); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + try { + compiler = this.manager.getCompiler(this.compilerProvider); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } - if ( this.javahOS != null ) - { + if (this.javahOS != null) { this.addJavaHIncludePaths(); } @@ -163,115 +156,99 @@ public void execute() CompilerConfiguration config = this.createProviderConfiguration(); List objectFiles; - try - { - objectFiles = compiler.compile( config, NativeSources.getAllSourceFiles( this.sources ) ); - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + try { + objectFiles = compiler.compile(config, NativeSources.getAllSourceFiles(this.sources)); + } catch (NativeBuildException e) { + throw new MojoExecutionException(e.getMessage(), e); } - this.saveCompilerOutputFilePaths( objectFiles ); - + this.saveCompilerOutputFilePaths(objectFiles); } - private void addJavaHIncludePaths() - { - List sourceArray = new ArrayList<>( Arrays.asList( this.sources ) ); + private void addJavaHIncludePaths() { + List sourceArray = new ArrayList<>(Arrays.asList(this.sources)); NativeSources jdkIncludeSource = new NativeSources(); - jdkIncludeSource.setDirectory( this.jdkIncludePath ); + jdkIncludeSource.setDirectory(this.jdkIncludePath); - jdkIncludeSource.setDependencyAnalysisParticipation( false ); + jdkIncludeSource.setDependencyAnalysisParticipation(false); - sourceArray.add( jdkIncludeSource ); + sourceArray.add(jdkIncludeSource); - File jdkOsIncludeDir = new File( this.jdkIncludePath, this.javahOS ); + File jdkOsIncludeDir = new File(this.jdkIncludePath, this.javahOS); NativeSources jdkIncludeOsSource = new NativeSources(); - jdkIncludeOsSource.setDirectory( jdkOsIncludeDir ); - - jdkIncludeOsSource.setDependencyAnalysisParticipation( false ); + jdkIncludeOsSource.setDirectory(jdkOsIncludeDir); - sourceArray.add( jdkIncludeOsSource ); + jdkIncludeOsSource.setDependencyAnalysisParticipation(false); - this.sources = sourceArray.toArray( new NativeSources[sourceArray.size()] ); + sourceArray.add(jdkIncludeOsSource); + this.sources = sourceArray.toArray(new NativeSources[sourceArray.size()]); } /** * Pickup additional source paths that previous phases added to source root Note: we intentionally ignore the first * item of source root ( ie ${project.build.directory}/classes since this plugin never use it. */ - private void addAdditionalIncludePath() - { + private void addAdditionalIncludePath() { List additionalIncludePaths = project.getCompileSourceRoots(); - boolean includeDependencyFound = this.getPluginContext().get( AbstractNativeMojo.INCZIP_FOUND ) != null; + boolean includeDependencyFound = this.getPluginContext().get(AbstractNativeMojo.INCZIP_FOUND) != null; - if ( !includeDependencyFound ) - { - if ( additionalIncludePaths == null || additionalIncludePaths.size() < 2 ) - { + if (!includeDependencyFound) { + if (additionalIncludePaths == null || additionalIncludePaths.size() < 2) { return; } } - if ( this.sources == null ) - { + if (this.sources == null) { return; } - List sourceArray = new ArrayList<>( Arrays.asList( this.sources ) ); + List sourceArray = new ArrayList<>(Arrays.asList(this.sources)); - if ( additionalIncludePaths.size() > 1 ) - { - for ( int i = 1; i < additionalIncludePaths.size(); ++i ) - { - File genIncludeDir = new File( additionalIncludePaths.get( i ).toString() ); + if (additionalIncludePaths.size() > 1) { + for (int i = 1; i < additionalIncludePaths.size(); ++i) { + File genIncludeDir = new File(additionalIncludePaths.get(i).toString()); NativeSources genIncludeSource = new NativeSources(); - genIncludeSource.setDirectory( genIncludeDir ); + genIncludeSource.setDirectory(genIncludeDir); - sourceArray.add( genIncludeSource ); + sourceArray.add(genIncludeSource); } } - if ( includeDependencyFound ) - { + if (includeDependencyFound) { NativeSources dependencyIncludeSource = new NativeSources(); - dependencyIncludeSource.setDependencyAnalysisParticipation( false ); - dependencyIncludeSource.setDirectory( this.dependencyIncludeDirectory ); + dependencyIncludeSource.setDependencyAnalysisParticipation(false); + dependencyIncludeSource.setDirectory(this.dependencyIncludeDirectory); - sourceArray.add( dependencyIncludeSource ); + sourceArray.add(dependencyIncludeSource); } - this.sources = sourceArray.toArray( new NativeSources[sourceArray.size()] ); - + this.sources = sourceArray.toArray(new NativeSources[sourceArray.size()]); } /* * use protected scope for unit test purpose */ - protected CompilerConfiguration createProviderConfiguration() - throws MojoExecutionException - { + protected CompilerConfiguration createProviderConfiguration() throws MojoExecutionException { this.config = new CompilerConfiguration(); - config.setWorkingDirectory( this.workingDirectory ); - config.setExecutable( this.compilerExecutable ); - config.setStartOptions( removeEmptyOptions( this.compilerStartOptions ) ); - config.setMiddleOptions( removeEmptyOptions( this.compilerMiddleOptions ) ); - config.setEndOptions( removeEmptyOptions( this.compilerEndOptions ) ); - config.setIncludePaths( NativeSources.getIncludePaths( this.sources ) ); - config.setSystemIncludePaths( NativeSources.getSystemIncludePaths( this.sources ) ); - config.setOutputDirectory( this.compilerOutputDirectory ); - config.setObjectFileExtension( this.objectFileExtension ); - config.setEnvFactory( this.getEnvFactory() ); - config.setNumberOfConcurrentCompilation( numberOfConcurrentCompilation ); + config.setWorkingDirectory(this.workingDirectory); + config.setExecutable(this.compilerExecutable); + config.setStartOptions(removeEmptyOptions(this.compilerStartOptions)); + config.setMiddleOptions(removeEmptyOptions(this.compilerMiddleOptions)); + config.setEndOptions(removeEmptyOptions(this.compilerEndOptions)); + config.setIncludePaths(NativeSources.getIncludePaths(this.sources)); + config.setSystemIncludePaths(NativeSources.getSystemIncludePaths(this.sources)); + config.setOutputDirectory(this.compilerOutputDirectory); + config.setObjectFileExtension(this.objectFileExtension); + config.setEnvFactory(this.getEnvFactory()); + config.setNumberOfConcurrentCompilation(numberOfConcurrentCompilation); return config; } @@ -289,8 +266,7 @@ protected CompilerConfiguration createProviderConfiguration() * * @return */ - protected CompilerConfiguration getCompilerConfiguration() - { + protected CompilerConfiguration getCompilerConfiguration() { return this.config; } } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojo.java index bea652c8..5be6c23e 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojo.java @@ -25,6 +25,7 @@ import java.io.File; import java.util.List; + import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -36,21 +37,16 @@ * Initialize build lifecycle */ @Mojo(name = "initialize", defaultPhase = LifecyclePhase.INITIALIZE) -public class NativeInitializeMojo - extends AbstractMojo -{ +public class NativeInitializeMojo extends AbstractMojo { @Parameter(defaultValue = "${project}", readonly = true, required = true) protected MavenProject project; @Override - public void execute() - throws MojoExecutionException - { - File buildDirectory = new File( this.project.getBuild().getDirectory() ); + public void execute() throws MojoExecutionException { + File buildDirectory = new File(this.project.getBuild().getDirectory()); - if ( !buildDirectory.exists() ) - { + if (!buildDirectory.exists()) { buildDirectory.mkdirs(); } @@ -60,19 +56,16 @@ public void execute() // version String finalName = project.getArtifactId(); - project.getBuild().setFinalName( finalName ); + project.getBuild().setFinalName(finalName); // we need to clear out object files list since it possible that compile phase // gets called // mulitple times // and produce duplicate objects, and therefore will fail at link phase @SuppressWarnings("unchecked") - List objList = (List) this.getPluginContext().get( AbstractNativeMojo.LINKER_INPUT_LIST_NAME ); - if ( objList != null ) - { + List objList = (List) this.getPluginContext().get(AbstractNativeMojo.LINKER_INPUT_LIST_NAME); + if (objList != null) { objList.clear(); } - } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeJavahMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeJavahMojo.java index 9c5521e8..264243bf 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeJavahMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeJavahMojo.java @@ -29,6 +29,7 @@ import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; + import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; @@ -54,10 +55,11 @@ /** * Generate JNI include files based on a set of class names */ -@Mojo(name = "javah", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) -public class NativeJavahMojo - extends AbstractNativeMojo -{ +@Mojo( + name = "javah", + defaultPhase = LifecyclePhase.GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.COMPILE) +public class NativeJavahMojo extends AbstractNativeMojo { /** * Javah Provider. @@ -74,7 +76,7 @@ public class NativeJavahMojo * @since 1.0-alpha-4 */ @Parameter - private List javahClassNames = new ArrayList<>( 0 ); + private List javahClassNames = new ArrayList<>(0); /** * Enable the search from project dependencies for JNI interfaces, in addition to javahClassNames @@ -169,7 +171,6 @@ public class NativeJavahMojo * * @since 1.0-alpha-2 */ - @Component private JavahManager manager; @@ -187,88 +188,65 @@ public class NativeJavahMojo private JavahConfiguration config; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { this.discoverAdditionalJNIClassName(); - if ( this.javahClassNames.size() == 0 && this.javahIncludes.size() == 0 ) - { + if (this.javahClassNames.size() == 0 && this.javahIncludes.size() == 0) { return; } - try - { - if ( this.javahClassNames.size() != 0 ) - { + try { + if (this.javahClassNames.size() != 0) { this.config = this.createProviderConfiguration( - javahClassNames.toArray( new String[javahClassNames.size()] ), this.javahOutputFileName ); - this.getJavah().compile( config ); + javahClassNames.toArray(new String[javahClassNames.size()]), this.javahOutputFileName); + this.getJavah().compile(config); } - for ( JavahInclude javahInclude : this.javahIncludes ) - { - this.config = this.createProviderConfiguration( new String[] {javahInclude.getClassName()}, - javahInclude.getHeaderName() ); - this.getJavah().compile( config ); + for (JavahInclude javahInclude : this.javahIncludes) { + this.config = this.createProviderConfiguration( + new String[] {javahInclude.getClassName()}, javahInclude.getHeaderName()); + this.getJavah().compile(config); } - if ( this.attach ) - { + if (this.attach) { attachGeneratedIncludeFilesAsIncZip(); } - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( "Error running javah command", e ); + } catch (NativeBuildException e) { + throw new MojoExecutionException("Error running javah command", e); } - this.project.addCompileSourceRoot( this.javahOutputDirectory.getAbsolutePath() ); - + this.project.addCompileSourceRoot(this.javahOutputDirectory.getAbsolutePath()); } - private void attachGeneratedIncludeFilesAsIncZip() - throws MojoExecutionException - { - try - { + private void attachGeneratedIncludeFilesAsIncZip() throws MojoExecutionException { + try { ZipArchiver archiver = new ZipArchiver(); DefaultFileSet fileSet = new DefaultFileSet(); - fileSet.setUsingDefaultExcludes( true ); - fileSet.setDirectory( javahOutputDirectory ); - archiver.addFileSet( fileSet ); - archiver.setDestFile( this.incZipFile ); + fileSet.setUsingDefaultExcludes(true); + fileSet.setDirectory(javahOutputDirectory); + archiver.addFileSet(fileSet); + archiver.setDestFile(this.incZipFile); archiver.createArchive(); - if ( StringUtils.isBlank( this.classifier ) ) - { - projectHelper.attachArtifact( this.project, INCZIP_TYPE, null, this.incZipFile ); - } - else - { - projectHelper.attachArtifact( this.project, INCZIP_TYPE, this.classifier, this.incZipFile ); + if (StringUtils.isBlank(this.classifier)) { + projectHelper.attachArtifact(this.project, INCZIP_TYPE, null, this.incZipFile); + } else { + projectHelper.attachArtifact(this.project, INCZIP_TYPE, this.classifier, this.incZipFile); } - } - catch ( Exception e ) - { - throw new MojoExecutionException( "Unable to archive/deploy generated include files", e ); + } catch (Exception e) { + throw new MojoExecutionException("Unable to archive/deploy generated include files", e); } } - private Javah getJavah() - throws MojoExecutionException - { + private Javah getJavah() throws MojoExecutionException { Javah javah; - try - { - javah = this.manager.getJavah( this.javahProvider ); + try { + javah = this.manager.getJavah(this.javahProvider); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return javah; @@ -279,31 +257,26 @@ private Javah getJavah() * * @return */ - private List getJavahArtifacts() - { + private List getJavahArtifacts() { List list = new ArrayList<>(); Set artifacts = this.project.getArtifacts(); - if ( artifacts != null ) - { + if (artifacts != null) { - for ( Artifact artifact : artifacts ) - { + for (Artifact artifact : artifacts) { // pick up only jar files from class path for compile (and system) scope - if ( "jar".equals( artifact.getType() ) && artifact.getArtifactHandler().isAddedToClasspath() - && ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) - || Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) ) - { - list.add( artifact ); + if ("jar".equals(artifact.getType()) + && artifact.getArtifactHandler().isAddedToClasspath() + && (Artifact.SCOPE_COMPILE.equals(artifact.getScope()) + || Artifact.SCOPE_SYSTEM.equals(artifact.getScope()))) { + list.add(artifact); } } - } return list; - } /** @@ -311,8 +284,7 @@ private List getJavahArtifacts() * * @return */ - private String[] getJavahClassPath() - { + private String[] getJavahClassPath() { List artifacts = this.getJavahArtifacts(); String[] classPaths = new String[artifacts.size() + 1]; @@ -321,8 +293,7 @@ private String[] getJavahClassPath() Iterator iter = artifacts.iterator(); - for ( int i = 1; i < classPaths.length; ++i ) - { + for (int i = 1; i < classPaths.length; ++i) { Artifact artifact = iter.next(); classPaths[i] = artifact.getFile().getPath(); @@ -334,12 +305,8 @@ private String[] getJavahClassPath() /** * Get applicable class names to be "javahed" */ - - private void discoverAdditionalJNIClassName() - throws MojoExecutionException - { - if ( !this.javahSearchJNIFromDependencies ) - { + private void discoverAdditionalJNIClassName() throws MojoExecutionException { + if (!this.javahSearchJNIFromDependencies) { return; } @@ -347,34 +314,28 @@ private void discoverAdditionalJNIClassName() List artifacts = this.getJavahArtifacts(); - for ( Artifact artifact : artifacts ) - { - this.getLog().info( "Parsing " + artifact.getFile() + " for native classes." ); + for (Artifact artifact : artifacts) { + this.getLog().info("Parsing " + artifact.getFile() + " for native classes."); - try - { - ZipFile zipFile = new ZipFile( artifact.getFile() ); + try { + ZipFile zipFile = new ZipFile(artifact.getFile()); Enumeration zipEntries = zipFile.entries(); - while ( zipEntries.hasMoreElements() ) - { + while (zipEntries.hasMoreElements()) { ZipEntry zipEntry = zipEntries.nextElement(); - if ( "class".equals( FileUtils.extension( zipEntry.getName() ) ) ) - { - ClassParser parser = new ClassParser( artifact.getFile().getPath(), zipEntry.getName() ); + if ("class".equals(FileUtils.extension(zipEntry.getName()))) { + ClassParser parser = new ClassParser(artifact.getFile().getPath(), zipEntry.getName()); JavaClass clazz = parser.parse(); Method[] methods = clazz.getMethods(); - for ( Method method : methods ) - { - if ( method.isNative() ) - { - javahClassNames.add( clazz.getClassName() ); + for (Method method : methods) { + if (method.isNative()) { + javahClassNames.add(clazz.getClassName()); - this.getLog().info( "Found native class: " + clazz.getClassName() ); + this.getLog().info("Found native class: " + clazz.getClassName()); break; } @@ -384,26 +345,22 @@ private void discoverAdditionalJNIClassName() // not full proof zipFile.close(); - } - catch ( IOException ioe ) - { - throw new MojoExecutionException( "Error searching for native class in " + artifact.getFile(), ioe ); + } catch (IOException ioe) { + throw new MojoExecutionException("Error searching for native class in " + artifact.getFile(), ioe); } } - } - private JavahConfiguration createProviderConfiguration( String[] classNames, String javahOutputFileName ) - { + private JavahConfiguration createProviderConfiguration(String[] classNames, String javahOutputFileName) { JavahConfiguration config = new JavahConfiguration(); - config.setWorkingDirectory( this.workingDirectory ); - config.setVerbose( this.javahVerbose ); - config.setOutputDirectory( this.javahOutputDirectory ); - config.setFileName( javahOutputFileName ); - config.setClassPaths( this.getJavahClassPath() ); - config.setUseEnvClasspath( useEnvClasspath ); - config.setClassNames( classNames ); - config.setJavahPath( this.javahPath ); + config.setWorkingDirectory(this.workingDirectory); + config.setVerbose(this.javahVerbose); + config.setOutputDirectory(this.javahOutputDirectory); + config.setFileName(javahOutputFileName); + config.setClassPaths(this.getJavahClassPath()); + config.setUseEnvClasspath(useEnvClasspath); + config.setClassNames(classNames); + config.setJavahPath(this.javahPath); return config; } @@ -413,18 +370,15 @@ private JavahConfiguration createProviderConfiguration( String[] classNames, Str * * @return */ - protected JavahConfiguration getJavahConfiguration() - { + protected JavahConfiguration getJavahConfiguration() { return this.config; } /** * Internal for unit test only */ - @Override - protected MavenProject getProject() - { + protected MavenProject getProject() { return this.project; } } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeLinkMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeLinkMojo.java index 9da2c763..d997a45c 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeLinkMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeLinkMojo.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; @@ -46,9 +47,7 @@ * Link all previously built object and dependent library files into final build artifact */ @Mojo(name = "link", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE) -public class NativeLinkMojo - extends AbstractNativeMojo -{ +public class NativeLinkMojo extends AbstractNativeMojo { /** * Override this property if permitted by compilerProvider @@ -196,12 +195,9 @@ public class NativeLinkMojo private boolean checkStaleLinkage; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { - if ( StringUtils.isEmpty( this.classifier ) ) - { + if (StringUtils.isEmpty(this.classifier)) { this.classifier = null; } @@ -209,69 +205,57 @@ public void execute() this.config = this.createLinkerConfiguration(); - try - { + try { List allCompilerOuputFiles = this.getAllCompilersOutputFileList(); - File outputFile = linker.link( config, allCompilerOuputFiles ); + File outputFile = linker.link(config, allCompilerOuputFiles); allCompilerOuputFiles.clear(); // to be used by post linker mojo like native:manifest - @SuppressWarnings({ "unused", "unchecked" }) - Object unchecked = this.getPluginContext().put( AbstractNativeMojo.LINKER_OUTPUT_PATH, outputFile ); + @SuppressWarnings({"unused", "unchecked"}) + Object unchecked = this.getPluginContext().put(AbstractNativeMojo.LINKER_OUTPUT_PATH, outputFile); - } - catch ( IOException | NativeBuildException ioe ) - { - throw new MojoExecutionException( ioe.getMessage(), ioe ); + } catch (IOException | NativeBuildException ioe) { + throw new MojoExecutionException(ioe.getMessage(), ioe); } - if ( this.attach ) - { + if (this.attach) { this.attachPrimaryArtifact(); this.attachSecondaryArtifacts(); } } - private LinkerConfiguration createLinkerConfiguration() - throws MojoExecutionException - { + private LinkerConfiguration createLinkerConfiguration() throws MojoExecutionException { LinkerConfiguration config = new LinkerConfiguration(); - config.setWorkingDirectory( this.workingDirectory ); - config.setExecutable( this.linkerExecutable ); - config.setStartOptions( removeEmptyOptions( this.linkerStartOptions ) ); - config.setMiddleOptions( removeEmptyOptions( this.linkerMiddleOptions ) ); - config.setEndOptions( removeEmptyOptions( this.linkerEndOptions ) ); - config.setOutputDirectory( this.linkerOutputDirectory ); - config.setOutputFileName( this.linkerFinalName ); - config.setOutputFileExtension( this.linkerFinalNameExt ); - config.setExternalLibDirectory( this.externalLibDirectory ); - config.setExternalLibFileNames( this.getLibFileNames() ); - config.setEnvFactory( this.getEnvFactory() ); - config.setUsingLinkerResponseFile( usingLinkerResponseFile ); - config.setCheckStaleLinkage( this.checkStaleLinkage ); + config.setWorkingDirectory(this.workingDirectory); + config.setExecutable(this.linkerExecutable); + config.setStartOptions(removeEmptyOptions(this.linkerStartOptions)); + config.setMiddleOptions(removeEmptyOptions(this.linkerMiddleOptions)); + config.setEndOptions(removeEmptyOptions(this.linkerEndOptions)); + config.setOutputDirectory(this.linkerOutputDirectory); + config.setOutputFileName(this.linkerFinalName); + config.setOutputFileExtension(this.linkerFinalNameExt); + config.setExternalLibDirectory(this.externalLibDirectory); + config.setExternalLibFileNames(this.getLibFileNames()); + config.setEnvFactory(this.getEnvFactory()); + config.setUsingLinkerResponseFile(usingLinkerResponseFile); + config.setCheckStaleLinkage(this.checkStaleLinkage); return config; } - private Linker getLinker() - throws MojoExecutionException - { + private Linker getLinker() throws MojoExecutionException { Linker linker; - try - { - if ( this.linkerProvider == null ) - { + try { + if (this.linkerProvider == null) { this.linkerProvider = this.compilerProvider; } - linker = this.manager.getLinker( this.linkerProvider ); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + linker = this.manager.getLinker(this.linkerProvider); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return linker; @@ -280,96 +264,89 @@ private Linker getLinker() /** * */ - private void attachPrimaryArtifact() - { + private void attachPrimaryArtifact() { Artifact artifact = this.project.getArtifact(); - if ( null == this.classifier ) - { - artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." - + this.project.getArtifact().getArtifactHandler().getExtension() ) ); - } - else - { + if (null == this.classifier) { + artifact.setFile(new File( + this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + + this.project.getArtifact().getArtifactHandler().getExtension())); + } else { // install primary artifact as a classifier - DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersionRange().cloneOf(), artifact.getScope(), artifact.getType(), classifier, - artifact.getArtifactHandler(), artifact.isOptional() ); - - clone.setRelease( artifact.isRelease() ); - clone.setResolvedVersion( artifact.getVersion() ); - clone.setResolved( artifact.isResolved() ); - clone.setFile( artifact.getFile() ); - - if ( artifact.getAvailableVersions() != null ) - { - clone.setAvailableVersions( new ArrayList<>( artifact.getAvailableVersions() ) ); + DefaultArtifact clone = new DefaultArtifact( + artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersionRange().cloneOf(), + artifact.getScope(), + artifact.getType(), + classifier, + artifact.getArtifactHandler(), + artifact.isOptional()); + + clone.setRelease(artifact.isRelease()); + clone.setResolvedVersion(artifact.getVersion()); + clone.setResolved(artifact.isResolved()); + clone.setFile(artifact.getFile()); + + if (artifact.getAvailableVersions() != null) { + clone.setAvailableVersions(new ArrayList<>(artifact.getAvailableVersions())); } - clone.setBaseVersion( artifact.getBaseVersion() ); - clone.setDependencyFilter( artifact.getDependencyFilter() ); + clone.setBaseVersion(artifact.getBaseVersion()); + clone.setDependencyFilter(artifact.getDependencyFilter()); - if ( artifact.getDependencyTrail() != null ) - { - clone.setDependencyTrail( new ArrayList<>( artifact.getDependencyTrail() ) ); + if (artifact.getDependencyTrail() != null) { + clone.setDependencyTrail(new ArrayList<>(artifact.getDependencyTrail())); } - clone.setDownloadUrl( artifact.getDownloadUrl() ); - clone.setRepository( artifact.getRepository() ); + clone.setDownloadUrl(artifact.getDownloadUrl()); + clone.setRepository(artifact.getRepository()); - clone.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." - + this.project.getArtifact().getArtifactHandler().getExtension() ) ); + clone.setFile(new File( + this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + + this.project.getArtifact().getArtifactHandler().getExtension())); - project.setArtifact( clone ); + project.setArtifact(clone); } } - private void attachSecondaryArtifacts() - { + private void attachSecondaryArtifacts() { final String[] tokens; - if ( this.linkerSecondaryOutputExtensions != null ) - { - tokens = StringUtils.split( this.linkerSecondaryOutputExtensions, "," ); - } - else - { + if (this.linkerSecondaryOutputExtensions != null) { + tokens = StringUtils.split(this.linkerSecondaryOutputExtensions, ","); + } else { tokens = new String[0]; } - for ( String token : tokens ) - { + for (String token : tokens) { // TODO: shouldn't need classifier - Artifact artifact = artifactFactory.createArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), this.classifier, token.trim() ); - artifact.setFile( new File( this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." - + token.trim() ) ); + Artifact artifact = artifactFactory.createArtifact( + project.getGroupId(), project.getArtifactId(), project.getVersion(), this.classifier, token.trim()); + artifact.setFile(new File( + this.linkerOutputDirectory + "/" + this.project.getBuild().getFinalName() + "." + token.trim())); - project.addAttachedArtifact( artifact ); + project.addAttachedArtifact(artifact); } - } - private List getLibFileNames() - throws MojoExecutionException - { + private List getLibFileNames() throws MojoExecutionException { List libList = new ArrayList<>(); Set artifacts = this.project.getArtifacts(); - for ( Artifact artifact : artifacts ) - { - if ( INCZIP_TYPE.equals( artifact.getType() ) ) - { + for (Artifact artifact : artifacts) { + if (INCZIP_TYPE.equals(artifact.getType())) { continue; } - String libFileName = FileUtils.filename( this.getDependencyFile( artifact, true ).getPath() ); + String libFileName = + FileUtils.filename(this.getDependencyFile(artifact, true).getPath()); - libList.add( libFileName ); + libList.add(libFileName); } - libList = this.reorderLibDependencies( libList ); + libList = this.reorderLibDependencies(libList); return libList; } @@ -379,26 +356,20 @@ private List getLibFileNames() * * @return */ - private List getDependenciesFileOrderList() - throws MojoExecutionException - { + private List getDependenciesFileOrderList() throws MojoExecutionException { List list = new ArrayList<>(); - if ( this.linkingOrderLibs != null ) - { - for ( String element : linkingOrderLibs ) - { - Artifact artifact = lookupDependencyUsingGroupArtifactIdPair( element ); + if (this.linkingOrderLibs != null) { + for (String element : linkingOrderLibs) { + Artifact artifact = lookupDependencyUsingGroupArtifactIdPair(element); - if ( artifact != null ) - { - String libFileName = FileUtils.filename( this.getDependencyFile( artifact, false ).getPath() ); + if (artifact != null) { + String libFileName = FileUtils.filename( + this.getDependencyFile(artifact, false).getPath()); - list.add( libFileName ); - } - else - { - throw new MojoExecutionException( element + " not found on project dependencies." ); + list.add(libFileName); + } else { + throw new MojoExecutionException(element + " not found on project dependencies."); } } } @@ -415,77 +386,64 @@ private List getDependenciesFileOrderList() * @return * @throws MojoExecutionException */ - private Artifact lookupDependencyUsingGroupArtifactIdPair( String groupArtifactIdPair ) - throws MojoExecutionException - { - String[] tokens = StringUtils.split( groupArtifactIdPair, ":" ); - - if ( tokens.length != 2 ) - { - throw new MojoExecutionException( "Invalid groupId and artifactId pair: " + groupArtifactIdPair ); + private Artifact lookupDependencyUsingGroupArtifactIdPair(String groupArtifactIdPair) + throws MojoExecutionException { + String[] tokens = StringUtils.split(groupArtifactIdPair, ":"); + + if (tokens.length != 2) { + throw new MojoExecutionException("Invalid groupId and artifactId pair: " + groupArtifactIdPair); } Set allDependencyArtifacts = project.getDependencyArtifacts(); - for ( Artifact artifact : allDependencyArtifacts ) - { - if ( INCZIP_TYPE.equals( artifact.getType() ) ) - { + for (Artifact artifact : allDependencyArtifacts) { + if (INCZIP_TYPE.equals(artifact.getType())) { continue; } - if ( tokens[0].equals( artifact.getGroupId() ) && tokens[1].equals( artifact.getArtifactId() ) ) - { + if (tokens[0].equals(artifact.getGroupId()) && tokens[1].equals(artifact.getArtifactId())) { return artifact; } } return null; - } - private List reorderLibDependencies( List libs ) - throws MojoExecutionException - { + private List reorderLibDependencies(List libs) throws MojoExecutionException { List requestedOrderList = getDependenciesFileOrderList(); - if ( requestedOrderList.size() != 0 ) - { + if (requestedOrderList.size() != 0) { // remove from original list first - for ( String s : requestedOrderList ) - { - libs.remove( s ); + for (String s : requestedOrderList) { + libs.remove(s); } - requestedOrderList.addAll( libs ); + requestedOrderList.addAll(libs); return requestedOrderList; - } - else - { + } else { return libs; } } - private File getDependencyFile( Artifact artifact, boolean doCopy ) - throws MojoExecutionException - { + private File getDependencyFile(Artifact artifact, boolean doCopy) throws MojoExecutionException { - File newLocation = new File( this.externalLibDirectory, - artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension() ); + File newLocation = new File( + this.externalLibDirectory, + artifact.getArtifactId() + "." + artifact.getArtifactHandler().getExtension()); - try - { - if ( doCopy && !artifact.getFile().isDirectory() - && ( !newLocation.exists() || newLocation.lastModified() <= artifact.getFile().lastModified() ) ) - { - FileUtils.copyFile( artifact.getFile(), newLocation ); + try { + if (doCopy + && !artifact.getFile().isDirectory() + && (!newLocation.exists() + || newLocation.lastModified() <= artifact.getFile().lastModified())) { + FileUtils.copyFile(artifact.getFile(), newLocation); } - } - catch ( IOException ioe ) - { - throw new MojoExecutionException( "Unable to copy dependency to staging area. Could not copy " - + artifact.getFile() + " to " + newLocation, ioe ); + } catch (IOException ioe) { + throw new MojoExecutionException( + "Unable to copy dependency to staging area. Could not copy " + artifact.getFile() + " to " + + newLocation, + ioe); } return newLocation; @@ -499,9 +457,7 @@ private File getDependencyFile( Artifact artifact, boolean doCopy ) */ private LinkerConfiguration config; - protected LinkerConfiguration getLgetLinkerConfiguration() - { + protected LinkerConfiguration getLgetLinkerConfiguration() { return this.config; } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeManifestMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeManifestMojo.java index 1581ff39..d29f6c0b 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeManifestMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeManifestMojo.java @@ -39,9 +39,7 @@ * @since 1.0-alpha4 */ @Mojo(name = "manifest", defaultPhase = LifecyclePhase.PACKAGE) -public class NativeManifestMojo - extends AbstractNativeMojo -{ +public class NativeManifestMojo extends AbstractNativeMojo { /** * Manifest Provider. * @@ -74,61 +72,47 @@ public class NativeManifestMojo @Component private ManifestManager manager; - public void execute() - throws MojoExecutionException - { - File linkerOutputFile = (File) this.getPluginContext().get( LINKER_OUTPUT_PATH ); + public void execute() throws MojoExecutionException { + File linkerOutputFile = (File) this.getPluginContext().get(LINKER_OUTPUT_PATH); - if ( !linkerOutputFile.exists() ) - { + if (!linkerOutputFile.exists()) { // @TODO ERROR? return; } - File linkerManifestFile = new File( linkerOutputFile.getAbsolutePath() + "." + manifestExtension ); + File linkerManifestFile = new File(linkerOutputFile.getAbsolutePath() + "." + manifestExtension); - if ( !linkerManifestFile.exists() ) - { + if (!linkerManifestFile.exists()) { // no need to inject manifest file into the executable return; } // @Todo check for stale output, and skip if needed - try - { + try { ManifestConfiguration config = new ManifestConfiguration(); - config.setEnvFactory( this.getEnvFactory() ); - config.setWorkingDirectory( this.workingDirectory ); - config.setInputFile( linkerOutputFile ); - config.setManifestFile( linkerManifestFile ); + config.setEnvFactory(this.getEnvFactory()); + config.setWorkingDirectory(this.workingDirectory); + config.setInputFile(linkerOutputFile); + config.setManifestFile(linkerManifestFile); Manifest Manifest = this.getManifest(); - Manifest.run( config ); + Manifest.run(config); + } catch (NativeBuildException e) { + throw new MojoExecutionException("Error executing Manifest.", e); } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( "Error executing Manifest.", e ); - } - } - private Manifest getManifest() - throws MojoExecutionException - { + private Manifest getManifest() throws MojoExecutionException { Manifest Manifest; - try - { - Manifest = this.manager.getManifest( this.provider ); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + try { + Manifest = this.manager.getManifest(this.provider); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return Manifest; } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMessageCompileMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMessageCompileMojo.java index 44a0c30f..9429db80 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMessageCompileMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMessageCompileMojo.java @@ -22,6 +22,7 @@ import java.io.File; import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -37,9 +38,7 @@ * Compile Windows message files */ @Mojo(name = "compile-message", defaultPhase = LifecyclePhase.GENERATE_RESOURCES) -public class NativeMessageCompileMojo - extends AbstractNativeMojo -{ +public class NativeMessageCompileMojo extends AbstractNativeMojo { /** * Compiler Provider Type @@ -90,50 +89,38 @@ public class NativeMessageCompileMojo private MessageCompilerManager manager; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { - if ( !this.messageCompilerOutputDirectory.exists() ) - { + if (!this.messageCompilerOutputDirectory.exists()) { this.messageCompilerOutputDirectory.mkdirs(); } MessageCompiler compiler = this.getMessageCompiler(); MessageCompilerConfiguration config = new MessageCompilerConfiguration(); - config.setExecutable( this.messageCompilerExecutable ); - config.setWorkingDirectory( this.workingDirectory ); - config.setOutputDirectory( this.messageCompilerOutputDirectory ); - config.setOptions( NativeMojoUtils.trimParams( this.messageCompilerOptions ) ); - config.setEnvFactory( this.getEnvFactory() ); + config.setExecutable(this.messageCompilerExecutable); + config.setWorkingDirectory(this.workingDirectory); + config.setOutputDirectory(this.messageCompilerOutputDirectory); + config.setOptions(NativeMojoUtils.trimParams(this.messageCompilerOptions)); + config.setEnvFactory(this.getEnvFactory()); - try - { - compiler.compile( config, this.messageFiles ); - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + try { + compiler.compile(config, this.messageFiles); + } catch (NativeBuildException e) { + throw new MojoExecutionException(e.getMessage(), e); } - this.project.addCompileSourceRoot( this.messageCompilerOutputDirectory.getAbsolutePath() ); - + this.project.addCompileSourceRoot(this.messageCompilerOutputDirectory.getAbsolutePath()); } - private MessageCompiler getMessageCompiler() - throws MojoExecutionException - { + private MessageCompiler getMessageCompiler() throws MojoExecutionException { MessageCompiler mc; - try - { - mc = this.manager.getMessageCompiler( this.provider ); + try { + mc = this.manager.getMessageCompiler(this.provider); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return mc; diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMojoUtils.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMojoUtils.java index 2c34c211..ef32fdca 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMojoUtils.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeMojoUtils.java @@ -25,46 +25,39 @@ import java.util.ArrayList; import java.util.List; + import org.codehaus.plexus.util.StringUtils; -public class NativeMojoUtils -{ +public class NativeMojoUtils { /** * Remove/trim empty or null member of a string array * * @param args * @return */ - public static String[] trimParams( List args ) - { - if ( args == null ) - { + public static String[] trimParams(List args) { + if (args == null) { return new String[0]; } List tokenArray = new ArrayList<>(); - for ( String arg : args ) - { - if ( arg == null || arg.length() == 0 ) - { + for (String arg : args) { + if (arg == null || arg.length() == 0) { continue; } - String[] tokens = StringUtils.split( arg ); + String[] tokens = StringUtils.split(arg); - for ( String token : tokens ) - { - if ( token == null || token.trim().length() == 0 ) - { + for (String token : tokens) { + if (token == null || token.trim().length() == 0) { continue; } - tokenArray.add( token.trim() ); + tokenArray.add(token.trim()); } } - return tokenArray.toArray( new String[tokenArray.size()] ); + return tokenArray.toArray(new String[tokenArray.size()]); } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojo.java index 14d15034..92b08460 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojo.java @@ -39,9 +39,7 @@ * ranlib a Unix linker output file */ @Mojo(name = "ranlib", defaultPhase = LifecyclePhase.PACKAGE) -public class NativeRanlibMojo - extends AbstractNativeMojo -{ +public class NativeRanlibMojo extends AbstractNativeMojo { /** * Where to place the final packaging @@ -67,45 +65,33 @@ public class NativeRanlibMojo @Component private RanlibManager manager; - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { - try - { + try { String finalName = this.project.getBuild().getFinalName(); String fileExt = this.project.getArtifact().getArtifactHandler().getExtension(); - File outputFile = - new File( this.ranlibOutputDirectory.getAbsolutePath() + "/" + finalName + "." + fileExt ); + File outputFile = new File(this.ranlibOutputDirectory.getAbsolutePath() + "/" + finalName + "." + fileExt); Ranlib ranlib = this.getRanlib(); - ranlib.run( outputFile ); - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( "Error executing ranlib.", e ); + ranlib.run(outputFile); + } catch (NativeBuildException e) { + throw new MojoExecutionException("Error executing ranlib.", e); } } - private Ranlib getRanlib() - throws MojoExecutionException - { + private Ranlib getRanlib() throws MojoExecutionException { Ranlib ranlib; - try - { - ranlib = this.manager.getRanlib( this.provider ); + try { + ranlib = this.manager.getRanlib(this.provider); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return ranlib; } - } diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeResourceCompileMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeResourceCompileMojo.java index 6ed30722..8bba0320 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeResourceCompileMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeResourceCompileMojo.java @@ -22,6 +22,7 @@ import java.io.File; import java.util.List; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -39,9 +40,7 @@ * Compile Windows resource files */ @Mojo(name = "resource-compile", defaultPhase = LifecyclePhase.GENERATE_RESOURCES) -public class NativeResourceCompileMojo - extends AbstractNativeMojo -{ +public class NativeResourceCompileMojo extends AbstractNativeMojo { /** * Compiler Provider Type @@ -90,53 +89,41 @@ public class NativeResourceCompileMojo private ResourceCompilerManager manager; @Override - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { - if ( !this.resourceCompilerOutputDirectory.exists() ) - { + if (!this.resourceCompilerOutputDirectory.exists()) { this.resourceCompilerOutputDirectory.mkdirs(); } - FileUtils.mkdir( project.getBuild().getDirectory() ); + FileUtils.mkdir(project.getBuild().getDirectory()); ResourceCompiler compiler = this.getResourceCompiler(); ResourceCompilerConfiguration config = new ResourceCompilerConfiguration(); - config.setExecutable( this.resourceCompilerExecutable ); - config.setWorkingDirectory( this.workingDirectory ); - config.setOptions( NativeMojoUtils.trimParams( this.resourceCompilerOptions ) ); - config.setOutputDirectory( this.resourceCompilerOutputDirectory ); - config.setEnvFactory( this.getEnvFactory() ); - - try - { + config.setExecutable(this.resourceCompilerExecutable); + config.setWorkingDirectory(this.workingDirectory); + config.setOptions(NativeMojoUtils.trimParams(this.resourceCompilerOptions)); + config.setOutputDirectory(this.resourceCompilerOutputDirectory); + config.setEnvFactory(this.getEnvFactory()); + + try { List resourceOutputFiles; - resourceOutputFiles = compiler.compile( config, this.resources ); + resourceOutputFiles = compiler.compile(config, this.resources); - this.saveCompilerOutputFilePaths( resourceOutputFiles ); - } - catch ( NativeBuildException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + this.saveCompilerOutputFilePaths(resourceOutputFiles); + } catch (NativeBuildException e) { + throw new MojoExecutionException(e.getMessage(), e); } - } - private ResourceCompiler getResourceCompiler() - throws MojoExecutionException - { + private ResourceCompiler getResourceCompiler() throws MojoExecutionException { ResourceCompiler rc; - try - { - rc = this.manager.getResourceCompiler( this.provider ); + try { + rc = this.manager.getResourceCompiler(this.provider); - } - catch ( NoSuchNativeProviderException pe ) - { - throw new MojoExecutionException( pe.getMessage() ); + } catch (NoSuchNativeProviderException pe) { + throw new MojoExecutionException(pe.getMessage()); } return rc; diff --git a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeUnZipIncMojo.java b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeUnZipIncMojo.java index 1958cb7f..1128a820 100644 --- a/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeUnZipIncMojo.java +++ b/native-maven-plugin/src/main/java/org/codehaus/mojo/natives/plugin/NativeUnZipIncMojo.java @@ -26,6 +26,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -41,10 +42,11 @@ * * @since 1.0-alpha-4 */ -@Mojo(name = "unzipinc", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) -public class NativeUnZipIncMojo - extends AbstractNativeMojo -{ +@Mojo( + name = "unzipinc", + defaultPhase = LifecyclePhase.GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.COMPILE) +public class NativeUnZipIncMojo extends AbstractNativeMojo { /** * Internal @@ -63,80 +65,61 @@ public class NativeUnZipIncMojo private ArchiverManager archiverManager; @Override - public void execute() - throws MojoExecutionException - { - if ( unpackIncZipDepenedencies() ) - { - @SuppressWarnings({ "unused", "unchecked" }) - Object unchecked = this.getPluginContext().put( AbstractNativeMojo.INCZIP_FOUND, Boolean.TRUE ); + public void execute() throws MojoExecutionException { + if (unpackIncZipDepenedencies()) { + @SuppressWarnings({"unused", "unchecked"}) + Object unchecked = this.getPluginContext().put(AbstractNativeMojo.INCZIP_FOUND, Boolean.TRUE); } } - private boolean unpackIncZipDepenedencies() - throws MojoExecutionException - { + private boolean unpackIncZipDepenedencies() throws MojoExecutionException { List files = getIncZipDependencies(); Iterator iter = files.iterator(); - for ( int i = 0; i < files.size(); ++i ) - { + for (int i = 0; i < files.size(); ++i) { Artifact artifact = iter.next(); File incZipFile = artifact.getFile(); - File marker = new File( this.dependencyIncZipMarkerDirectory, - artifact.getGroupId() + "." + artifact.getArtifactId() ); + File marker = new File( + this.dependencyIncZipMarkerDirectory, artifact.getGroupId() + "." + artifact.getArtifactId()); - if ( !marker.exists() || marker.lastModified() < incZipFile.lastModified() ) - { - try - { - unpackZipFile( incZipFile ); + if (!marker.exists() || marker.lastModified() < incZipFile.lastModified()) { + try { + unpackZipFile(incZipFile); marker.delete(); - if ( !dependencyIncZipMarkerDirectory.exists() ) - { + if (!dependencyIncZipMarkerDirectory.exists()) { dependencyIncZipMarkerDirectory.mkdirs(); } marker.createNewFile(); - } - catch ( IOException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); } } } return files.size() != 0; - } - protected void unpackZipFile( File zipFile ) - throws MojoExecutionException - { - this.getLog().info( "Unpacking: " + zipFile ); + protected void unpackZipFile(File zipFile) throws MojoExecutionException { + this.getLog().info("Unpacking: " + zipFile); - try - { - if ( !dependencyIncludeDirectory.exists() ) - { + try { + if (!dependencyIncludeDirectory.exists()) { dependencyIncludeDirectory.mkdirs(); } - UnArchiver archiver = this.archiverManager.getUnArchiver( "zip" ); - archiver.setOverwrite( true ); - archiver.setDestDirectory( this.dependencyIncludeDirectory ); - archiver.setSourceFile( zipFile ); + UnArchiver archiver = this.archiverManager.getUnArchiver("zip"); + archiver.setOverwrite(true); + archiver.setDestDirectory(this.dependencyIncludeDirectory); + archiver.setSourceFile(zipFile); archiver.extract(); + } catch (Exception e) { + throw new MojoExecutionException(e.getMessage(), e); } - catch ( Exception e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - } /** @@ -144,27 +127,22 @@ protected void unpackZipFile( File zipFile ) * * @return */ - private List getIncZipDependencies() - { + private List getIncZipDependencies() { List list = new ArrayList<>(); Set artifacts = this.project.getDependencyArtifacts(); - if ( artifacts != null ) - { - for ( Artifact artifact : artifacts ) - { + if (artifacts != null) { + for (Artifact artifact : artifacts) { // pick up only native header archive - if ( !INCZIP_TYPE.equals( artifact.getType() ) ) - { + if (!INCZIP_TYPE.equals(artifact.getType())) { continue; } - list.add( artifact ); + list.add(artifact); } } return list; } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopCompiler.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopCompiler.java index d1a206a3..23ae93ec 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopCompiler.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopCompiler.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.compiler.Compiler; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; @@ -13,24 +14,18 @@ * Helper class to test native-maven-plugin */ @Component(role = Compiler.class, hint = "noop") -public class NoopCompiler - implements Compiler -{ +public class NoopCompiler implements Compiler { @Override - public List compile( CompilerConfiguration config, File[] sourceFiles ) - throws NativeBuildException - { - List compilerOutputFiles = new ArrayList<>( sourceFiles.length ); - - for ( File sourceFile : sourceFiles ) - { - File source = new File( sourceFile.toString() ); + public List compile(CompilerConfiguration config, File[] sourceFiles) throws NativeBuildException { + List compilerOutputFiles = new ArrayList<>(sourceFiles.length); - File objectFile = this.getObjectFile( source, config ); + for (File sourceFile : sourceFiles) { + File source = new File(sourceFile.toString()); - compilerOutputFiles.add( objectFile ); + File objectFile = this.getObjectFile(source, config); + compilerOutputFiles.add(objectFile); } return compilerOutputFiles; @@ -39,8 +34,7 @@ public List compile( CompilerConfiguration config, File[] sourceFiles ) /** * @return */ - protected String getObjectFileExtension() - { + protected String getObjectFileExtension() { // no need to test system specific extension return "o"; } @@ -51,14 +45,12 @@ protected String getObjectFileExtension() * @param sourceFile * @return */ - private File getObjectFile( File sourceFile, CompilerConfiguration config ) - { + private File getObjectFile(File sourceFile, CompilerConfiguration config) { String srcPath = sourceFile.getPath(); - String destPath = config.getOutputDirectory().getPath() + "/" + FileUtils.basename( srcPath ) + String destPath = config.getOutputDirectory().getPath() + "/" + FileUtils.basename(srcPath) + this.getObjectFileExtension(); - return new File( destPath ); + return new File(destPath); } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopJavah.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopJavah.java index 1df6b0de..e11af0c4 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopJavah.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopJavah.java @@ -9,14 +9,7 @@ * Helper class to test native-maven-plugin' javah mojo */ @Component(role = Javah.class, hint = "noop") -public class NoopJavah - implements Javah -{ - - public void compile( JavahConfiguration config ) - throws NativeBuildException - { - - } +public class NoopJavah implements Javah { + public void compile(JavahConfiguration config) throws NativeBuildException {} } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopLinker.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopLinker.java index f9c38d11..c025a3cf 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopLinker.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopLinker.java @@ -2,27 +2,22 @@ import java.io.File; import java.util.List; + import org.codehaus.mojo.natives.NativeBuildException; import org.codehaus.mojo.natives.linker.Linker; import org.codehaus.mojo.natives.linker.LinkerConfiguration; import org.codehaus.plexus.component.annotations.Component; @Component(role = Linker.class, hint = "noop") -public class NoopLinker - implements Linker -{ +public class NoopLinker implements Linker { @Override - public File link( LinkerConfiguration config, List compilerOutputFiles ) - throws NativeBuildException - { + public File link(LinkerConfiguration config, List compilerOutputFiles) throws NativeBuildException { String fileName = config.getOutputFileName(); - if ( config.getOutputFileExtension() != null ) - { + if (config.getOutputFileExtension() != null) { fileName += "." + config.getOutputFileExtension(); } - return new File( config.getOutputDirectory(), fileName ); + return new File(config.getOutputDirectory(), fileName); } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopRanlib.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopRanlib.java index 43e519d0..5301c6cb 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopRanlib.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/noop/NoopRanlib.java @@ -10,14 +10,7 @@ * Helper class to test native-maven-plugin' javah mojo */ @Component(role = Ranlib.class, hint = "noop") -public class NoopRanlib - implements Ranlib -{ - - public void run( File file ) - throws NativeBuildException - { - - } +public class NoopRanlib implements Ranlib { + public void run(File file) throws NativeBuildException {} } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeCompileMojoTest.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeCompileMojoTest.java index afb5f745..1efc5945 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeCompileMojoTest.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeCompileMojoTest.java @@ -3,32 +3,27 @@ import java.io.File; import java.util.HashMap; import java.util.List; + import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.mojo.natives.compiler.CompilerConfiguration; -public class NativeCompileMojoTest - extends AbstractMojoTestCase -{ - public void testMojoLookup() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/compiler/plugin-config.xml" ); - NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo( "compile", pluginXml ); - assertNotNull( mojo ); +public class NativeCompileMojoTest extends AbstractMojoTestCase { + public void testMojoLookup() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/compiler/plugin-config.xml"); + NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo("compile", pluginXml); + assertNotNull(mojo); } - public void testSources() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/compiler/plugin-config.xml" ); - NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo( "compile", pluginXml ); - assertNotNull( mojo ); + public void testSources() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/compiler/plugin-config.xml"); + NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo("compile", pluginXml); + assertNotNull(mojo); // must init this - mojo.setPluginContext( new HashMap<>() ); + mojo.setPluginContext(new HashMap<>()); // simulate extra path to be added into includePath - mojo.getProject().addCompileSourceRoot( "dummy" ); + mojo.getProject().addCompileSourceRoot("dummy"); // until the maven project stub is fixed // mojo.getProject().addCompileSourceRoot( "target/javah" ); @@ -36,79 +31,75 @@ public void testSources() CompilerConfiguration config = mojo.getCompilerConfiguration(); - assertNotNull( config ); + assertNotNull(config); // validate data from pom which is fed into mojo.execute() - assertEquals( new File( getBasedir() ), config.getWorkingDirectory() ); + assertEquals(new File(getBasedir()), config.getWorkingDirectory()); - assertEquals( "someExe", config.getExecutable() ); + assertEquals("someExe", config.getExecutable()); - assertEquals( new File( "target" ), config.getOutputDirectory() ); + assertEquals(new File("target"), config.getOutputDirectory()); - assertEquals( 4, config.getStartOptions().length ); - assertEquals( "-s0", config.getStartOptions()[0] ); - assertEquals( "-s1", config.getStartOptions()[1] ); - assertEquals( "-s2", config.getStartOptions()[2] ); - assertEquals( "-s3", config.getStartOptions()[3] ); + assertEquals(4, config.getStartOptions().length); + assertEquals("-s0", config.getStartOptions()[0]); + assertEquals("-s1", config.getStartOptions()[1]); + assertEquals("-s2", config.getStartOptions()[2]); + assertEquals("-s3", config.getStartOptions()[3]); - assertEquals( 4, config.getMiddleOptions().length ); - assertEquals( "-m0", config.getMiddleOptions()[0] ); - assertEquals( "-m1", config.getMiddleOptions()[1] ); - assertEquals( "-m2", config.getMiddleOptions()[2] ); - assertEquals( "-m3", config.getMiddleOptions()[3] ); + assertEquals(4, config.getMiddleOptions().length); + assertEquals("-m0", config.getMiddleOptions()[0]); + assertEquals("-m1", config.getMiddleOptions()[1]); + assertEquals("-m2", config.getMiddleOptions()[2]); + assertEquals("-m3", config.getMiddleOptions()[3]); - assertEquals( 4, config.getEndOptions().length ); - assertEquals( "-e0", config.getEndOptions()[0] ); - assertEquals( "-e1", config.getEndOptions()[1] ); - assertEquals( "-e2", config.getEndOptions()[2] ); - assertEquals( "-e3", config.getEndOptions()[3] ); + assertEquals(4, config.getEndOptions().length); + assertEquals("-e0", config.getEndOptions()[0]); + assertEquals("-e1", config.getEndOptions()[1]); + assertEquals("-e2", config.getEndOptions()[2]); + assertEquals("-e3", config.getEndOptions()[3]); // there are 2 source element with dependencyAnalysisParticipation is set to // false - assertEquals( 2, config.getSystemIncludePaths().length ); - assertEquals( new File( "src/main/native/dir4" ), config.getSystemIncludePaths()[0] ); - assertEquals( new File( "src/main/native/dir5" ), config.getSystemIncludePaths()[1] ); + assertEquals(2, config.getSystemIncludePaths().length); + assertEquals(new File("src/main/native/dir4"), config.getSystemIncludePaths()[0]); + assertEquals(new File("src/main/native/dir5"), config.getSystemIncludePaths()[1]); // there are 3 normal source elements + 2 javah include - assertEquals( 3, config.getIncludePaths().length ); - assertEquals( new File( "src/main/native/dir1" ), config.getIncludePaths()[0] ); - assertEquals( new File( "src/main/native/dir2" ), config.getIncludePaths()[1] ); - assertEquals( new File( "src/main/native/dir3" ), config.getIncludePaths()[2] ); + assertEquals(3, config.getIncludePaths().length); + assertEquals(new File("src/main/native/dir1"), config.getIncludePaths()[0]); + assertEquals(new File("src/main/native/dir2"), config.getIncludePaths()[1]); + assertEquals(new File("src/main/native/dir3"), config.getIncludePaths()[2]); // until maven project stub is fixes were we can simulate more than 1 source // root in the list // assertEquals( new File( "target/javah" ), config.getIncludePaths()[3] ); // we have 4 source files, so in output directory, there must be 4 object files List objectFileList = mojo.getAllCompilersOutputFileList(); - assertEquals( 4, objectFileList.size() ); - assertEquals( new File( "target/file11.o" ), objectFileList.get( 0 ) ); - assertEquals( new File( "target/file12.o" ), objectFileList.get( 1 ) ); - assertEquals( new File( "target/file21.o" ), objectFileList.get( 2 ) ); - assertEquals( new File( "target/file22.o" ), objectFileList.get( 3 ) ); - + assertEquals(4, objectFileList.size()); + assertEquals(new File("target/file11.o"), objectFileList.get(0)); + assertEquals(new File("target/file12.o"), objectFileList.get(1)); + assertEquals(new File("target/file21.o"), objectFileList.get(2)); + assertEquals(new File("target/file22.o"), objectFileList.get(3)); } - public void testJavahOS() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/compiler/plugin-config-javahOS.xml" ); - NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo( "compile", pluginXml ); - assertNotNull( mojo ); + public void testJavahOS() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/compiler/plugin-config-javahOS.xml"); + NativeCompileMojo mojo = (NativeCompileMojo) lookupMojo("compile", pluginXml); + assertNotNull(mojo); - mojo.setPluginContext( new HashMap<>() ); + mojo.setPluginContext(new HashMap<>()); mojo.execute(); CompilerConfiguration config = mojo.getCompilerConfiguration(); - assertNotNull( config ); + assertNotNull(config); // javah induces 2 system include paths into configuration - assertEquals( 2, config.getSystemIncludePaths().length ); + assertEquals(2, config.getSystemIncludePaths().length); // note "somJDKPath comes from the simulated pom above - assertEquals( new File( "someJDKPath" ), config.getSystemIncludePaths()[0] ); - assertEquals( new File( "someJDKPath/someOS" ), config.getSystemIncludePaths()[1] ); + assertEquals(new File("someJDKPath"), config.getSystemIncludePaths()[0]); + assertEquals(new File("someJDKPath/someOS"), config.getSystemIncludePaths()[1]); } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojoTest.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojoTest.java index 13d5a5ac..5f844450 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojoTest.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeInitializeMojoTest.java @@ -2,6 +2,7 @@ import java.io.File; import java.util.HashMap; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -9,26 +10,27 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.testing.AbstractMojoTestCase; -public class NativeInitializeMojoTest - extends AbstractMojoTestCase -{ - public void testMojoLookup() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/initialize/plugin-config.xml" ); - NativeInitializeMojo mojo = (NativeInitializeMojo) lookupMojo( "initialize", pluginXml ); - assertNotNull( mojo ); +public class NativeInitializeMojoTest extends AbstractMojoTestCase { + public void testMojoLookup() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/initialize/plugin-config.xml"); + NativeInitializeMojo mojo = (NativeInitializeMojo) lookupMojo("initialize", pluginXml); + assertNotNull(mojo); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); - Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), - "compile", "exe", null, artifactHandler ); - mojo.project.setArtifact( artifact ); - mojo.setPluginContext( new HashMap<>() ); + Artifact artifact = new DefaultArtifact( + "test", + "test", + VersionRange.createFromVersion("1.0-SNAPSHOT"), + "compile", + "exe", + null, + artifactHandler); + mojo.project.setArtifact(artifact); + mojo.setPluginContext(new HashMap<>()); mojo.execute(); - assertEquals( "someArtifactId", mojo.project.getBuild().getFinalName() ); + assertEquals("someArtifactId", mojo.project.getBuild().getFinalName()); } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeJavahMojoTest.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeJavahMojoTest.java index 366bf28b..c162ef35 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeJavahMojoTest.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeJavahMojoTest.java @@ -5,40 +5,33 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.mojo.natives.javah.JavahConfiguration; -public class NativeJavahMojoTest - extends AbstractMojoTestCase -{ - public void testMojoLookup() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/javah/plugin-config.xml" ); - NativeJavahMojo mojo = (NativeJavahMojo) lookupMojo( "javah", pluginXml ); - assertNotNull( mojo ); +public class NativeJavahMojoTest extends AbstractMojoTestCase { + public void testMojoLookup() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/javah/plugin-config.xml"); + NativeJavahMojo mojo = (NativeJavahMojo) lookupMojo("javah", pluginXml); + assertNotNull(mojo); } - public void testClassPathBeginsWithProjectOutputDirectory() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/javah/plugin-config.xml" ); - NativeJavahMojo mojo = (NativeJavahMojo) this.lookupMojo( "javah", pluginXml ); + public void testClassPathBeginsWithProjectOutputDirectory() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/javah/plugin-config.xml"); + NativeJavahMojo mojo = (NativeJavahMojo) this.lookupMojo("javah", pluginXml); mojo.execute(); JavahConfiguration config = mojo.getJavahConfiguration(); // only found ${project.build.outputDirectory} - assertEquals( 1, config.getClassPaths().length ); + assertEquals(1, config.getClassPaths().length); String classesDir = config.getClassPaths()[0]; - assertEquals( mojo.getProject().getBuild().getOutputDirectory(), classesDir ); + assertEquals(mojo.getProject().getBuild().getOutputDirectory(), classesDir); - assertEquals( new File( "target/javah" ), config.getOutputDirectory() ); + assertEquals(new File("target/javah"), config.getOutputDirectory()); - assertEquals( new File( getBasedir() ), config.getWorkingDirectory() ); + assertEquals(new File(getBasedir()), config.getWorkingDirectory()); // in test mode, the project starts out of 0 source root instead of 1 - assertEquals( 1, mojo.getProject().getCompileSourceRoots().size() ); - + assertEquals(1, mojo.getProject().getCompileSourceRoots().size()); } } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeLinkerMojoTest.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeLinkerMojoTest.java index 8a5851c3..061ca2fb 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeLinkerMojoTest.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeLinkerMojoTest.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -13,93 +14,95 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.codehaus.mojo.natives.linker.LinkerConfiguration; -public class NativeLinkerMojoTest - extends AbstractMojoTestCase -{ - private NativeLinkMojo getMojo() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/linker/plugin-config.xml" ); - NativeLinkMojo mojo = (NativeLinkMojo) lookupMojo( "link", pluginXml ); - assertNotNull( mojo ); +public class NativeLinkerMojoTest extends AbstractMojoTestCase { + private NativeLinkMojo getMojo() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/linker/plugin-config.xml"); + NativeLinkMojo mojo = (NativeLinkMojo) lookupMojo("link", pluginXml); + assertNotNull(mojo); // must init this - mojo.setPluginContext( new HashMap<>() ); + mojo.setPluginContext(new HashMap<>()); return mojo; } - public void testExecute() - throws Exception - { + public void testExecute() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List objectList = new ArrayList<>(); - objectList.add( new File( "o1.o" ) ); - objectList.add( new File( "o2.o" ) ); - mojo.saveCompilerOutputFilePaths( objectList ); + objectList.add(new File("o1.o")); + objectList.add(new File("o2.o")); + mojo.saveCompilerOutputFilePaths(objectList); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); - Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), - "compile", "exe", null, artifactHandler ); - mojo.getProject().setArtifact( artifact ); + Artifact artifact = new DefaultArtifact( + "test", + "test", + VersionRange.createFromVersion("1.0-SNAPSHOT"), + "compile", + "exe", + null, + artifactHandler); + mojo.getProject().setArtifact(artifact); // simulate artifacts - mojo.getProject().setArtifacts( new HashSet<>() ); // no extern libs for now + mojo.getProject().setArtifacts(new HashSet<>()); // no extern libs for now String linkerFinalName = "some-final-name"; - setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); + setVariableValueToObject(mojo, "linkerFinalName", linkerFinalName); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub - assertEquals( new File( "target" ), conf.getOutputDirectory() ); - assertEquals( linkerFinalName, conf.getOutputFileName() ); - assertNull( conf.getOutputFileExtension() ); + assertEquals(new File("target"), conf.getOutputDirectory()); + assertEquals(linkerFinalName, conf.getOutputFileName()); + assertNull(conf.getOutputFileExtension()); // current artifactHandler mocking return null extension name - assertEquals( new File( "target/some-final-name.null" ), conf.getOutputFile() ); - + assertEquals(new File("target/some-final-name.null"), conf.getOutputFile()); } - public void testExecuteWithFinalNameExtension() - throws Exception - { + public void testExecuteWithFinalNameExtension() throws Exception { NativeLinkMojo mojo = getMojo(); // simulate object files List objectList = new ArrayList<>(); - objectList.add( new File( "o1.o" ) ); - objectList.add( new File( "o2.o" ) ); - mojo.saveCompilerOutputFilePaths( objectList ); + objectList.add(new File("o1.o")); + objectList.add(new File("o2.o")); + mojo.saveCompilerOutputFilePaths(objectList); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); - Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), - "compile", "exe", null, artifactHandler ); - mojo.getProject().setArtifact( artifact ); + Artifact artifact = new DefaultArtifact( + "test", + "test", + VersionRange.createFromVersion("1.0-SNAPSHOT"), + "compile", + "exe", + null, + artifactHandler); + mojo.getProject().setArtifact(artifact); // simulate artifacts - mojo.getProject().setArtifacts( new HashSet<>() ); // no extern libs for now + mojo.getProject().setArtifacts(new HashSet<>()); // no extern libs for now String linkerFinalName = "some-final-name"; - setVariableValueToObject( mojo, "linkerFinalName", linkerFinalName ); + setVariableValueToObject(mojo, "linkerFinalName", linkerFinalName); String linkerFinalNameExt = "some-extension"; - setVariableValueToObject( mojo, "linkerFinalNameExt", linkerFinalNameExt ); + setVariableValueToObject(mojo, "linkerFinalNameExt", linkerFinalNameExt); mojo.execute(); LinkerConfiguration conf = mojo.getLgetLinkerConfiguration(); // "target is set in the stub - assertEquals( new File( "target" ), conf.getOutputDirectory() ); - assertEquals( linkerFinalName, conf.getOutputFileName() ); - assertEquals( linkerFinalNameExt, conf.getOutputFileExtension() ); - assertEquals( new File( "target/some-final-name.some-extension" ), conf.getOutputFile() ); - + assertEquals(new File("target"), conf.getOutputDirectory()); + assertEquals(linkerFinalName, conf.getOutputFileName()); + assertEquals(linkerFinalNameExt, conf.getOutputFileExtension()); + assertEquals(new File("target/some-final-name.some-extension"), conf.getOutputFile()); } } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojoTest.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojoTest.java index 9da82132..4aa8d264 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojoTest.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/NativeRanlibMojoTest.java @@ -9,24 +9,25 @@ import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.plugin.testing.AbstractMojoTestCase; -public class NativeRanlibMojoTest - extends AbstractMojoTestCase -{ - public void testMojoLookup() - throws Exception - { - File pluginXml = new File( getBasedir(), "src/test/resources/linker/plugin-config-ranlib.xml" ); - NativeRanlibMojo mojo = (NativeRanlibMojo) lookupMojo( "ranlib", pluginXml ); - assertNotNull( mojo ); +public class NativeRanlibMojoTest extends AbstractMojoTestCase { + public void testMojoLookup() throws Exception { + File pluginXml = new File(getBasedir(), "src/test/resources/linker/plugin-config-ranlib.xml"); + NativeRanlibMojo mojo = (NativeRanlibMojo) lookupMojo("ranlib", pluginXml); + assertNotNull(mojo); // simulate artifact ArtifactHandler artifactHandler = new DefaultArtifactHandler(); - Artifact artifact = new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), - "compile", "exe", null, artifactHandler ); - mojo.getProject().setArtifact( artifact ); + Artifact artifact = new DefaultArtifact( + "test", + "test", + VersionRange.createFromVersion("1.0-SNAPSHOT"), + "compile", + "exe", + null, + artifactHandler); + mojo.getProject().setArtifact(artifact); mojo.execute(); } - } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/BuildStub.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/BuildStub.java index 04c2b6ea..5f8ea2b7 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/BuildStub.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/BuildStub.java @@ -2,9 +2,7 @@ import org.apache.maven.model.Build; -public class BuildStub - extends Build -{ +public class BuildStub extends Build { /** * */ @@ -12,23 +10,19 @@ public class BuildStub private String finalName = "some-final-name"; - public String getOutputDirectory() - { + public String getOutputDirectory() { return "fake-output-directory"; } - public String getFinalName() - { + public String getFinalName() { return this.finalName; } - public void setFinalName( String name ) - { + public void setFinalName(String name) { this.finalName = name; } - public String getDirectory() - { + public String getDirectory() { return "target"; } } diff --git a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/ProjectStub.java b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/ProjectStub.java index 16cfc4e3..28c2dc14 100644 --- a/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/ProjectStub.java +++ b/native-maven-plugin/src/test/java/org/codehaus/mojo/natives/plugin/stubs/ProjectStub.java @@ -2,6 +2,7 @@ import java.util.HashSet; import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Build; import org.apache.maven.model.Model; @@ -11,67 +12,54 @@ /** * Stub MavenProject to support native-maven-plugin test harness */ - -public class ProjectStub - extends MavenProjectStub -{ +public class ProjectStub extends MavenProjectStub { private Build build = new BuildStub(); private Set dependencyArtifacts = new HashSet<>(); - public ProjectStub() - { - super( (Model) null ); + public ProjectStub() { + super((Model) null); } // kinda dangerous... - public ProjectStub( Model model ) - { + public ProjectStub(Model model) { // super(model); - super( (Model) null ); + super((Model) null); } // kinda dangerous... - public ProjectStub( MavenProject project ) - { + public ProjectStub(MavenProject project) { // super(project); - super( (Model) null ); + super((Model) null); } @Override - public Build getBuild() - { + public Build getBuild() { return this.build; } @Override - public Set getDependencyArtifacts() - { + public Set getDependencyArtifacts() { return this.dependencyArtifacts; } private Set artifacts; @Override - public void setArtifacts( Set artifacts ) - { + public void setArtifacts(Set artifacts) { this.artifacts = artifacts; } @Override - public Set getArtifacts() - { - if ( this.artifacts == null ) - { + public Set getArtifacts() { + if (this.artifacts == null) { this.artifacts = new HashSet<>(); } return this.artifacts; } @Override - public String getArtifactId() - { + public String getArtifactId() { return "someArtifactId"; } - } diff --git a/pom.xml b/pom.xml index f5a1af71..34c3181a 100644 --- a/pom.xml +++ b/pom.xml @@ -175,6 +175,7 @@ + junit @@ -185,11 +186,6 @@ - - org.apache.maven.plugins - maven-plugin-plugin - 3.11.0 - org.codehaus.plexus plexus-component-metadata