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