AMQP-303 - Improve Rules Compliance (Sonar)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,9 @@ public interface ConnectionCallback<T> {
|
||||
/**
|
||||
* Execute any number of operations against the supplied OTP connection,
|
||||
* possibly returning a result.
|
||||
*
|
||||
* @throws Exception We are not sure everything it throws
|
||||
*/
|
||||
T doInConnection(Connection connection) throws Exception; //Not sure everything it throws
|
||||
T doInConnection(Connection connection) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,12 +33,15 @@ public class Background {
|
||||
throws IOException
|
||||
{
|
||||
File devNull;
|
||||
if(Os.isFamily("unix"))
|
||||
if(Os.isFamily("unix")) {
|
||||
devNull = new File("/dev/null");
|
||||
else if (Os.isFamily("windows"))
|
||||
}
|
||||
else if (Os.isFamily("windows")) {
|
||||
devNull = new File("NUL");
|
||||
else
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unhandled Java environment");
|
||||
}
|
||||
exec(cmd, devNull, false, devNull, false);
|
||||
}
|
||||
|
||||
@@ -57,12 +60,15 @@ public class Background {
|
||||
File errFile, boolean appendErr)
|
||||
throws IOException
|
||||
{
|
||||
if(Os.isFamily("unix"))
|
||||
if(Os.isFamily("unix")) {
|
||||
execUnix(cmd, outFile, appendOut, errFile, appendErr);
|
||||
else if (Os.isFamily("windows"))
|
||||
}
|
||||
else if (Os.isFamily("windows")) {
|
||||
execWin(cmd, outFile, appendOut, errFile, appendErr);
|
||||
else
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unhandled Java environment");
|
||||
}
|
||||
}
|
||||
|
||||
private static void execUnix(String[] cmd,
|
||||
@@ -95,7 +101,7 @@ public class Background {
|
||||
p.waitFor();
|
||||
} catch(Exception exc){
|
||||
throw new IOException("Unable to properly background process: " +
|
||||
exc.getMessage());
|
||||
exc.getMessage(), exc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -38,7 +38,7 @@ public class Execute {
|
||||
private static Log log = LogFactory.getLog(Execute.class);
|
||||
|
||||
/** Invalid exit code. **/
|
||||
public final static int INVALID = Integer.MAX_VALUE;
|
||||
public static final int INVALID = Integer.MAX_VALUE;
|
||||
|
||||
private String[] cmdl = null;
|
||||
private String[] env = null;
|
||||
@@ -55,8 +55,10 @@ public class Execute {
|
||||
* Find the list of environment variables for this process.
|
||||
*/
|
||||
public static synchronized Vector<String> getProcEnvironment() {
|
||||
if (procEnvironment != null)
|
||||
|
||||
if (procEnvironment != null) {
|
||||
return procEnvironment;
|
||||
}
|
||||
|
||||
procEnvironment = new Vector<String>();
|
||||
try {
|
||||
@@ -188,8 +190,9 @@ public class Execute {
|
||||
* @return the environment used to create a subprocess
|
||||
*/
|
||||
public String[] getEnvironment() {
|
||||
if (env == null || newEnvironment)
|
||||
if (env == null || newEnvironment) {
|
||||
return env;
|
||||
}
|
||||
return patchEnvironment();
|
||||
}
|
||||
|
||||
@@ -258,8 +261,9 @@ public class Execute {
|
||||
}
|
||||
if (watchdog != null) {
|
||||
Exception ex = watchdog.getException();
|
||||
if (ex != null)
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
int exit = getExitValue();
|
||||
|
||||
@@ -276,11 +280,13 @@ public class Execute {
|
||||
}
|
||||
|
||||
private String array2string(String sa[]) {
|
||||
if (sa == null)
|
||||
if (sa == null) {
|
||||
return "null";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < sa.length; i++)
|
||||
for (int i = 0; i < sa.length; i++) {
|
||||
sb.append(sa[i]).append(" ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -381,8 +387,9 @@ public class Execute {
|
||||
}
|
||||
|
||||
exec.setNewenvironment(false);
|
||||
if (baseDir != null)
|
||||
if (baseDir != null) {
|
||||
exec.setWorkingDirectory(baseDir);
|
||||
}
|
||||
|
||||
exec.execute();
|
||||
int status = exec.getExitValue();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util.exec;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -71,7 +70,9 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
|
||||
|
||||
|
||||
public void stop() {
|
||||
if( ! running ) return;
|
||||
if( !running ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
inputThread.join(1000);
|
||||
} catch(InterruptedException e) {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,43 +27,43 @@ import java.io.OutputStream;
|
||||
*/
|
||||
public class StreamPumper implements Runnable {
|
||||
|
||||
// TODO: make SIZE and SLEEP instance variables.
|
||||
// TODO: add a status flag to note if an error occured in run.
|
||||
// TODO: make SIZE and SLEEP instance variables.
|
||||
// TODO: add a status flag to note if an error occured in run.
|
||||
|
||||
private final static int SLEEP = 5;
|
||||
private final static int SIZE = 128;
|
||||
private InputStream is;
|
||||
private OutputStream os;
|
||||
private static final int SLEEP = 5;
|
||||
private static final int SIZE = 128;
|
||||
private InputStream is;
|
||||
private OutputStream os;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new stream pumper.
|
||||
*
|
||||
* @param is input stream to read data from
|
||||
* @param os output stream to write data to.
|
||||
*/
|
||||
public StreamPumper(InputStream is, OutputStream os) {
|
||||
this.is = is;
|
||||
this.os = os;
|
||||
}
|
||||
/**
|
||||
* Create a new stream pumper.
|
||||
*
|
||||
* @param is input stream to read data from
|
||||
* @param os output stream to write data to.
|
||||
*/
|
||||
public StreamPumper(InputStream is, OutputStream os) {
|
||||
this.is = is;
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies data from the input stream to the output stream.
|
||||
*
|
||||
* Terminates as soon as the input stream is closed or an error occurs.
|
||||
*/
|
||||
public void run() {
|
||||
final byte[] buf = new byte[SIZE];
|
||||
/**
|
||||
* Copies data from the input stream to the output stream.
|
||||
*
|
||||
* Terminates as soon as the input stream is closed or an error occurs.
|
||||
*/
|
||||
public void run() {
|
||||
final byte[] buf = new byte[SIZE];
|
||||
|
||||
int length;
|
||||
try {
|
||||
while ((length = is.read(buf)) > 0) {
|
||||
os.write(buf, 0, length);
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
} catch(IOException e) {}
|
||||
}
|
||||
int length;
|
||||
try {
|
||||
while ((length = is.read(buf)) > 0) {
|
||||
os.write(buf, 0, length);
|
||||
try {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
} catch(IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user