
The branch, master has been updated via 19fc29d089340cb27c541db2b77dc7b7a991cbec (commit) from bd6f4a930aa5fed314d3fc54f39a283103551b6d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.qos.ch/gitweb/?p=slf4j.git;a=commit;h=19fc29d089340cb27c541db2b77... http://github.com/ceki/slf4j/commit/19fc29d089340cb27c541db2b77dc7b7a991cbec commit 19fc29d089340cb27c541db2b77dc7b7a991cbec Author: Ceki Gulcu <ceki@qos.ch> Date: Sat Nov 28 19:35:28 2009 +0100 - added unit tests verifying that the slf4j artifacts can actually be used by other osgi bundles within a real osgi framework. The tests depend on Felix. diff --git a/.gitignore b/.gitignore index 9539fb5..ebc44e1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ target .classpath .project -*~ \ No newline at end of file +*~ +integration/bundle/ +integration/felix-cache/ \ No newline at end of file diff --git a/integration/build.xml b/integration/build.xml index a73f9bf..cc54949 100644 --- a/integration/build.xml +++ b/integration/build.xml @@ -47,7 +47,8 @@ <!-- this is really very ugly, but it's the only way to circumvent http://jira.codehaus.org/browse/MANTRUN-95 --> - <taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" /> + <taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" + classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" /> <target name="init"> <mkdir dir="target/unit-reports" /> diff --git a/integration/osgi-build.xml b/integration/osgi-build.xml new file mode 100644 index 0000000..00f59f7 --- /dev/null +++ b/integration/osgi-build.xml @@ -0,0 +1,92 @@ +<project name="osgi-test" default="testAll"> + + <!-- + This build file is usually run indirectly via Maven. + + When running this build file through Ant directly, you must + define the currentVersion property on the command line, e.g.: + + ant -DcurrentVersion=1.5.4-SNAPSHOT + --> + + <echo message="compile classpath: ${currentVersion}" /> + <echo message="test classpath: ${test_classpath}" /> + <echo message="basedir: ${basedir}" /> + + <property name="iBundleJar" value="target/iBundle.jar"/> + <property name="bundlesDir" value="bundle"/> + + + <!-- this is really very ugly, but it's the only way to circumvent + http://jira.codehaus.org/browse/MANTRUN-95 + --> + <taskdef name="junit" classpath="${test_classpath}" + classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" /> + + <path id="minimal"> + <pathelement location="target/test-classes/" /> + </path > + + <target name="init"> + <mkdir dir="target/unit-reports" /> + </target> + + <target name="createIBundle"> + <mkdir dir="${bundlesDir}"/> + <jar destFile="${iBundleJar}" + manifest="src/IBUNDLE-META-INF/MANIFEST.MF" + basedir="target/test-classes/" + includes="integrator/**.class"/> + + </target> + + <target name="testAll" depends="init, createIBundle, nop, simple, jdk14"> + </target> + + + <macrodef name="prepareOSGiHarness"> + <attribute name="binding"/> + <sequential> + <delete> + <fileset dir="${bundlesDir}" includes="*.jar"/> + </delete> + <copy file="${iBundleJar}" todir="${bundlesDir}"/> + <copy file="../slf4j-api/target/slf4j-api-${currentVersion}.jar" todir="${bundlesDir}"/> + <copy file="../slf4j-@{binding}/target/slf4j-@{binding}-${currentVersion}.jar" todir="${bundlesDir}"/> + <echo>value of t = @{t}</echo> + </sequential> + </macrodef> + + + <!-- for some reason if mvn is invoked from the parent directory, junit gets + invoked from the parent dir, which messes up theses tests. Hence, the + fork="yes" dir="${basedir}" --> + + <target name="nop"> + <prepareOSGiHarness binding="nop"/> + <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> + <classpath path="${test_classpath}"/> + <formatter type="plain" /> + <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> + </junit> + </target> + + <target name="simple"> + <prepareOSGiHarness binding="simple"/> + <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> + <classpath path="${test_classpath}"/> + <formatter type="plain" /> + <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> + </junit> + </target> + + <target name="jdk14"> + <prepareOSGiHarness binding="jdk14"/> + <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> + <classpath path="${test_classpath}"/> + <formatter type="plain" /> + <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> + </junit> + </target> + +</project> \ No newline at end of file diff --git a/integration/pom.xml b/integration/pom.xml index 092b264..52e530e 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -38,6 +38,13 @@ <version>1.6.5</version> </dependency> + + <!-- some test run Felix in hosted mode --> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.main</artifactId> + <version>2.0.2</version> + </dependency> </dependencies> <build> @@ -75,6 +82,22 @@ <goal>run</goal> </goals> </execution> + <execution> + <id>ant-osgi-test</id> + <phase>package</phase> + <configuration> + <tasks> + <property name="currentVersion" value="${version}" /> + <property name="test_classpath" refid="maven.test.classpath"/> + <property name="basedir" value="${basedir}"/> + <ant antfile="${basedir}/osgi-build.xml"/> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> </plugin> diff --git a/integration/src/IBUNDLE-META-INF/MANIFEST.MF b/integration/src/IBUNDLE-META-INF/MANIFEST.MF new file mode 100644 index 0000000..c06e460 --- /dev/null +++ b/integration/src/IBUNDLE-META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Archiver-Version: Plexus Archiver +Created-By: Apache Maven +Built-By: ceki +Build-Jdk: 1.6.0_16 +Bundle-Description: iBundle +Bundle-Version: 0.1 +Bundle-Activator: integrator.Activator +Implementation-Title: iBundle +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: iBundle +Bundle-Name: abundle +Bundle-RequiredExecutionEnvironment: J2SE-1.3 +Export-Package: apack +Import-Package: org.osgi.framework, org.slf4j;version=1.5 \ No newline at end of file diff --git a/integration/src/test/java/integrator/Activator.java b/integration/src/test/java/integrator/Activator.java new file mode 100644 index 0000000..c2f6617 --- /dev/null +++ b/integration/src/test/java/integrator/Activator.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004-2009 QOS.ch All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package integrator; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A BundleActivator which invokes slf4j loggers + * @author Ceki Gülcü + * + */ +public class Activator implements BundleActivator { + + private BundleContext m_context = null; + + public void start(BundleContext context) { + Logger logger = LoggerFactory.getLogger(this.getClass()); + logger.info("Activator.start()"); + m_context = context; + } + + public void stop(BundleContext context) { + m_context = null; + Logger logger = LoggerFactory.getLogger(this.getClass()); + logger.info("Activator.stop"); + } + + public Bundle[] getBundles() { + if (m_context != null) { + return m_context.getBundles(); + } + return null; + } +} \ No newline at end of file diff --git a/integration/src/test/java/org/slf4j/test_osgi/BundleTest.java b/integration/src/test/java/org/slf4j/test_osgi/BundleTest.java new file mode 100644 index 0000000..6488a9a --- /dev/null +++ b/integration/src/test/java/org/slf4j/test_osgi/BundleTest.java @@ -0,0 +1,35 @@ +package org.slf4j.test_osgi; + +import java.io.File; + +import junit.framework.TestCase; + +public class BundleTest extends TestCase { + + FrameworkErrorListener fel = new FrameworkErrorListener(); + CheckingBundleListener mbl = new CheckingBundleListener(); + + FelixHost felixHost = new FelixHost(fel, mbl); + + protected void setUp() throws Exception { + super.setUp(); + felixHost.doLaunch(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + felixHost.stop(); + } + + public void testSmoke() { + System.out.println("==========="+new File(".").getAbsolutePath()); + mbl.dumpAll(); + // check that the bundle was installed + assertTrue(mbl.exists("iBundle")); + if(fel.errorList.size() != 0) { + fel.dumpAll(); + } + // check that no errors occured + assertEquals(0, fel.errorList.size()); + } +} diff --git a/integration/src/test/java/org/slf4j/test_osgi/CheckingBundleListener.java b/integration/src/test/java/org/slf4j/test_osgi/CheckingBundleListener.java new file mode 100644 index 0000000..bfaeed0 --- /dev/null +++ b/integration/src/test/java/org/slf4j/test_osgi/CheckingBundleListener.java @@ -0,0 +1,43 @@ +package org.slf4j.test_osgi; + +import java.util.ArrayList; +import java.util.List; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; + +public class CheckingBundleListener implements BundleListener { + + List eventList = new ArrayList(); + + public void bundleChanged(BundleEvent be) { + eventList.add(be); + } + + private void dump(BundleEvent be) { + System.out.println("BE:" + ", source " + be.getSource() + ", bundle=" + + be.getBundle() + ", type=" + be.getType()); + + } + + public void dumpAll() { + for (int i = 0; i < eventList.size(); i++) { + BundleEvent fe = (BundleEvent) eventList.get(i); + dump(fe); + } + } + + boolean exists(String bundleName) { + for (int i = 0; i < eventList.size(); i++) { + BundleEvent fe = (BundleEvent) eventList.get(i); + Bundle b = fe.getBundle(); + System.out.println("===["+b+"]"); + if (bundleName.equals(b.getSymbolicName())) { + return true; + } + } + return false; + } + +} diff --git a/integration/src/test/java/org/slf4j/test_osgi/FelixHost.java b/integration/src/test/java/org/slf4j/test_osgi/FelixHost.java new file mode 100644 index 0000000..4fd572d --- /dev/null +++ b/integration/src/test/java/org/slf4j/test_osgi/FelixHost.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2004-2009 QOS.ch All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.slf4j.test_osgi; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.felix.framework.Felix; +import org.apache.felix.framework.util.FelixConstants; +import org.apache.felix.framework.util.StringMap; +import org.apache.felix.main.AutoProcessor; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; + +/** + * Runs a hosted version of Felix for testing purposes. Any bundle errors are + * reported via the FrameworkListener passed to the constructor. + * + * @author Ceki Gücü + */ +public class FelixHost { + + private Felix felix = null; + + Properties otherProps = new Properties(); + + final FrameworkErrorListener frameworkErrorListener; + final CheckingBundleListener myBundleListener; + + public FelixHost(FrameworkErrorListener frameworkErrorListener, + CheckingBundleListener myBundleListener) { + this.frameworkErrorListener = frameworkErrorListener; + this.myBundleListener = myBundleListener; + } + + public void doLaunch() { + // Create a case-insensitive configuration property map. + Map configMap = new StringMap(false); + // Configure the Felix instance to be embedded. + // configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); + // Add core OSGi packages to be exported from the class path + // via the system bundle. + configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, + "org.osgi.framework; version=1.3.0," + + "org.osgi.service.packageadmin; version=1.2.0," + + "org.osgi.service.startlevel; version=1.0.0," + + "org.osgi.service.url; version=1.0.0"); + + configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, + Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); + + // Explicitly specify the directory to use for caching bundles. + // configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache"); + + try { + // Create host activator; + + List list = new ArrayList(); + + // list.add(new HostActivator()); + configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, + "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming"); + configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list); + configMap.put("felix.log.level", "4"); + + // Now create an instance of the framework with + // our configuration properties and activator. + felix = new Felix(configMap); + felix.init(); + + // otherProps.put(Constants.FRAMEWORK_STORAGE, "bundles"); + + otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, + AutoProcessor.AUTO_DEPLOY_DIR_VALUE); + otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY, + AutoProcessor.AUTO_DEPLOY_START_VALUE + "," + + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE); + + BundleContext felixBudleContext = felix.getBundleContext(); + + AutoProcessor.process(otherProps, felixBudleContext); + // listen to errors + felixBudleContext.addFrameworkListener(frameworkErrorListener); + felixBudleContext.addBundleListener(myBundleListener); + // Now start Felix instance. + felix.start(); + System.out.println("felix started"); + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void stop() throws BundleException { + felix.stop(); + } + + public Bundle[] getInstalledBundles() { + // Use the system bundle activator to gain external + // access to the set of installed bundles. + return null;// m_activator.getBundles(); + } +} \ No newline at end of file diff --git a/integration/src/test/java/org/slf4j/test_osgi/FrameworkErrorListener.java b/integration/src/test/java/org/slf4j/test_osgi/FrameworkErrorListener.java new file mode 100644 index 0000000..3e9ee36 --- /dev/null +++ b/integration/src/test/java/org/slf4j/test_osgi/FrameworkErrorListener.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004-2009 QOS.ch All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.slf4j.test_osgi; + +import java.util.ArrayList; +import java.util.List; + +import org.osgi.framework.FrameworkEvent; +import org.osgi.framework.FrameworkListener; + +public class FrameworkErrorListener implements FrameworkListener { + + public List errorList = new ArrayList(); + + public void frameworkEvent(FrameworkEvent fe) { + if (fe.getType() == FrameworkEvent.ERROR) { + errorList.add(fe); + + } + } + + private void dump(FrameworkEvent fe) { + Throwable t = fe.getThrowable(); + String tString = null; + if (t != null) { + tString = t.toString(); + } + System.out.println("Framework ERROR:" + ", source " + fe.getSource() + + ", bundle=" + fe.getBundle() + ", ex=" + tString); + if(t != null) { + t.printStackTrace(); + } + } + + public void dumpAll() { + for(int i = 0; i < errorList.size(); i++) { + FrameworkEvent fe = (FrameworkEvent) errorList.get(i); + dump(fe); + } + } +} diff --git a/slf4j-site/src/site/pages/mailing-lists.html b/slf4j-site/src/site/pages/mailing-lists.html index 1f17e11..84b262b 100644 --- a/slf4j-site/src/site/pages/mailing-lists.html +++ b/slf4j-site/src/site/pages/mailing-lists.html @@ -65,11 +65,11 @@ <p> <b>Low Traffic:</b> - <a href="http://slf4j.org/mailman/listinfo/announce">Subscribe</a> | - <a href="http://slf4j.org/mailman/options/announce">Unsubscribe</a> + <a href="http://www.qos.ch/mailman/listinfo/announce">Subscribe</a> | + <a href="http://www.qos.ch/mailman/options/announce">Unsubscribe</a> <br/> <b>Archives:</b> - <a href="http://www.slf4j.org/pipermail/announce/">Pipermail</a> | + <a href="http://www.www.qos.ch/pipermail/announce/">Pipermail</a> | <a href="http://marc.theaimsgroup.com/?l=slf4j-announce">MARC</a> </p> <p>The announcements list is reserved for important SLF4J API @@ -86,11 +86,11 @@ <p> <b>Medium Traffic:</b> - <a href="http://slf4j.org/mailman/listinfo/user">Subscribe</a> | - <a href="http://slf4j.org/mailman/options/user">Unsubscribe</a> + <a href="http://www.qos.ch/mailman/listinfo/slf4j-user">Subscribe</a> | + <a href="http://www.qos.ch/mailman/options/slf4j-user">Unsubscribe</a> <br/> <b>Archives:</b> - <a href="http://www.slf4j.org/pipermail/user/">Pipermail</a> | + <a href="http://www.qos.ch/pipermail/slf4j-user/">Pipermail</a> | <a href="http://news.gmane.org/gmane.comp.java.slf4j.user">Gmane</a> | <a href="http://marc.theaimsgroup.com/?l=slf4j-user">MARC</a> | <a href="http://www.nabble.com/Slf4J---user-f13203.html">Nabble</a> | @@ -109,11 +109,11 @@ <p> <b>Medium Traffic:</b> - <a href="http://slf4j.org/mailman/listinfo/dev">Subscribe</a> | - <a href="http://slf4j.org/mailman/options/dev">Unsubscribe</a> + <a href="http://www.qos.ch/mailman/listinfo/slf4j-dev">Subscribe</a> | + <a href="http://www.qos.ch/mailman/options/slf4j-dev">Unsubscribe</a> <br/> <b>Archives:</b> - <a href="http://www.slf4j.org/pipermail/dev/">Pipermail</a> | + <a href="http://www.qos.ch/pipermail/slf4j-dev/">Pipermail</a> | <a href="http://news.gmane.org/gmane.comp.java.slf4j.devel">Gmane</a> | <a href="http://marc.theaimsgroup.com/?l=slf4j-dev">MARC</a> | <a href="http://www.nabble.com/Slf4J---dev-f13200.html">Nabble</a> | ----------------------------------------------------------------------- Summary of changes: .gitignore | 4 +- integration/build.xml | 3 +- integration/osgi-build.xml | 92 ++++++++++++++ integration/pom.xml | 23 ++++ integration/src/IBUNDLE-META-INF/MANIFEST.MF | 15 +++ .../src/test/java/integrator/Activator.java | 57 +++++++++ .../test/java/org/slf4j/test_osgi/BundleTest.java | 35 ++++++ .../slf4j/test_osgi/CheckingBundleListener.java | 43 +++++++ .../test/java/org/slf4j/test_osgi/FelixHost.java | 126 ++++++++++++++++++++ .../slf4j/test_osgi/FrameworkErrorListener.java | 60 +++++++++ slf4j-site/src/site/pages/mailing-lists.html | 18 ++-- 11 files changed, 465 insertions(+), 11 deletions(-) create mode 100644 integration/osgi-build.xml create mode 100644 integration/src/IBUNDLE-META-INF/MANIFEST.MF create mode 100644 integration/src/test/java/integrator/Activator.java create mode 100644 integration/src/test/java/org/slf4j/test_osgi/BundleTest.java create mode 100644 integration/src/test/java/org/slf4j/test_osgi/CheckingBundleListener.java create mode 100644 integration/src/test/java/org/slf4j/test_osgi/FelixHost.java create mode 100644 integration/src/test/java/org/slf4j/test_osgi/FrameworkErrorListener.java hooks/post-receive -- SLF4J: Simple Logging Facade for Java