Feature Requests item #1656024, was opened at 2007-02-09 14:21
Message generated for change (Comment added) made by juldsc
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397081&aid=1656024&group_id=29721
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core Framework
Group: None
Status: Open
Priority: 5
Private: No
Submitted By: Yoyo (yoyo_daul)
Assigned to: Nobody/Anonymous (nobody)
Summary: Custom messages for modules in configuration file
Initial Comment:
Hi,
It would be nice to have the possibility to specifie a custom message for a
specific module in the configuration , like in the following :
<module name="MethodLength">
<property name="max" value="0"/>
<property name="customMessage"
value="FILE.LENGTH={0}"/>
</module>
<module name="MethodLength">
<property name="max" value="500}"/>
<property name="customMessage"
value="FILE.LENGTH={0}.EXCEEDS.{1}"/>
</module>
In fact I need this functionnality to automatically process messages in the XML
output file that CheckStyle generates (<error> tags ...)
In addition, it can help to distinct errors from the same Check in different
contexts. (as it is done in the exemple above with the MethodLengthCheck)
I tried to modify the CheckStyle distribution with a minimal set of code modifs
to handle this function, and it was quite easy because of the great readability
and clarity of the code ;)
here are the details below (needed only to slightly modify the Check and
LocalizedMessage classes) :
in the Check class :
--------------------
- add the String customMessage bean property
+ getter/setter :
// mCustomMessage can be null
private String mCustomMessage;
public String getCustomMessage() {
return mCustomMessage;
}
// aMessage can be null
public void setCustomMessage(String aMessage) {
mCustomMessage = aMessage;
}
- and in the log methods manage the fact that
mCustomMessage may be not null, and in this case
just use the mCustomMessage as the key and pass null
as the messageBundle :
if (mCustomMessage != null) {
mMessages.add(
new LocalizedMessage(
aLineNo,
col,
null,
mCustomMessage,
aArgs,
getSeverityLevel(),
getId(),
this.getClass()));
} else {
mMessages.add(
new LocalizedMessage(
aLineNo,
col,
getMessageBundle(),
aKey,
aArgs,
getSeverityLevel(),
getId(),
this.getClass()));
}
in the LocalizedMessage class :
-------------------------------
- modify the 2 following methods in order to manage
the bundle nullity (if so, then message key must
then be interpreted as a custom message) :
public String getMessage()
{
try {
// .....
final ResourceBundle bundle =
getBundle(mBundle);
String pattern;
if (bundle == null) {
pattern = mKey; // => customMessage
} else {
pattern = bundle.getString(mKey);
}
return MessageFormat.
format(pattern, mArgs);
}
// ......
}
private ResourceBundle getBundle(
String aBundleName) {
synchronized (BUNDLE_CACHE) {
if (aBundleName != null) {
ResourceBundle bundle =
(ResourceBundle) BUNDLE_CACHE
.get(aBundleName);
if (bundle == null) {
bundle =
ResourceBundle.
getBundle(
aBundleName, sLocale,
mSourceClass.
getClassLoader());
BUNDLE_CACHE.put
(aBundleName, bundle);
}
return bundle;
} else {
return null;
}
}
}
----------------------------------------------------------------------
Comment By: Julien De Santis-Caron (juldsc)
Date: 2007-06-25 13:29
Message:
Logged In: YES
user_id=1771547
Originator: NO
Hi,
I'm working in a very large project and this would be very interresting
for us as we use very granular checkstyle rules and we would like to
provide solutions as coding patterns to the developers.
Also,we would like to point-out to some of our best-practices online
documentation for handling checkstyle issues!
Sincerely
Julien De Santis-Caron
----------------------------------------------------------------------
Comment By: Alexandre NOUVEL (nouvel)
Date: 2007-03-28 17:28
Message:
Logged In: YES
user_id=420021
Originator: NO
Hi, this one seems to be a pretty good and simple solution for the feature
request # 1402607 (Which check produced what message?).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397081&aid=1656024&group_id=29721
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
|