Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support testExcludeOptions to remove compiler/linker options in test phase. #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.7.0-SNAPSHOT</version>
<version>3.8.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Native ARchive plugin for Maven</name>
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/github/maven_nar/Linker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/github/maven_nar/cpptasks/LinkerDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/github/maven_nar/cpptasks/ProcessorDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ protected void addConfiguredProcessorArg(final CommandLineArgument arg) throws N
this.processorArgs.addElement(arg);
}

/**
* Remove a <compilerarg> or <linkerarg>
*
* @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 <compilerarg>or <linkerarg>
*
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.github.maven_nar.cpptasks.types;

import java.util.Objects;

/**
* A compiler command line argument.
*/
Expand All @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.github.maven_nar.cpptasks.types;

import java.util.Objects;

/**
* A linker command line argument.
*/
Expand All @@ -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()));
}
}
7 changes: 7 additions & 0 deletions src/site/apt/configuration.apt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ NAR Configuration
<testOptions>
<testOption/>
</testOptions>
<testExcludeOptions>
<testExcludeOption/>
</testExcludeOptions>
<clearDefaultOptions/>
<libs>
<lib>
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/github/maven_nar/cpptasks/TestLinkerDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}