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

Add support for HPE Fortify code scanning during compilation #274

Merged
merged 1 commit into from
May 11, 2017
Merged
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
15 changes: 15 additions & 0 deletions src/main/java/com/github/maven_nar/AbstractCompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ public abstract class AbstractCompileMojo extends AbstractDependencyMojo {
@Parameter
private Java java;

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is not javadoc, but should be. And note that javadoc is HTML, so line breaks mean nothing without <p> or <br> tags. Best is to use the IDE to preview the final result.

* To support scanning the code with HPE Fortify
* The attribute is used both as a flag that Fortify is required and the value set is used for the
* When setting a value - sourceanalyzer –b <fortifyID> will be prepended to the
* command line
* */
@Parameter(defaultValue = "")
private String fortifyID;


/**
* Flag to cpptasks to indicate whether linker options should be decorated or
* not
Expand Down Expand Up @@ -228,6 +238,11 @@ public void setCpp(final Cpp cpp) {
this.cpp = cpp;
cpp.setAbstractCompileMojo(this);
}

protected final String getfortifyID()
{
return this.fortifyID;
}

public final void setDependencyLibOrder(final List/* <String> */order) {
this.dependencyLibOrder = order;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/maven_nar/NarCompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ private void createLibrary(final Project antProject, final Library library)
if (getCpp() != null) {
final CompilerDef cpp = getCpp().getCompiler(Compiler.MAIN, null);
if (cpp != null) {
// Set FortifyID attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please watch the whitespace. It does not match.

cpp.setFortifyID(getfortifyID());
task.addConfiguredCompiler(cpp);
}
}
Expand All @@ -187,6 +189,8 @@ private void createLibrary(final Project antProject, final Library library)
if (getC() != null) {
final CompilerDef c = getC().getCompiler(Compiler.MAIN, null);
if (c != null) {
// Set FortifyID attribute
c.setFortifyID(getfortifyID());
task.addConfiguredCompiler(c);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/github/maven_nar/cpptasks/CompilerDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public final class CompilerDef extends ProcessorDef {
private String compilerPrefix;
private File workDir;
private boolean gccFileAbsolutePath;
private String fortifyID="";

private boolean clearDefaultOptions;

Expand Down Expand Up @@ -571,7 +572,14 @@ public void setCompilerPrefix(final String prefix) {
public void setWorkDir(final File workDir) {
this.workDir = workDir;
}


public void setFortifyID(final String fortifyID) {
this.fortifyID = fortifyID;
}

public String getFortifyID() {
return this.fortifyID;
}
/**
* Enumerated attribute with the values "none", "severe", "default",
* "production", "diagnostic", and "aserror".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public abstract class CommandLineCompiler extends AbstractCompiler {
private final boolean libtool;
private final CommandLineCompiler libtoolCompiler;
private final boolean newEnvironment;
private String fortifyID="";

protected CommandLineCompiler(final String command, final String identifierArg, final String[] sourceExtensions,
final String[] headerExtensions,
Expand Down Expand Up @@ -215,6 +216,13 @@ public void compile(final CCTask task, final File outputDir, final String[] sour
if (this.libtool) {
commandlinePrefix.add("libtool");
}
if((this.fortifyID !=null) && (!this.fortifyID.equals("")))
{// If FortifyID attribute was set, run the Fortify framework

commandlinePrefix.add("sourceanalyzer");
commandlinePrefix.add("-b");
commandlinePrefix.add(this.fortifyID);
}
commandlinePrefix.add(command);
Collections.addAll(commandlinePrefix, args);

Expand Down Expand Up @@ -404,6 +412,7 @@ protected CompilerConfiguration createConfiguration(final CCTask task, final Lin
final String path = specificDef.getToolPath();

CommandLineCompiler compiler = this;

Environment environment = specificDef.getEnv();
if (environment == null) {
for (final ProcessorDef baseDef : baseDefs) {
Expand All @@ -415,6 +424,9 @@ protected CompilerConfiguration createConfiguration(final CCTask task, final Lin
} else {
compiler = (CommandLineCompiler) compiler.changeEnvironment(specificDef.isNewEnvironment(), environment);
}
// Pass the fortifyID for compiler
compiler.fortifyID = specificDef.getFortifyID();

return new CommandLineCompilerConfiguration(compiler, configId, incPath, sysIncPath, envIncludePath,
includePathIdentifier.toString(), argArray, paramArray, rebuild, endArgs, path, specificDef.getCcache());
}
Expand Down