1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.osgi.boot.logback;
20
21 import java.io.File;
22 import java.util.Map;
23
24 import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper;
25 import org.eclipse.jetty.osgi.boot.internal.webapp.OSGiWebappClassLoader;
26 import org.eclipse.jetty.osgi.boot.internal.webapp.LibExtClassLoaderHelper.IFilesInJettyHomeResourcesProcessor;
27 import org.eclipse.jetty.osgi.boot.logback.internal.LogbackInitializer;
28 import org.osgi.framework.BundleActivator;
29 import org.osgi.framework.BundleContext;
30
31
32 /**
33 * Pseudo fragment activator.
34 * Called by the main org.eclipse.jetty.osgi.boot bundle.
35 * Please note: this is not a real BundleActivator. Simply something called back by
36 * the host bundle.
37 * The fragment is in charge of placing a hook to configure logback
38 * when the files inside jettyhome/resources are parsed.
39 */
40 public class FragmentActivator implements BundleActivator, IFilesInJettyHomeResourcesProcessor
41 {
42 /**
43 *
44 */
45 public void start(BundleContext context) throws Exception
46 {
47 LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.add(this);
48
49 //now let's make sure no log4j, no slf4j and no commons.logging
50 //get inserted as a library that is not an osgi library
51 OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.commons.logging.Log");
52 OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.apache.log4j.Logger");
53 OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected("org.slf4j.Logger");
54 //OSGiWebappClassLoader.addClassThatIdentifiesAJarThatMustBeRejected(java.util.logging.Logger.class);
55
56 }
57
58 /**
59 * Called when this bundle is stopped so the Framework can perform the
60 * bundle-specific activities necessary to stop the bundle. In general, this
61 * method should undo the work that the <code>BundleActivator.start</code>
62 * method started. There should be no active threads that were started by
63 * this bundle when this bundle returns. A stopped bundle must not call any
64 * Framework objects.
65 *
66 * <p>
67 * This method must complete and return to its caller in a timely manner.
68 *
69 * @param context The execution context of the bundle being stopped.
70 * @throws Exception If this method throws an exception, the
71 * bundle is still marked as stopped, and the Framework will remove
72 * the bundle's listeners, unregister all services registered by the
73 * bundle, and release all services used by the bundle.
74 */
75 public void stop(BundleContext context) throws Exception
76 {
77 LibExtClassLoaderHelper.registeredFilesInJettyHomeResourcesProcessors.remove(this);
78 }
79
80 public void processFilesInResourcesFolder(File jettyHome, Map<String,File> files)
81 {
82 try
83 {
84 LogbackInitializer.processFilesInResourcesFolder(jettyHome, files);
85 }
86 catch (Throwable t)
87 {
88 t.printStackTrace();
89 }
90 }
91
92 }