mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Reworked OSGi support of Smack (SMACK-343)
Because of OSGi, no subproject of Smack (which is the same as a OSGi bundle) must export a package that is already exported by another subproject. Therefore it was necessary to move the TCP and BOSH code into their own packages: org.jivesoftware.smack.(tcp|bosh). OSGi classloader restrictions also made it necessary to create a Declarative Service for smack-extensions, smack-experimental and smack-lagacy (i.e. smack subprojects which should be initialized), in order to initialize them accordingly, as smack-core is, when used in a OSGi environment, unable to load and initialize classes from other smack bundles. OSGi's "Service Component Runtime" (SCR) will now take care of running the initialization code of the particular Smack bundle by activating its Declarative Service. That is also the reason why most initialization related method now have an additional classloader argument. Note that due the refactoring, some ugly changes in XMPPTCPConnection and its PacketReader and PacketWriter where necessary.
This commit is contained in:
parent
541b8b3798
commit
4c76f2652d
39 changed files with 413 additions and 446 deletions
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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<Exception> exceptions = new LinkedList<Exception>();
|
||||
// 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<Exception> getExceptions() {
|
||||
return Collections.unmodifiableList(exceptions);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0"
|
||||
enabled="true" immediate="true" name="Smack Extensions API">
|
||||
<implementation
|
||||
class="org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer" />
|
||||
</scr:component>
|
|
@ -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 ExtensionsProviderInitializerTest {
|
||||
public class ExtensionsInitializerTest {
|
||||
|
||||
@Test
|
||||
public void testExtensionProviderInitializer() {
|
||||
ExtensionsProviderInitializer ei = new ExtensionsProviderInitializer();
|
||||
ei.initialize();
|
||||
assertTrue(ei.getExceptions().size() == 0);
|
||||
public void testExtensionInitializer() {
|
||||
ExtensionsInitializer ei = new ExtensionsInitializer();
|
||||
List<Exception> exceptions = ei.initialize();
|
||||
assertTrue(exceptions.size() == 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 ExtensionsStartupClassesTest {
|
||||
|
||||
@Test
|
||||
public void testExtensiosnStartupClasses() {
|
||||
ExtensionsStartupClasses esc = new ExtensionsStartupClasses();
|
||||
esc.initialize();
|
||||
assertTrue(esc.getExceptions().size() == 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue