Skip to content

Commit

Permalink
[JENKINS-51623] change logger due to problems with JEP-200 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
irissmann committed Jun 1, 2018
1 parent d947bba commit 5868496
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -13,6 +13,7 @@
<packaging>hpi</packaging>
<properties>
<jenkins.version>2.124</jenkins.version>
<java.level>8</java.level>
</properties>
<name>Arachni Scanner Plugin</name>
<description>Runs security scans on an Arachni Rest Server. For communication the Arachni REST API is used.</description>
Expand Down Expand Up @@ -74,7 +75,7 @@
<scope>test</scope>
</dependency>
</dependencies>

<licenses>
<license>
<name>MIT License</name>
Expand Down
Expand Up @@ -8,8 +8,6 @@

import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import hudson.Extension;
import hudson.util.FormValidation;
Expand All @@ -18,7 +16,6 @@

@Extension
public class ArachniPluginConfiguration extends GlobalConfiguration {
Logger log = LoggerFactory.getLogger(ArachniPluginConfiguration.class);

private String arachniServerUrl;

Expand Down
Expand Up @@ -2,9 +2,7 @@

import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;

import hudson.Extension;
import hudson.model.FreeStyleProject;
Expand All @@ -14,7 +12,7 @@

@Extension
public class ArachniRunListener extends RunListener<Run<?,?>> {
Logger log = LoggerFactory.getLogger(ArachniRunListener.class);
Logger log = Logger.getLogger(ArachniRunListener.class.getName());

This comment has been minimized.

Copy link
@oleg-nenashev

oleg-nenashev Jun 9, 2018

Member

It would be still preferable to make it static final IMHO


@Override
public void onFinalized(Run<?, ?> run) {
Expand All @@ -26,7 +24,7 @@ public void onFinalized(Run<?, ?> run) {
try {
((ArachniScanner) builder).shutdownScan();
} catch (IOException exception) {
log.error(exception.getMessage(), exception);
log.severe(exception.getMessage());
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/jenkinsci/plugins/arachni/ArachniScanner.java
Expand Up @@ -7,13 +7,12 @@
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.irissmann.arachni.client.ArachniClient;
import de.irissmann.arachni.client.Scan;
Expand All @@ -36,7 +35,7 @@
import jenkins.tasks.SimpleBuildStep;

public class ArachniScanner extends Builder implements SimpleBuildStep {
Logger log = LoggerFactory.getLogger(ArachniScanner.class);
transient private static final Logger log = Logger.getLogger(ArachniScanner.class.getName());

This comment has been minimized.

Copy link
@oleg-nenashev

oleg-nenashev Jun 9, 2018

Member

No need to make static fields transient.
It is enough to make the field static to prevent serialization


private String url;
private String checks;
Expand Down Expand Up @@ -129,10 +128,9 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
String configuration = null;
if (userConfig != null && StringUtils.isNotBlank(userConfig.getFilename())) {
FilePath configFile = workspace.child(userConfig.getFilename());
log.debug("Configuration filename: {}", configFile.getRemote());
if (!configFile.exists()) {
String message = String.format("Configuration file %s does not exists", userConfig.getFilename());
log.warn(message);
log.warning(message);
throw new AbortException(message);
}
configuration = configFile.readToString();
Expand All @@ -142,7 +140,7 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
try {
scan = arachniClient.performScan(scanRequest, configuration);
console.println("Scan started with id: " + scan.getId());
log.info("Scan started with id: {}", scan.getId());
log.info(String.format("Scan started with id: %s", scan.getId()));

This comment has been minimized.

Copy link
@oleg-nenashev

oleg-nenashev Jun 9, 2018

Member

The framework supports formatted logging via

log.log(Level.INFO, "Scan started with id: {0}", scan.getId())


ScanResponse scanInfo;
while (true) {
Expand All @@ -153,13 +151,11 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
+ scanInfo.getStatistics().getAuditedPages());
if (!scanInfo.isBusy()) {
console.println("Scan finished for id: " + scan.getId());
log.info("Scan finished for id {}", scan.getId());
log.info(String.format("Scan finished for id %s", scan.getId()));
break;
}
}

log.debug("Path for arachni results: {}", workspace);

File reportFile = new File(workspace.getRemote(), "arachni-report-html.zip");
if (!reportFile.exists()) {
if (!reportFile.createNewFile()) {
Expand All @@ -169,7 +165,7 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
outstream = new FileOutputStream(reportFile);
scan.getReportHtml(outstream);
} catch (Exception exception) {
log.warn("Error when start Arachni Security Scan", exception);
log.warning("Error when start Arachni Security Scan");
console.println(exception.getMessage());
throw new AbortException();
} finally {
Expand All @@ -184,13 +180,13 @@ protected void shutdownScan() throws IOException {
return;
}

log.info("Shutdown scanner for id: {}", scan.getId());
log.info(String.format("Shutdown scanner for id: %s", scan.getId()));

try {
scan.shutdown();
log.info("Shutdown successful.");
} catch (Exception exception) {
log.warn("Error when shutdown Arachni Security Scan", exception);
log.warning("Error when shutdown Arachni Security Scan");
} finally {
arachniClient.close();
}
Expand Down

0 comments on commit 5868496

Please sign in to comment.