diff --git a/pom.xml b/pom.xml index 0ba2a187b..327652535 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.github.maven-nar nar-maven-plugin - 3.7.0-SNAPSHOT + 3.8.0-SNAPSHOT maven-plugin Native ARchive plugin for Maven diff --git a/src/main/java/com/github/maven_nar/Linker.java b/src/main/java/com/github/maven_nar/Linker.java index 41f8e4164..acf0feba9 100755 --- a/src/main/java/com/github/maven_nar/Linker.java +++ b/src/main/java/com/github/maven_nar/Linker.java @@ -103,6 +103,14 @@ public class Linker { @Parameter private List testOptions; + /** + * Additional options for the linker when running in the nar-testCompile + * phase. + * + */ + @Parameter + private List testExcludeOptions; + /** * Options for the linker as a whitespace separated list. Defaults to * Architecture-OS-Linker specific values. Will @@ -518,7 +526,23 @@ public final LinkerDef getTestLinker(final AbstractCompileMojo mojo, final CCTas linker.addConfiguredLinkerArg(arg); } } - return linker; + if (this.testExcludeOptions != null) { + for (final Object testExcludeOption : this.testExcludeOptions) { + final LinkerArgument arg = new LinkerArgument(); + arg.setValue((String) testExcludeOption); + if (linker.removeConfiguredLinkerArg(arg)) { + mojo.getLog().debug(String.format("TestExcludeOption removed %s from the list of test execution arguments." , + arg.getValue())); + } + else { + mojo.getLog().debug(String.format ("%s%s%s", + "TestExcludeOption didn't find ", + arg.getValue(), + " as a matching argument among the list of test execution arguments.")); + } + } + } + return linker; } public final String getVersion() throws MojoFailureException, MojoExecutionException { diff --git a/src/main/java/com/github/maven_nar/cpptasks/LinkerDef.java b/src/main/java/com/github/maven_nar/cpptasks/LinkerDef.java index 9f1e0384f..a7739daea 100644 --- a/src/main/java/com/github/maven_nar/cpptasks/LinkerDef.java +++ b/src/main/java/com/github/maven_nar/cpptasks/LinkerDef.java @@ -99,6 +99,13 @@ public void addConfiguredLinkerArg(final LinkerArgument arg) { addConfiguredProcessorArg(arg); } + /** + * Removes a linker command-line arg. + */ + public boolean removeConfiguredLinkerArg(final LinkerArgument arg) { + return removeConfiguredProcessorArg(arg); + } + /** * Adds a compiler command-line arg. */ diff --git a/src/main/java/com/github/maven_nar/cpptasks/ProcessorDef.java b/src/main/java/com/github/maven_nar/cpptasks/ProcessorDef.java index 16d10da17..cdbd2247c 100644 --- a/src/main/java/com/github/maven_nar/cpptasks/ProcessorDef.java +++ b/src/main/java/com/github/maven_nar/cpptasks/ProcessorDef.java @@ -133,6 +133,26 @@ protected void addConfiguredProcessorArg(final CommandLineArgument arg) throws N this.processorArgs.addElement(arg); } + /** + * Remove a or + * + * @param arg + * command line argument, must not be null + * @throws NullPointerException + * if arg is null + * @throws BuildException + * if this definition is a reference + */ + protected boolean removeConfiguredProcessorArg(final CommandLineArgument arg) throws NullPointerException, BuildException { + if (arg == null) { + throw new NullPointerException("arg"); + } + if (isReference()) { + throw noChildrenAllowed(); + } + return this.processorArgs.removeElement(arg); + } + /** * Adds a or * @@ -318,6 +338,13 @@ public Environment getEnv() { return this.env; } + /** + * Provide direct access to copy of processorArgs for validation testing. + * + * @return processorArgs + */ + public Vector getProcessorArgs() { return this.processorArgs; } + /** * Gets the ProcessorDef specified by the extends attribute * diff --git a/src/main/java/com/github/maven_nar/cpptasks/types/CommandLineArgument.java b/src/main/java/com/github/maven_nar/cpptasks/types/CommandLineArgument.java index 74e79d35f..60f756766 100644 --- a/src/main/java/com/github/maven_nar/cpptasks/types/CommandLineArgument.java +++ b/src/main/java/com/github/maven_nar/cpptasks/types/CommandLineArgument.java @@ -45,6 +45,10 @@ public String[] getValues() { public CommandLineArgument() { } + protected String getIfCond() { return this.ifCond; } + + protected String getUnlessCond() { return this.unlessCond; } + public int getLocation() { return this.location; } @@ -69,6 +73,13 @@ public boolean isActive(final org.apache.tools.ant.Project p) { return true; } + /** + * Returns true if both of the objects are null or are equal by value. + */ + protected static boolean compareStrings (String object1, String object2) { + return (object1 == null ? object2 == null : object1.equals(object2)); + } + /** * Sets the property name for the 'if' condition. * diff --git a/src/main/java/com/github/maven_nar/cpptasks/types/CompilerArgument.java b/src/main/java/com/github/maven_nar/cpptasks/types/CompilerArgument.java index f965d861d..8231658fb 100644 --- a/src/main/java/com/github/maven_nar/cpptasks/types/CompilerArgument.java +++ b/src/main/java/com/github/maven_nar/cpptasks/types/CompilerArgument.java @@ -19,6 +19,8 @@ */ package com.github.maven_nar.cpptasks.types; +import java.util.Objects; + /** * A compiler command line argument. */ @@ -29,4 +31,33 @@ public CompilerArgument() { public void execute() throws org.apache.tools.ant.BuildException { throw new org.apache.tools.ant.BuildException("Not an actual task, but looks like one for documentation purposes"); } + + /** + * Since equals method is overloaded, also overload hashCode() to be consistent + * when comparing objects for collections. + * @return calculated hashcode of an object. + */ + @Override + public int hashCode() { + return Objects.hashCode(this.getValue()); + } + + + /** + * Override default equals method to compare objects based on the string value, + * consumed by Collections (Vector, etc.,) methods for its comparisons. + * @return true if the comparing object has the same superclass & contains the same value. + */ + @Override + public boolean equals(Object arg) + { + if((arg== null) || (arg.getClass() != CompilerArgument.class)) { + return false; + } + CompilerArgument cmdLineArg = (CompilerArgument) arg; + return (cmdLineArg.compareStrings(cmdLineArg.getValue(),this.getValue()) + && cmdLineArg.getLocation() == this.getLocation() + && cmdLineArg.compareStrings(cmdLineArg.getIfCond(),this.getIfCond()) + && cmdLineArg.compareStrings(cmdLineArg.getUnlessCond(),this.getUnlessCond())); + } } diff --git a/src/main/java/com/github/maven_nar/cpptasks/types/LinkerArgument.java b/src/main/java/com/github/maven_nar/cpptasks/types/LinkerArgument.java index 3e57937e7..67a547119 100644 --- a/src/main/java/com/github/maven_nar/cpptasks/types/LinkerArgument.java +++ b/src/main/java/com/github/maven_nar/cpptasks/types/LinkerArgument.java @@ -19,6 +19,8 @@ */ package com.github.maven_nar.cpptasks.types; +import java.util.Objects; + /** * A linker command line argument. */ @@ -29,4 +31,33 @@ public LinkerArgument() { public void execute() throws org.apache.tools.ant.BuildException { throw new org.apache.tools.ant.BuildException("Not an actual task, but looks like one for documentation purposes"); } + + /** + * Since equals method is overloaded, also overload hashCode() to be consistent + * when comparing objects for collections. + * @return calculated hashcode of an object. + */ + @Override + public int hashCode() { + return Objects.hashCode(this.getValue()); + } + + + /** + * Override default equals method to compare objects based on the string value, + * consumed by Collections (Vector, etc.,) methods for its comparisons. + * @return true if the comparing object has the same superclass & contains the same value. + */ + @Override + public boolean equals(Object arg) + { + if((arg== null) || (arg.getClass() != LinkerArgument.class)) { + return false; + } + LinkerArgument cmdLineArg = (LinkerArgument) arg; + return (cmdLineArg.compareStrings(cmdLineArg.getValue(),this.getValue()) + && cmdLineArg.getLocation() == this.getLocation() + && cmdLineArg.compareStrings(cmdLineArg.getIfCond(),this.getIfCond()) + && cmdLineArg.compareStrings(cmdLineArg.getUnlessCond(),this.getUnlessCond())); + } } diff --git a/src/site/apt/configuration.apt b/src/site/apt/configuration.apt index e3cd61571..ef299f0d6 100644 --- a/src/site/apt/configuration.apt +++ b/src/site/apt/configuration.apt @@ -95,6 +95,9 @@ NAR Configuration + + + @@ -356,6 +359,10 @@ wish to run a GNU configure step but not the full make process. Additional options for the linker during the nar-testCompile phase. +** {linker testExcludeOptions} + + Additional options to be excluded for the linker during the nar-testCompile phase. + ** {linker clearDefaultOptions} Clear options specified in AOL properties. diff --git a/src/test/java/com/github/maven_nar/cpptasks/TestLinkerDef.java b/src/test/java/com/github/maven_nar/cpptasks/TestLinkerDef.java index 2d62f1c68..f2ff7c1b3 100644 --- a/src/test/java/com/github/maven_nar/cpptasks/TestLinkerDef.java +++ b/src/test/java/com/github/maven_nar/cpptasks/TestLinkerDef.java @@ -361,4 +361,21 @@ public void testWrongType() { } fail("should have thrown exception"); } + /** + * Tests the behavior of testExcludeOptions, + * ensures that linker arguments are removed as expected. + */ + public void testLinkerBase() { + final LinkerDef baseLinkerDef = new LinkerDef(); + final LinkerArgument argument1 = new LinkerArgument(); + argument1.setValue("OPTION1"); + baseLinkerDef.addConfiguredLinkerArg(argument1); + final LinkerArgument argument2 = new LinkerArgument(); + argument2.setValue("OPTION2"); + baseLinkerDef.addConfiguredLinkerArg(argument2); + assertEquals(2,baseLinkerDef.getProcessorArgs().size()); + baseLinkerDef.removeConfiguredLinkerArg(argument1); + baseLinkerDef.removeConfiguredLinkerArg(argument2); + assertEquals(0,baseLinkerDef.getProcessorArgs().size()); + } }