1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-18 01:14:50 +02:00

Add more checkstyle tests

- Lines containing tab(s) after space
- Usage of printStackTrace
- Usage of println
- Add SupressionCommentFilter module

SuppressionCommentFilter can be enabled with
// CHECKSTYLE:OFF
and disabled with
// CHECKSTYLE:ON
This commit is contained in:
Florian Schmaus 2015-03-17 21:19:06 +01:00
parent 4f64bb1036
commit b2221d5483
59 changed files with 382 additions and 202 deletions

View file

@ -6,6 +6,7 @@
<module name="SuppressionFilter">
<property name="file" value="config/suppressions.xml"/>
</module>
<module name="SuppressionCommentFilter"/>
<module name="Header">
<property name="headerFile" value="config/header.txt"/>
<property name="ignoreLines" value="3"/>
@ -22,6 +23,10 @@
<property name="format" value="^\s+$"/>
<property name="message" value="Line containing only whitespace character(s)"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="^ +\t+"/>
<property name="message" value="Line containing tab(s) after space"/>
</module>
<!-- TODO enable this once eclilpse does no longer add javadoc with trailing whitespaces
<module name="RegexpSingleline">
<property name="format" value="^.*\S+\s+$"/>
@ -29,6 +34,7 @@
</module>
-->
<module name="TreeWalker">
<module name="FileContentsHolder"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
@ -40,5 +46,15 @@
<module name="GenericWhitespace"/>
<module name="EmptyStatement"/>
<module name="PackageDeclaration"/>
<module name="RegexpSinglelineJava">
<property name="format" value="printStackTrace"/>
<property name="message" value="Usage of printStackTrace"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="format" value="println"/>
<property name="message" value="Usage of println"/>
<property name="ignoreComments" value="true"/>
</module>
</module>
</module>

View file

@ -45,4 +45,9 @@ public class AndroidDebugger extends AbstractDebugger {
protected void log(String logMessage) {
Log.d("SMACK", logMessage);
}
@Override
protected void log(String logMessage, Throwable throwable) {
Log.d("SMACK", logMessage, throwable);
}
}

View file

