Skip to content

Commit

Permalink
remove suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
akostadinov committed Jun 21, 2018
1 parent d24beb3 commit 20f4a6a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import java.nio.charset.Charset;

import org.kohsuke.stapler.DataBoundConstructor;

Expand Down Expand Up @@ -95,12 +98,13 @@ public SecureGroovyScript getSecureGroovyScript() {

// Method to encapsulate calls for unit-testing
LogstashWriter getLogStashWriter(AbstractBuild<?, ?> build, OutputStream errorStream) {
Charset charset = build.getCharset();
LogstashScriptProcessor processor = null;
if (secureGroovyScript != null) {
processor = new LogstashScriptProcessor(secureGroovyScript, errorStream);
processor = new LogstashScriptProcessor(secureGroovyScript, new OutputStreamWriter(errorStream, charset));
}

return new LogstashWriter(build, errorStream, null, build.getCharset(), processor);
return new LogstashWriter(build, errorStream, null, charset, processor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.io.IOException;
import java.io.OutputStream;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Output stream that writes each line to the provided delegate output stream
* and also sends it to an indexer for logstash to consume.
Expand All @@ -56,9 +54,6 @@ LogstashWriter getLogstashWriter()
}

@Override
@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
protected void eol(byte[] b, int len) throws IOException {
delegate.write(b, 0, len);
this.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package jenkins.plugins.logstash;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.LinkedHashMap;

Expand All @@ -39,8 +39,6 @@
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* This class is handling custom groovy script processing of JSON payload.
* Each call to process executes the script provided in job configuration.
Expand All @@ -58,7 +56,7 @@ public class LogstashScriptProcessor implements LogstashPayloadProcessor{
private final SecureGroovyScript script;

@Nonnull
private final OutputStream consoleOut;
private final OutputStreamWriter consoleWriter;

/** Groovy binding for script execution */
@Nonnull
Expand All @@ -68,9 +66,9 @@ public class LogstashScriptProcessor implements LogstashPayloadProcessor{
@Nonnull
private final ClassLoader classLoader;

public LogstashScriptProcessor(SecureGroovyScript script, OutputStream consoleOut) {
public LogstashScriptProcessor(SecureGroovyScript script, OutputStreamWriter consoleWriter) {
this.script = script;
this.consoleOut = consoleOut;
this.consoleWriter = consoleWriter;

// TODO: should we put variables in the binding like manager, job, etc.?
binding = new Binding();
Expand All @@ -84,13 +82,9 @@ public LogstashScriptProcessor(SecureGroovyScript script, OutputStream consoleOu
/**
* Helper method to allow logging to build console.
*/
@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
private void buildLogPrintln(Object o) throws IOException {
consoleOut.write(o.toString().getBytes());
consoleOut.write("\n".getBytes());
consoleOut.flush();
consoleWriter.write(o.toString() + "\n");
consoleWriter.flush();
}

/*
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/jenkins/plugins/logstash/LogstashWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import java.util.Date;
import java.util.List;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.CheckForNull;

/**
Expand Down Expand Up @@ -77,7 +75,7 @@ public LogstashWriter(Run<?, ?> run, OutputStream error, TaskListener listener)
public LogstashWriter(Run<?, ?> run, OutputStream error, TaskListener listener, Charset charset) {
this(run, error, listener, charset, null);
}

public LogstashWriter(Run<?, ?> run, OutputStream error, TaskListener listener, Charset charset, LogstashPayloadProcessor payloadProcessor) {
this.errorStream = error != null ? error : System.err;
this.build = run;
Expand Down Expand Up @@ -248,9 +246,6 @@ private LogstashIndexerDao getDaoOrNull() {
/**
* Write error message to errorStream and set connectionBroken to true.
*/
@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
private void logErrorMessage(String msg) {
try {
connectionBroken = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
package jenkins.plugins.logstash.persistence;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import jenkins.plugins.logstash.LogstashConfiguration;
import net.sf.json.JSONObject;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Abstract data access object for Logstash indexers.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* POJO for mapping build info to JSON.
*
Expand Down Expand Up @@ -96,9 +94,6 @@ public TestData() {
this(null);
}

@SuppressFBWarnings(
value="URF_UNREAD_FIELD",
justification="TODO: not sure how to fix this")
public TestData(Action action) {
AbstractTestResultAction<?> testResultAction = null;
if (action instanceof AbstractTestResultAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

import jenkins.plugins.logstash.configuration.ElasticSearch;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Elastic Search Data Access Object.
Expand All @@ -78,9 +77,6 @@ public ElasticSearchDao(URI uri, String username, String password) {
}

// Factored for unit testing
@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
ElasticSearchDao(HttpClientBuilder factory, URI uri, String username, String password) {

if (uri == null)
Expand Down Expand Up @@ -196,9 +192,6 @@ public void push(String data) throws IOException {
}
}

@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
private String getErrorMessage(CloseableHttpResponse response) {
ByteArrayOutputStream byteStream = null;
PrintStream stream = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* RabbitMQ Data Access Object.
*
Expand Down Expand Up @@ -124,9 +122,6 @@ public String getVirtualHost()
* @see jenkins.plugins.logstash.persistence.LogstashIndexerDao#push(java.lang.String)
*/
@Override
@SuppressFBWarnings(
value="DM_DEFAULT_ENCODING",
justification="TODO: not sure how to fix this")
public void push(String data) throws IOException {
Connection connection = null;
Channel channel = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -319,7 +320,7 @@ public void writeProcessedSuccess() throws Exception {

SecureGroovyScript script = new SecureGroovyScript(scriptString, true, null);
script.configuringWithNonKeyItem();
LogstashScriptProcessor processor = new LogstashScriptProcessor(script, errorBuffer);
LogstashScriptProcessor processor = new LogstashScriptProcessor(script, new OutputStreamWriter(errorBuffer, mockBuild.getCharset()));
LogstashWriter writer = createLogstashWriter(mockBuild, errorBuffer, "http://my-jenkins-url", mockDao, mockBuildData, processor);
errorBuffer.reset();

Expand All @@ -343,8 +344,8 @@ public void writeProcessedSuccess() throws Exception {
// the message at close time is generated by the script so no call to DAO for that
inOrder.verify(mockDao, times(2)).push("{\"data\":{},\"message\":[\"" + goodMsg + "\"],\"source\":\"jenkins\",\"source_host\":\"http://my-jenkins-url\",\"@version\":1}");

// when creating the mock LogstashWriter by `createLogstashWriter`
verify(mockBuild).getCharset();
// when creating Processor and LogstashWriter by `createLogstashWriter`
verify(mockBuild, times(2)).getCharset();

// building payload
verify(mockBuildData, times(3)).updateResult();
Expand Down

0 comments on commit 20f4a6a

Please sign in to comment.