Skip to content

Commit

Permalink
including PMD
Browse files Browse the repository at this point in the history
  • Loading branch information
Kallin committed Sep 2, 2014
1 parent 4be8ce9 commit 0f716d5
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 21 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'pmd'

repositories {
jcenter()
Expand All @@ -12,8 +13,13 @@ task wrapper(type: Wrapper) {
gradleVersion = "2.0"
}

pmd {
ignoreFailures = true
}

dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'ch.qos.logback:logback-classic:1.1.2'

compile 'org.apache.commons:commons-math3:3.3'
compile 'org.json:json:20140107'

Expand Down
1 change: 1 addition & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<module name="Checker">
<module name="TreeWalker">
<module name="UnusedImports"/>
<module name="EmptyBlock"/>
</module>
</module>
6 changes: 3 additions & 3 deletions src/main/java/com/hearthsim/gui/HSDeckCreatePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public void actionPerformed(ActionEvent e) {
}
label.setText((String)heroChoice_.getSelectedItem());
} catch (HSException exception) {
}
System.out.println(exception);
}
}

});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.nio.file.Path;

public class ArtificialPlayer {

int nLookahead_;

private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());

int nLookahead_;

double my_wAttack_; //weight for the attack score
double my_wHealth_;
Expand Down Expand Up @@ -349,7 +351,9 @@ public void writeOut(String filename, Object node) {
} catch (IOException e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {writer.close();} catch (Exception e) {}
try {writer.close();} catch (Exception e) {
log.warn("ignoring..", e);
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/ptplot/FileUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
@Pt.AcceptedRating Green (cxh)
*/
public class FileUtilities {

private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
/** Instances of this class cannot be created.
*/
private FileUtilities() {
Expand Down Expand Up @@ -208,6 +210,7 @@ public static void main(String[] args) {
* @see #nameToURL(String, URI, ClassLoader)
*/
public static File nameToFile(String name, URI base) {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FileUtilities.class);
if ((name == null) || name.trim().equals("")) {
return null;
}
Expand All @@ -217,6 +220,7 @@ public static File nameToFile(String name, URI base) {
try {
result = _searchClassPath(name, null);
} catch (IOException ex) {
log.warn("error in nameToFile", ex);
// Ignore. In nameToFile(), it is ok if we don't find the variable
}
if (result != null) {
Expand Down Expand Up @@ -280,6 +284,7 @@ public static File nameToFile(String name, URI base) {
*/
public static URL nameToURL(String name, URI baseDirectory,
ClassLoader classLoader) throws IOException {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FileUtilities.class);
if ((name == null) || name.trim().equals("")) {
return null;
}
Expand Down Expand Up @@ -409,14 +414,13 @@ public static URL nameToURL(String name, URI baseDirectory,
// requires this because the URL is relative.
return new URL(baseDirectory.toURL(), urlString);
} catch (Exception ex4) {

try {
// Under Webstart, ptalon, EightChannelFFT
// requires this.
return new URL(baseDirectory.toURL(), newURI
.toString());
} catch (Exception ex5) {
// Ignore
log.warn("ignoring..", ex5);
}

IOException io = new IOException(
Expand Down Expand Up @@ -449,7 +453,7 @@ public static URL nameToURL(String name, URI baseDirectory,
"(https?:)//?", "$1//");
url = new URL(fixedURLAsString);
} catch (Exception e) {
// Ignore
log.warn("ignoring..",e);
}
return url;
}
Expand All @@ -474,6 +478,7 @@ public static URL nameToURL(String name, URI baseDirectory,
*/
public static BufferedReader openForReading(String name, URI base,
ClassLoader classLoader) throws IOException {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FileUtilities.class);
if ((name == null) || name.trim().equals("")) {
return null;
}
Expand Down Expand Up @@ -516,7 +521,7 @@ public static BufferedReader openForReading(String name, URI base,
inputStreamReader.close();
}
} catch (IOException ex3) {
// Ignore
log.warn("ignoring..", ex3);
}
IOException ioException = new IOException("Failed to open \""
+ url + "\".");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ptplot/JFileChooserBugFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ clause, restoreBackground() should be called. For example:
@Pt.AcceptedRating Red (cxh)
*/
public class JFileChooserBugFix {
private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());

/** Instantiate a JFileChooserBugFix object. */
public JFileChooserBugFix() {
Expand Down Expand Up @@ -117,6 +118,7 @@ public Color saveBackground() {
javax.swing.text.StyleConstants.ResolveAttribute);
background = styleSheet.getBackground(bodyAttribute);
} catch (Exception ex) {
log.warn("ignoring..", ex);
// Ignore, we just won't set the background.
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/ptplot/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ the derived class GraphicalMessageHandler.
@Pt.AcceptedRating Green (cxh)
*/
public class MessageHandler {
private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
///////////////////////////////////////////////////////////////////
//// public methods ////

Expand Down Expand Up @@ -280,6 +281,7 @@ protected boolean _yesNoQuestion(String question) {
return true;
}
} catch (IOException ex) {
log.warn("ignoring..", ex);
}

return false;
Expand Down Expand Up @@ -317,6 +319,7 @@ protected boolean _yesNoCancelQuestion(String question)
}
}
} catch (IOException ex) {
log.warn("ignoring..", ex);
}

return false;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/ptplot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void run() {
@Pt.AcceptedRating Yellow (cxh)
*/
public class Plot extends PlotBox {
private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
///////////////////////////////////////////////////////////////////
//// public methods ////

Expand Down Expand Up @@ -1613,6 +1614,7 @@ protected boolean _parseLine(String line) {

setBars(bwidth, boffset);
} catch (NumberFormatException e) {
log.warn("ignoring..", e);
// ignore if format is bogus.
}
}
Expand Down Expand Up @@ -1719,6 +1721,7 @@ protected boolean _parseLine(String line) {
return true;
}
} catch (NumberFormatException e) {
log.warn("ignoring", e);
// ignore if format is bogus.
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/ptplot/PlotBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ enables wrapping of the X (horizontal) axis, which means that if
@Pt.AcceptedRating Yellow (cxh)
*/
public class PlotBox extends JPanel implements Printable {
private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
///////////////////////////////////////////////////////////////////
//// constructor ////

Expand Down Expand Up @@ -421,6 +422,7 @@ public void run() {
// deadlock. Don't do it!
SwingUtilities.invokeLater(doActions);
} catch (Exception ex) {
log.warn("ignoring", ex);
// Ignore InterruptedException.
// Other exceptions should not occur.
}
Expand Down Expand Up @@ -629,6 +631,7 @@ public Color[] getColors() {
* @return An instance of Color.
*/
public static Color getColorByName(String name) {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PlotBox.class);
try {
// Check to see if it is a hexadecimal
if (name.startsWith("#")) {
Expand All @@ -638,6 +641,7 @@ public static Color getColorByName(String name) {
Color col = new Color(Integer.parseInt(name, 16));
return col;
} catch (NumberFormatException e) {
log.warn("ignoring", e);
}

// FIXME: This is a poor excuse for a list of colors and values.
Expand All @@ -653,6 +657,7 @@ public static Color getColorByName(String name) {
Color col = new Color(Integer.parseInt(names[i][1], 16));
return col;
} catch (NumberFormatException e) {
log.warn("ignoring", e);
}
}
}
Expand Down Expand Up @@ -1055,6 +1060,7 @@ public synchronized void parseFile(String filespec, URL documentBase) {
try {
in.close();
} catch (IOException me) {
log.warn("ignoring", me);
}
}
}
Expand Down Expand Up @@ -2756,6 +2762,7 @@ protected boolean _parseLine(String line) {
Double dmax = Double.valueOf(max);
setXRange(dmin.doubleValue(), dmax.doubleValue());
} catch (NumberFormatException e) {
log.warn("ignoring", e);
// ignore if format is bogus.
}
}
Expand All @@ -2773,6 +2780,7 @@ protected boolean _parseLine(String line) {
Double dmax = Double.valueOf(max);
setYRange(dmin.doubleValue(), dmax.doubleValue());
} catch (NumberFormatException e) {
log.warn("ignoring", e);
// ignore if format is bogus.
}
}
Expand Down Expand Up @@ -3487,8 +3495,7 @@ private Vector _gridInit(double low, double step, boolean labeled,
// or equal to x. This sets us up to process the first point.
for (_gridCurJuke = -1; ((_gridCurJuke + 1) < grid.size())
&& (x >= ((Double) grid.elementAt(_gridCurJuke + 1))
.doubleValue()); _gridCurJuke++) {
}
.doubleValue()); _gridCurJuke++) ;

return grid;
}
Expand All @@ -3500,9 +3507,7 @@ private double _gridRoundUp(Vector grid, double pos) {
double x = pos - Math.floor(pos);
int i;

for (i = 0; (i < grid.size())
&& (x >= ((Double) grid.elementAt(i)).doubleValue()); i++) {
}
for (i = 0; (i < grid.size()) && (x >= ((Double) grid.elementAt(i)).doubleValue()); i++);

if (i >= grid.size()) {
return pos;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/ptplot/PlotFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void windowClosing(WindowEvent e) {
@Pt.AcceptedRating Yellow (cxh)
*/
public class PlotFrame extends JFrame {

private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
/** Construct a plot frame with a default title and by default contains
* an instance of Plot. After constructing this, it is necessary
* to call setVisible(true) to make the plot appear.
Expand Down Expand Up @@ -114,7 +116,7 @@ public PlotFrame(String title, PlotBox plotArg) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
// Ignore exceptions, which only result in the wrong look and feel.
log.warn("ignoring..", e);
}

if (plotArg == null) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/ptplot/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ public void setToolTip(String name, String tip) {
* @return A string representing the color.
*/
public static Color stringToColor(String description) {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Query.class);
String[] specArray = description.split("[{},]");
float red = 0f;
float green = 0f;
Expand Down Expand Up @@ -1571,7 +1572,7 @@ public static Color stringToColor(String description) {
alpha = Float.parseFloat(specArray[i]);
}
} catch (Exception ex) {
// Ignore and use default color.
log.warn("ignoring..", ex);
}
return new Color(red, green, blue, alpha);
}
Expand Down Expand Up @@ -1891,6 +1892,8 @@ public void setColor(String name) {
*
*/
public static class QueryFileChooser extends Box implements ActionListener {

private final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
/** Construct a query file chooser. The background will be white and
* the foreground will be black.
* @param owner The query object that owns the file chooser
Expand Down Expand Up @@ -2052,7 +2055,7 @@ public void approveSelection() {
try {
selectedFile = selectedFile.getCanonicalFile();
} catch (IOException ex) {
// Ignore, since we can't do much about it anyway.
log.warn("ignoring", ex);
}

URI relativeURI = _base
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/ptplot/StringUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public static String getIndentPrefix(int level) {
* If the property is not found, then we return the empty string.
*/
public static String getProperty(String propertyName) {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FileUtilities.class);
// NOTE: getProperty() will probably fail in applets, which
// is why this is in a try block.
String property = null;
Expand Down Expand Up @@ -502,7 +503,7 @@ public static String getProperty(String propertyName) {
// will get the correct value.
System.setProperty("ptolemy.ptII.dir", _ptolemyPtIIDir);
} catch (SecurityException security) {
// Ignore, we are probably running as an applet or -sandbox
log.warn("ignoring", security);
}

return _ptolemyPtIIDir;
Expand Down Expand Up @@ -848,6 +849,7 @@ public static String substitute(String string, String pattern,
*/
public static String substituteFilePrefix(String prefix, String string,
String replacement) {
final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StringUtilities.class);
// This method is currently used by $PTII/util/testsuite/auto.tcl
if (string.startsWith(prefix)) {
// Hmm, what about file separators?
Expand All @@ -866,7 +868,7 @@ public static String substituteFilePrefix(String prefix, String string,
.length());
}
} catch (Throwable throwable) {
// ignore.
log.warn("ignoring", throwable);
}
}

Expand Down

0 comments on commit 0f716d5

Please sign in to comment.