Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring based on static code analysis #383

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update-arlington-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
git fetch origin arlington:arlington
git checkout -b test-branch arlington
- name: Configure user nameF
- name: Configure user name
run: |
git config user.name "Git User"
git config user.email "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void shouldCreateXmlReportsInGivenDirectory() throws Exception {
List<Future<ValidationResult>> futureResult = startValidation(fileToValidate, numberOfThreads);
List<ValidationResult> validationResults = getValidationResult(futureResult);

Boolean isExpectedResults = compareResultsFromDifferentThreads(validationResults);
boolean isExpectedResults = compareResultsFromDifferentThreads(validationResults);

assertTrue(isExpectedResults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.Callable;

public class CallableValidatorForTest implements Callable<ValidationResult> {
private File fileToValidate;
private final File fileToValidate;

public CallableValidatorForTest(File fileToValidate) {
this.fileToValidate = fileToValidate;
Expand Down
3 changes: 0 additions & 3 deletions gui/src/main/java/org/verapdf/apps/Applications.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ private static boolean areDirectoryFilesWritable(File directory) {
if (files == null) {
return Files.isWritable(directory.toPath());
}
if (files.length == 0) {
return true;
}
for (String fileName : files) {
if (!Files.isWritable(new File(directory + File.separator + fileName).toPath())) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions gui/src/main/java/org/verapdf/apps/SoftwareUpdaterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/

public class SoftwareUpdaterImpl implements SoftwareUpdater {
private final static Logger logger = Logger.getLogger(SoftwareUpdaterImpl.class.getCanonicalName());
private final static String latestGF = "https://search.maven.org/solrsearch/select?q=g:org.verapdf.apps+AND+a:greenfield-apps&core=gav&rows=20&wt=xml";
private final static String latestPDFBox = "https://search.maven.org/solrsearch/select?q=g:org.verapdf.apps+AND+a:pdfbox-apps&core=gav&rows=20&wt=xml";
private static final Logger logger = Logger.getLogger(SoftwareUpdaterImpl.class.getCanonicalName());
private static final String latestGF = "https://search.maven.org/solrsearch/select?q=g:org.verapdf.apps+AND+a:greenfield-apps&core=gav&rows=1&wt=xml";
private static final String latestPDFBox = "https://search.maven.org/solrsearch/select?q=g:org.verapdf.apps+AND+a:pdfbox-apps&core=gav&rows=1&wt=xml";
private final String currentVersion = Applications.getAppDetails().getVersion();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private ApplicationUtils() {
*
* @param toFilter
* the list of files to filter, can not be null
* @return an immutable list of the filtered files, i.e. all PDF extenstions
* @return an immutable list of the filtered files, i.e. all PDF extensions
* @throws IllegalArgumentException
* when toFilter is null
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ public static FeatureExtractorConfig mergeEnabledFeaturesFromPolicy(FeatureExtra
SimpleNamespaceContext nsc = new SimpleNamespaceContext();
nsc.setPrefix(SchematronGenerator.SCH_PREFIX, SchematronGenerator.SCH_NAMESPACE);
xpath.setNamespaceContext(nsc);
String path = "/" + SchematronGenerator.SCH_PREFIX + ":" + SchematronGenerator.ROOT_NAME
String path = '/' + SchematronGenerator.SCH_PREFIX + ':' + SchematronGenerator.ROOT_NAME
+ "/@" + SchematronGenerator.ENABLED_FEATURES_ATTRIBUTE_NAME;
String value = (String) xpath.evaluate(path,
document,
Expand Down
2 changes: 0 additions & 2 deletions gui/src/main/java/org/verapdf/cli/CliConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
package org.verapdf.cli;

import java.util.Arrays;
import java.util.List;

/**
* @author <a href="mailto:[email protected]">Carl Wilson</a>
Expand Down
8 changes: 4 additions & 4 deletions gui/src/main/java/org/verapdf/cli/FormatterHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public FormatterHelper(JCommander commander) {

@Override
public void appendAllParametersDetails(StringBuilder out, int indentCount, String indent, List<ParameterDescription> sortedParameters) {
if (sortedParameters.size() > 0) {
if (!sortedParameters.isEmpty()) {
out.append(indent).append(" Options:\n");
}

Expand All @@ -33,7 +33,7 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin
.append(" ")
.append(parameter.required() ? "* " : " ")
.append(pd.getNames())
.append("\n");
.append('\n');

if (hasDescription) {
wrapDescription(out, indentCount, s(indentCount) + description);
Expand Down Expand Up @@ -107,11 +107,11 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin
out.append(possibleValues);
}
}
out.append("\n");
out.append('\n');
}
}

private static String newLineAndIndent(int indent) {
return "\n" + s(indent);
return '\n' + s(indent);
}
}
7 changes: 3 additions & 4 deletions gui/src/main/java/org/verapdf/cli/VeraPdfCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ public static void main(final String[] args) throws VeraPDFException {
try {
if (!cliArgParser.isMultiprocessing()) {
System.exit(singleThreadProcess(cliArgParser).value);
} else {
System.exit(MultiThreadProcessor.process(cliArgParser).value);
}
System.exit(MultiThreadProcessor.process(cliArgParser).value);
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Interrupted", e);
System.exit(ExitCodes.INTERRUPTED_EXCEPTION.value);
Expand All @@ -116,7 +115,7 @@ public static void main(final String[] args) throws VeraPDFException {
long maxMemory = heapUsage.getMax() / MEGABYTE;
long usedMemory = heapUsage.getUsed() / MEGABYTE;
System.out.format(",%s\n", message); //$NON-NLS-1$
System.out.format("Memory Use: %sM/%sM\n", Long.valueOf(usedMemory), Long.valueOf(maxMemory)); //$NON-NLS-1$
System.out.format("Memory Use: %sM/%sM\n", usedMemory, maxMemory); //$NON-NLS-1$
System.out.format(
"To increase the memory available to the JVM please assign the JAVA_OPTS environment variable.\n"); //$NON-NLS-1$
System.out.format("The examples below increase the maximum heap available to the JVM to 2GB:\n"); //$NON-NLS-1$
Expand Down Expand Up @@ -205,7 +204,7 @@ private static void showUpdateInfo(final ReleaseDetails details) {
return;
}
if (!updater.isUpdateAvailable(details)) {
System.out.format(Applications.UPDATE_LATEST_VERSION, ",", details.getVersion() + "\n"); //$NON-NLS-1$
System.out.format(Applications.UPDATE_LATEST_VERSION, ',', details.getVersion() + '\n'); //$NON-NLS-1$
return;
}
System.out.format(
Expand Down
90 changes: 45 additions & 45 deletions gui/src/main/java/org/verapdf/cli/commands/VeraCliArgParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,50 +68,50 @@
public class VeraCliArgParser {
private static final Logger LOGGER = Logger.getLogger(VeraCliArgParser.class.getCanonicalName());

final static VeraCliArgParser DEFAULT_ARGS = new VeraCliArgParser();
final static String FLAG_SEP = "-"; //$NON-NLS-1$
final static String OPTION_SEP = "--"; //$NON-NLS-1$
final static String HELP_FLAG = FLAG_SEP + "h"; //$NON-NLS-1$
final static String HELP = OPTION_SEP + "help"; //$NON-NLS-1$
final static String VERSION = OPTION_SEP + "version"; //$NON-NLS-1$
final static String FLAVOUR_FLAG = FLAG_SEP + "f"; //$NON-NLS-1$
final static String FLAVOUR = OPTION_SEP + "flavour"; //$NON-NLS-1$
final static String DEFAULT_FLAVOUR_FLAG = FLAG_SEP + "df"; //$NON-NLS-1$
final static String DEFAULT_FLAVOUR = OPTION_SEP + "defaultflavour"; //$NON-NLS-1$
final static String SUCCESS = OPTION_SEP + "success"; //$NON-NLS-1$
final static String PASSED = OPTION_SEP + "passed"; //$NON-NLS-1$
final static String LIST_FLAG = FLAG_SEP + "l"; //$NON-NLS-1$
final static String LIST = OPTION_SEP + "list"; //$NON-NLS-1$
final static String LOAD_PROFILE_FLAG = FLAG_SEP + "p"; //$NON-NLS-1$
final static String LOAD_PROFILE = OPTION_SEP + "profile"; //$NON-NLS-1$
final static String EXTRACT_FLAG = FLAG_SEP + "x"; //$NON-NLS-1$
final static String EXTRACT = OPTION_SEP + "extract"; //$NON-NLS-1$
final static String FORMAT = OPTION_SEP + "format"; //$NON-NLS-1$
final static String RECURSE_FLAG = FLAG_SEP + "r"; //$NON-NLS-1$
final static String RECURSE = OPTION_SEP + "recurse"; //$NON-NLS-1$
final static String SERVER_MODE = OPTION_SEP + "servermode"; //$NON-NLS-1$
final static String VERBOSE_FLAG = FLAG_SEP + "v"; //$NON-NLS-1$
final static String VERBOSE = OPTION_SEP + "verbose"; //$NON-NLS-1$
final static String DEBUG_FLAG = FLAG_SEP + "d"; //$NON-NLS-1$
final static String DEBUG = OPTION_SEP + "debug"; //$NON-NLS-1$
final static String MAX_FAILURES_DISPLAYED = OPTION_SEP + "maxfailuresdisplayed"; //$NON-NLS-1$
final static String MAX_FAILURES = OPTION_SEP + "maxfailures"; //$NON-NLS-1$
final static String FIX_METADATA = OPTION_SEP + "fixmetadata"; //$NON-NLS-1$
final static String FIX_METADATA_PREFIX = OPTION_SEP + "prefix"; //$NON-NLS-1$
final static String FIX_METADATA_FOLDER = OPTION_SEP + "savefolder"; //$NON-NLS-1$
final static String NON_PDF_EXTENSION = OPTION_SEP + "nonpdfext";
final static String POLICY_FILE = OPTION_SEP + "policyfile"; //$NON-NLS-1$
final static String ADD_LOGS = OPTION_SEP + "addlogs"; //$NON-NLS-1$
final static String DISABLE_ERROR_MESSAGES = OPTION_SEP + "disableerrormessages"; //$NON-NLS-1$
final static String PASSWORD = OPTION_SEP + "password"; //$NON-NLS-1$
final static String LOG_LEVEL = OPTION_SEP + "loglevel"; //$NON-NLS-1$
final static String PROGRESS = OPTION_SEP + "progress"; //$NON-NLS-1$
final static String PROFILES_WIKI_FLAG = FLAG_SEP + "pw";
final static String PROFILES_WIKI = OPTION_SEP + "profilesWiki";
final static String VALID_OFF_FLAG = FLAG_SEP + "o"; //$NON-NLS-1$
final static String VALID_OFF = OPTION_SEP + "off"; //$NON-NLS-1$
final static String NUMBER_OF_PROCESSES_FLAG = OPTION_SEP + "processes"; //$NON-NLS-1$
final static String VERA_PATH_FLAG = OPTION_SEP + "verapath";
static final VeraCliArgParser DEFAULT_ARGS = new VeraCliArgParser();
static final String FLAG_SEP = "-"; //$NON-NLS-1$
static final String OPTION_SEP = "--"; //$NON-NLS-1$
static final String HELP_FLAG = FLAG_SEP + 'h'; //$NON-NLS-1$
static final String HELP = OPTION_SEP + "help"; //$NON-NLS-1$
static final String VERSION = OPTION_SEP + "version"; //$NON-NLS-1$
static final String FLAVOUR_FLAG = FLAG_SEP + 'f'; //$NON-NLS-1$
static final String FLAVOUR = OPTION_SEP + "flavour"; //$NON-NLS-1$
static final String DEFAULT_FLAVOUR_FLAG = FLAG_SEP + "df"; //$NON-NLS-1$
static final String DEFAULT_FLAVOUR = OPTION_SEP + "defaultflavour"; //$NON-NLS-1$
static final String SUCCESS = OPTION_SEP + "success"; //$NON-NLS-1$
static final String PASSED = OPTION_SEP + "passed"; //$NON-NLS-1$
static final String LIST_FLAG = FLAG_SEP + 'l'; //$NON-NLS-1$
static final String LIST = OPTION_SEP + "list"; //$NON-NLS-1$
static final String LOAD_PROFILE_FLAG = FLAG_SEP + 'p'; //$NON-NLS-1$
static final String LOAD_PROFILE = OPTION_SEP + "profile"; //$NON-NLS-1$
static final String EXTRACT_FLAG = FLAG_SEP + 'x'; //$NON-NLS-1$
static final String EXTRACT = OPTION_SEP + "extract"; //$NON-NLS-1$
static final String FORMAT = OPTION_SEP + "format"; //$NON-NLS-1$
static final String RECURSE_FLAG = FLAG_SEP + 'r'; //$NON-NLS-1$
static final String RECURSE = OPTION_SEP + "recurse"; //$NON-NLS-1$
static final String SERVER_MODE = OPTION_SEP + "servermode"; //$NON-NLS-1$
static final String VERBOSE_FLAG = FLAG_SEP + 'v'; //$NON-NLS-1$
static final String VERBOSE = OPTION_SEP + "verbose"; //$NON-NLS-1$
static final String DEBUG_FLAG = FLAG_SEP + 'd'; //$NON-NLS-1$
static final String DEBUG = OPTION_SEP + "debug"; //$NON-NLS-1$
static final String MAX_FAILURES_DISPLAYED = OPTION_SEP + "maxfailuresdisplayed"; //$NON-NLS-1$
static final String MAX_FAILURES = OPTION_SEP + "maxfailures"; //$NON-NLS-1$
static final String FIX_METADATA = OPTION_SEP + "fixmetadata"; //$NON-NLS-1$
static final String FIX_METADATA_PREFIX = OPTION_SEP + "prefix"; //$NON-NLS-1$
static final String FIX_METADATA_FOLDER = OPTION_SEP + "savefolder"; //$NON-NLS-1$
static final String NON_PDF_EXTENSION = OPTION_SEP + "nonpdfext";
static final String POLICY_FILE = OPTION_SEP + "policyfile"; //$NON-NLS-1$
static final String ADD_LOGS = OPTION_SEP + "addlogs"; //$NON-NLS-1$
static final String DISABLE_ERROR_MESSAGES = OPTION_SEP + "disableerrormessages"; //$NON-NLS-1$
static final String PASSWORD = OPTION_SEP + "password"; //$NON-NLS-1$
static final String LOG_LEVEL = OPTION_SEP + "loglevel"; //$NON-NLS-1$
static final String PROGRESS = OPTION_SEP + "progress"; //$NON-NLS-1$
static final String PROFILES_WIKI_FLAG = FLAG_SEP + "pw";
static final String PROFILES_WIKI = OPTION_SEP + "profilesWiki";
static final String VALID_OFF_FLAG = FLAG_SEP + 'o'; //$NON-NLS-1$
static final String VALID_OFF = OPTION_SEP + "off"; //$NON-NLS-1$
static final String NUMBER_OF_PROCESSES_FLAG = OPTION_SEP + "processes"; //$NON-NLS-1$
static final String VERA_PATH_FLAG = OPTION_SEP + "verapath";
public static final String USE_CONFIG = OPTION_SEP + "config";

@Parameter(names = { HELP_FLAG, HELP }, description = "Shows this message and exits.", help = true)
Expand Down Expand Up @@ -702,7 +702,7 @@ public static List<String> getBaseVeraPDFParameters(VeraCliArgParser cliArgParse

public void checkParametersCompatibility() {
if (this.format != FormatOption.MRR && this.format != FormatOption.XML && this.policyFile != null
&& !this.policyFile.getAbsolutePath().equals("")) {
&& !this.policyFile.getAbsolutePath().isEmpty()) {
LOGGER.log(Level.WARNING, "Policy report supports only xml (mrr) output format.");
this.format = FormatOption.XML;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public class MultiThreadProcessor {

private int filesQuantity;

private File veraPDFStarterPath;
private List<String> veraPDFParameters;
private final File veraPDFStarterPath;
private final List<String> veraPDFParameters;
private OutputStream os;
private OutputStream errorStream;
private final OutputStream errorStream;

private ReportWriter reportWriter;
private MultiThreadProcessingHandler processingHandler;
private final ReportWriter reportWriter;
private final MultiThreadProcessingHandler processingHandler;

private boolean isFirstReport = true;
private boolean isHTMLReport;
private File xmlReport;
private String wikiPath;
private final String wikiPath;

private ExitCodes currentExitCode = ExitCodes.VALID;
private CountDownLatch latch;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/java/org/verapdf/gui/AboutPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AboutPanel extends JPanel {

static final Logger logger = Logger.getLogger(AboutPanel.class.getCanonicalName());

private JButton okButton;
private final JButton okButton;
JDialog dialog;

AboutPanel() throws IOException {
Expand Down
Loading
Loading