checkstyle updates

Former-commit-id: e18a6c9a01cf3fdbbdd87446bb25b77e3e455c0f
This commit is contained in:
Jeremy Long
2013-03-30 22:11:04 -04:00
parent 13eb2b75d5
commit 772b0ca2b0
45 changed files with 743 additions and 503 deletions

View File

@@ -40,15 +40,15 @@ public final class CliParser {
/**
* The command line.
*/
private CommandLine line = null;
private CommandLine line;
/**
* The options for the command line parser.
*/
private Options options = createCommandLineOptions();
/**
* indicates whether the arguments are valid.
* Indicates whether the arguments are valid.
*/
boolean isValid = true;
private boolean isValid = true;
/**
* Parses the arguments passed in and captures the results for later use.
@@ -74,8 +74,8 @@ public final class CliParser {
* @throws ParseException if the arguments are invalid
*/
private CommandLine parseArgs(String[] args) throws ParseException {
CommandLineParser parser = new PosixParser();
CommandLine ln = parser.parse(options, args);
final CommandLineParser parser = new PosixParser();
final CommandLine ln = parser.parse(options, args);
return ln;
}
@@ -84,6 +84,7 @@ public final class CliParser {
*
* @throws FileNotFoundException if there is a file specified by either the
* SCAN or CPE command line arguments that does not exist.
* @throws ParseException is thrown if there is an exception parsing the command line.
*/
private void validateArgs() throws FileNotFoundException, ParseException {
if (isRunScan()) {
@@ -93,8 +94,8 @@ public final class CliParser {
throw new ParseException("Scan cannot be run without specifying a directory "
+ "to write the reports to via the 'out' argument.");
} else {
String p = line.getOptionValue(ArgumentName.OUT, "");
File f = new File(p);
final String p = line.getOptionValue(ArgumentName.OUT, "");
final File f = new File(p);
if ("".equals(p) || !(f.exists() && f.isDirectory())) {
//TODO - need a new exception type here, this isn't really a ParseException.
throw new ParseException("A valid directory name must be specified for "
@@ -106,8 +107,8 @@ public final class CliParser {
+ "name via the 'app' argument.");
}
if (line.hasOption(ArgumentName.OUTPUT_FORMAT)) {
String format = line.getOptionValue(ArgumentName.OUTPUT_FORMAT);
if (!(format.equalsIgnoreCase("XML") || format.equalsIgnoreCase("HTML"))) {
final String format = line.getOptionValue(ArgumentName.OUTPUT_FORMAT);
if (!("XML".equalsIgnoreCase(format) || "HTML".equalsIgnoreCase(format))) {
throw new ParseException("Supported output formats are XML and HTML");
}
}
@@ -139,7 +140,7 @@ public final class CliParser {
* not exist.
*/
private void validatePathExists(String path) throws FileNotFoundException {
File f = new File(path);
final File f = new File(path);
if (!f.exists()) {
isValid = false;
throw new FileNotFoundException("Invalid file argument: " + path);
@@ -154,47 +155,47 @@ public final class CliParser {
*/
@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
Option help = new Option(ArgumentName.HELP_SHORT, ArgumentName.HELP, false,
final Option help = new Option(ArgumentName.HELP_SHORT, ArgumentName.HELP, false,
"print this message.");
Option advancedHelp = new Option(ArgumentName.ADVANCED_HELP_SHORT, ArgumentName.ADVANCED_HELP, false,
final Option advancedHelp = new Option(ArgumentName.ADVANCED_HELP_SHORT, ArgumentName.ADVANCED_HELP, false,
"shows additional help regarding properties file.");
Option deepScan = new Option(ArgumentName.PERFORM_DEEP_SCAN_SHORT, ArgumentName.PERFORM_DEEP_SCAN, false,
final Option deepScan = new Option(ArgumentName.PERFORM_DEEP_SCAN_SHORT, ArgumentName.PERFORM_DEEP_SCAN, false,
"extracts extra information from dependencies that may increase false positives, but also decrease false negatives.");
Option version = new Option(ArgumentName.VERSION_SHORT, ArgumentName.VERSION,
final Option version = new Option(ArgumentName.VERSION_SHORT, ArgumentName.VERSION,
false, "print the version information.");
Option noupdate = new Option(ArgumentName.DISABLE_AUTO_UPDATE_SHORT, ArgumentName.DISABLE_AUTO_UPDATE,
final Option noupdate = new Option(ArgumentName.DISABLE_AUTO_UPDATE_SHORT, ArgumentName.DISABLE_AUTO_UPDATE,
false, "disables the automatic updating of the CPE data.");
Option appname = OptionBuilder.withArgName("name").hasArg().withLongOpt(ArgumentName.APPNAME)
final Option appname = OptionBuilder.withArgName("name").hasArg().withLongOpt(ArgumentName.APPNAME)
.withDescription("the name of the application being scanned.")
.create(ArgumentName.APPNAME_SHORT);
Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.SCAN)
final Option path = OptionBuilder.withArgName("path").hasArg().withLongOpt(ArgumentName.SCAN)
.withDescription("the path to scan - this option can be specified multiple times.")
.create(ArgumentName.SCAN_SHORT);
Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.PROP)
final Option props = OptionBuilder.withArgName("file").hasArg().withLongOpt(ArgumentName.PROP)
.withDescription("a property file to load.")
.create(ArgumentName.PROP_SHORT);
Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ArgumentName.OUT)
final Option out = OptionBuilder.withArgName("folder").hasArg().withLongOpt(ArgumentName.OUT)
.withDescription("the folder to write reports to.")
.create(ArgumentName.OUT_SHORT);
Option outputformat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ArgumentName.OUTPUT_FORMAT)
final Option outputformat = OptionBuilder.withArgName("format").hasArg().withLongOpt(ArgumentName.OUTPUT_FORMAT)
.withDescription("the output format to write to.")
.create(ArgumentName.OUTPUT_FORMAT_SHORT);
//TODO add the ability to load a properties file to override the defaults...
OptionGroup og = new OptionGroup();
final OptionGroup og = new OptionGroup();
og.addOption(path);
Options opts = new Options();
final Options opts = new Options();
opts.addOptionGroup(og);
opts.addOption(out);
opts.addOption(outputformat);
@@ -205,6 +206,7 @@ public final class CliParser {
opts.addOption(deepScan);
opts.addOption(props);
opts.addOption(advancedHelp);
return opts;
}
@@ -239,8 +241,8 @@ public final class CliParser {
* Displays the command line help message to the standard output.
*/
public void printHelp() {
HelpFormatter formatter = new HelpFormatter();
String nl = System.getProperty("line.separator");
final HelpFormatter formatter = new HelpFormatter();
final String nl = System.getProperty("line.separator");
String advancedHelp = null;
if (line != null && line.hasOption(ArgumentName.ADVANCED_HELP)) {
advancedHelp = nl + nl
@@ -273,11 +275,10 @@ public final class CliParser {
*/
public String[] getScanFiles() {
return line.getOptionValues(ArgumentName.SCAN);
}
/**
* returns the directory to write the reports to specified on the command
* Returns the directory to write the reports to specified on the command
* line.
*
* @return the path to the reports directory.
@@ -306,12 +307,12 @@ public final class CliParser {
}
/**
* <p>Prints the manifest information to standard output:</p>
* <p>Prints the manifest information to standard output.</p>
* <ul><li>Implementation-Title: ${pom.name}</li>
* <li>Implementation-Version: ${pom.version}</li></ul>
*/
public void printVersionInfo() {
String version = String.format("%s version %s",
final String version = String.format("%s version %s",
Settings.getString("application.name", "DependencyCheck"),
Settings.getString("application.version", "Unknown"));
System.out.println(version);
@@ -341,11 +342,11 @@ public final class CliParser {
public static class ArgumentName {
/**
* The long CLI argument name specifying the directory/file to scan
* The long CLI argument name specifying the directory/file to scan.
*/
public static final String SCAN = "scan";
/**
* The short CLI argument name specifying the directory/file to scan
* The short CLI argument name specifying the directory/file to scan.
*/
public static final String SCAN_SHORT = "s";
/**

View File

@@ -27,6 +27,9 @@ import java.io.IOException;
*/
public class DownloadFailedException extends IOException {
/**
* The serial version UID.
*/
private static final long serialVersionUID = 1L;
/**

View File

@@ -38,7 +38,7 @@ import java.util.zip.InflaterInputStream;
*
* @author Jeremy Long (jeremy.long@gmail.com)
*/
public class Downloader {
public final class Downloader {
/**
* Private constructor for utility class.
@@ -69,7 +69,7 @@ public class Downloader {
* downloading the file.
*/
public static void fetchFile(URL url, String outputPath, boolean unzip) throws DownloadFailedException {
File f = new File(outputPath);
final File f = new File(outputPath);
fetchFile(url, f, unzip);
}
@@ -111,7 +111,7 @@ public class Downloader {
}
throw new DownloadFailedException("Error downloading file.", ex);
}
String encoding = conn.getContentEncoding();
final String encoding = conn.getContentEncoding();
BufferedOutputStream writer = null;
InputStream reader = null;
@@ -125,7 +125,7 @@ public class Downloader {
}
writer = new BufferedOutputStream(new FileOutputStream(outputPath));
byte[] buffer = new byte[4096];
final byte[] buffer = new byte[4096];
int bytesRead = 0;
while ((bytesRead = reader.read(buffer)) > 0) {
writer.write(buffer, 0, bytesRead);
@@ -201,18 +201,18 @@ public class Downloader {
private static HttpURLConnection getConnection(URL url) throws DownloadFailedException {
HttpURLConnection conn = null;
Proxy proxy = null;
String proxyUrl = Settings.getString(Settings.KEYS.PROXY_URL);
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_URL);
try {
if (proxyUrl != null) {
int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT);
SocketAddress addr = new InetSocketAddress(proxyUrl, proxyPort);
final int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT);
final SocketAddress addr = new InetSocketAddress(proxyUrl, proxyPort);
proxy = new Proxy(Proxy.Type.HTTP, addr);
conn = (HttpURLConnection) url.openConnection(proxy);
} else {
conn = (HttpURLConnection) url.openConnection();
}
if (Settings.getString(Settings.KEYS.CONNECTION_TIMEOUT) != null) {
int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT);
final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT);
conn.setConnectTimeout(timeout);
}
} catch (IOException ex) {

View File

@@ -27,7 +27,7 @@ import java.io.IOException;
*
* @author Jeremy Long (jeremy.long@gmail.com)
*/
public class FileUtils {
public final class FileUtils {
/**
* Private constructor for a utility class.
@@ -43,7 +43,7 @@ public class FileUtils {
*/
public static String getFileExtension(String fileName) {
String ret = null;
int pos = fileName.lastIndexOf(".");
final int pos = fileName.lastIndexOf(".");
if (pos >= 0) {
ret = fileName.substring(pos + 1, fileName.length()).toLowerCase();
}

View File

@@ -27,6 +27,9 @@ import java.io.IOException;
*/
public class InvalidSettingException extends IOException {
/**
* The serial version UID.
*/
private static final long serialVersionUID = 1L;
/**

View File

@@ -22,17 +22,17 @@ import java.io.FilterInputStream;
import java.io.InputStream;
/**
* NonClosingStream is a stream filter which prevents
* another class that processes the stream from closing
* it. This is necessary when dealing with things like
* JAXB and zipInputStreams.
* NonClosingStream is a stream filter which prevents another class that
* processes the stream from closing it. This is necessary when dealing with
* things like JAXB and zipInputStreams.
*
* @author Jeremy Long (jeremy.long@gmail.com)
*/
public class NonClosingStream extends FilterInputStream {
/**
* Constructs a new NonClosingStream
* Constructs a new NonClosingStream.
*
* @param in an input stream.
*/
public NonClosingStream(InputStream in) {

View File

@@ -31,12 +31,12 @@ import java.util.logging.Logger;
*
* @author Jeremy Long (jeremy.long@gmail.com)
*/
public class Settings {
public final class Settings {
/**
* The collection of keys used within the properties file.
*/
public static class KEYS {
public static final class KEYS {
/**
* private constructor because this is a "utility" class containing constants
@@ -95,11 +95,11 @@ public class Settings {
*/
public static final String CVE_BASE_URL = "cve.url-";
/**
* The properties key for the CVE schema version 1.2
* The properties key for the CVE schema version 1.2.
*/
public static final String CVE_SCHEMA_1_2 = "1.2.";
/**
* The properties key for the CVE schema version 2.0
* The properties key for the CVE schema version 2.0.
*/
public static final String CVE_SCHEMA_2_0 = "2.0.";
@@ -122,8 +122,17 @@ public class Settings {
*/
public static final String PERFORM_DEEP_SCAN = "perform.deepscan";
}
/**
* The properties file location.
*/
private static final String PROPERTIES_FILE = "configuration/dependencycheck.properties";
/**
* The singleton instance variable.
*/
private static final Settings INSTANCE = new Settings();
/**
* The properties.
*/
private Properties props = null;
/**
@@ -131,7 +140,7 @@ public class Settings {
* properties files.
*/
private Settings() {
InputStream in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
final InputStream in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
props = new Properties();
try {
props.load(in);
@@ -176,7 +185,7 @@ public class Settings {
* the properties.
*/
public static void mergeProperties(String filePath) throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(filePath);
final FileInputStream fis = new FileInputStream(filePath);
mergeProperties(fis);
}
@@ -287,4 +296,4 @@ public class Settings {
}
return value;
}
}
}