From d5b8647d9d3c3f8fa3180cdc34a5c295f0337b24 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 22 Jan 2015 13:53:50 +0100 Subject: [PATCH] Create smack-im subproject for XMPP-IM Move Roster and Chat(Manager) code into their own packages within the new smack-im subproject. Apply Manager pattern to Roster. Fixes SMACK-637. --- build.gradle | 2 +- documentation/extensions/rosterexchange.md | 10 +- documentation/gettingstarted.md | 2 +- documentation/roster.md | 6 +- settings.gradle | 1 + .../smack/bosh/XMPPBOSHConnection.java | 4 +- .../smack/AbstractXMPPConnection.java | 63 +-------- .../smack/ConnectionConfiguration.java | 59 +------- .../smack/SmackInitialization.java | 3 - .../jivesoftware/smack/XMPPConnection.java | 31 ----- .../jivesoftware/smack/packet/Presence.java | 1 - .../org.jivesoftware.smack/smack-config.xml | 1 + .../jivesoftware/smack/DummyConnection.java | 14 -- smack-extensions/build.gradle | 3 + .../smackx/chatstates/ChatStateListener.java | 4 +- .../smackx/chatstates/ChatStateManager.java | 8 +- .../smackx/muc/MultiUserChat.java | 6 +- .../receipts/DeliveryReceiptManager.java | 3 +- .../xdata/provider/DataFormProvider.java | 4 +- smack-im/build.gradle | 11 ++ .../org/jivesoftware/smack/chat}/Chat.java | 3 +- .../jivesoftware/smack/chat}/ChatManager.java | 7 +- .../smack/chat}/ChatManagerListener.java | 2 +- .../smack/chat}/ChatMessageListener.java | 2 +- .../smack/im/SmackImInitializer.java | 33 +++++ .../jivesoftware/smack/roster}/Roster.java | 126 ++++++++++++++++-- .../smack/roster}/RosterEntry.java | 5 +- .../smack/roster}/RosterGroup.java | 6 +- .../smack/roster}/RosterListener.java | 2 +- .../smack/roster}/packet/RosterPacket.java | 4 +- .../smack/roster}/packet/RosterVer.java | 3 +- .../provider/RosterPacketProvider.java | 10 +- .../RosterVerStreamFeatureProvider.java | 35 +++++ .../rosterstore/DirectoryRosterStore.java | 6 +- .../roster}/rosterstore/RosterStore.java | 8 +- .../smackim.providers | 16 +++ .../org.jivesoftware.smack.im/smackim.xml | 5 + .../smack/chat}/ChatConnectionTest.java | 5 +- .../jivesoftware/smack/im/InitSmackIm.java | 25 ++++ .../smack/im/SmackImInitializerTest.java | 34 +++++ .../smack/roster}/RosterOfflineTest.java | 10 +- .../smack/roster}/RosterTest.java | 26 ++-- .../smack/roster}/RosterVersioningTest.java | 27 ++-- .../rosterstore/DirectoryRosterStoreTest.java | 10 +- .../smackx/jingleold/JingleManager.java | 5 +- .../smackx/xroster/RosterExchangeManager.java | 6 +- .../smackx/xroster/packet/RosterExchange.java | 6 +- 47 files changed, 392 insertions(+), 271 deletions(-) create mode 100644 smack-im/build.gradle rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/chat}/Chat.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/chat}/ChatManager.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/chat}/ChatManagerListener.java (96%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/chat}/ChatMessageListener.java (95%) create mode 100644 smack-im/src/main/java/org/jivesoftware/smack/im/SmackImInitializer.java rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/Roster.java (91%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/RosterEntry.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/RosterGroup.java (97%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/RosterListener.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/packet/RosterPacket.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/packet/RosterVer.java (92%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/provider/RosterPacketProvider.java (93%) create mode 100644 smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterVerStreamFeatureProvider.java rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/rosterstore/DirectoryRosterStore.java (98%) rename {smack-core/src/main/java/org/jivesoftware/smack => smack-im/src/main/java/org/jivesoftware/smack/roster}/rosterstore/RosterStore.java (89%) create mode 100644 smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.providers create mode 100644 smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.xml rename {smack-core/src/test/java/org/jivesoftware/smack => smack-im/src/test/java/org/jivesoftware/smack/chat}/ChatConnectionTest.java (98%) create mode 100644 smack-im/src/test/java/org/jivesoftware/smack/im/InitSmackIm.java create mode 100644 smack-im/src/test/java/org/jivesoftware/smack/im/SmackImInitializerTest.java rename {smack-tcp/src/test/java/org/jivesoftware/smack/tcp => smack-im/src/test/java/org/jivesoftware/smack/roster}/RosterOfflineTest.java (87%) rename {smack-core/src/test/java/org/jivesoftware/smack => smack-im/src/test/java/org/jivesoftware/smack/roster}/RosterTest.java (97%) rename {smack-core/src/test/java/org/jivesoftware/smack => smack-im/src/test/java/org/jivesoftware/smack/roster}/RosterVersioningTest.java (91%) rename {smack-core/src/test/java/org/jivesoftware/smack => smack-im/src/test/java/org/jivesoftware/smack/roster}/rosterstore/DirectoryRosterStoreTest.java (96%) diff --git a/build.gradle b/build.gradle index ded0e4544..8de9f197e 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ allprojects { // build, causing unnecessary rebuilds. builtDate = (new java.text.SimpleDateFormat("yyyy-MM-dd")).format(new Date()) oneLineDesc = 'An Open Source XMPP (Jabber) client library' - androidProjects = [':smack-tcp',':smack-core', ':smack-resolver-minidns', ':smack-sasl-provided', ':smack-extensions', ':smack-experimental'].collect{ project(it) } + androidProjects = [':smack-tcp', ':smack-core', ':smack-im', ':smack-resolver-minidns', ':smack-sasl-provided', ':smack-extensions', ':smack-experimental'].collect{ project(it) } androidBootClasspath = getAndroidRuntimeJar() androidJavadocOffline = getAndroidJavadocOffline() } diff --git a/documentation/extensions/rosterexchange.md b/documentation/extensions/rosterexchange.md index a8aa171ca..9526aa1a1 100644 --- a/documentation/extensions/rosterexchange.md +++ b/documentation/extensions/rosterexchange.md @@ -39,7 +39,7 @@ XMPPConnection conn1 = … // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send user1's roster to user2 -rosterExchangeManager.send(conn1.getRoster(), user2); +rosterExchangeManager.send(Roster.getInstanceFor(conn1), user2); ``` Send a roster group @@ -67,7 +67,7 @@ XMPPConnection conn1 = … // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send user1's RosterGroups to user2 -for (Iterator it = conn1.getRoster().getGroups(); it.hasNext(); ) +for (Iterator it = Roster.getInstanceFor(conn1).getGroups(); it.hasNext(); ) rosterExchangeManager.send((RosterGroup)it.next(), user2); ``` @@ -96,7 +96,7 @@ XMPPConnection conn1 = … // Create a new roster exchange manager on conn1 RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1); // Send a roster entry (any) to user2 -rosterExchangeManager1.send((RosterEntry)conn1.getRoster().getEntries().next(), user2); +rosterExchangeManager1.send((RosterEntry)Roster.getInstanceFor(conn1).getEntries().next(), user2); ``` Receive roster entries @@ -124,7 +124,7 @@ adds the received entries to his roster. XMPPConnection conn1 = … XMPPConnection conn2 = … -final Roster user2_roster = conn2.getRoster(); +final Roster user2_roster = Roster.getInstanceFor(conn2); // Create a RosterExchangeManager that will help user2 to listen and accept the entries received @@ -156,5 +156,5 @@ rosterExchangeManager2.addRosterListener(rosterExchangeListener); // Create a RosterExchangeManager that will help user1 to send his roster RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1); // Send user1's roster to user2 -rosterExchangeManager1.send(conn1.getRoster(), user2); +rosterExchangeManager1.send(Roster.getInstanceFor(conn1), user2); ``` diff --git a/documentation/gettingstarted.md b/documentation/gettingstarted.md index 1cd93ae2a..52cda7535 100644 --- a/documentation/gettingstarted.md +++ b/documentation/gettingstarted.md @@ -79,7 +79,7 @@ The roster lets you keep track of the availability (presence) of other users. Users can be organized into groups such as "Friends" and "Co-workers", and then you discover whether each user is online or offline. -Retrieve the roster using the `XMPPConnection.getRoster()` method. The roster +Retrieve the roster using the `Roster.getInstanceFor(XMPPConnection)` method. The roster class allows you to find all the roster entries, the groups they belong to, and the current presence status of each entry. diff --git a/documentation/roster.md b/documentation/roster.md index 906022b0b..c37b6ea5f 100644 --- a/documentation/roster.md +++ b/documentation/roster.md @@ -8,7 +8,7 @@ users. A roster also allows you to organize users into groups such as "Friends" and "Co-workers". Other IM systems refer to the roster as the buddy list, contact list, etc. -A `Roster` instance is obtained using the `XMPPConnection.getRoster()` method. +A `Roster` instance is obtained using the `Roster.getInstanceFor(XMPPConnection)` method. Roster Entries -------------- @@ -20,7 +20,7 @@ Every user in a roster is represented by a RosterEntry, which consists of: * The list of groups in the roster that the entry belongs to. If the roster entry belongs to no groups, it's called an "unfiled entry". The following code snippet prints all entries in the roster: ``` -Roster roster = connection.getRoster(); +Roster roster = Roster.getInstanceFor(connection); Collection entries = roster.getEntries(); for (RosterEntry entry : entries) { System.out.println(entry); @@ -63,7 +63,7 @@ out. A normal client would use similar code to update the roster UI with the changing information. ``` -Roster roster = con.getRoster(); +Roster roster = Roster.getInstanceFor(con); roster.addRosterListener(new RosterListener() { // Ignored events public void entriesAdded(Collection addresses) {} public void entriesDeleted(Collection addresses) {} diff --git a/settings.gradle b/settings.gradle index 9c4bf1343..d452c94c7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ include 'smack-core', + 'smack-im', 'smack-tcp', 'smack-extensions', 'smack-experimental', diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index d938c49e4..b757cb295 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -34,7 +34,6 @@ import org.jivesoftware.smack.SmackException.ConnectionException; import org.jivesoftware.smack.XMPPException.StreamErrorException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.ConnectionCreationListener; -import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Element; import org.jivesoftware.smack.packet.IQ; @@ -295,8 +294,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { * Closes the connection by setting presence to unavailable and closing the * HTTP client. The shutdown logic will be used during a planned disconnection or when * dealing with an unexpected disconnection. Unlike {@link #disconnect()} the connection's - * BOSH packet reader and {@link Roster} will not be removed; thus - * connection's state is kept. + * BOSH packet reader will not be removed; thus connection's state is kept. * */ @Override diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 99eb1d56d..48fca605f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -66,7 +66,6 @@ import org.jivesoftware.smack.packet.Mechanisms; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smack.packet.RosterVer; import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.packet.StartTls; import org.jivesoftware.smack.packet.PlainStreamElement; @@ -75,7 +74,6 @@ import org.jivesoftware.smack.parsing.ParsingExceptionCallback; import org.jivesoftware.smack.parsing.UnparsablePacket; import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.ProviderManager; -import org.jivesoftware.smack.rosterstore.RosterStore; import org.jivesoftware.smack.util.DNSUtil; import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.ParserUtils; @@ -264,8 +262,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { private final ExecutorService singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory( getConnectionCounter(), "Single Threaded Executor")); - private Roster roster; - /** * The used host to establish the connection to */ @@ -380,9 +376,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { *

*

* It is possible to log in without sending an initial available presence by using - * {@link ConnectionConfiguration.Builder#setSendPresence(boolean)}. If this connection is - * not interested in loading its roster upon login then use - * {@link ConnectionConfiguration.Builder#setRosterLoadedAtLogin(boolean)}. + * {@link ConnectionConfiguration.Builder#setSendPresence(boolean)}. * Finally, if you want to not pass a password and instead use a more advanced mechanism * while using SASL then you may be interested in using * {@link ConnectionConfiguration.Builder#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}. @@ -527,11 +521,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { // eventually load the roster. And we should load the roster before we // send the initial presence. if (config.isSendPresence() && !resumed) { - if (!isAnonymous()) { - // Make sure that the roster has setup its listeners prior sending the initial presence by calling - // getRoster() - getRoster(); - } sendPacket(new Presence(Presence.Type.available)); } } @@ -603,36 +592,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { sendPacketInternal(packet); } - @Override - public Roster getRoster() { - if (isAnonymous()) { - throw new IllegalStateException("Anonymous users can't have a roster"); - } - // synchronize against login() - synchronized(this) { - if (roster == null) { - roster = new Roster(this); - } - if (!isAuthenticated()) { - return roster; - } - } - - // If this is the first time the user has asked for the roster after calling - // login, we want to wait for the server to send back the user's roster. This - // behavior shields API users from having to worry about the fact that roster - // operations are asynchronous, although they'll still have to listen for - // changes to the roster. Note: because of this waiting logic, internal - // Smack code should be wary about calling the getRoster method, and may need to - // access the roster object directly. - // Also only check for rosterIsLoaded is isRosterLoadedAtLogin is set, otherwise the user - // has to manually call Roster.reload() before he can expect a initialized roster. - if (!roster.isLoaded() && config.isRosterLoadedAtLogin()) { - roster.waitUntilLoaded(); - } - return roster; - } - /** * Returns the SASLAuthentication manager that is responsible for authenticating with * the server. @@ -1284,16 +1243,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } - @Override - public RosterStore getRosterStore() { - return config.getRosterStore(); - } - - @Override - public boolean isRosterLoadedAtLogin() { - return config.isRosterLoadedAtLogin(); - } - protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException { streamFeatures.clear(); @@ -1318,16 +1267,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { case Session.ELEMENT: streamFeature = PacketParserUtils.parseSessionFeature(parser); break; - case RosterVer.ELEMENT: - if(namespace.equals(RosterVer.NAMESPACE)) { - streamFeature = RosterVer.INSTANCE; - } - else { - LOGGER.severe("Unknown Roster Versioning Namespace: " - + namespace - + ". Roster versioning not enabled"); - } - break; case Compress.Feature.ELEMENT: streamFeature = PacketParserUtils.parseCompressionFeature(parser); break; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java index e39499a2e..e74dc272f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java @@ -19,7 +19,6 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.Session; import org.jivesoftware.smack.proxy.ProxyInfo; -import org.jivesoftware.smack.rosterstore.RosterStore; import javax.net.SocketFactory; import javax.net.ssl.HostnameVerifier; @@ -66,8 +65,13 @@ public abstract class ConnectionConfiguration { private final CharSequence username; private final String password; private final String resource; + + /** + * Initial presence as of RFC 6121 § 4.2 + * @see RFC 6121 § 4.2 Initial Presence + */ private final boolean sendPresence; - private final boolean rosterLoadedAtLogin; + private final boolean legacySessionDisabled; private final SecurityMode securityMode; @@ -83,11 +87,6 @@ public abstract class ConnectionConfiguration { private final HostnameVerifier hostnameVerifier; - /** - * Permanent store for the Roster, needed for roster versioning - */ - private final RosterStore rosterStore; - // Holds the proxy information (such as proxyhost, proxyport, username, password etc) protected final ProxyInfo proxy; @@ -127,9 +126,7 @@ public abstract class ConnectionConfiguration { enabledSSLCiphers = builder.enabledSSLCiphers; hostnameVerifier = builder.hostnameVerifier; sendPresence = builder.sendPresence; - rosterLoadedAtLogin = builder.rosterLoadedAtLogin; legacySessionDisabled = builder.legacySessionDisabled; - rosterStore = builder.rosterStore; debuggerEnabled = builder.debuggerEnabled; allowNullOrEmptyUsername = builder.allowEmptyOrNullUsername; } @@ -234,17 +231,6 @@ public abstract class ConnectionConfiguration { return debuggerEnabled; } - /** - * Returns true if the roster will be loaded from the server when logging in. This - * is the common behaviour for clients but sometimes clients may want to differ this - * or just never do it if not interested in rosters. - * - * @return true if the roster will be loaded from the server when logging in. - */ - public boolean isRosterLoadedAtLogin() { - return rosterLoadedAtLogin; - } - /** * Returns true if a {@link Session} will be requested on login if the server * supports it. Although this was mandatory on RFC 3921, RFC 6120/6121 don't @@ -282,14 +268,6 @@ public abstract class ConnectionConfiguration { return this.socketFactory; } - /** - * Get the permanent roster store - */ - public RosterStore getRosterStore() { - return rosterStore; - } - - /** * An enumeration for TLS security modes that are available when making a connection * to the XMPP server. @@ -394,9 +372,7 @@ public abstract class ConnectionConfiguration { private String password; private String resource = "Smack"; private boolean sendPresence = true; - private boolean rosterLoadedAtLogin = true; private boolean legacySessionDisabled = false; - private RosterStore rosterStore; private ProxyInfo proxy; private CallbackHandler callbackHandler; private boolean debuggerEnabled = SmackConfiguration.DEBUG; @@ -595,19 +571,6 @@ public abstract class ConnectionConfiguration { return getThis(); } - /** - * Sets if the roster will be loaded from the server when logging in. This - * is the common behaviour for clients but sometimes clients may want to differ this - * or just never do it if not interested in rosters. - * - * @param rosterLoadedAtLogin if the roster will be loaded from the server when logging in. - * @return a reference to this builder. - */ - public B setRosterLoadedAtLogin(boolean rosterLoadedAtLogin) { - this.rosterLoadedAtLogin = rosterLoadedAtLogin; - return getThis(); - } - /** * Sets if an initial available presence will be sent to the server. By default * an available presence will be sent to the server indicating that this presence @@ -622,16 +585,6 @@ public abstract class ConnectionConfiguration { return getThis(); } - /** - * Set the permanent roster store. - * - * @return a reference to this builder. - */ - public B setRosterStore(RosterStore store) { - rosterStore = store; - return getThis(); - } - /** * Sets if the new connection about to be establish is going to be debugged. By * default the value of {@link SmackConfiguration#DEBUG} is used. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java index 116a0bfcb..3bef58be2 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java @@ -30,10 +30,8 @@ import java.util.logging.Logger; import org.jivesoftware.smack.compression.Java7ZlibInputOutputStream; import org.jivesoftware.smack.initializer.SmackInitializer; import org.jivesoftware.smack.packet.Bind; -import org.jivesoftware.smack.packet.RosterPacket; import org.jivesoftware.smack.provider.BindIQProvider; import org.jivesoftware.smack.provider.ProviderManager; -import org.jivesoftware.smack.provider.RosterPacketProvider; import org.jivesoftware.smack.sasl.core.SASLXOauth2Mechanism; import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism; import org.jivesoftware.smack.util.FileUtils; @@ -140,7 +138,6 @@ public final class SmackInitialization { SASLAuthentication.registerSASLMechanism(new SCRAMSHA1Mechanism()); SASLAuthentication.registerSASLMechanism(new SASLXOauth2Mechanism()); - ProviderManager.addIQProvider(RosterPacket.ELEMENT, RosterPacket.NAMESPACE, RosterPacketProvider.INSTANCE); ProviderManager.addIQProvider(Bind.ELEMENT, Bind.NAMESPACE, new BindIQProvider()); SmackConfiguration.smackInitialized = true; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java index 5b12adb8a..6efc362cc 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -26,7 +26,6 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PlainStreamElement; -import org.jivesoftware.smack.rosterstore.RosterStore; /** * The abstract XMPPConnection class provides an interface for connections to a XMPP server and @@ -167,20 +166,6 @@ public interface XMPPConnection { */ public void send(PlainStreamElement element) throws NotConnectedException; - /** - * Returns the roster for the user. - *

- * This method will never return null, instead if the user has not yet logged into - * the server or is logged in anonymously all modifying methods of the returned roster object - * like {@link Roster#createEntry(String, String, String[])}, - * {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing - * {@link RosterListener}s will throw an IllegalStateException. - * - * @return the user's roster. - * @throws IllegalStateException if the connection is anonymous - */ - public Roster getRoster(); - /** * Adds a connection listener to this connection that will be notified when * the connection closes or fails. @@ -438,22 +423,6 @@ public interface XMPPConnection { */ public FromMode getFromMode(); - /** - * Get the permanent roster store. - * @return the permanent roster store or null - */ - public RosterStore getRosterStore(); - - /** - * Returns true if the roster will be loaded from the server when logging in. This - * is the common behavior for clients but sometimes clients may want to differ this - * or just never do it if not interested in rosters. - * - * @return true if the roster will be loaded from the server when logging in. - * @see RFC 6121 2.2 - Retrieving the Roster on Login - */ - public boolean isRosterLoadedAtLogin(); - /** * Get the feature packet extensions for a given stream feature of the * server, or null if the server doesn't support that feature. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index 69852d3f1..7fa39edeb 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -52,7 +52,6 @@ import org.jivesoftware.smack.util.XmlStringBuilder; * the user's current presence status. Second, they are used to subscribe and * unsubscribe users from the roster. * - * @see RosterPacket * @author Matt Tucker */ public final class Presence extends Packet { diff --git a/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml b/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml index d4a3262f0..03ffe987c 100644 --- a/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml +++ b/smack-core/src/main/resources/org.jivesoftware.smack/smack-config.xml @@ -19,5 +19,6 @@ org.jivesoftware.smack.sasl.provided.SASLProvidedSmackInitializer org.jivesoftware.smack.android.AndroidSmackInitializer org.jivesoftware.smack.java7.Java7SmackInitializer + org.jivesoftware.smack.im.SmackImInitializer diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java index 290031b9f..78c6ad789 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -49,7 +49,6 @@ public class DummyConnection extends AbstractXMPPConnection { private boolean reconnect = false; private String connectionID; - private Roster roster; private final BlockingQueue queue = new LinkedBlockingQueue(); @@ -89,7 +88,6 @@ public class DummyConnection extends AbstractXMPPConnection { protected void shutdown() { user = null; connectionID = null; - roster = null; authenticated = false; callConnectionClosedListener(); @@ -107,17 +105,6 @@ public class DummyConnection extends AbstractXMPPConnection { return connectionID; } - @Override - public Roster getRoster() { - if (isAnonymous()) { - return null; - } - if (roster == null) { - roster = new Roster(this); - } - return roster; - } - @Override public boolean isSecureConnection() { return false; @@ -136,7 +123,6 @@ public class DummyConnection extends AbstractXMPPConnection { + config.getServiceName() + "/" + (resource != null ? resource : "Test"); - roster = new Roster(this); authenticated = true; } diff --git a/smack-extensions/build.gradle b/smack-extensions/build.gradle index 67a5a09fd..ade5dccbf 100644 --- a/smack-extensions/build.gradle +++ b/smack-extensions/build.gradle @@ -7,5 +7,8 @@ Classes and methods that implement support for the various XMPP XEPs // sourceSet.test of the core subproject dependencies { compile project(':smack-core') + // Some implementations need APIs provided by smack-im, + // e.g. message delivery receipts the roster + compile project(':smack-im') testCompile project(':smack-core').sourceSets.test.runtimeClasspath } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateListener.java index 856b769f1..55a2841e7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateListener.java @@ -17,8 +17,8 @@ package org.jivesoftware.smackx.chatstates; -import org.jivesoftware.smack.Chat; -import org.jivesoftware.smack.ChatMessageListener; +import org.jivesoftware.smack.chat.Chat; +import org.jivesoftware.smack.chat.ChatMessageListener; /** * Events for when the state of a user in a chat changes. diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java index 2674c2c9d..0dd4278e7 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/chatstates/ChatStateManager.java @@ -20,14 +20,14 @@ package org.jivesoftware.smackx.chatstates; import java.util.Map; import java.util.WeakHashMap; -import org.jivesoftware.smack.Chat; -import org.jivesoftware.smack.ChatManager; -import org.jivesoftware.smack.ChatManagerListener; -import org.jivesoftware.smack.ChatMessageListener; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.chat.Chat; +import org.jivesoftware.smack.chat.ChatManager; +import org.jivesoftware.smack.chat.ChatManagerListener; +import org.jivesoftware.smack.chat.ChatMessageListener; import org.jivesoftware.smack.filter.NotFilter; import org.jivesoftware.smack.filter.PacketExtensionFilter; import org.jivesoftware.smack.filter.PacketFilter; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index 3dd70af52..5fdd0ff9f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -29,9 +29,6 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Level; import java.util.logging.Logger; -import org.jivesoftware.smack.Chat; -import org.jivesoftware.smack.ChatManager; -import org.jivesoftware.smack.ChatMessageListener; import org.jivesoftware.smack.MessageListener; import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketListener; @@ -42,6 +39,9 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; +import org.jivesoftware.smack.chat.Chat; +import org.jivesoftware.smack.chat.ChatManager; +import org.jivesoftware.smack.chat.ChatMessageListener; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.filter.MessageTypeFilter; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index 934827e6a..5f72ed575 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -36,6 +36,7 @@ import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; /** @@ -147,7 +148,7 @@ public class DeliveryReceiptManager extends Manager { case disabled: return; case ifIsSubscribed: - if (!connection.getRoster().isSubscribedToMyPresence(from)) { + if (!Roster.getInstanceFor(connection).isSubscribedToMyPresence(from)) { return; } break; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/provider/DataFormProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/provider/DataFormProvider.java index a5ad417c4..2b52a4404 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/provider/DataFormProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/provider/DataFormProvider.java @@ -18,9 +18,9 @@ package org.jivesoftware.smackx.xdata.provider; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.packet.RosterPacket; import org.jivesoftware.smack.provider.PacketExtensionProvider; -import org.jivesoftware.smack.provider.RosterPacketProvider; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.provider.RosterPacketProvider; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jivesoftware.smackx.xdatalayout.packet.DataLayout; diff --git a/smack-im/build.gradle b/smack-im/build.gradle new file mode 100644 index 000000000..ca8b23e84 --- /dev/null +++ b/smack-im/build.gradle @@ -0,0 +1,11 @@ +description = """\ +Smack IM. +Classes and methods for XMPP-IM (RFC 6121): +Roster, Chat and other functionality.""" + +// Note that the test dependencies (junit, …) are inferred from the +// sourceSet.test of the core subproject +dependencies { + compile project(':smack-core') + testCompile project(':smack-core').sourceSets.test.runtimeClasspath +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Chat.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/Chat.java rename to smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java index d78277ad0..b9465b53b 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Chat.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/Chat.java @@ -15,8 +15,9 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.chat; +import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.StringUtils; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java rename to smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java index 47696ca74..2e2205795 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ChatManager.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManager.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.chat; import java.util.Collections; import java.util.Map; @@ -25,6 +25,11 @@ import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArraySet; +import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.MessageListener; +import org.jivesoftware.smack.PacketCollector; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.FlexiblePacketTypeFilter; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ChatManagerListener.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManagerListener.java similarity index 96% rename from smack-core/src/main/java/org/jivesoftware/smack/ChatManagerListener.java rename to smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManagerListener.java index da93c6a61..eaa706810 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ChatManagerListener.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatManagerListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.chat; /** * A listener for chat related events. diff --git a/smack-core/src/main/java/org/jivesoftware/smack/ChatMessageListener.java b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatMessageListener.java similarity index 95% rename from smack-core/src/main/java/org/jivesoftware/smack/ChatMessageListener.java rename to smack-im/src/main/java/org/jivesoftware/smack/chat/ChatMessageListener.java index 9fcdec355..c1f178259 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/ChatMessageListener.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/chat/ChatMessageListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.chat; import org.jivesoftware.smack.packet.Message; diff --git a/smack-im/src/main/java/org/jivesoftware/smack/im/SmackImInitializer.java b/smack-im/src/main/java/org/jivesoftware/smack/im/SmackImInitializer.java new file mode 100644 index 000000000..6a301f198 --- /dev/null +++ b/smack-im/src/main/java/org/jivesoftware/smack/im/SmackImInitializer.java @@ -0,0 +1,33 @@ +/** + * + * Copyright © 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.im; + +import org.jivesoftware.smack.initializer.UrlInitializer; + +public class SmackImInitializer extends UrlInitializer { + + @Override + protected String getProvidersUrl() { + return "classpath:org.jivesoftware.smack.im/smackim.providers"; + } + + @Override + protected String getConfigUrl() { + return "classpath:org.jivesoftware.smack.im/smackim.xml"; + } + +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java similarity index 91% rename from smack-core/src/main/java/org/jivesoftware/smack/Roster.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java index da3396afe..c44918b4d 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/Roster.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import java.util.ArrayList; import java.util.Arrays; @@ -27,14 +27,23 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import org.jivesoftware.smack.AbstractConnectionClosedListener; +import org.jivesoftware.smack.ConnectionCreationListener; +import org.jivesoftware.smack.ExceptionCallback; +import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotLoggedInException; +import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketTypeFilter; @@ -43,12 +52,12 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smack.packet.RosterPacket; -import org.jivesoftware.smack.packet.RosterVer; -import org.jivesoftware.smack.packet.RosterPacket.Item; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Condition; -import org.jivesoftware.smack.rosterstore.RosterStore; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterVer; +import org.jivesoftware.smack.roster.packet.RosterPacket.Item; +import org.jivesoftware.smack.roster.rosterstore.RosterStore; import org.jxmpp.util.XmppStringUtils; /** @@ -63,22 +72,55 @@ import org.jxmpp.util.XmppStringUtils; * * * @author Matt Tucker - * @see XMPPConnection#getRoster() + * @see #getInstanceFor(XMPPConnection) */ -public class Roster { +public class Roster extends Manager { private static final Logger LOGGER = Logger.getLogger(Roster.class.getName()); + static { + XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { + @Override + public void connectionCreated(XMPPConnection connection) { + getInstanceFor(connection); + } + }); + } + + private static final Map INSTANCES = new WeakHashMap<>(); + + /** + * Returns the roster for the user. + *

+ * This method will never return null, instead if the user has not yet logged into + * the server or is logged in anonymously all modifying methods of the returned roster object + * like {@link Roster#createEntry(String, String, String[])}, + * {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing + * {@link RosterListener}s will throw an IllegalStateException. + * + * @return the user's roster. + * @throws IllegalStateException if the connection is anonymous + */ + public static synchronized Roster getInstanceFor(XMPPConnection connection) { + Roster roster = INSTANCES.get(connection); + if (roster == null) { + roster = new Roster(connection); + INSTANCES.put(connection, roster); + } + return roster; + } + private static final PacketFilter PRESENCE_PACKET_FILTER = new PacketTypeFilter(Presence.class); + private static boolean rosterLoadedAtLoginDefault = true; + /** * The default subscription processing mode to use when a Roster is created. By default * all subscription requests are automatically accepted. */ private static SubscriptionMode defaultSubscriptionMode = SubscriptionMode.accept_all; - private final XMPPConnection connection; - private final RosterStore rosterStore; + private RosterStore rosterStore; private final Map groups = new ConcurrentHashMap(); private final Map entries = new ConcurrentHashMap(); private final List unfiledEntries = new CopyOnWriteArrayList(); @@ -91,6 +133,11 @@ public class Roster { private final PresencePacketListener presencePacketListener = new PresencePacketListener(); + /** + * + */ + private boolean rosterLoadedAtLogin = rosterLoadedAtLoginDefault; + private SubscriptionMode subscriptionMode = getDefaultSubscriptionMode(); /** @@ -122,9 +169,8 @@ public class Roster { * * @param connection an XMPP connection. */ - Roster(final XMPPConnection connection) { - this.connection = connection; - rosterStore = connection.getRosterStore(); + private Roster(final XMPPConnection connection) { + super(connection); // Note that we use sync packet listeners because RosterListeners should be invoked in the same order as the // roster stanzas arrive. @@ -143,7 +189,7 @@ public class Roster { // again if it's an anonymous connection. if (connection.isAnonymous()) return; - if (!connection.isRosterLoadedAtLogin()) + if (!isRosterLoadedAtLogin()) return; // We are done here if the connection was resumed if (resumed) { @@ -214,6 +260,7 @@ public class Roster { * @throws NotConnectedException */ public void reload() throws NotLoggedInException, NotConnectedException{ + final XMPPConnection connection = connection(); if (!connection.isAuthenticated()) { throw new NotLoggedInException(); } @@ -233,7 +280,25 @@ public class Roster { }); } + public void reloadAndWait() throws NotLoggedInException, NotConnectedException { + reload(); + waitUntilLoaded(); + } + + public boolean setRosterStore(RosterStore rosterStore) { + this.rosterStore = rosterStore; + try { + reload(); + } + catch (NotLoggedInException | NotConnectedException e) { + LOGGER.log(Level.FINER, "Could not reload roster", e); + return false; + } + return true; + } + protected boolean waitUntilLoaded() { + final XMPPConnection connection = connection(); while (!loaded) { long waitTime = connection.getPacketReplyTimeout(); long start = System.currentTimeMillis(); @@ -301,6 +366,7 @@ public class Roster { * @throws IllegalStateException if logged in anonymously */ public RosterGroup createGroup(String name) { + final XMPPConnection connection = connection(); if (connection.isAnonymous()) { throw new IllegalStateException("Anonymous users can't have a roster."); } @@ -327,6 +393,7 @@ public class Roster { * @throws NotConnectedException */ public void createEntry(String user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException { + final XMPPConnection connection = connection(); if (!connection.isAuthenticated()) { throw new NotLoggedInException(); } @@ -368,6 +435,7 @@ public class Roster { * @throws IllegalStateException if connection is not logged in or logged in anonymously */ public void removeEntry(RosterEntry entry) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException { + final XMPPConnection connection = connection(); if (!connection.isAuthenticated()) { throw new NotLoggedInException(); } @@ -723,6 +791,33 @@ public class Roster { } } + /** + * Sets if the roster will be loaded from the server when logging in. This + * is the common behaviour for clients but sometimes clients may want to differ this + * or just never do it if not interested in rosters. + * + * @param rosterLoadedAtLogin if the roster will be loaded from the server when logging in. + */ + public void setRosterLoadedAtLogin(boolean rosterLoadedAtLogin) { + this.rosterLoadedAtLogin = rosterLoadedAtLogin; + } + + /** + * Returns true if the roster will be loaded from the server when logging in. This + * is the common behavior for clients but sometimes clients may want to differ this + * or just never do it if not interested in rosters. + * + * @return true if the roster will be loaded from the server when logging in. + * @see RFC 6121 2.2 - Retrieving the Roster on Login + */ + public boolean isRosterLoadedAtLogin() { + return rosterLoadedAtLogin; + } + + RosterStore getRosterStore() { + return rosterStore; + } + /** * Returns the key to use in the presenceMap and entries Map for a fully qualified XMPP ID. * The roster can contain any valid address format such us "domain/resource", @@ -921,7 +1016,7 @@ public class Roster { } private boolean isRosterVersioningSupported() { - return connection.hasFeature(RosterVer.ELEMENT, RosterVer.NAMESPACE); + return connection().hasFeature(RosterVer.ELEMENT, RosterVer.NAMESPACE); } /** @@ -973,6 +1068,7 @@ public class Roster { } public void processPacket(Packet packet) throws NotConnectedException { + final XMPPConnection connection = connection(); Presence presence = (Presence) packet; String from = presence.getFrom(); String key = getMapKey(from); @@ -1078,6 +1174,7 @@ public class Roster { @Override public void processPacket(Packet packet) { + final XMPPConnection connection = connection(); LOGGER.fine("RosterResultListener received stanza"); Collection addedEntries = new ArrayList(); Collection updatedEntries = new ArrayList(); @@ -1153,6 +1250,7 @@ public class Roster { @Override public IQ handleIQRequest(IQ iqRequest) { + final XMPPConnection connection = connection(); RosterPacket rosterPacket = (RosterPacket) iqRequest; // Roster push (RFC 6121, 2.1.6) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/RosterEntry.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/RosterEntry.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java index f03f8bab3..bc3870405 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/RosterEntry.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterEntry.java @@ -15,16 +15,17 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket; /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/RosterGroup.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java similarity index 97% rename from smack-core/src/main/java/org/jivesoftware/smack/RosterGroup.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java index 2fae4c36e..502be1b12 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/RosterGroup.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterGroup.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -23,11 +23,13 @@ import java.util.List; import java.util.Locale; import java.util.Set; +import org.jivesoftware.smack.PacketCollector; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket; import org.jxmpp.util.XmppStringUtils; /** diff --git a/smack-core/src/main/java/org/jivesoftware/smack/RosterListener.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/RosterListener.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java index 159274a43..2a00de66a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/RosterListener.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/RosterListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import org.jivesoftware.smack.packet.Presence; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/RosterPacket.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/packet/RosterPacket.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java index 8e36462e3..0b63f0a5e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/RosterPacket.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterPacket.java @@ -15,8 +15,10 @@ * limitations under the License. */ -package org.jivesoftware.smack.packet; +package org.jivesoftware.smack.roster.packet; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.util.XmlStringBuilder; import java.util.ArrayList; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/RosterVer.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterVer.java similarity index 92% rename from smack-core/src/main/java/org/jivesoftware/smack/packet/RosterVer.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterVer.java index 850fe38f2..91a1cb7fd 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/RosterVer.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/packet/RosterVer.java @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.packet; +package org.jivesoftware.smack.roster.packet; +import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.util.XmlStringBuilder; public class RosterVer implements PacketExtension { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/RosterPacketProvider.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java similarity index 93% rename from smack-core/src/main/java/org/jivesoftware/smack/provider/RosterPacketProvider.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java index 000da6a4c..eaddfb504 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/provider/RosterPacketProvider.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterPacketProvider.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2003-2007 Jive Software, 2014 Florian Schmaus + * Copyright © 2003-2007 Jive Software, 2014-2015 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.provider; +package org.jivesoftware.smack.roster.provider; import java.io.IOException; import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.packet.RosterPacket; +import org.jivesoftware.smack.provider.IQProvider; +import org.jivesoftware.smack.roster.packet.RosterPacket; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -27,9 +28,6 @@ public class RosterPacketProvider extends IQProvider { public static final RosterPacketProvider INSTANCE = new RosterPacketProvider(); - private RosterPacketProvider() { - } - @Override public RosterPacket parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterVerStreamFeatureProvider.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterVerStreamFeatureProvider.java new file mode 100644 index 000000000..f59a61706 --- /dev/null +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/provider/RosterVerStreamFeatureProvider.java @@ -0,0 +1,35 @@ +/** + * + * Copyright © 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.roster.provider; + +import java.io.IOException; + +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.provider.PacketExtensionProvider; +import org.jivesoftware.smack.roster.packet.RosterVer; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +public class RosterVerStreamFeatureProvider extends PacketExtensionProvider { + + @Override + public RosterVer parse(XmlPullParser parser, int initialDepth) + throws XmlPullParserException, IOException, SmackException { + return RosterVer.INSTANCE; + } + +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java similarity index 98% rename from smack-core/src/main/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStore.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java index a0a68359f..5bdde3ea9 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStore.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStore.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.rosterstore; +package org.jivesoftware.smack.roster.rosterstore; import java.io.File; import java.io.FileFilter; @@ -26,8 +26,8 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import org.jivesoftware.smack.packet.RosterPacket; -import org.jivesoftware.smack.packet.RosterPacket.Item; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket.Item; import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.stringencoder.Base32; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/rosterstore/RosterStore.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java similarity index 89% rename from smack-core/src/main/java/org/jivesoftware/smack/rosterstore/RosterStore.java rename to smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java index f5bceb507..b732da296 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/rosterstore/RosterStore.java +++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/rosterstore/RosterStore.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.rosterstore; +package org.jivesoftware.smack.roster.rosterstore; import java.util.Collection; -import org.jivesoftware.smack.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket; /** * This is an interface for persistent roster store needed to implement @@ -29,13 +29,13 @@ public interface RosterStore { /** * This method returns a collection of all roster items contained in this store. - * @return List of {@link org.jivesoftware.smack.RosterEntry} + * @return List of {@link org.jivesoftware.smack.roster.RosterEntry} */ public Collection getEntries(); /** * This method returns the roster item in this store for the given JID. * @param bareJid The bare JID of the RosterEntry - * @return The {@link org.jivesoftware.smack.RosterEntry} which belongs to that user + * @return The {@link org.jivesoftware.smack.roster.RosterEntry} which belongs to that user */ public RosterPacket.Item getEntry(String bareJid); /** diff --git a/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.providers b/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.providers new file mode 100644 index 000000000..41d2aa617 --- /dev/null +++ b/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.providers @@ -0,0 +1,16 @@ + + + + + query + jabber:iq:roster + org.jivesoftware.smack.roster.provider.RosterPacketProvider + + + + ver + urn:xmpp:features:rosterver + org.jivesoftware.smack.roster.provider.RosterVerStreamFeatureProvider + + + diff --git a/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.xml b/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.xml new file mode 100644 index 000000000..e52a5243e --- /dev/null +++ b/smack-im/src/main/resources/org.jivesoftware.smack.im/smackim.xml @@ -0,0 +1,5 @@ + + + org.jivesoftware.smack.roster.Roster + + diff --git a/smack-core/src/test/java/org/jivesoftware/smack/ChatConnectionTest.java b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java similarity index 98% rename from smack-core/src/test/java/org/jivesoftware/smack/ChatConnectionTest.java rename to smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java index 6f8658ebf..916bdc2ac 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/ChatConnectionTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.chat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -23,7 +23,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.jivesoftware.smack.ChatManager.MatchMode; +import org.jivesoftware.smack.DummyConnection; +import org.jivesoftware.smack.chat.ChatManager.MatchMode; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message.Type; import org.jivesoftware.smack.packet.Packet; diff --git a/smack-im/src/test/java/org/jivesoftware/smack/im/InitSmackIm.java b/smack-im/src/test/java/org/jivesoftware/smack/im/InitSmackIm.java new file mode 100644 index 000000000..5bfa34031 --- /dev/null +++ b/smack-im/src/test/java/org/jivesoftware/smack/im/InitSmackIm.java @@ -0,0 +1,25 @@ +/** + * + * Copyright 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.im; + +public class InitSmackIm { + + static { + (new SmackImInitializer()).initialize(); + } + +} diff --git a/smack-im/src/test/java/org/jivesoftware/smack/im/SmackImInitializerTest.java b/smack-im/src/test/java/org/jivesoftware/smack/im/SmackImInitializerTest.java new file mode 100644 index 000000000..ac76e5331 --- /dev/null +++ b/smack-im/src/test/java/org/jivesoftware/smack/im/SmackImInitializerTest.java @@ -0,0 +1,34 @@ +/** + * + * Copyright 2015 Florian Schmaus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.im; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; + +public class SmackImInitializerTest { + + @Test + public void testExtensionInitializer() { + SmackImInitializer initializer = new SmackImInitializer(); + List exceptions = initializer.initialize(); + assertTrue(exceptions.size() == 0); + } + +} diff --git a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java similarity index 87% rename from smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java rename to smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java index 35ffecbcc..005c3c837 100644 --- a/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterOfflineTest.java @@ -14,12 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.tcp; +package org.jivesoftware.smack.roster; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.junit.Before; @@ -32,16 +32,16 @@ import org.junit.Test; */ public class RosterOfflineTest { - XMPPTCPConnection connection; + DummyConnection connection; Roster roster; @Before public void setup() throws XMPPException, SmackException { - this.connection = new XMPPTCPConnection("user", "pass", "example.org"); + this.connection = new DummyConnection(); assertFalse(connection.isConnected()); - roster = connection.getRoster(); + roster = Roster.getInstanceFor(connection); assertNotNull(roster); } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java similarity index 97% rename from smack-core/src/test/java/org/jivesoftware/smack/RosterTest.java rename to smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java index ad8f56b67..d810b2715 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/RosterTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -30,15 +30,20 @@ import java.util.Collections; 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; import org.jivesoftware.smack.packet.ErrorIQ; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smack.packet.RosterPacket; import org.jivesoftware.smack.packet.IQ.Type; -import org.jivesoftware.smack.packet.RosterPacket.Item; -import org.jivesoftware.smack.packet.RosterPacket.ItemType; import org.jivesoftware.smack.packet.XMPPError.Condition; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket.Item; +import org.jivesoftware.smack.roster.packet.RosterPacket.ItemType; import org.jivesoftware.smack.test.util.TestUtils; import org.jivesoftware.smack.test.util.WaitForPacketListener; import org.jivesoftware.smack.util.PacketParserUtils; @@ -54,7 +59,7 @@ import org.xmlpull.v1.XmlPullParser; * @see Roster Management * @author Guenther Niess */ -public class RosterTest { +public class RosterTest extends InitSmackIm { private DummyConnection connection; private Roster roster; @@ -62,14 +67,11 @@ public class RosterTest { @Before public void setUp() throws Exception { - // Uncomment this to enable debug output - //SmackConfiguration.DEBUG = true; - connection = new DummyConnection(); connection.connect(); connection.login(); rosterListener = new TestRosterListener(); - roster = connection.getRoster(); + roster = Roster.getInstanceFor(connection); roster.addRosterListener(rosterListener); connection.setPacketReplyTimeout(1000 * 60 * 5); } @@ -77,8 +79,8 @@ public class RosterTest { @After public void tearDown() throws Exception { if (connection != null) { - if (rosterListener != null && connection.getRoster() != null) { - connection.getRoster().removeRosterListener(rosterListener); + if (rosterListener != null) { + roster.removeRosterListener(rosterListener); rosterListener = null; } connection.disconnect(); @@ -381,7 +383,7 @@ public class RosterTest { assertEquals(requestId, errorIQ.getPacketID()); assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition()); - assertNull("Contact was added to roster", connection.getRoster().getEntry("spam@example.com")); + assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry("spam@example.com")); } /** diff --git a/smack-core/src/test/java/org/jivesoftware/smack/RosterVersioningTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java similarity index 91% rename from smack-core/src/test/java/org/jivesoftware/smack/RosterVersioningTest.java rename to smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java index 2b12e08cf..f642dcfb5 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/RosterVersioningTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.roster; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -26,16 +26,19 @@ import java.io.IOException; import java.util.Collection; import java.util.HashSet; +import org.jivesoftware.smack.DummyConnection; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.ConnectionConfiguration.Builder; -import org.jivesoftware.smack.RosterTest.TestRosterListener; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ.Type; import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.RosterPacket; -import org.jivesoftware.smack.packet.RosterPacket.Item; -import org.jivesoftware.smack.packet.RosterPacket.ItemType; -import org.jivesoftware.smack.rosterstore.DirectoryRosterStore; -import org.jivesoftware.smack.rosterstore.RosterStore; +import org.jivesoftware.smack.roster.RosterTest.TestRosterListener; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket.Item; +import org.jivesoftware.smack.roster.packet.RosterPacket.ItemType; +import org.jivesoftware.smack.roster.rosterstore.DirectoryRosterStore; +import org.jivesoftware.smack.roster.rosterstore.RosterStore; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -66,12 +69,12 @@ public class RosterVersioningTest { populateStore(store); Builder builder = DummyConnection.getDummyConfigurationBuilder(); - builder.setRosterStore(store); connection = new DummyConnection(builder.build()); connection.connect(); connection.login(); rosterListener = new TestRosterListener(); - roster = connection.getRoster(); + roster = Roster.getInstanceFor(connection); + roster.setRosterStore(store); roster.addRosterListener(rosterListener); roster.reload(); } @@ -152,13 +155,13 @@ public class RosterVersioningTest { assertTrue("Expected to get a RosterPacket ", false); } - Roster roster = connection.getRoster(); + Roster roster = Roster.getInstanceFor(connection); assertEquals("Size of roster", 1, roster.getEntries().size()); RosterEntry entry = roster.getEntry(vaglafItem.getUser()); assertNotNull("Roster contains vaglaf entry", entry); assertEquals("vaglaf entry in roster equals the sent entry", vaglafItem, RosterEntry.toRosterItem(entry)); - RosterStore store = connection.getConfiguration().getRosterStore(); + RosterStore store = roster.getRosterStore(); assertEquals("Size of store", 1, store.getEntries().size()); Item item = store.getEntry(vaglafItem.getUser()); assertNotNull("Store contains vaglaf entry"); @@ -173,7 +176,7 @@ public class RosterVersioningTest { answerWithEmptyRosterResult(); rosterListener.waitAndReset(); - RosterStore store = connection.getConfiguration().getRosterStore(); + RosterStore store = roster.getRosterStore(); // Simulate a roster push adding vaglaf { diff --git a/smack-core/src/test/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStoreTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java similarity index 96% rename from smack-core/src/test/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStoreTest.java rename to smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java index fbc10ce70..96c7e17a9 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/rosterstore/DirectoryRosterStoreTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/rosterstore/DirectoryRosterStoreTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.rosterstore; +package org.jivesoftware.smack.roster.rosterstore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -25,10 +25,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.jivesoftware.smack.packet.RosterPacket; -import org.jivesoftware.smack.packet.RosterPacket.Item; -import org.jivesoftware.smack.packet.RosterPacket.ItemStatus; -import org.jivesoftware.smack.packet.RosterPacket.ItemType; +import org.jivesoftware.smack.roster.packet.RosterPacket; +import org.jivesoftware.smack.roster.packet.RosterPacket.Item; +import org.jivesoftware.smack.roster.packet.RosterPacket.ItemStatus; +import org.jivesoftware.smack.roster.packet.RosterPacket.ItemType; import org.junit.After; import org.junit.Before; import org.junit.Rule; diff --git a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java index 275cf2591..2dd83faae 100644 --- a/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java +++ b/smack-jingle-old/src/main/java/org/jivesoftware/smackx/jingleold/JingleManager.java @@ -23,7 +23,6 @@ import java.util.logging.Logger; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.RosterListener; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnectionRegistry; @@ -33,6 +32,8 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.provider.ProviderManager; +import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.roster.RosterListener; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener; import org.jivesoftware.smackx.jingleold.listeners.JingleListener; @@ -213,7 +214,7 @@ public class JingleManager implements JingleSessionListener { this.connection = connection; this.jingleMediaManagers = jingleMediaManagers; - connection.getRoster().addRosterListener(new RosterListener() { + Roster.getInstanceFor(connection).addRosterListener(new RosterListener() { public void entriesAdded(Collection addresses) { } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java index 42d5abeb0..6d0e1d4a6 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/RosterExchangeManager.java @@ -25,15 +25,15 @@ import java.util.Set; import java.util.WeakHashMap; import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.Roster; -import org.jivesoftware.smack.RosterEntry; -import org.jivesoftware.smack.RosterGroup; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.filter.PacketExtensionFilter; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.roster.RosterEntry; +import org.jivesoftware.smack.roster.RosterGroup; import org.jivesoftware.smackx.xroster.packet.RosterExchange; /** diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java index 3b156af76..ea4ad201b 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/xroster/packet/RosterExchange.java @@ -17,10 +17,10 @@ package org.jivesoftware.smackx.xroster.packet; -import org.jivesoftware.smack.Roster; -import org.jivesoftware.smack.RosterEntry; -import org.jivesoftware.smack.RosterGroup; import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.roster.RosterEntry; +import org.jivesoftware.smack.roster.RosterGroup; import org.jivesoftware.smackx.xroster.RemoteRosterEntry; import org.jivesoftware.smackx.xroster.RosterExchangeManager;