From 0da805d65076d5118187d7b8ff979e420341f771 Mon Sep 17 00:00:00 2001 From: vladt Date: Tue, 15 Feb 2011 09:59:27 -0500 Subject: Export the main package --- .../eclipse/m2e/internal/logging/LogHelper.java | 33 ------ .../eclipse/m2e/internal/logging/LogPlugin.java | 113 --------------------- .../m2e/logback/configuration/LogHelper.java | 33 ++++++ .../m2e/logback/configuration/LogPlugin.java | 113 +++++++++++++++++++++ 4 files changed, 146 insertions(+), 146 deletions(-) delete mode 100644 org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogHelper.java delete mode 100644 org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogPlugin.java create mode 100644 org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogHelper.java create mode 100644 org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java (limited to 'org.eclipse.m2e.logback.configuration/src/org/eclipse') diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogHelper.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogHelper.java deleted file mode 100644 index eb0fbf18..00000000 --- a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogHelper.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.internal.logging; - -import java.util.Properties; -import java.util.SortedMap; -import java.util.TreeMap; - -import org.slf4j.Logger; - - -public class LogHelper { - public static void logJavaProperties(Logger log) { - Properties javaProperties = System.getProperties(); - SortedMap sortedProperties = new TreeMap(); - for(Object key : javaProperties.keySet()) { - sortedProperties.put((String) key, (String) javaProperties.get(key)); - } - log.info("Java properties (ordered by property name):"); //$NON-NLS-1$ - for(String key : sortedProperties.keySet()) { - log.info(" {}={}", key, sortedProperties.get(key)); - } - } -} diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogPlugin.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogPlugin.java deleted file mode 100644 index 1be9a145..00000000 --- a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/internal/logging/LogPlugin.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.internal.logging; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.net.URL; - -import org.osgi.framework.BundleContext; -import org.slf4j.LoggerFactory; - -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.classic.joran.JoranConfigurator; -import ch.qos.logback.classic.util.ContextInitializer; -import ch.qos.logback.core.joran.spi.JoranException; -import ch.qos.logback.core.util.StatusPrinter; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.service.datalocation.Location; - -public class LogPlugin extends Plugin { - private static final String PLUGIN_ID = "org.eclipse.m2e.logback.configuration"; //$NON-NLS-1$ - - // This has to match the log directory in defaultLogbackConfiguration/logback.xml - public static final String PROPERTY_LOG_DIRECTORY = "org.eclipse.m2e.log.dir"; //$NON-NLS-1$ - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - - configureLogger(context); - - LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class)); - } - - private void systemOut(String message) { - System.out.println(PLUGIN_ID + ": " + message); - } - - private void configureLogger(BundleContext context) { - if(System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) != null) { - systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "=" - + System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY)); - return; - } - Location instanceLocation = Platform.getInstanceLocation(); - if(!instanceLocation.isSet()) { - new Exception("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized."); - return; - } - File stateDir = getStateLocation().toFile(); - - File configFile = new File(stateDir, "logback." + context.getBundle().getVersion().toString() + ".xml"); - systemOut("Logback config file: " + configFile.getAbsolutePath()); - - try { - if(!configFile.isFile()) { - // Copy the default config file to the actual config file - InputStream is = context.getBundle().getEntry("defaultLogbackConfiguration/logback.xml").openStream(); - try { - configFile.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(configFile); - try { - for(byte[] buffer = new byte[1024 * 4];;) { - int n = is.read(buffer); - if(n < 0) { - break; - } - fos.write(buffer, 0, n); - } - } finally { - fos.close(); - } - } finally { - is.close(); - } - } - - if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) { - System.setProperty(PROPERTY_LOG_DIRECTORY, stateDir.getAbsolutePath()); - } - loadConfiguration(configFile.toURL()); - } catch(Exception e) { - e.printStackTrace(); - getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, "Exception while setting up logging:" + e.getMessage(), e)); - return; - } - } - - private void loadConfiguration(URL configFile) throws JoranException { - LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); - lc.reset(); - - JoranConfigurator configurator = new JoranConfigurator(); - configurator.setContext(lc); - configurator.doConfigure(configFile); - - StatusPrinter.printInCaseOfErrorsOrWarnings(lc); - } -} diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogHelper.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogHelper.java new file mode 100644 index 00000000..30a1c595 --- /dev/null +++ b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogHelper.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.logback.configuration; + +import java.util.Properties; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.slf4j.Logger; + + +public class LogHelper { + public static void logJavaProperties(Logger log) { + Properties javaProperties = System.getProperties(); + SortedMap sortedProperties = new TreeMap(); + for(Object key : javaProperties.keySet()) { + sortedProperties.put((String) key, (String) javaProperties.get(key)); + } + log.info("Java properties (ordered by property name):"); //$NON-NLS-1$ + for(String key : sortedProperties.keySet()) { + log.info(" {}={}", key, sortedProperties.get(key)); + } + } +} diff --git a/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java new file mode 100644 index 00000000..af71c2e2 --- /dev/null +++ b/org.eclipse.m2e.logback.configuration/src/org/eclipse/m2e/logback/configuration/LogPlugin.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.logback.configuration; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.net.URL; + +import org.osgi.framework.BundleContext; +import org.slf4j.LoggerFactory; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.joran.JoranConfigurator; +import ch.qos.logback.classic.util.ContextInitializer; +import ch.qos.logback.core.joran.spi.JoranException; +import ch.qos.logback.core.util.StatusPrinter; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.service.datalocation.Location; + +public class LogPlugin extends Plugin { + private static final String PLUGIN_ID = "org.eclipse.m2e.logback.configuration"; //$NON-NLS-1$ + + // This has to match the log directory in defaultLogbackConfiguration/logback.xml + public static final String PROPERTY_LOG_DIRECTORY = "org.eclipse.m2e.log.dir"; //$NON-NLS-1$ + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + + configureLogger(context); + + LogHelper.logJavaProperties(LoggerFactory.getLogger(LogPlugin.class)); + } + + private void systemOut(String message) { + System.out.println(PLUGIN_ID + ": " + message); + } + + private void configureLogger(BundleContext context) { + if(System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY) != null) { + systemOut(ContextInitializer.CONFIG_FILE_PROPERTY + "=" + + System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY)); + return; + } + Location instanceLocation = Platform.getInstanceLocation(); + if(!instanceLocation.isSet()) { + new Exception("The " + PLUGIN_ID + " bundle was activated before the platform instance location was initialized."); + return; + } + File stateDir = getStateLocation().toFile(); + + File configFile = new File(stateDir, "logback." + context.getBundle().getVersion().toString() + ".xml"); + systemOut("Logback config file: " + configFile.getAbsolutePath()); + + try { + if(!configFile.isFile()) { + // Copy the default config file to the actual config file + InputStream is = context.getBundle().getEntry("defaultLogbackConfiguration/logback.xml").openStream(); + try { + configFile.getParentFile().mkdirs(); + FileOutputStream fos = new FileOutputStream(configFile); + try { + for(byte[] buffer = new byte[1024 * 4];;) { + int n = is.read(buffer); + if(n < 0) { + break; + } + fos.write(buffer, 0, n); + } + } finally { + fos.close(); + } + } finally { + is.close(); + } + } + + if(System.getProperty(PROPERTY_LOG_DIRECTORY, "").length() <= 0) { + System.setProperty(PROPERTY_LOG_DIRECTORY, stateDir.getAbsolutePath()); + } + loadConfiguration(configFile.toURL()); + } catch(Exception e) { + e.printStackTrace(); + getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, "Exception while setting up logging:" + e.getMessage(), e)); + return; + } + } + + public static void loadConfiguration(URL configFile) throws JoranException { + LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); + lc.reset(); + + JoranConfigurator configurator = new JoranConfigurator(); + configurator.setContext(lc); + configurator.doConfigure(configFile); + + StatusPrinter.printInCaseOfErrorsOrWarnings(lc); + } +} -- cgit v1.2.3