Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugues Malphettes2010-08-24 11:06:31 -0400
committerHugues Malphettes2010-08-24 11:06:31 -0400
commitae061725da2a8d33631c242a09878fa5a5a02c3b (patch)
tree313b9a00de9d6dbf9f662928b00a4904ac102e58 /jetty-osgi
parent8750c7d258815f70c84dc0be08ed2cf61915d32a (diff)
downloadorg.eclipse.jetty.project-ae061725da2a8d33631c242a09878fa5a5a02c3b.tar.gz
org.eclipse.jetty.project-ae061725da2a8d33631c242a09878fa5a5a02c3b.tar.xz
org.eclipse.jetty.project-ae061725da2a8d33631c242a09878fa5a5a02c3b.zip
bug 323497 put back logback fragment and add the package ch.qos.logback.access.jetty.v7 as an option
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2224 7e9141cc-0065-0410-87d8-b60c137991c4
Diffstat (limited to 'jetty-osgi')
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF20
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/META-INF/readme.txt12
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/build.properties5
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/pom.xml109
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/FragmentActivator.java86
-rw-r--r--jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/internal/LogbackInitializer.java98
-rw-r--r--jetty-osgi/pom.xml1
7 files changed, 331 insertions, 0 deletions
diff --git a/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF b/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..10db6be813
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Jetty-OSGi-Logback integration
+Fragment-Host: org.eclipse.jetty.osgi.boot
+Bundle-SymbolicName: org.eclipse.jetty.osgi.boot.logback;singleton:=true
+Bundle-Version: 7.1.0.qualifier
+Bundle-Vendor: Mort Bay Consulting
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: ch.qos.logback.classic,
+ ch.qos.logback.classic.joran,
+ ch.qos.logback.core,
+ ch.qos.logback.core.joran,
+ ch.qos.logback.core.joran.spi,
+ ch.qos.logback.core.spi,
+ ch.qos.logback.core.util,
+ ch.qos.logback.access.jetty.v7;resolution:=optional,
+ org.apache.commons.logging;resolution:=optional,
+ org.apache.log4j;resolution:=optional,
+ org.osgi.framework,
+ org.slf4j
diff --git a/jetty-osgi/jetty-osgi-boot-logback/META-INF/readme.txt b/jetty-osgi/jetty-osgi-boot-logback/META-INF/readme.txt
new file mode 100644
index 0000000000..20960b4bd4
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/META-INF/readme.txt
@@ -0,0 +1,12 @@
+This bundle is made to inject the logback dependencies along with the slf4j dependencies to support log4j and commons-logging.
+It will read the configuration in the jettyhome/resources/logback-test.xml or jettyhome/resources/logback.xml folder.
+
+
+It was tested with these bundles:
+#this provides lg4j and commons-logging via slf4j
+SLF4J = group("com.springsource.slf4j.api", "com.springsource.slf4j.org.apache.log4j", "com.springsource.slf4j.org.apache.commons.logging",
+ :under=>"org.slf4j", :version=>"1.5.6")
+
+#logback is not exporting enough packages for us to be able to configure logback classic programatically.. on the springsource version they are fine...
+LOGBACK = group("com.springsource.ch.qos.logback.core", "com.springsource.ch.qos.logback.classic",
+ :under=>"ch.qos.logback", :version=>"0.9.15") \ No newline at end of file
diff --git a/jetty-osgi/jetty-osgi-boot-logback/build.properties b/jetty-osgi/jetty-osgi-boot-logback/build.properties
new file mode 100644
index 0000000000..6d10c98886
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/build.properties
@@ -0,0 +1,5 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .
+src.includes = META-INF/
diff --git a/jetty-osgi/jetty-osgi-boot-logback/pom.xml b/jetty-osgi/jetty-osgi-boot-logback/pom.xml
new file mode 100644
index 0000000000..d83e3b8fd3
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/pom.xml
@@ -0,0 +1,109 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.eclipse.jetty.osgi</groupId>
+ <artifactId>jetty-osgi-project</artifactId>
+ <version>7.1.7-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.jetty.osgi</groupId>
+ <artifactId>jetty-osgi-boot-logback</artifactId>
+ <name>Jetty :: OSGi :: Boot Logback</name>
+ <description>Jetty OSGi Boot Logback bundle</description>
+ <properties>
+ <bundle-symbolic-name>${project.groupId}.boot.logback</bundle-symbolic-name>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.jetty.osgi</groupId>
+ <artifactId>jetty-osgi-boot</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.osgi</groupId>
+ <artifactId>services</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>log4j-over-slf4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>process-resources</phase>
+ <configuration>
+ <tasks>
+ <replace file="target/classes/META-INF/MANIFEST.MF" token="Bundle-Version: 7.1.0.qualifier" value="Bundle-Version: ${parsedVersion.osgiVersion}" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>artifact-jar</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>test-jar</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <archive>
+ <manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <onlyAnalyze>org.eclipse.jetty.osgi.boot.logback.*</onlyAnalyze>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/FragmentActivator.java b/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/FragmentActivator.java
new file mode 100644
index 0000000000..919c10fada
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/FragmentActivator.java
@@ -0,0 +1,86 @@
+// ========================================================================
+// Copyright (c) 2009 Intalio, Inc.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+package org.eclipse.jetty.osgi.boot.logback;
+
+import java.io.File;
+import java.util.Map;
+
+import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper;
+import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader;
+import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper.IFilesInJettyHomeResourcesProcessor;
+import org.eclipse.jetty.osgi.boot.logback.internal.LogbackInitializer;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * Pseudo fragment activator.
+ * Called by the main org.eclipse.jetty.osgi.boot bundle.
+ * Please note: this is not a real BundleActivator. Simply something called back by
+ * the host bundle.
+ * The fragment is in charge of placing a hook to configure logback
+ * when the files inside jettyhome/resources are parsed.
+ */
+public class FragmentActivator implements BundleActivator, IFilesInJettyHomeResourcesProcessor
+{
+ /**
+ *
+ */
+ public void start(BundleContext context) throws Exception
+ {
+ LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.add(this);
+
+ //now let's make sure no log4j, no slf4j and no commons.logging
+ //get inserted as a library that is not an osgi library
+ OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.commons.logging.Log");
+ OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.log4j.Logger");
+ OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.slf4j.Logger");
+ //OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected(java.util.logging.Logger.class);
+
+ }
+
+ /**
+ * Called when this bundle is stopped so the Framework can perform the
+ * bundle-specific activities necessary to stop the bundle. In general, this
+ * method should undo the work that the <code>BundleActivator.start</code>
+ * method started. There should be no active threads that were started by
+ * this bundle when this bundle returns. A stopped bundle must not call any
+ * Framework objects.
+ *
+ * <p>
+ * This method must complete and return to its caller in a timely manner.
+ *
+ * @param context The execution context of the bundle being stopped.
+ * @throws Exception If this method throws an exception, the
+ * bundle is still marked as stopped, and the Framework will remove
+ * the bundle's listeners, unregister all services registered by the
+ * bundle, and release all services used by the bundle.
+ */
+ public void stop(BundleContext context) throws Exception
+ {
+ LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.remove(this);
+ }
+
+ public void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
+ {
+ try
+ {
+ LogbackInitializer.processFilesInResourcesFolder(jettyHome, files);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ }
+
+}
diff --git a/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/internal/LogbackInitializer.java b/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/internal/LogbackInitializer.java
new file mode 100644
index 0000000000..71134ab2c1
--- /dev/null
+++ b/jetty-osgi/jetty-osgi-boot-logback/src/main/java/org/eclipse/jetty/osgi/boot/logback/internal/LogbackInitializer.java
@@ -0,0 +1,98 @@
+// ========================================================================
+// Copyright (c) 2009 Intalio, Inc.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+// You may elect to redistribute this code under either of these licenses.
+// Contributors:
+// Hugues Malphettes - initial API and implementation
+// ========================================================================
+package org.eclipse.jetty.osgi.boot.logback.internal;
+
+import java.io.File;
+import java.util.Map;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.JoranConfiguratorBase;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+
+/**
+ * Setup logback eventually located in the config file inside jettyhome/resources
+ * All logback related code is done in this separate class for better debug
+ * and isolation when it does not load.
+ */
+public class LogbackInitializer {
+
+ /**
+ * @return true when we are currently being run by the pde in development mode.
+ */
+ private static boolean isPDEDevelopment()
+ {
+ String eclipseCommands = System.getProperty("eclipse.commands");
+ // detect if we are being run from the pde: ie during development.
+ return eclipseCommands != null && eclipseCommands.indexOf("-dev") != -1
+ && (eclipseCommands.indexOf("-dev\n") != -1
+ || eclipseCommands.indexOf("-dev\r") != -1
+ || eclipseCommands.indexOf("-dev ") != -1);
+ }
+
+
+ /**
+ * Follow the configuration for logback.
+ * unless the system propery was set in which case it
+ * was assume it was already setup.
+ */
+ public static void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
+ {
+ String logbackConf = System.getProperty("logback.configurationFile");
+ if (logbackConf != null)
+ {
+ File confFile = new File(logbackConf);
+ if (confFile.exists())
+ {
+ //assume logback was configured by this one?
+ return;
+ }
+ }
+
+ File logConf = isPDEDevelopment() ? files.get("logback-dev.xml") : null;
+ if (logConf == null)
+ {
+ logConf = files.get("logback-test.xml");
+ }
+ if (logConf == null)
+ {
+ logConf = files.get("logback.xml");
+ }
+ if (logConf == null)
+ {
+ return;
+ }
+ // assume SLF4J is bound to logback in the current environment
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try
+ {
+ JoranConfiguratorBase configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ lc.reset();
+ configurator.doConfigure(logConf.getAbsoluteFile().getAbsolutePath());
+ }
+ catch (JoranException je)
+ {
+ je.printStackTrace();
+ }
+ StatusPrinter.printIfErrorsOccured(lc);
+
+ }
+
+}
diff --git a/jetty-osgi/pom.xml b/jetty-osgi/pom.xml
index 1ee9d6adb5..4b77c94cf5 100644
--- a/jetty-osgi/pom.xml
+++ b/jetty-osgi/pom.xml
@@ -21,6 +21,7 @@
<modules>
<module>jetty-osgi-boot</module>
<module>jetty-osgi-boot-jsp</module>
+ <module>jetty-osgi-boot-logback</module>
<module>jetty-osgi-boot-warurl</module>
<module>jetty-osgi-httpservice</module>
<module>test-jetty-osgi</module>

Back to the top