Fix improper MessageFormat in some messages
This commit is contained in:
4 files changed
+18
-27
No files matched your search
@@ -49,6 +49,7 @@ import net.sourceforge.pmd.util.ResourceLoader;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter;
|
||||
import net.sourceforge.pmd.util.internal.xml.SchemaConstants;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages;
|
||||
import net.sourceforge.pmd.util.internal.xml.XmlUtil;
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
|
||||
@@ -236,11 +237,13 @@ final class RuleSetFactory {
|
||||
try {
|
||||
parseRuleNode(ruleSetReferenceId, builder, node, withDeprecatedRuleReferences, rulesetReferences, err);
|
||||
} catch (XmlException recoveredFrom) {
|
||||
// will be thrown later.
|
||||
err.addExceptionToThrowLater(recoveredFrom);
|
||||
// already reported (it's an XmlException), error count
|
||||
// was incremented so parent method will throw RuleSetLoadException.
|
||||
}
|
||||
} else {
|
||||
throw err.at(node).error("Unexpected element as child of <ruleset>");
|
||||
err.at(node).error(XmlErrorMessages.ERR__UNEXPECTED_ELEMENT_IN,
|
||||
node.getTagName(),
|
||||
SchemaConstants.RULESET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +262,7 @@ final class RuleSetFactory {
|
||||
try {
|
||||
pattern = Pattern.compile(text);
|
||||
} catch (PatternSyntaxException pse) {
|
||||
err.addExceptionToThrowLater((XmlException) err.at(node).error(pse));
|
||||
err.at(node).error(pse);
|
||||
return null;
|
||||
}
|
||||
return pattern;
|
||||
@@ -651,11 +654,6 @@ final class RuleSetFactory {
|
||||
private int errCount;
|
||||
private final List<RuntimeException> delayedExceptions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addExceptionToThrowLater(XmlException e) {
|
||||
delayedExceptions.add(e);
|
||||
}
|
||||
|
||||
PmdXmlReporterImpl(MessageReporter pmdReporter, OoxmlFacade ooxml, XmlPositioner positioner) {
|
||||
super(ooxml, positioner);
|
||||
this.pmdReporter = pmdReporter;
|
||||
@@ -677,15 +675,12 @@ final class RuleSetFactory {
|
||||
|
||||
@Override
|
||||
public void logEx(Level level, String message, Object[] formatArgs, @Nullable Throwable error) {
|
||||
XmlException ex = newException(level, error, message, formatArgs);
|
||||
ooxml.getPrinter().accept(ex);
|
||||
newException(level, error, message, formatArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlException error(@Nullable Throwable cause, @Nullable String contextMessage, Object... formatArgs) {
|
||||
XmlException ex = newException(Level.ERROR, cause, contextMessage, formatArgs);
|
||||
ooxml.getPrinter().accept(ex);
|
||||
return ex;
|
||||
return newException(Level.ERROR, cause, contextMessage, formatArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -714,7 +709,9 @@ final class RuleSetFactory {
|
||||
.withSeverity(severity)
|
||||
.withCause(cause);
|
||||
String fullMessage = ooxml.getFormatter().formatSpec(ooxml, spec, positioner);
|
||||
return new XmlException(spec, fullMessage);
|
||||
XmlException ex = new XmlException(spec, fullMessage);
|
||||
ooxml.getPrinter().accept(ex); // spec of newException is also to log.
|
||||
return ex;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -162,7 +162,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
public boolean addFile(Path file, Language language) {
|
||||
AssertionUtil.requireParamNotNull("language", language);
|
||||
if (!Files.isRegularFile(file)) {
|
||||
reporter.error("Not a regular file: {}", file);
|
||||
reporter.error("Not a regular file: {0}", file);
|
||||
return false;
|
||||
}
|
||||
NioTextFile nioTextFile = new NioTextFile(file, charset, discoverer.getDefaultLanguageVersion(language), getDisplayName(file));
|
||||
@@ -238,7 +238,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
LanguageVersion contextVersion = discoverer.getDefaultLanguageVersion(language);
|
||||
if (!fileVersion.equals(contextVersion)) {
|
||||
reporter.error(
|
||||
"Cannot add file {}: version ''{}'' does not match ''{}''",
|
||||
"Cannot add file {0}: version ''{1}'' does not match ''{2}''",
|
||||
textFile.getPathId(),
|
||||
fileVersion,
|
||||
contextVersion
|
||||
@@ -281,7 +281,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
*/
|
||||
public boolean addDirectory(Path dir) throws IOException {
|
||||
if (!Files.isDirectory(dir)) {
|
||||
reporter.error("Not a directory {}", dir);
|
||||
reporter.error("Not a directory {0}", dir);
|
||||
return false;
|
||||
}
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||
@@ -309,7 +309,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
} else if (Files.isRegularFile(file)) {
|
||||
return addFile(file);
|
||||
} else {
|
||||
reporter.error("Not a file or directory {}", file);
|
||||
reporter.error("Not a file or directory {0}", file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package net.sourceforge.pmd.util.internal.xml;
|
||||
|
||||
import net.sourceforge.pmd.util.log.MessageReporter;
|
||||
|
||||
import com.github.oowekyala.ooxml.messages.XmlException;
|
||||
import com.github.oowekyala.ooxml.messages.XmlMessageReporter;
|
||||
|
||||
/**
|
||||
@@ -14,6 +13,4 @@ import com.github.oowekyala.ooxml.messages.XmlMessageReporter;
|
||||
*/
|
||||
public interface PmdXmlReporter extends XmlMessageReporter<MessageReporter> {
|
||||
|
||||
void addExceptionToThrowLater(XmlException e);
|
||||
|
||||
}
|
||||
@@ -18,18 +18,15 @@ public final class SchemaConstants {
|
||||
public static final SchemaConstant DESCRIPTION = new SchemaConstant("description");
|
||||
public static final SchemaConstant PROPERTY_VALUE = new SchemaConstant("value");
|
||||
|
||||
public static final SchemaConstant PROPERTY_ELT = new SchemaConstant("property");
|
||||
|
||||
public static final SchemaConstant PROPERTIES = new SchemaConstant("properties");
|
||||
public static final SchemaConstant PROPERTY_ELT = new SchemaConstant("property");
|
||||
public static final SchemaConstant DEPRECATED = new SchemaConstant("deprecated");
|
||||
|
||||
|
||||
// ruleset
|
||||
public static final SchemaConstant RULESET = new SchemaConstant("ruleset");
|
||||
public static final SchemaConstant EXCLUDE_PATTERN = new SchemaConstant("exclude-pattern");
|
||||
public static final SchemaConstant INCLUDE_PATTERN = new SchemaConstant("include-pattern");
|
||||
public static final SchemaConstant RULE = new SchemaConstant("rule");
|
||||
public static final SchemaConstant REF = new SchemaConstant("ref");
|
||||
|
||||
public static final SchemaConstant EXCLUDE = new SchemaConstant("exclude");
|
||||
public static final SchemaConstant PRIORITY = new SchemaConstant("priority");
|
||||
public static final SchemaConstant MINIMUM_LANGUAGE_VERSION = new SchemaConstant("minimumLanguageVersion");
|
||||
|
||||
Reference in new issue
Block a user