@ -244,10 +244,12 @@ public class PacketCollector {
*/
protected void processPacket(Stanza packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
// CHECKSTYLE:OFF
while (!resultQueue.offer(packet)) {
// Since we know the queue is full, this poll should never actually block.
resultQueue.poll();
}
// CHECKSTYLE:ON
if (collectorToReset != null) {
collectorToReset.waitStart = System.currentTimeMillis();
}

View file

@ -98,15 +98,13 @@ public abstract class AbstractDebugger implements SmackDebugger {
log(
"XMPPConnection closed due to an exception (" +
connection.getConnectionCounter() +
")");
e.printStackTrace();
")", e);
}
public void reconnectionFailed(Exception e) {
log(
"Reconnection failed due to an exception (" +
connection.getConnectionCounter() +
")");
e.printStackTrace();
")", e);
}
public void reconnectionSuccessful() {
log(
@ -125,6 +123,8 @@ public abstract class AbstractDebugger implements SmackDebugger {
protected abstract void log(String logMessage);
protected abstract void log(String logMessage, Throwable throwable);
public Reader newConnectionReader(Reader newReader) {
reader.removeReaderListener(readerListener);
ObservableReader debugReader = new ObservableReader(newReader);

View file

@ -18,7 +18,9 @@ package org.jivesoftware.smack.debugger;
import org.jivesoftware.smack.XMPPConnection;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -47,7 +49,19 @@ public class ConsoleDebugger extends AbstractDebugger {
synchronized (dateFormatter) {
formatedDate = dateFormatter.format(new Date());
}
// CHECKSTYLE:OFF
System.out.println(formatedDate + ' ' + logMessage);
// CHECKSTYLE:ON
}
@Override
protected void log(String logMessage, Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
// CHECKSTYLE:OFF
throwable.printStackTrace(pw);
// CHECKSTYLE:ON
log(logMessage + sw);
}
}

View file

@ -20,6 +20,7 @@ import org.jivesoftware.smack.XMPPConnection;
import java.io.Reader;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
@ -46,4 +47,8 @@ public class JulDebugger extends AbstractDebugger {
LOGGER.fine(logMessage);
}
@Override
protected void log(String logMessage, Throwable throwable) {
LOGGER.log(Level.FINE, logMessage, throwable);
}
}

View file

@ -528,7 +528,9 @@ public class PacketParserUtils {
String language = getLanguageAttribute(parser);
if (language != null && !"".equals(language.trim())) {
// CHECKSTYLE:OFF
presence.setLanguage(language);
// CHECKSTYLE:ON
}
// Parse sub-elements
@ -993,15 +995,19 @@ public class PacketParserUtils {
}
private static String getLanguageAttribute(XmlPullParser parser) {
// CHECKSTYLE:OFF
for (int i = 0; i < parser.getAttributeCount(); i++) {
// CHECKSTYLE:ON
String attributeName = parser.getAttributeName(i);
if ( "xml:lang".equals(attributeName) ||
("lang".equals(attributeName) &&
"xml".equals(parser.getAttributePrefix(i)))) {
// CHECKSTYLE:OFF
return parser.getAttributeValue(i);
}
}
return null;
// CHECKSTYLE:ON
}
@Deprecated

View file

@ -134,17 +134,11 @@ public class DummyConnection extends AbstractXMPPConnection {
@Override
public void send(PlainStreamElement element) {
if (SmackConfiguration.DEBUG) {
System.out.println("[SEND]: " + element.toXML());
}
queue.add(element);
}
@Override
protected void sendStanzaInternal(Stanza packet) {
if (SmackConfiguration.DEBUG) {
System.out.println("[SEND]: " + packet.toXML());
}
queue.add(packet);
}
@ -194,10 +188,6 @@ public class DummyConnection extends AbstractXMPPConnection {
* @param packet the packet to process.
*/
public void processPacket(Stanza packet) {
if (SmackConfiguration.DEBUG) {
System.out.println("[RECV]: " + packet.toXML());
}
invokePacketCollectorsAndNotifyRecvListeners(packet);
}

View file

@ -20,6 +20,8 @@ import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.IQ;
@ -33,6 +35,8 @@ import org.jivesoftware.smack.packet.IQ.Type;
*
*/
public class ThreadedDummyConnection extends DummyConnection {
private static final Logger LOGGER = Logger.getLogger(ThreadedDummyConnection.class.getName());
private BlockingQueue<IQ> replyQ = new ArrayBlockingQueue<IQ>(1);
private BlockingQueue<Stanza> messageQ = new LinkedBlockingQueue<Stanza>(5);
private volatile boolean timeout = false;
@ -82,7 +86,7 @@ public class ThreadedDummyConnection extends DummyConnection {
if (!messageQ.isEmpty())
new ProcessQueue(messageQ).start();
else
System.out.println("No messages to process");
LOGGER.warning("No messages to process");
}
class ProcessQueue extends Thread {
@ -97,7 +101,7 @@ public class ThreadedDummyConnection extends DummyConnection {
try {
processPacket(processQ.take());
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
}

View file

@ -754,25 +754,30 @@ public class PacketParserUtilsTest {
@Test
public void validateSimplePresence() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
assertXMLEqual(stanza, presence.toXML().toString());
// CHECKSTYLE:ON
}
@Test
public void validatePresenceProbe() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
assertXMLEqual(stanza, presence.toXML().toString());
assertEquals(Presence.Type.unsubscribed, presence.getType());
// CHECKSTYLE:ON
}
@Test
public void validatePresenceOptionalElements() throws Exception {
// CHECKSTYLE:OFF
String stanza = "<presence xml:lang='en' type='unsubscribed'>"
+ "<show>dnd</show>"
+ "<status>Wooing Juliet</status>"
@ -786,6 +791,7 @@ public class PacketParserUtilsTest {
assertEquals("en", presence.getLanguage());
assertEquals("Wooing Juliet", presence.getStatus());
assertEquals(1, presence.getPriority());
// CHECKSTYLE:ON
}
@Test

View file

@ -289,8 +289,10 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel(
new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"},
0) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = 8136121224474217264L;
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
@ -583,7 +585,7 @@ public class EnhancedDebugger implements SmackDebugger {
connection.sendStanza(packetToSend);
}
catch (InterruptedException | NotConnectedException e1) {
e1.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
@ -704,8 +706,10 @@ public class EnhancedDebugger implements SmackDebugger {
new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0},
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
new Object[]{"Type", "Received", "Sent"}) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = -6793886085109589269L;
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
};

View file

@ -93,11 +93,15 @@ public class Privacy extends IQ {
*/
public void deletePrivacyList(String listName) {
// Remove the list from the cache
// CHECKSTYLE:OFF
this.getItemLists().remove(listName);
// CHECKSTYLE:ON
// Check if deleted list was the default list
if (this.getDefaultName() != null && listName.equals(this.getDefaultName())) {
// CHECKSTYLE:OFF
this.setDefaultName(null);
// CHECKSTYLE:ON
}
}
@ -108,11 +112,13 @@ public class Privacy extends IQ {
*/
public List<PrivacyItem> getActivePrivacyList() {
// Check if we have the default list
// CHECKSTYLE:OFF
if (this.getActiveName() == null) {
return null;
} else {
return this.getItemLists().get(this.getActiveName());
}
// CHECKSTYLE:ON
}
/**
@ -122,11 +128,13 @@ public class Privacy extends IQ {
*/
public List<PrivacyItem> getDefaultPrivacyList() {
// Check if we have the default list
// CHECKSTYLE:OFF
if (this.getDefaultName() == null) {
return null;
} else {
return this.getItemLists().get(this.getDefaultName());
}
// CHECKSTYLE:ON
}
/**
@ -147,6 +155,7 @@ public class Privacy extends IQ {
* @return a List with {@link PrivacyItem}
*/
public PrivacyItem getItem(String listName, int order) {
// CHECKSTYLE:OFF
Iterator<PrivacyItem> values = getPrivacyList(listName).iterator();
PrivacyItem itemFound = null;
while (itemFound == null && values.hasNext()) {
@ -156,6 +165,7 @@ public class Privacy extends IQ {
}
}
return itemFound;
// CHECKSTYLE:ON
}
/**
@ -169,7 +179,9 @@ public class Privacy extends IQ {
this.setDefaultName(newDefault);
return true;
} else {
// CHECKSTYLE:OFF
return false;
// CHECKSTYLE:ON
}
}
@ -179,7 +191,9 @@ public class Privacy extends IQ {
* @param listName name of the list to remove.
*/
public void deleteList(String listName) {
// CHECKSTYLE:OFF
this.getItemLists().remove(listName);
// CHECKSTYLE:ON
}
/**
@ -188,9 +202,11 @@ public class Privacy extends IQ {
*
* @return the name of the active list.
*/
// CHECKSTYLE:OFF
public String getActiveName() {
return activeName;
}
// CHECKSTYLE:ON
/**
* Sets the name associated with the active list set for the session. Communications
@ -198,9 +214,11 @@ public class Privacy extends IQ {
*
* @param activeName is the name of the active list.
*/
// CHECKSTYLE:OFF
public void setActiveName(String activeName) {
this.activeName = activeName;
}
// CHECKSTYLE:ON
/**
* Returns the name of the default list that applies to the user as a whole. Default list is
@ -209,9 +227,11 @@ public class Privacy extends IQ {
*
* @return the name of the default list.
*/
// CHECKSTYLE:OFF
public String getDefaultName() {
return defaultName;
}
// CHECKSTYLE:ON
/**
* Sets the name of the default list that applies to the user as a whole. Default list is
@ -222,9 +242,11 @@ public class Privacy extends IQ {
*
* @param defaultName is the name of the default list.
*/
// CHECKSTYLE:OFF
public void setDefaultName(String defaultName) {
this.defaultName = defaultName;
}
// CHECKSTYLE:ON
/**
* Returns the collection of privacy list that the user holds. A Privacy List contains a set of
@ -234,42 +256,51 @@ public class Privacy extends IQ {
* @return a map where the key is the name of the list and the value the
* collection of privacy items.
*/
// CHECKSTYLE:OFF
public Map<String, List<PrivacyItem>> getItemLists() {
return itemLists;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or declines the use of an active list.
*
* @return the decline status of the list.
*/
// CHECKSTYLE:OFF
public boolean isDeclineActiveList() {
return declineActiveList;
}
// CHECKSYTLE:ON
/**
* Sets whether the receiver allows or declines the use of an active list.
*
* @param declineActiveList indicates if the receiver declines the use of an active list.
*/
// CHECKSTYLE:OFF
public void setDeclineActiveList(boolean declineActiveList) {
this.declineActiveList = declineActiveList;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or declines the use of a default list.
*
* @return the decline status of the list.
*/
// CHECKSTYLE:OFF
public boolean isDeclineDefaultList() {
return declineDefaultList;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or declines the use of a default list.
*
* @param declineDefaultList indicates if the receiver declines the use of a default list.
*/
// CHECKSTYLE:OFF
public void setDeclineDefaultList(boolean declineDefaultList) {
this.declineDefaultList = declineDefaultList;
}
@ -282,10 +313,12 @@ public class Privacy extends IQ {
public Set<String> getPrivacyListNames() {
return this.itemLists.keySet();
}
// CHECKSTYLE:ON
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
buf.rightAngleBracket();
// CHECKSTYLE:OFF
// Add the active tag
if (this.isDeclineActiveList()) {
@ -323,7 +356,7 @@ public class Privacy extends IQ {
buf.append("</list>");
}
}
// CHECKSTYLE:ON
return buf;
}

View file

@ -131,8 +131,10 @@ public class PrivacyItem {
* @return the allow communication status.
*/
public boolean isAllow() {
// CHECKSTYLE:OFF
return allow;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allow or deny incoming IQ stanzas or not.
@ -140,8 +142,10 @@ public class PrivacyItem {
* @return the iq filtering status.
*/
public boolean isFilterIQ() {
// CHECKSTYLE:OFF
return filterIQ;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies incoming IQ stanzas or not.
@ -149,8 +153,11 @@ public class PrivacyItem {
* @param filterIQ indicates if the receiver allows or denies incoming IQ stanzas.
*/
public void setFilterIQ(boolean filterIQ) {
// CHECKSTYLE:OFF
this.filterIQ = filterIQ;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming messages or not.
@ -158,8 +165,10 @@ public class PrivacyItem {
* @return the message filtering status.
*/
public boolean isFilterMessage() {
// CHECKSTYLE:OFF
return filterMessage;
}
// CHECKSTYLE:ON
/**
* Sets wheather the receiver allows or denies incoming messages or not.
@ -167,8 +176,10 @@ public class PrivacyItem {
* @param filterMessage indicates if the receiver allows or denies incoming messages or not.
*/
public void setFilterMessage(boolean filterMessage) {
// CHECKSTYLE:OFF
this.filterMessage = filterMessage;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming presence or not.
@ -176,8 +187,10 @@ public class PrivacyItem {
* @return the iq filtering incoming presence status.
*/
public boolean isFilterPresenceIn() {
// CHECKSTYLE:OFF
return filterPresenceIn;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies incoming presence or not.
@ -185,8 +198,10 @@ public class PrivacyItem {
* @param filterPresenceIn indicates if the receiver allows or denies filtering incoming presence.
*/
public void setFilterPresenceIn(boolean filterPresenceIn) {
// CHECKSTYLE:OFF
this.filterPresenceIn = filterPresenceIn;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming presence or not.
@ -194,8 +209,10 @@ public class PrivacyItem {
* @return the iq filtering incoming presence status.
*/
public boolean isFilterPresenceOut() {
// CHECKSTYLE:OFF
return filterPresenceOut;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies outgoing presence or not.
@ -203,8 +220,10 @@ public class PrivacyItem {
* @param filterPresenceOut indicates if the receiver allows or denies filtering outgoing presence
*/
public void setFilterPresenceOut(boolean filterPresenceOut) {
// CHECKSTYLE:OFF
this.filterPresenceOut = filterPresenceOut;
}
// CHECKSTYLE:ON
/**
* Returns the order where the receiver is processed. List items are processed in
@ -216,8 +235,10 @@ public class PrivacyItem {
* @return the order number.
*/
public long getOrder() {
// CHECKSTYLE:OFF
return order;
}
// CHECKSTYLE:ON
/**
* Returns the type hold the kind of communication it will allow or block.
@ -227,7 +248,9 @@ public class PrivacyItem {
*/
public Type getType() {
return type;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
/**
* Returns the element identifier to apply the action.
@ -242,7 +265,9 @@ public class PrivacyItem {
*/
public String getValue() {
return value;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies every kind of communication.
@ -253,6 +278,7 @@ public class PrivacyItem {
* @return the all communications status.
*/
public boolean isFilterEverything() {
// CHECKSTYLE:OFF
return !(this.isFilterIQ() || this.isFilterMessage() || this.isFilterPresenceIn()
|| this.isFilterPresenceOut());
}
@ -295,6 +321,7 @@ public class PrivacyItem {
}
buf.append("</item>");
}
// CHECKSTYLE:ON
return buf.toString();
}

View file

@ -45,6 +45,7 @@ public class PrivacyProvider extends IQProvider<Privacy> {
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
// CHECKSTYLE:OFF
if (parser.getName().equals("active")) {
String activeName = parser.getAttributeValue("", "name");
if (activeName == null) {
@ -61,6 +62,7 @@ public class PrivacyProvider extends IQProvider<Privacy> {
privacy.setDefaultName(defaultName);
}
}
// CHECKSTYLE:ON
else if (parser.getName().equals("list")) {
parseList(parser, privacy);
}
@ -84,7 +86,9 @@ public class PrivacyProvider extends IQProvider<Privacy> {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
// CHECKSTYLE:OFF
items.add(parseItem(parser));
// CHECKSTYLE:ON
}
}
else if (eventType == XmlPullParser.END_TAG) {
@ -95,10 +99,12 @@ public class PrivacyProvider extends IQProvider<Privacy> {
}
privacy.setPrivacyList(listName, items);
// CHECKSTYLE:OFF
}
// Parse the list complex type
private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
// CHECKSTYLE:ON
// Retrieves the required attributes
String actionValue = parser.getAttributeValue("", "action");
// Set the order number, this attribute is required
@ -135,7 +141,9 @@ public class PrivacyProvider extends IQProvider<Privacy> {
}
parseItemChildElements(parser, item);
return item;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
private static void parseItemChildElements(XmlPullParser parser, PrivacyItem privacyItem) throws XmlPullParserException, IOException {
final int initialDepth = parser.getDepth();

View file

@ -85,7 +85,9 @@ public class Item extends NodeExtension
*/
public Item(String itemId, String nodeId)
{
// CHECKSTYLE:OFF
super(PubSubElementType.ITEM_EVENT, nodeId);
// CHECKSTYLE:ON
id = itemId;
}

View file

@ -26,6 +26,8 @@ import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
@ -36,6 +38,7 @@ import org.jivesoftware.smack.SmackException;
* @author Henning Staib
*/
public class Socks5TestProxy {
private static final Logger LOGGER = Logger.getLogger(Socks5TestProxy.class.getName());
/* SOCKS5 proxy singleton */
private static Socks5TestProxy socks5Server;
@ -102,7 +105,7 @@ public class Socks5TestProxy {
this.serverThread.start();
}
catch (IOException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
// do nothing
}
}
@ -120,7 +123,7 @@ public class Socks5TestProxy {
}
catch (IOException e) {
// do nothing
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
}
if (this.serverThread != null && this.serverThread.isAlive()) {
@ -130,7 +133,7 @@ public class Socks5TestProxy {
}
catch (InterruptedException e) {
// do nothing
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
}
}
this.serverThread = null;
@ -176,7 +179,7 @@ public class Socks5TestProxy {
try {
wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
} finally {
if (!startupComplete) {
throw new IllegalStateException("Startup of Socks5TestProxy failed within 5 seconds");
@ -230,7 +233,7 @@ public class Socks5TestProxy {
}
catch (Exception e) {
try {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
socket.close();
}
catch (IOException e1) {

View file

@ -124,6 +124,7 @@ public class Protocol {
*/
@SuppressWarnings("unchecked")
public void verifyAll() {
// CHECKSTYLE:OFF
assertEquals(requests.size(), responsesList.size());
if (printProtocol)
@ -154,6 +155,7 @@ public class Protocol {
}
if (printProtocol)
System.out.println("=================== End =================\n");
// CHECKSTYLE:ON
}
/**

View file

@ -153,7 +153,9 @@ public class ChatManager extends Manager{
Message message = (Message) packet;
Chat chat;
if (message.getThread() == null) {
// CHECKSTYLE:OFF
chat = getUserChat(message.getFrom());
// CHECKSTYLE:ON
}
else {
chat = getThreadChat(message.getThread());

View file

@ -122,7 +122,7 @@ public class DirectoryRosterStore implements RosterStore {
for (File file : fileDir.listFiles(rosterDirFilter)) {
Item entry = readEntry(file);
if (entry == null) {
log("Roster store file '" + file + "' is invalid.");
LOGGER.severe("Roster store file '" + file + "' is invalid.");
}
else {
entries.add(entry);
@ -228,7 +228,7 @@ public class DirectoryRosterStore implements RosterStore {
groupNames.add(group);
}
else {
log("Invalid group entry in store entry file "
LOGGER.severe("Invalid group entry in store entry file "
+ file);
}
}
@ -245,9 +245,7 @@ public class DirectoryRosterStore implements RosterStore {
return null;
}
catch (XmlPullParserException e) {
log("Invalid group entry in store entry file "
+ file);
LOGGER.log(Level.SEVERE, "readEntry()", e);
LOGGER.log(Level.SEVERE, "Invalid group entry in store entry file", e);
return null;
}
@ -264,14 +262,14 @@ public class DirectoryRosterStore implements RosterStore {
item.setItemType(RosterPacket.ItemType.valueOf(type));
}
catch (IllegalArgumentException e) {
log("Invalid type in store entry file " + file);
LOGGER.log(Level.SEVERE, "Invalid type in store entry file " + file, e);
return null;
}
if (status != null) {
RosterPacket.ItemStatus itemStatus = RosterPacket.ItemStatus
.fromString(status);
if (itemStatus == null) {
log("Invalid status in store entry file " + file);
LOGGER.severe("Invalid status in store entry file " + file);
return null;
}
item.setItemStatus(itemStatus);
@ -304,8 +302,4 @@ public class DirectoryRosterStore implements RosterStore {
String encodedJid = Base32.encode(bareJid.toString());
return new File(fileDir, ENTRY_PREFIX + encodedJid);
}
private void log(String error) {
System.err.println(error);
}
}

View file

@ -31,7 +31,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.im.InitSmackIm;
@ -716,38 +715,20 @@ public class RosterTest extends InitSmackIm {
public synchronized void entriesAdded(Collection<Jid> addresses) {
addressesAdded.addAll(addresses);
if (SmackConfiguration.DEBUG) {
for (Jid address : addresses) {
System.out.println("Roster entry for " + address + " added.");
}
}
reportInvoked();
}
public synchronized void entriesDeleted(Collection<Jid> addresses) {
addressesDeleted.addAll(addresses);
if (SmackConfiguration.DEBUG) {
for (Jid address : addresses) {
System.out.println("Roster entry for " + address + " deleted.");
}
}
reportInvoked();
}
public synchronized void entriesUpdated(Collection<Jid> addresses) {
addressesUpdated.addAll(addresses);
if (SmackConfiguration.DEBUG) {
for (Jid address : addresses) {
System.out.println("Roster entry for " + address + " updated.");
}
}
reportInvoked();
}
public void presenceChanged(Presence presence) {
if (SmackConfiguration.DEBUG) {
System.out.println("Roster presence changed: " + presence.toXML());
}
reportInvoked();
}

View file

@ -73,7 +73,7 @@ public class Demo extends JFrame {
initialize();
}
catch (XMPPException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
@ -100,7 +100,7 @@ public class Demo extends JFrame {
incoming.startIncoming();
}
catch (XMPPException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}

View file

@ -233,7 +233,7 @@ public class JingleManagerTest extends SmackTestCase {
assertTrue(valCounter() > 0);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
@ -278,7 +278,7 @@ public class JingleManagerTest extends SmackTestCase {
JingleSession session1 = request.accept();
session1.startIncoming();
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
@ -293,7 +293,7 @@ public class JingleManagerTest extends SmackTestCase {
assertTrue(valCounter() > 0);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
@ -369,7 +369,7 @@ public class JingleManagerTest extends SmackTestCase {
session1.startIncoming();
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
@ -384,7 +384,7 @@ public class JingleManagerTest extends SmackTestCase {
assertTrue(valCounter() == 1);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
@ -456,7 +456,7 @@ public class JingleManagerTest extends SmackTestCase {
session1.startIncoming();
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
@ -498,7 +498,7 @@ public class JingleManagerTest extends SmackTestCase {
assertTrue(valCounter() == 2);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
@ -542,7 +542,7 @@ public class JingleManagerTest extends SmackTestCase {
session.startIncoming();
session.terminate();
} catch (XMPPException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
@ -588,7 +588,7 @@ public class JingleManagerTest extends SmackTestCase {
assertTrue(valCounter() > 0);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
@ -625,7 +625,7 @@ public class JingleManagerTest extends SmackTestCase {
incCounter();
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
@ -666,11 +666,11 @@ public class JingleManagerTest extends SmackTestCase {
ds1.close();
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
@ -737,7 +737,7 @@ public class JingleManagerTest extends SmackTestCase {
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
@ -783,7 +783,7 @@ public class JingleManagerTest extends SmackTestCase {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
System.out.println(valCounter());
@ -871,7 +871,7 @@ public class JingleManagerTest extends SmackTestCase {
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
LOGGER.log(Level.WARNING, "exception", e);
}
}
@ -893,7 +893,7 @@ public class JingleManagerTest extends SmackTestCase {
Thread.sleep(15000);
} catch (Exception e) {