Fix some things

This commit is contained in:
Clément Fournier
2020-08-30 20:14:20 +02:00
parent 76d81e6979
commit 3f00548e5f
8 changed files with 41 additions and 41 deletions

View File

@ -132,4 +132,4 @@ public class DartTokenizerTest extends CpdTextComparisonTest {
}
}
```
```

View File

@ -222,7 +222,7 @@ public class PMD {
// in case we analyzed files within Zip Files/Jars, we need to close them after
// the analysis is finished
Exception closed = FileUtil.closeAll(files);
Exception closed = IOUtil.closeAll(files);
if (closed != null) {
if (ex != null) {

View File

@ -96,7 +96,7 @@ class PmdRunnable implements Runnable {
TimeTracker.finishThread();
}
public void processSource(RuleContext ruleCtx, LanguageVersion languageVersion, RuleSets ruleSets) throws IOException, FileAnalysisException {
private void processSource(RuleContext ruleCtx, LanguageVersion languageVersion, RuleSets ruleSets) throws IOException, FileAnalysisException {
String fullSource = DataSource.readToString(dataSource, configuration.getSourceEncoding());
String filename = dataSource.getNiceFileName(false, null);
@ -116,7 +116,7 @@ class PmdRunnable implements Runnable {
}
}
private RootNode parse(Parser parser, ParserTask task) throws IOException {
private RootNode parse(Parser parser, ParserTask task) {
try (TimedOperation to = TimeTracker.startOperation(TimedOperationCategory.PARSER)) {
return parser.parse(task);
}
@ -127,7 +127,7 @@ class PmdRunnable implements Runnable {
RuleSets ruleSets,
RuleContext ctx,
LanguageVersion languageVersion,
String filename) throws FileAnalysisException, IOException {
String filename) throws FileAnalysisException {
ParserTask task = new ParserTask(
languageVersion,

View File

@ -13,7 +13,7 @@ import net.sourceforge.pmd.Report.ProcessingError;
import net.sourceforge.pmd.Report.SuppressedViolation;
import net.sourceforge.pmd.RuleViolation;
import net.sourceforge.pmd.internal.util.AssertionUtil;
import net.sourceforge.pmd.util.FileUtil;
import net.sourceforge.pmd.util.IOUtil;
/**
* A handler for events occuring during analysis of a single file. Instances
@ -117,7 +117,7 @@ public interface FileAnalysisListener extends AutoCloseable {
@Override
public void close() throws Exception {
Exception composed = FileUtil.closeAll(list);
Exception composed = IOUtil.closeAll(list);
if (composed != null) {
throw composed;
}

View File

@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.ast.FileAnalysisException;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.util.BaseResultProducingCloseable;
import net.sourceforge.pmd.util.CollectionUtil;
import net.sourceforge.pmd.util.FileUtil;
import net.sourceforge.pmd.util.IOUtil;
import net.sourceforge.pmd.util.datasource.DataSource;
/**
@ -129,7 +129,7 @@ public interface GlobalAnalysisListener extends AutoCloseable {
@Override
public void close() throws Exception {
Exception composed = FileUtil.closeAll(myList);
Exception composed = IOUtil.closeAll(myList);
if (composed != null) {
throw composed;
}

View File

@ -43,32 +43,6 @@ public final class FileUtil {
private FileUtil() {
}
/**
* Close all closeable resources in order. If any exception occurs,
* it is saved and returned. If more than one exception occurs, the
* following are accumulated as suppressed violations.
*
* @param closeables Resources to close
*
* @return An exception, or null if no 'close' routine threw
*/
@SuppressWarnings("PMD.CloseResource") // false-positive
public static Exception closeAll(Collection<? extends AutoCloseable> closeables) {
Exception composed = null;
for (AutoCloseable it : closeables) {
try {
it.close();
} catch (Exception e) {
if (composed == null) {
composed = e;
} else {
composed.addSuppressed(e);
}
}
}
return composed;
}
/**
* Helper method to get a filename without its extension
*

View File

@ -17,6 +17,7 @@ import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Files;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@ -97,4 +98,29 @@ public final class IOUtil {
}
}
/**
* Close all closeable resources in order. If any exception occurs,
* it is saved and returned. If more than one exception occurs, the
* following are accumulated as suppressed exceptions in the first.
*
* @param closeables Resources to close
*
* @return An exception, or null if no 'close' routine threw
*/
@SuppressWarnings("PMD.CloseResource") // false-positive
public static Exception closeAll(Collection<? extends AutoCloseable> closeables) {
Exception composed = null;
for (AutoCloseable it : closeables) {
try {
it.close();
} catch (Exception e) {
if (composed == null) {
composed = e;
} else {
composed.addSuppressed(e);
}
}
}
return composed;
}
}

View File

@ -17,7 +17,7 @@ import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
*/
public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
private final String source =
private static final String SOURCE =
"create or replace\n" + "package pkg_xpath_problem\n" + "AS\n" + " PROCEDURE pkg_minimal\n" + " IS\n"
+ " a_variable VARCHAR2(1);\n" + " BEGIN \n" + " --PRAGMA INLINE(output,'YES');\n"
+ " a_variable := 'Y' ;\n" + " END ;\n" + "end pkg_xpath_problem;\n" + "/\n";
@ -29,7 +29,7 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
* See https://sourceforge.net/p/pmd/bugs/1166/
*/
@Test
public void testXPathRule1() throws Exception {
public void testXPathRule1() {
testOnVersion(XPathVersion.XPATH_1_0);
}
@ -37,7 +37,7 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
* See https://sourceforge.net/p/pmd/bugs/1166/
*/
@Test
public void testXPathRule1Compatibility() throws Exception {
public void testXPathRule1Compatibility() {
testOnVersion(XPathVersion.XPATH_1_0_COMPATIBILITY);
}
@ -45,17 +45,17 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
* See https://sourceforge.net/p/pmd/bugs/1166/
*/
@Test
public void testXPathRule2() throws Exception {
public void testXPathRule2() {
testOnVersion(XPathVersion.XPATH_2_0);
}
private void testOnVersion(XPathVersion xpath10) throws Exception {
private void testOnVersion(XPathVersion xpath10) {
XPathRule rule = new XPathRule(xpath10, "//PrimaryPrefix");
rule.setLanguage(LanguageRegistry.getLanguage(PLSQLLanguageModule.NAME));
rule.setMessage("Test Violation");
Report report = plsql.executeRule(rule, source);
Report report = plsql.executeRule(rule, SOURCE);
Assert.assertEquals(2, report.getViolations().size());
}