diff --git a/build.gradle b/build.gradle index 100e6dd7e..54abdac94 100644 --- a/build.gradle +++ b/build.gradle @@ -197,6 +197,16 @@ subprojects { } } +['smack-extensions', 'smack-experimental', 'smack-legacy'].each { name -> + project(":$name") { + jar { + manifest { + instruction 'Service-Component', "org.jivesoftware.smackx/$name-components.xml" + } + } + } +} + def getGitCommit() { def dotGit = new File("$projectDir/.git") if (!dotGit.isDirectory()) return 'non-git build' diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java similarity index 99% rename from smack-bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java rename to smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java index 3f24b3f0d..a1f1dbc9a 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/BOSHConfiguration.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHConfiguration.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.bosh; import java.net.URI; import java.net.URISyntaxException; diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/BOSHPacketReader.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHPacketReader.java similarity index 98% rename from smack-bosh/src/main/java/org/jivesoftware/smack/BOSHPacketReader.java rename to smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHPacketReader.java index 56700f296..e53e50f59 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/BOSHPacketReader.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/BOSHPacketReader.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.bosh; import java.io.StringReader; @@ -153,7 +153,7 @@ public class BOSHPacketReader implements BOSHClientResponseListener { // The server supports sessions connection.serverSupportsSession(); } else if (parser.getName().equals("register")) { - AccountManager.getInstance(connection).setSupportsAccountCreation(true); + connection.serverSupportsAccountCreation(); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("features")) { diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java similarity index 95% rename from smack-bosh/src/main/java/org/jivesoftware/smack/XMPPBOSHConnection.java rename to smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index 34ab3b5a6..ba18c2734 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.bosh; import java.io.IOException; import java.io.PipedReader; @@ -27,9 +27,11 @@ import java.util.logging.Logger; import javax.security.sasl.SaslException; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.AlreadyLoggedInException; import org.jivesoftware.smack.SmackException.ConnectionException; +import org.jivesoftware.smack.SASLAuthentication; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.ConnectionListener; @@ -137,7 +139,7 @@ public class XMPPBOSHConnection extends XMPPConnection { } @Override - void connectInternal() throws SmackException { + protected void connectInternal() throws SmackException { if (connected) { throw new IllegalStateException("Already connected to a server."); } @@ -267,7 +269,7 @@ public class XMPPBOSHConnection extends XMPPConnection { if (response != null) { this.user = response; // Update the serviceName with the one returned by the server - config.setServiceName(StringUtils.parseServer(response)); + setServiceName(StringUtils.parseServer(response)); } else { this.user = username + "@" + getServiceName(); if (resource != null) { @@ -285,7 +287,7 @@ public class XMPPBOSHConnection extends XMPPConnection { anonymous = false; // Stores the autentication for future reconnection - config.setLoginInfo(username, password, resource); + setLoginInfo(username, password, resource); // If debugging is enabled, change the the debug window title to include // the @@ -316,7 +318,7 @@ public class XMPPBOSHConnection extends XMPPConnection { // Set the user value. this.user = response; // Update the serviceName with the one returned by the server - config.setServiceName(StringUtils.parseServer(response)); + setServiceName(StringUtils.parseServer(response)); // Set presence to online. if (config.isSendPresence()) { @@ -337,7 +339,8 @@ public class XMPPBOSHConnection extends XMPPConnection { callConnectionAuthenticatedListener(); } - void sendPacketInternal(Packet packet) throws NotConnectedException { + @Override + protected void sendPacketInternal(Packet packet) throws NotConnectedException { if (done) { throw new NotConnectedException(); } @@ -508,6 +511,30 @@ public class XMPPBOSHConnection extends XMPPConnection { callConnectionClosedOnErrorListener(e); } + @Override + protected void processPacket(Packet packet) { + super.processPacket(packet); + } + + @Override + protected SASLAuthentication getSASLAuthentication() { + return super.getSASLAuthentication(); + } + + @Override + protected void serverRequiresBinding() { + super.serverRequiresBinding(); + } + + @Override + protected void serverSupportsSession() { + super.serverSupportsSession(); + } + + @Override + protected void serverSupportsAccountCreation() { + super.serverSupportsAccountCreation(); + } /** * A listener class which listen for a successfully established connection diff --git a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/JzlibInputOutputStream.java b/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java similarity index 94% rename from smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/JzlibInputOutputStream.java rename to smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java index 744625fc6..6dfc6568f 100644 --- a/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/JzlibInputOutputStream.java +++ b/smack-compression-jzlib/src/main/java/org/jivesoftware/smack/compression/jzlib/JzlibInputOutputStream.java @@ -14,13 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.compression; +package org.jivesoftware.smack.compression.jzlib; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.compression.XMPPInputOutputStream; import com.jcraft.jzlib.JZlib; import com.jcraft.jzlib.ZInputStream; diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java index a5c2a068d..263e40e89 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java @@ -406,7 +406,7 @@ public class SASLAuthentication { * @param mechanisms collection of strings with the available SASL mechanism reported * by the server. */ - void setAvailableSASLMethods(Collection mechanisms) { + public void setAvailableSASLMethods(Collection mechanisms) { this.serverMechanisms = mechanisms; } @@ -429,7 +429,7 @@ public class SASLAuthentication { * @throws IOException If a network error occures while authenticating. * @throws NotConnectedException */ - void challengeReceived(String challenge) throws IOException, NotConnectedException { + public void challengeReceived(String challenge) throws IOException, NotConnectedException { currentMechanism.challengeReceived(challenge); } @@ -437,7 +437,7 @@ public class SASLAuthentication { * Notification message saying that SASL authentication was successful. The next step * would be to bind the resource. */ - void authenticated() { + public void authenticated() { saslNegotiated = true; // Wake up the thread that is waiting in the #authenticate method synchronized (this) { @@ -452,7 +452,7 @@ public class SASLAuthentication { * @param saslFailure the SASL failure as reported by the server * @see RFC6120 6.5 */ - void authenticationFailed(SASLFailure saslFailure) { + public void authenticationFailed(SASLFailure saslFailure) { this.saslFailure = saslFailure; // Wake up the thread that is waiting in the #authenticate method synchronized (this) { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index beb14ca51..34a8c6ace 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -311,7 +311,13 @@ public final class SmackConfiguration { return res; } - public static void processConfigFile(InputStream cfgFileStream, Collection exceptions) throws Exception { + public static void processConfigFile(InputStream cfgFileStream, + Collection exceptions) throws Exception { + processConfigFile(cfgFileStream, exceptions, SmackConfiguration.class.getClassLoader()); + } + + public static void processConfigFile(InputStream cfgFileStream, + Collection exceptions, ClassLoader classLoader) throws Exception { XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); parser.setInput(cfgFileStream, "UTF-8"); @@ -319,10 +325,10 @@ public final class SmackConfiguration { do { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("startupClasses")) { - parseClassesToLoad(parser, false, exceptions); + parseClassesToLoad(parser, false, exceptions, classLoader); } else if (parser.getName().equals("optionalStartupClasses")) { - parseClassesToLoad(parser, true, exceptions); + parseClassesToLoad(parser, true, exceptions, classLoader); } } eventType = parser.next(); @@ -336,7 +342,9 @@ public final class SmackConfiguration { } } - private static void parseClassesToLoad(XmlPullParser parser, boolean optional, Collection exceptions) throws XmlPullParserException, IOException, Exception { + private static void parseClassesToLoad(XmlPullParser parser, boolean optional, + Collection exceptions, ClassLoader classLoader) + throws XmlPullParserException, IOException, Exception { final String startName = parser.getName(); int eventType; String name; @@ -350,26 +358,30 @@ public final class SmackConfiguration { } else { try { - loadSmackClass(classToLoad, optional); - } catch (Exception e) { + loadSmackClass(classToLoad, optional, classLoader); + } + catch (Exception e) { // Don't throw the exception if an exceptions collection is given, instead // record it there. This is used for unit testing purposes. if (exceptions != null) { exceptions.add(e); - } else { + } + else { throw e; } } } } - } while (! (eventType == XmlPullParser.END_TAG && startName.equals(name))); + } + while (!(eventType == XmlPullParser.END_TAG && startName.equals(name))); } - private static void loadSmackClass(String className, boolean optional) throws Exception { + private static void loadSmackClass(String className, boolean optional, ClassLoader classLoader) throws Exception { Class initClass; try { - // Attempt to load the class so that the class can get initialized - initClass = Class.forName(className); + // Attempt to load and initialize the class so that all static initializer blocks of + // class are executed + initClass = Class.forName(className, true, classLoader); } catch (ClassNotFoundException cnfe) { Level logLevel; @@ -388,8 +400,7 @@ public final class SmackConfiguration { } if (SmackInitializer.class.isAssignableFrom(initClass)) { SmackInitializer initializer = (SmackInitializer) initClass.newInstance(); - initializer.initialize(); - List exceptions = initializer.getExceptions(); + List exceptions = initializer.initialize(); if (exceptions.size() == 0) { LOGGER.log(Level.FINE, "Loaded SmackInitializer " + className); } else { 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 fa18e1f73..3269a8f47 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -352,7 +352,7 @@ public abstract class XMPPConnection { */ public abstract boolean isSecureConnection(); - abstract void sendPacketInternal(Packet packet) throws NotConnectedException; + protected abstract void sendPacketInternal(Packet packet) throws NotConnectedException; /** * Returns true if network traffic is being compressed. When using stream compression network @@ -398,7 +398,7 @@ public abstract class XMPPConnection { * @throws IOException * @throws XMPPException */ - abstract void connectInternal() throws SmackException, IOException, XMPPException; + protected abstract void connectInternal() throws SmackException, IOException, XMPPException; /** * Logs in to the server using the strongest authentication mode supported by @@ -476,7 +476,7 @@ public abstract class XMPPConnection { * Notification message saying that the server requires the client to bind a * resource to the stream. */ - void serverRequiresBinding() { + protected void serverRequiresBinding() { synchronized (bindingRequired) { bindingRequired.set(true); bindingRequired.notify(); @@ -488,11 +488,11 @@ public abstract class XMPPConnection { * sessions the client needs to send a Session packet after successfully binding a resource * for the session. */ - void serverSupportsSession() { + protected void serverSupportsSession() { sessionSupported = true; } - String bindResourceAndEstablishSession(String resource) throws XMPPErrorException, + protected String bindResourceAndEstablishSession(String resource) throws XMPPErrorException, ResourceBindingNotOfferedException, NoResponseException, NotConnectedException { synchronized (bindingRequired) { @@ -537,6 +537,30 @@ public abstract class XMPPConnection { } } + protected Reader getReader() { + return reader; + } + + protected Writer getWriter() { + return writer; + } + + protected void setServiceName(String serviceName) { + config.setServiceName(serviceName); + } + + protected void setLoginInfo(String username, String password, String resource) { + config.setLoginInfo(username, password, resource); + } + + protected void serverSupportsAccountCreation() { + AccountManager.getInstance(this).setSupportsAccountCreation(true); + } + + protected void maybeResolveDns() throws Exception { + config.maybeResolveDns(); + } + /** * Sends the specified packet to the server. * @@ -627,6 +651,7 @@ public abstract class XMPPConnection { } return roster; } + /** * Returns the SASLAuthentication manager that is responsible for authenticating with * the server. @@ -634,7 +659,7 @@ public abstract class XMPPConnection { * @return the SASLAuthentication manager that is responsible for authenticating with * the server. */ - public SASLAuthentication getSASLAuthentication() { + protected SASLAuthentication getSASLAuthentication() { return saslAuthentication; } @@ -1127,13 +1152,13 @@ public abstract class XMPPConnection { } } - void callConnectionConnectedListener() { + protected void callConnectionConnectedListener() { for (ConnectionListener listener : getConnectionListeners()) { listener.connected(this); } } - void callConnectionAuthenticatedListener() { + protected void callConnectionAuthenticatedListener() { for (ConnectionListener listener : getConnectionListeners()) { listener.authenticated(this); } @@ -1152,7 +1177,7 @@ public abstract class XMPPConnection { } } - void callConnectionClosedOnErrorListener(Exception e) { + protected void callConnectionClosedOnErrorListener(Exception e) { LOGGER.log(Level.WARNING, "Connection closed with error", e); for (ConnectionListener listener : getConnectionListeners()) { try { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/initializer/LoggingInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/initializer/LoggingInitializer.java deleted file mode 100644 index a0b2acc41..000000000 --- a/smack-core/src/main/java/org/jivesoftware/smack/initializer/LoggingInitializer.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.initializer; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; - -import org.jivesoftware.smack.util.FileUtils; - -/** - * Initializes the Java logging system. - * - * @author Robin Collier - * - */ -public class LoggingInitializer implements SmackInitializer { - - private static final Logger LOGGER = Logger.getLogger(LoggingInitializer.class.getName()); - - private List exceptions = new LinkedList(); - - @Override - public void initialize() { - try { - LogManager.getLogManager().readConfiguration(FileUtils.getStreamForUrl("classpath:org.jivesofware.smack/jul.properties", null)); - } - catch (Exception e) { - LOGGER.log(Level.WARNING, "Could not initialize Java Logging from default file.", e); - exceptions.add(e); - } - } - - @Override - public List getExceptions() { - return Collections.unmodifiableList(exceptions); - } -} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/initializer/SmackInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/initializer/SmackInitializer.java index 1d8a22d15..42b0e954f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/initializer/SmackInitializer.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/initializer/SmackInitializer.java @@ -30,6 +30,6 @@ import org.jivesoftware.smack.SmackConfiguration; * */ public interface SmackInitializer { - void initialize(); - List getExceptions(); + public List initialize(); + public List initialize(ClassLoader classLoader); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlInitializer.java new file mode 100644 index 000000000..d716a7286 --- /dev/null +++ b/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlInitializer.java @@ -0,0 +1,99 @@ +/** + * + * Copyright 2014 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.initializer; + +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.provider.ProviderFileLoader; +import org.jivesoftware.smack.provider.ProviderManager; +import org.jivesoftware.smack.util.FileUtils; + +/** + * Loads the provider file defined by the URL returned by {@link #getProvidersUrl()} and the generic + * smack configuration file returned {@link #getConfigUrl()}. + * + * @author Florian Schmaus + */ +public abstract class UrlInitializer implements SmackInitializer { + private static final Logger LOGGER = Logger.getLogger(UrlInitializer.class.getName()); + + /** + * A simple wrapper around {@link #initialize} for OSGi, as the activate method of a component + * must have a void return type. + */ + public final void activate() { + initialize(); + } + + @Override + public List initialize() { + return initialize(this.getClass().getClassLoader()); + } + + @Override + public List initialize(ClassLoader classLoader) { + InputStream is; + final List exceptions = new LinkedList(); + final String providerUrl = getProvidersUrl(); + if (providerUrl != null) { + try { + is = FileUtils.getStreamForUrl(providerUrl, classLoader); + + if (is != null) { + LOGGER.log(Level.FINE, "Loading providers for providerUrl [" + providerUrl + + "]"); + ProviderFileLoader pfl = new ProviderFileLoader(is, classLoader); + ProviderManager.addLoader(pfl); + exceptions.addAll(pfl.getLoadingExceptions()); + } + else { + LOGGER.log(Level.WARNING, "No input stream created for " + providerUrl); + exceptions.add(new IOException("No input stream created for " + providerUrl)); + } + } + catch (Exception e) { + LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUrl, e); + exceptions.add(e); + } + } + final String configUrl = getConfigUrl(); + if (configUrl != null) { + try { + is = FileUtils.getStreamForUrl(configUrl, classLoader); + SmackConfiguration.processConfigFile(is, exceptions, classLoader); + } + catch (Exception e) { + exceptions.add(e); + } + } + return exceptions; + } + + protected String getProvidersUrl() { + return null; + } + + protected String getConfigUrl() { + return null; + } +} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlProviderFileInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlProviderFileInitializer.java deleted file mode 100644 index f9f43cb38..000000000 --- a/smack-core/src/main/java/org/jivesoftware/smack/initializer/UrlProviderFileInitializer.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.initializer; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.jivesoftware.smack.provider.ProviderFileLoader; -import org.jivesoftware.smack.provider.ProviderManager; -import org.jivesoftware.smack.util.FileUtils; - -/** - * Loads the provider file defined by the URL returned by {@link #getFilePath()}. This file will be loaded on Smack initialization. - * - * @author Robin Collier - * - */ -public abstract class UrlProviderFileInitializer implements SmackInitializer { - private static final Logger LOGGER = Logger.getLogger(UrlProviderFileInitializer.class.getName()); - - private List exceptions = new LinkedList(); - - @Override - public void initialize() { - String filePath = getFilePath(); - - try { - InputStream is = FileUtils.getStreamForUrl(filePath, getClassLoader()); - - if (is != null) { - LOGGER.log(Level.INFO, "Loading providers for file [" + filePath + "]"); - ProviderFileLoader pfl = new ProviderFileLoader(is); - ProviderManager.addLoader(pfl); - exceptions.addAll(pfl.getLoadingExceptions()); - } - else { - LOGGER.log(Level.WARNING, "No input stream created for " + filePath); - exceptions.add(new IOException("No input stream created for " + filePath)); - } - } - catch (Exception e) { - LOGGER.log(Level.SEVERE, "Error trying to load provider file " + filePath, e); - exceptions.add(e); - } - } - - @Override - public List getExceptions() { - return Collections.unmodifiableList(exceptions); - } - - protected abstract String getFilePath(); - - /** - * Returns an array of class loaders to load resources from. - * - * @return an array of ClassLoader instances. - */ - protected ClassLoader getClassLoader() { - return null; - } -} diff --git a/smack-core/src/main/java/org/jivesoftware/smack/initializer/VmArgInitializer.java b/smack-core/src/main/java/org/jivesoftware/smack/initializer/VmArgInitializer.java index d84ffa0ab..5b3ce046a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/initializer/VmArgInitializer.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/initializer/VmArgInitializer.java @@ -16,6 +16,9 @@ */ package org.jivesoftware.smack.initializer; +import java.util.Collections; +import java.util.List; + import org.jivesoftware.smack.provider.ProviderManager; @@ -26,16 +29,17 @@ import org.jivesoftware.smack.provider.ProviderManager; * @author Robin Collier * */ -public class VmArgInitializer extends UrlProviderFileInitializer { +public class VmArgInitializer extends UrlInitializer { protected String getFilePath() { return System.getProperty("smack.provider.file"); } @Override - public void initialize() { + public List initialize() { if (getFilePath() != null) { super.initialize(); } + return Collections.emptyList(); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java index 49610afce..96f5a1640 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java @@ -45,8 +45,12 @@ public class ProviderFileLoader implements ProviderLoader { private List exceptions = new LinkedList(); - @SuppressWarnings("unchecked") public ProviderFileLoader(InputStream providerStream) { + this(providerStream, ProviderFileLoader.class.getClassLoader()); + } + + @SuppressWarnings("unchecked") + public ProviderFileLoader(InputStream providerStream, ClassLoader classLoader) { iqProviders = new ArrayList(); extProviders = new ArrayList(); @@ -73,13 +77,13 @@ public class ProviderFileLoader implements ProviderLoader { String className = parser.nextText(); try { + final Class provider = classLoader.loadClass(className); // Attempt to load the provider class and then create // a new instance if it's an IQProvider. Otherwise, if it's // an IQ class, add the class object itself, then we'll use // reflection later to create instances of the class. if ("iqProvider".equals(typeName)) { // Add the provider to the map. - Class provider = Class.forName(className); if (IQProvider.class.isAssignableFrom(provider)) { iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider) provider.newInstance())); @@ -94,7 +98,6 @@ public class ProviderFileLoader implements ProviderLoader { // a PacketExtension, add the class object itself and // then we'll use reflection later to create instances // of the class. - Class provider = Class.forName(className); if (PacketExtensionProvider.class.isAssignableFrom(provider)) { extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider) provider.newInstance())); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java index dd93398c2..bfbac44b1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/FileUtils.java @@ -46,7 +46,10 @@ public final class FileUtils { if (fileUri.getScheme().equals("classpath")) { // Get an array of class loaders to try loading the providers files from. - ClassLoader[] classLoaders = getClassLoaders(); + List classLoaders = getClassLoaders(); + if (loader != null) { + classLoaders.add(0, loader); + } for (ClassLoader classLoader : classLoaders) { InputStream is = classLoader.getResourceAsStream(fileUri.getSchemeSpecificPart()); @@ -64,21 +67,21 @@ public final class FileUtils { /** * Returns default classloaders. * - * @return an array of ClassLoader instances. + * @return a List of ClassLoader instances. */ - public static ClassLoader[] getClassLoaders() { + public static List getClassLoaders() { ClassLoader[] classLoaders = new ClassLoader[2]; classLoaders[0] = FileUtils.class.getClassLoader(); classLoaders[1] = Thread.currentThread().getContextClassLoader(); - // Clean up possible null values. Note that #getClassLoader may return a null value. - List loaders = new ArrayList(); + // Clean up possible null values. Note that #getClassLoader may return a null value. + List loaders = new ArrayList(classLoaders.length); for (ClassLoader classLoader : classLoaders) { if (classLoader != null) { loaders.add(classLoader); } } - return loaders.toArray(new ClassLoader[loaders.size()]); + return loaders; } public static boolean addLines(String url, Set set) throws MalformedURLException, IOException { 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 3c6484bb0..500b048ff 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 @@ -8,12 +8,9 @@ - org.jivesoftware.smack.util.dns.JavaxResolver - org.jivesoftware.smackx.ExtensionsProviderInitializer - org.jivesoftware.smackx.ExtensionsStartupClasses - org.jivesoftware.smackx.ExperimentalProviderInitializer - org.jivesoftware.smackx.ExperimentalStartupClasses - org.jivesoftware.smackx.WorkgroupProviderInitializer - org.jivesoftware.smackx.LegacyProviderInitializer + org.jivesoftware.smack.util.dns.javax.JavaxResolver + org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer + org.jivesoftware.smack.initializer.experimental.ExperimentalInitializer + org.jivesoftware.smack.initializer.legacy.LegacyInitializer 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 4e4fdd8e7..22db8f32f 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -74,7 +74,7 @@ public class DummyConnection extends XMPPConnection { } @Override - void connectInternal() { + protected void connectInternal() { connectionID = "dummy-" + new Random(new Date().getTime()).nextInt(); if (reconnect) { @@ -185,7 +185,7 @@ public class DummyConnection extends XMPPConnection { } @Override - void sendPacketInternal(Packet packet) { + protected void sendPacketInternal(Packet packet) { if (SmackConfiguration.DEBUG_ENABLED) { System.out.println("[SEND]: " + packet.toXML()); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalProviderInitializer.java b/smack-experimental/src/main/java/org/jivesoftware/smack/initializer/experimental/ExperimentalInitializer.java similarity index 64% rename from smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalProviderInitializer.java rename to smack-experimental/src/main/java/org/jivesoftware/smack/initializer/experimental/ExperimentalInitializer.java index c71b7752f..9c66e0506 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalProviderInitializer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smack/initializer/experimental/ExperimentalInitializer.java @@ -1,6 +1,6 @@ /** * - * Copyright 2013 Robin Collier + * Copyright 2014 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,20 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx; +package org.jivesoftware.smack.initializer.experimental; -import org.jivesoftware.smack.initializer.UrlProviderFileInitializer; +import org.jivesoftware.smack.initializer.UrlInitializer; /** * Initializes the providers in the experimental code stream. * - * @author Robin Collier - * + * @author Florian Schmaus */ -public class ExperimentalProviderInitializer extends UrlProviderFileInitializer { +public class ExperimentalInitializer extends UrlInitializer { @Override - protected String getFilePath() { + protected String getProvidersUrl() { return "classpath:org.jivesoftware.smackx/experimental.providers"; } + + @Override + protected String getConfigUrl() { + return "classpath:org.jivesoftware.smackx/extensions.xml"; + } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalStartupClasses.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalStartupClasses.java deleted file mode 100644 index fc6073c2e..000000000 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/ExperimentalStartupClasses.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - * Copyright 2014 Andriy Tsykholyas - * - * 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.smackx; - -import org.jivesoftware.smack.SmackConfiguration; -import org.jivesoftware.smack.initializer.SmackInitializer; -import org.jivesoftware.smack.util.FileUtils; - -import java.io.InputStream; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * {@link SmackInitializer} implementation for experimental module. - */ -public class ExperimentalStartupClasses implements SmackInitializer { - - private static final String EXTENSIONS_XML = "classpath:org.jivesoftware.smackx/extensions.xml"; - - private List exceptions = new LinkedList(); - // TODO log - - @Override - public void initialize() { - InputStream is; - try { - is = FileUtils.getStreamForUrl(EXTENSIONS_XML, null); - SmackConfiguration.processConfigFile(is, exceptions);; - } - catch (Exception e) { - exceptions.add(e); - } - } - - @Override - public List getExceptions() { - return Collections.unmodifiableList(exceptions); - } -} diff --git a/smack-experimental/src/main/resources/org.jivesoftware.smackx/smack-experimental-components.xml b/smack-experimental/src/main/resources/org.jivesoftware.smackx/smack-experimental-components.xml new file mode 100644 index 000000000..eb477cf07 --- /dev/null +++ b/smack-experimental/src/main/resources/org.jivesoftware.smackx/smack-experimental-components.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalProviderInitializerTest.java b/smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalInitializerTest.java similarity index 66% rename from smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalProviderInitializerTest.java rename to smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalInitializerTest.java index 186093627..1d0fb3f6b 100644 --- a/smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalProviderInitializerTest.java +++ b/smack-experimental/src/test/java/org/jivesoftware/smackx/ExperimentalInitializerTest.java @@ -18,14 +18,17 @@ package org.jivesoftware.smackx; import static org.junit.Assert.assertTrue; +import java.util.List; + +import org.jivesoftware.smack.initializer.experimental.ExperimentalInitializer; import org.junit.Test; -public class ExperimentalProviderInitializerTest { +public class ExperimentalInitializerTest { @Test - public void testExperimentalProviderInitialzer() { - ExperimentalProviderInitializer epi = new ExperimentalProviderInitializer(); - epi.initialize(); - assertTrue(epi.getExceptions().size() == 0); + public void testExperimentalInitialzer() { + ExperimentalInitializer epi = new ExperimentalInitializer(); + List exceptions = epi.initialize(); + assertTrue(exceptions.size() == 0); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsProviderInitializer.java b/smack-extensions/src/main/java/org/jivesoftware/smack/initializer/extensions/ExtensionsInitializer.java similarity index 59% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsProviderInitializer.java rename to smack-extensions/src/main/java/org/jivesoftware/smack/initializer/extensions/ExtensionsInitializer.java index 055e257f0..9a5a9c82f 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsProviderInitializer.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smack/initializer/extensions/ExtensionsInitializer.java @@ -1,6 +1,6 @@ /** * - * Copyright the original author or authors + * Copyright 2014 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,19 +14,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx; +package org.jivesoftware.smack.initializer.extensions; -import org.jivesoftware.smack.initializer.UrlProviderFileInitializer; +import org.jivesoftware.smack.initializer.UrlInitializer; /** - * Loads the default provider file for the Smack extensions on initialization. + * Initializes the providers in the experimental code stream. * - * @author Robin Collier - * + * @author Florian Schmaus */ -public class ExtensionsProviderInitializer extends UrlProviderFileInitializer { +public class ExtensionsInitializer extends UrlInitializer { + @Override - protected String getFilePath() { + protected String getProvidersUrl() { return "classpath:org.jivesoftware.smackx/extensions.providers"; } + + @Override + protected String getConfigUrl() { + return "classpath:org.jivesoftware.smackx/extensions.xml"; + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java deleted file mode 100644 index 7ec5d2aa5..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.smackx; - -import java.io.InputStream; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import org.jivesoftware.smack.SmackConfiguration; -import org.jivesoftware.smack.initializer.SmackInitializer; -import org.jivesoftware.smack.util.FileUtils; - -public class ExtensionsStartupClasses implements SmackInitializer { - - private static final String EXTENSIONS_XML = "classpath:org.jivesoftware.smackx/extensions.xml"; - - private List exceptions = new LinkedList(); - // TODO log - - @Override - public void initialize() { - InputStream is; - try { - is = FileUtils.getStreamForUrl(EXTENSIONS_XML, null); - SmackConfiguration.processConfigFile(is, exceptions);; - } - catch (Exception e) { - exceptions.add(e); - } - } - - @Override - public List getExceptions() { - return Collections.unmodifiableList(exceptions); - } - -} diff --git a/smack-extensions/src/main/resources/org.jivesoftware.smackx/smack-extensions-components.xml b/smack-extensions/src/main/resources/org.jivesoftware.smackx/smack-extensions-components.xml new file mode 100644 index 000000000..4333efc5f --- /dev/null +++ b/smack-extensions/src/main/resources/org.jivesoftware.smackx/smack-extensions-components.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsStartupClassesTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsInitializerTest.java similarity index 67% rename from smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsStartupClassesTest.java rename to smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsInitializerTest.java index 7280d7020..4e755e9b3 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsStartupClassesTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsInitializerTest.java @@ -18,15 +18,18 @@ package org.jivesoftware.smackx; import static org.junit.Assert.assertTrue; +import java.util.List; + +import org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer; import org.junit.Test; -public class ExtensionsStartupClassesTest { +public class ExtensionsInitializerTest { @Test - public void testExtensiosnStartupClasses() { - ExtensionsStartupClasses esc = new ExtensionsStartupClasses(); - esc.initialize(); - assertTrue(esc.getExceptions().size() == 0); + public void testExtensionInitializer() { + ExtensionsInitializer ei = new ExtensionsInitializer(); + List exceptions = ei.initialize(); + assertTrue(exceptions.size() == 0); } } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsProviderInitializerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsProviderInitializerTest.java deleted file mode 100644 index 8d4969b56..000000000 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ExtensionsProviderInitializerTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.smackx; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class ExtensionsProviderInitializerTest { - - @Test - public void testExtensionProviderInitializer() { - ExtensionsProviderInitializer ei = new ExtensionsProviderInitializer(); - ei.initialize(); - assertTrue(ei.getExceptions().size() == 0); - } - -} diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/InitExtensions.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/InitExtensions.java index 4d1a67265..5c0c87228 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/InitExtensions.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/InitExtensions.java @@ -16,11 +16,12 @@ */ package org.jivesoftware.smackx; +import org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer; + public class InitExtensions { static { - (new ExtensionsProviderInitializer()).initialize(); - (new ExtensionsStartupClasses()).initialize(); + (new ExtensionsInitializer()).initialize(); } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/LegacyProviderInitializer.java b/smack-legacy/src/main/java/org/jivesoftware/smack/initializer/legacy/LegacyInitializer.java similarity index 76% rename from smack-legacy/src/main/java/org/jivesoftware/smackx/LegacyProviderInitializer.java rename to smack-legacy/src/main/java/org/jivesoftware/smack/initializer/legacy/LegacyInitializer.java index 81ba5aa09..e4764e594 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/LegacyProviderInitializer.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smack/initializer/legacy/LegacyInitializer.java @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx; +package org.jivesoftware.smack.initializer.legacy; -import org.jivesoftware.smack.initializer.UrlProviderFileInitializer; +import org.jivesoftware.smack.initializer.UrlInitializer; -public class LegacyProviderInitializer extends UrlProviderFileInitializer { +public class LegacyInitializer extends UrlInitializer { @Override - protected String getFilePath() { + protected String getProvidersUrl() { return "classpath:org.jivesoftware.smackx/legacy.providers"; } } diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/WorkgroupProviderInitializer.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/WorkgroupProviderInitializer.java deleted file mode 100644 index 3765129a2..000000000 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/WorkgroupProviderInitializer.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.smackx; - -import org.jivesoftware.smack.initializer.UrlProviderFileInitializer; - -public class WorkgroupProviderInitializer extends UrlProviderFileInitializer { - - @Override - protected String getFilePath() { - return "classpath:org.jivesoftware.smackx/workgroup.providers"; - } -} diff --git a/smack-legacy/src/main/resources/org.jivesoftware.smackx/smack-legacy-components.xml b/smack-legacy/src/main/resources/org.jivesoftware.smackx/smack-legacy-components.xml new file mode 100644 index 000000000..1bca19539 --- /dev/null +++ b/smack-legacy/src/main/resources/org.jivesoftware.smackx/smack-legacy-components.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyProviderInitializerTest.java b/smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyInitializerTest.java similarity index 73% rename from smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyProviderInitializerTest.java rename to smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyInitializerTest.java index 5147457cc..441251bd1 100644 --- a/smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyProviderInitializerTest.java +++ b/smack-legacy/src/test/java/org/jivesoftware/smackx/LegacyInitializerTest.java @@ -18,14 +18,17 @@ package org.jivesoftware.smackx; import static org.junit.Assert.assertTrue; +import java.util.List; + +import org.jivesoftware.smack.initializer.legacy.LegacyInitializer; import org.junit.Test; -public class LegacyProviderInitializerTest { +public class LegacyInitializerTest { @Test public void testWorkgroupProviderInitializer() { - LegacyProviderInitializer lpi = new LegacyProviderInitializer(); - lpi.initialize(); - assertTrue(lpi.getExceptions().size() == 0); + LegacyInitializer lpi = new LegacyInitializer(); + List exceptions = lpi.initialize(); + assertTrue(exceptions.size() == 0); } } diff --git a/smack-legacy/src/test/java/org/jivesoftware/smackx/WorkgroupProviderInitializerTest.java b/smack-legacy/src/test/java/org/jivesoftware/smackx/WorkgroupProviderInitializerTest.java deleted file mode 100644 index 67356ccdc..000000000 --- a/smack-legacy/src/test/java/org/jivesoftware/smackx/WorkgroupProviderInitializerTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * - * Copyright the original author or authors - * - * 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.smackx; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class WorkgroupProviderInitializerTest { - - @Test - public void testWorkgroupProviderInitializer() { - WorkgroupProviderInitializer wpi = new WorkgroupProviderInitializer(); - wpi.initialize(); - assertTrue(wpi.getExceptions().size() == 0); - } -} diff --git a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/DNSJavaResolver.java b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java similarity index 93% rename from smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/DNSJavaResolver.java rename to smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java index d3d8a6859..8784eb8f8 100644 --- a/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/DNSJavaResolver.java +++ b/smack-resolver-dnsjava/src/main/java/org/jivesoftware/smack/util/dns/dnsjava/DNSJavaResolver.java @@ -14,11 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.util.dns; +package org.jivesoftware.smack.util.dns.dnsjava; import java.util.ArrayList; import java.util.List; +import org.jivesoftware.smack.util.dns.DNSResolver; +import org.jivesoftware.smack.util.dns.SRVRecord; import org.xbill.DNS.Lookup; import org.xbill.DNS.Record; import org.xbill.DNS.TextParseException; diff --git a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/JavaxResolver.java b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java similarity index 95% rename from smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/JavaxResolver.java rename to smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java index 3733ae21d..5b8ac03e4 100644 --- a/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/JavaxResolver.java +++ b/smack-resolver-javax/src/main/java/org/jivesoftware/smack/util/dns/javax/JavaxResolver.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.util.dns; +package org.jivesoftware.smack.util.dns.javax; import java.util.ArrayList; import java.util.Hashtable; @@ -28,6 +28,8 @@ import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import org.jivesoftware.smack.util.DNSUtil; +import org.jivesoftware.smack.util.dns.DNSResolver; +import org.jivesoftware.smack.util.dns.SRVRecord; /** * A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namespace. diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/PacketReader.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketReader.java similarity index 97% rename from smack-tcp/src/main/java/org/jivesoftware/smack/PacketReader.java rename to smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketReader.java index dbae2df95..f40ac5dd3 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/PacketReader.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketReader.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.tcp; import java.io.IOException; @@ -28,6 +28,8 @@ import org.jivesoftware.smack.sasl.SASLMechanism.Challenge; import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure; import org.jivesoftware.smack.sasl.SASLMechanism.Success; import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.SecurityRequiredException; import org.jivesoftware.smack.XMPPException.StreamErrorException; @@ -80,7 +82,7 @@ class PacketReader { parsePackets(this); } }; - readerThread.setName("Smack Packet Reader (" + connection.connectionCounterValue + ")"); + readerThread.setName("Smack Packet Reader (" + connection.getConnectionCounter() + ")"); readerThread.setDaemon(true); resetParser(); @@ -131,7 +133,7 @@ class PacketReader { try { parser = XmlPullParserFactory.newInstance().newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(connection.reader); + parser.setInput(connection.getReader()); } catch (XmlPullParserException e) { throw new SmackException(e); @@ -205,7 +207,7 @@ class PacketReader { } else if (parser.getAttributeName(i).equals("from")) { // Use the server name that the server says that it is. - connection.config.setServiceName(parser.getAttributeValue(i)); + connection.setServiceName(parser.getAttributeValue(i)); } } } @@ -342,7 +344,7 @@ class PacketReader { connection.setAvailableCompressionMethods(PacketParserUtils.parseCompressionMethods(parser)); } else if (parser.getName().equals("register")) { - AccountManager.getInstance(connection).setSupportsAccountCreation(true); + connection.serverSupportsAccountCreation(); } } else if (eventType == XmlPullParser.END_TAG) { diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/PacketWriter.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketWriter.java similarity index 98% rename from smack-tcp/src/main/java/org/jivesoftware/smack/PacketWriter.java rename to smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketWriter.java index 18f7b555a..68d8bf0d3 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/PacketWriter.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/PacketWriter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.tcp; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.packet.Packet; @@ -67,7 +67,7 @@ class PacketWriter { * is invoked if the connection is disconnected by an error. */ protected void init() { - this.writer = connection.writer; + writer = connection.getWriter(); done = false; shutdownDone.set(false); @@ -77,7 +77,7 @@ class PacketWriter { writePackets(this); } }; - writerThread.setName("Smack Packet Writer (" + connection.connectionCounterValue + ")"); + writerThread.setName("Smack Packet Writer (" + connection.getConnectionCounter() + ")"); writerThread.setDaemon(true); } diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java similarity index 93% rename from smack-tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java rename to smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 1ce7b86f0..10a11054f 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -14,11 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.tcp; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionCreationListener; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.SASLAuthentication; +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.AlreadyLoggedInException; +import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.ConnectionException; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.compression.XMPPInputOutputStream; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Presence; @@ -44,7 +53,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.Reader; import java.io.UnsupportedEncodingException; +import java.io.Writer; import java.lang.reflect.Constructor; import java.net.Socket; import java.security.KeyStore; @@ -248,7 +259,7 @@ public class XMPPTCPConnection extends XMPPConnection { if (response != null) { this.user = response; // Update the serviceName with the one returned by the server - config.setServiceName(StringUtils.parseServer(response)); + setServiceName(StringUtils.parseServer(response)); } else { this.user = username + "@" + getServiceName(); @@ -267,7 +278,7 @@ public class XMPPTCPConnection extends XMPPConnection { } // Stores the authentication for future reconnection - config.setLoginInfo(username, password, resource); + setLoginInfo(username, password, resource); // If debugging is enabled, change the the debug window title to include the // name we are now logged-in as. @@ -299,7 +310,7 @@ public class XMPPTCPConnection extends XMPPConnection { // Set the user value. this.user = response; // Update the serviceName with the one returned by the server - config.setServiceName(StringUtils.parseServer(response)); + setServiceName(StringUtils.parseServer(response)); // If compression is enabled then request the server to use stream compression if (config.isCompressionEnabled()) { @@ -375,14 +386,15 @@ public class XMPPTCPConnection extends XMPPConnection { writer = null; } - void sendPacketInternal(Packet packet) throws NotConnectedException { + @Override + protected void sendPacketInternal(Packet packet) throws NotConnectedException { packetWriter.sendPacket(packet); } private void connectUsingConfiguration(ConnectionConfiguration config) throws SmackException, IOException { Exception exception = null; try { - config.maybeResolveDns(); + maybeResolveDns(); } catch (Exception e) { throw new SmackException(e); @@ -782,7 +794,7 @@ public class XMPPTCPConnection extends XMPPConnection { * @throws IOException */ @Override - void connectInternal() throws SmackException, IOException, XMPPException { + protected void connectInternal() throws SmackException, IOException, XMPPException { // Establishes the connection, readers and writers connectUsingConfiguration(config); // TODO is there a case where connectUsing.. does not throw an exception but connected is @@ -823,10 +835,70 @@ public class XMPPTCPConnection extends XMPPConnection { callConnectionClosedOnErrorListener(e); } + @Override + protected void processPacket(Packet packet) { + super.processPacket(packet); + } + + @Override + protected Reader getReader() { + return super.getReader(); + } + + @Override + protected Writer getWriter() { + return super.getWriter(); + } + + @Override + protected void throwConnectionExceptionOrNoResponse() throws IOException, NoResponseException { + super.throwConnectionExceptionOrNoResponse(); + } + + @Override + protected void setServiceName(String serviceName) { + super.setServiceName(serviceName); + } + + @Override + protected void serverRequiresBinding() { + super.serverRequiresBinding(); + } + + @Override + protected void setServiceCapsNode(String node) { + super.setServiceCapsNode(node); + } + + @Override + protected void serverSupportsSession() { + super.serverSupportsSession(); + } + + @Override + protected void setRosterVersioningSupported() { + super.setRosterVersioningSupported(); + } + + @Override + protected void serverSupportsAccountCreation() { + super.serverSupportsAccountCreation(); + } + + @Override + protected SASLAuthentication getSASLAuthentication() { + return super.getSASLAuthentication(); + } + + @Override + protected ConnectionConfiguration getConfiguration() { + return super.getConfiguration(); + } + /** * Sends a notification indicating that the connection was reconnected successfully. */ - protected void notifyReconnection() { + private void notifyReconnection() { // Notify connection listeners of the reconnection. for (ConnectionListener listener : getConnectionListeners()) { try { diff --git a/smack-tcp/src/test/java/org/jivesoftware/smack/PacketWriterTest.java b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java similarity index 96% rename from smack-tcp/src/test/java/org/jivesoftware/smack/PacketWriterTest.java rename to smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.java index 8d78c3728..f344c590d 100644 --- a/smack-tcp/src/test/java/org/jivesoftware/smack/PacketWriterTest.java +++ b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/PacketWriterTest.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.tcp; import java.io.IOException; import java.io.Writer; @@ -34,7 +34,7 @@ public class PacketWriterTest { /** * Make sure that packet writer does block once the queue reaches * {@link PacketWriter#QUEUE_SIZE} and that - * {@link PacketWriter#sendPacket(org.jivesoftware.smack.packet.Packet)} does unblock after the + * {@link PacketWriter#sendPacket(org.jivesoftware.smack.tcp.packet.Packet)} does unblock after the * interrupt. * * @throws InterruptedException diff --git a/smack-tcp/src/test/java/org/jivesoftware/smack/RosterOfflineTest.java b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java similarity index 88% rename from smack-tcp/src/test/java/org/jivesoftware/smack/RosterOfflineTest.java rename to smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java index 48f602b73..ca3b2f1c6 100644 --- a/smack-tcp/src/test/java/org/jivesoftware/smack/RosterOfflineTest.java +++ b/smack-tcp/src/test/java/org/jivesoftware/smack/tcp/RosterOfflineTest.java @@ -14,10 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack; +package org.jivesoftware.smack.tcp; import static org.junit.Assert.*; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; import org.junit.Before; import org.junit.Test;