Author: vyemialyanchyk
Date: 2010-03-30 09:36:44 -0400 (Tue, 30 Mar 2010)
New Revision: 21136
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/build/
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/hibernate-log4j.properties
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingHelper.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingStreamManager.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginFileAppender.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogAppender.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogListener.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogManager.java
Removed:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/hibernate-log4j.properties
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/LoggingHelper.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginFileAppender.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogAppender.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogListener.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogManager.java
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/build.properties
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/HibernatePlugin.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/.classpath
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/META-INF/MANIFEST.MF
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/MediatorPlugin.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/Messages.java
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-6070 - update
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/build.properties
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/build.properties 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/build.properties 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,30 +1,15 @@
bin.includes = plugin.xml,\
org.hibernate.eclipse.jar,\
- lib/,\
META-INF/,\
hibernate-log4j.properties,\
about.html,\
- lib/tools/jtidy-r8-20060801.jar,\
- lib/annotations/hibernate-entitymanager.jar,\
- lib/hibernate/javassist.jar,\
- lib/hibernate/ehcache-1.2.3.jar,\
- lib/hibernate/c3p0-0.9.1.jar,\
- lib/annotations/hibernate-commons-annotations.jar,\
- lib/annotations/hibernate-validator.jar,\
- lib/hibernate/log4j-1.2.15.jar,\
- lib/hibernate/slf4j-api-1.5.8.jar,\
- lib/hibernate/slf4j-log4j12-1.5.8.jar,\
about.ini,\
about.mappings,\
about.properties,\
hibernate_icon.gif,\
- plugin.properties,\
- lib/hibernate/cglib-2.2.jar,\
- lib/hibernate/commons-collections-3.1.jar,\
- lib/hibernate/hibernate-jmx.jar
+ plugin.properties
jars.compile.order = org.hibernate.eclipse.jar
source.org.hibernate.eclipse.jar = src/
output.org.hibernate.eclipse.jar = bin/
src.includes = src/,\
about.html
-bin.excludes = lib/.cvsignore
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/hibernate-log4j.properties
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/hibernate-log4j.properties 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/hibernate-log4j.properties 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,42 +0,0 @@
-### This file is used to control the logging done by the hibernate tools eclipse plugins
-### You can modfiy these to be more or less verbose depending on your needs
-
-### Direct messages to Eclipse logging system (will be shown in Error Log)
-log4j.appender.eclipselog=org.hibernate.eclipse.logging.PluginLogAppender
-log4j.appender.eclipselog.layout=org.apache.log4j.PatternLayout
-log4j.appender.eclipselog.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m
-
-### Direct messages from Eclipse loggin system to
.metadata/plugins/org.hibernate.eclipse/hibernate-tools.log
-log4j.appender.pluginlog=org.hibernate.eclipse.logging.PluginFileAppender
-log4j.appender.pluginlog.File=hibernate-tools.log
-log4j.appender.pluginlog.MaxFileSize=1MB
-log4j.appender.pluginlog.MaxBackupIndex=1
-log4j.appender.pluginlog.layout=org.apache.log4j.PatternLayout
-log4j.appender.pluginlog.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c
%x - %m\n
-
-### set log levels - for more verbose logging change 'info' to 'debug'
###
-log4j.rootLogger=warn, eclipselog, pluginlog
-
-log4j.logger.org.hibernate=warn
-
-# Disable superflous PARSER errors.
-log4j.logger.org.hibernate.PARSER=none
-
-### log just the SQL
-#log4j.logger.org.hibernate.SQL=debug
-
-### log JDBC bind parameters ###
-#log4j.logger.org.hibernate.type=info
-
-### log schema export/update ###
-#log4j.logger.org.hibernate.tool.hbm2ddl=debug
-
-### log cache activity ###
-#log4j.logger.org.hibernate.cache=debug
-
-### log JDBC resource acquisition
-#log4j.logger.org.hibernate.jdbc=debug
-
-### enable the following line if you want to track down connection ###
-### leakages when using DriverManagerConnectionProvider ###
-#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/KnownConfigurations.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -22,11 +22,9 @@
package org.hibernate.console;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -45,14 +43,10 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.eclipse.ui.console.ConsolePlugin;
-import org.eclipse.ui.console.IConsole;
-import org.eclipse.ui.console.IConsoleManager;
-import org.eclipse.ui.console.MessageConsole;
-import org.eclipse.ui.console.MessageConsoleStream;
import org.hibernate.console.node.BaseNode;
import org.hibernate.console.node.ConfigurationListNode;
import org.hibernate.mediator.ConsoleQueryParameter;
+import org.hibernate.mediator.logging.LoggingStreamManager;
import org.hibernate.mediator.stubs.HibernateConsoleRuntimeException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -196,7 +190,7 @@
}
});
oldConfig.reset();
- removeLoggingStream( oldConfig );
+ LoggingStreamManager.getInstance().removeLoggingStream(oldConfig.getName());
}
@@ -267,34 +261,6 @@
return rootNode;
}
- // TODO: decouple this logging from Eclipse platform!
- private Map<String, Object[]> loggingStreams = new HashMap<String,
Object[]>();
- public MessageConsoleStream findLoggingStream(String name) {
- Object[] console = loggingStreams.get(name);
- if(console==null) {
- console = new Object[2];
- String secondaryId = ConsoleMessages.KnownConfigurations_hibernate_log +
(name==null?ConsoleMessages.KnownConfigurations_unknown:name);
- console[0] = new MessageConsole(secondaryId, null);
- IConsoleManager consoleManager =
ConsolePlugin.getDefault().getConsoleManager();
- consoleManager.addConsoles(new IConsole[] { (IConsole) console[0] });
- console[1] = ((MessageConsole)console[0]).newMessageStream();
- loggingStreams.put(name, console);
- }
- return (MessageConsoleStream) console[1];
- }
-
- private void removeLoggingStream(ConsoleConfiguration oldConfig) {
- Object[] object = loggingStreams.remove( oldConfig.getName() );
- if(object!=null) {
- MessageConsole mc = (MessageConsole)object[0];
- MessageConsoleStream stream = (MessageConsoleStream)object[1];
- try { stream.close(); } catch(IOException ie) { /* ignore */ };
- IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
- consoleManager.removeConsoles( new IConsole[] { mc } );
- }
- }
-
-
public ConsoleConfiguration find(String lastUsedName) {
if(configurations==null) return null;
if(lastUsedName==null) return null;
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/HibernatePlugin.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/HibernatePlugin.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/HibernatePlugin.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -21,13 +21,7 @@
*/
package org.hibernate.eclipse;
-import java.net.URL;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.eclipse.core.runtime.Plugin;
-import org.hibernate.eclipse.logging.LoggingHelper;
-import org.hibernate.eclipse.logging.PluginLogManager;
import org.osgi.framework.BundleContext;
/**
@@ -38,31 +32,9 @@
public void start(BundleContext context) throws Exception {
super.start(context);
- configureLog4jHooks();
- Log log = LogFactory.getLog(HibernatePlugin.class);
- log.info("HibernatePlugin Started"); //$NON-NLS-1$
}
-
- private void configureLog4jHooks() {
- URL entry = getBundle().getEntry("hibernate-log4j.xml"); //$NON-NLS-1$
- if(entry==null) {
- entry = getBundle().getEntry("hibernate-log4j.properties"); //$NON-NLS-1$
- }
-
- if(entry==null) {
- // should log this!
- } else {
- LoggingHelper helper = LoggingHelper.getDefault();
- PluginLogManager manager = new PluginLogManager(this, helper, entry);
- }
-
-
-
-
- }
public void stop(BundleContext context) throws Exception {
- LoggingHelper.getDefault().stop(context);
super.stop( context );
}
}
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/LoggingHelper.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/LoggingHelper.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/LoggingHelper.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,77 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.logging;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.Plugin;
-import org.osgi.framework.BundleContext;
-
-public class LoggingHelper {
-
- private static LoggingHelper helper;
-
- private List<PluginLogManager> logManagers = new
ArrayList<PluginLogManager>();
-
- public LoggingHelper() {
- super();
- }
-
- synchronized public static LoggingHelper getDefault() {
- if(helper==null) { helper = new LoggingHelper(); }
- return helper;
- }
-
- /**
- * Iterates over the list of active log managers and shutdowns each one
- * @see Plugin#stop
- */
- public void stop(BundleContext context) throws Exception {
- synchronized (this.logManagers) {
- for (PluginLogManager logManager : logManagers) {
- logManager.internalShutdown();
- }
- this.logManagers.clear();
- }
- }
-
- /**
- * Adds a log manager object to the list of active log managers
- */
- void addLogManager(PluginLogManager logManager) {
- synchronized (this.logManagers) {
- if (logManager != null)
- this.logManagers.add(logManager);
- }
- }
-
- /**
- * Removes a log manager object from the list of active log managers
- */
- void removeLogManager(PluginLogManager logManager) {
- synchronized (this.logManagers) {
- if (logManager != null)
- this.logManagers.remove(logManager);
- }
- }
-}
\ No newline at end of file
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginFileAppender.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginFileAppender.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginFileAppender.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,177 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.logging;
-
-import java.io.IOException;
-
-import org.apache.log4j.Layout;
-import org.apache.log4j.RollingFileAppender;
-import org.apache.log4j.spi.LoggingEvent;
-import org.eclipse.core.runtime.IPath;
-import org.hibernate.mediator.Messages;
-
-/**
- * PluginFileAppender
- * This class is a custom Log4J appender that sends Log4J events to
- * the Eclipse plug-in state location. It extends the RollingFileAppender class.
- * @author Manoel Marques
- */
-public class PluginFileAppender extends RollingFileAppender {
-
- private IPath stateLocation;
- private boolean activateOptionsPending;
- private boolean translatePath = true;
-
- /**
- * Creates a new PluginFileAppender.
- */
- public PluginFileAppender() {
- super();
- }
-
- /**
- * Creates a new PluginFileAppender.
- * @param layout layout instance.
- * @param stateLocation IPath containing the plug-in state location
- */
- public PluginFileAppender(Layout layout,IPath stateLocation) {
- super();
- setLayout(layout);
- setStateLocation(stateLocation);
- }
-
- /**
- * Creates a new PluginFileAppender.
- * @param layout layout instance.
- * @param stateLocation IPath containing the plug-in state location
- * @param file file name
- * @param append true if file is to be appended
- */
- public PluginFileAppender(Layout layout,IPath stateLocation, String file, boolean
append)
- throws IOException {
- super();
- setLayout(layout);
- setStateLocation(stateLocation);
- setFile(file);
- setAppend(append);
- activateOptions();
- }
-
- /**
- * Creates a new PluginFileAppender.
- * @param layout layout instance.
- * @param stateLocation IPath containing the plug-in state location
- * @param file file name
- */
- public PluginFileAppender(Layout layout,IPath stateLocation, String file) throws
IOException {
- super();
- setLayout(layout);
- setStateLocation(stateLocation);
- setFile(file);
- activateOptions();
- }
-
- /**
- * Sets the state location. If activateOptions call is pending, translate the file name
- * and call activateOptions
- * @param stateLocation IPath containing the plug-in state location
- */
- public void setStateLocation(IPath stateLocation) {
- this.stateLocation = stateLocation;
- if (this.stateLocation != null && this.activateOptionsPending) {
- this.activateOptionsPending = false;
- setFile(getFile());
- activateOptions();
- }
- }
-
- /**
- * Sets the file name.Translate it before setting.
- * @param file file name
- */
- public void setFile(String file) {
- super.setFile(getTranslatedFileName(file));
- }
-
- /**
- * Set file options and opens it, leaving ready to write.
- * @param file file name
- * @param append true if file is to be appended
- * @param bufferedIO true if file is to buffered
- * @param bufferSize buffer size
- * @throws IOException - IO Error happend or the state location was not set
- */
- public void setFile(String fileName,boolean append,boolean bufferedIO,int bufferSize)
throws IOException {
- if (this.stateLocation == null)
- throw new IOException(Messages.PluginFileAppender_missing_plugin_state_location);
-
- fileName = (this.translatePath) ? getTranslatedFileName(fileName) : fileName;
- super.setFile(fileName,append,bufferedIO,bufferSize);
- }
-
- /**
- * Finishes instance initialization. If state location was not set, set activate as
- * pending and does nothing.
- */
- public void activateOptions() {
- if (this.stateLocation == null) {
- this.activateOptionsPending = true;
- return;
- }
-
- // base class will call setFile, don't translate the name
- // because it was already translated
- this.translatePath = false;
- super.activateOptions();
- this.translatePath = true;
- }
-
- /**
- * Any path part of a file is removed and the state location is added to the name
- * to form a new path. If there is not state location, returns the name unmodified.
- * @param file file name
- * @return translated file name
- */
- private String getTranslatedFileName(String file) {
-
- if (this.stateLocation == null || file == null)
- return file;
-
- file = file.trim();
- if (file.length() == 0)
- return file;
-
- int index = file.lastIndexOf('/');
- if (index == -1)
- index = file.lastIndexOf('\\');
-
- if (index != -1)
- file = file.substring(index + 1);
-
- IPath newPath = this.stateLocation.append(file);
- return newPath.toString();
- }
-
- public void append(LoggingEvent event) {
- super.append( event );
- }
-}
\ No newline at end of file
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogAppender.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogAppender.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogAppender.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,128 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.logging;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.spi.ErrorCode;
-import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.spi.ThrowableInformation;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.ui.console.MessageConsoleStream;
-import org.hibernate.console.ConsoleMessages;
-import org.hibernate.console.KnownConfigurations;
-import org.hibernate.mediator.logging.CurrentContext;
-
-/**
- * PluginLogAppender
- * This class is a custom Log4J appender that sends Log4J events to
- * the Eclipse plug-in log.
- * @author Manoel Marques
- */
-public class PluginLogAppender extends AppenderSkeleton {
-
- private ILog pluginLog;
-
-
- /**
- * Sets the Eclipse log instance
- * @param log plug-in log
- */
- void setLog(ILog pluginLog) {
- this.pluginLog = pluginLog;
- }
-
- /**
- * Log event happened.
- * Translates level to status instance codes:
- * level > Level.ERROR - Status.ERROR
- * level > Level.WARN - Status.WARNING
- * level > Level.DEBUG - Status.INFO
- * default - Status.OK
- * @param event LoggingEvent instance
- */
- public void append(LoggingEvent event) {
-
- if (this.layout == null) {
- this.errorHandler.error(ConsoleMessages.PluginLogAppender_missing_layout_for_appender
+
- this.name,null,ErrorCode.MISSING_LAYOUT);
- return;
- }
-
- String text = this.layout.format(event);
-
- Throwable thrown = null;
- if (this.layout.ignoresThrowable()) {
- ThrowableInformation info = event.getThrowableInformation();
- if (info != null)
- thrown = info.getThrowable();
- }
- /*
- Level level = event.getLevel();
- int severity = IStatus.OK;
-
- if (level.toInt() >= Priority.ERROR_INT)
- severity = IStatus.ERROR;
- else
- if (level.toInt() >= Priority.WARN_INT)
- severity = IStatus.WARNING;
- else
- if (level.toInt() >= Priority.DEBUG_INT)
- severity = IStatus.INFO;
-
-
- this.pluginLog.log(new Status(severity,
- this.pluginLog.getBundle().getSymbolicName(),
- level.toInt(),text,thrown));*/
-
- Object peek = CurrentContext.peek();
- MessageConsoleStream stream = KnownConfigurations.getInstance().findLoggingStream(
(String)peek );
- if(stream!=null) {
- stream.println(text);
- if(thrown!=null) {
- StringWriter stringWriter = new StringWriter();
- thrown.printStackTrace( new PrintWriter(stringWriter) );
- stream.println(stringWriter.getBuffer().toString());
- }
- }
-
- }
-
-
-
- /**
- * Closes this appender
- */
- public void close() {
- this.closed = true;
- }
-
- /**
- * Checks if this appender requires layout
- * @return true if layout is required.
- */
- public boolean requiresLayout() {
- return true;
- }
-}
\ No newline at end of file
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogListener.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogListener.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogListener.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.logging;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.ILogListener;
-import org.eclipse.core.runtime.IStatus;
-
-/**
- * PluginLogListener
- * This class is responsible for adding itself to the plug-in logging framework
- * and translating plug-in log requests to Logger events.
- * @author Manoel Marques
- */
-public class PluginLogListener implements ILogListener {
-
- private ILog log;
- private Logger logger;
-
- /**
- * Creates a new PluginLogListener. Saves the plug-in log and logger instance.
- * Adds itself to the plug-in log.
- * @param plugin the plug-in object
- * @param logger logger instance
- */
- public PluginLogListener(ILog log,Logger logger) {
- this.log = log;
- this.logger = logger;
- log.addLogListener(this);
- }
-
- /**
- * Removes itself from the plug-in log, reset instance variables.
- */
- public void dispose() {
- if (this.log != null) {
- this.log.removeLogListener(this);
- this.log = null;
- this.logger = null;
- }
- }
-
- /**
- * Log event happened.
- * Translates status instance to Logger level and message.
- * Status.ERROR - Level.ERROR
- * Status.WARNING - Level.WARN
- * Status.INFO - Level.INFO
- * Status.CANCEL - Level.FATAL
- * default - Level.DEBUG
- * @param status Log Status
- * @param plugin plug-in id
- */
- public void logging(IStatus status, String plugin) {
- if (null == this.logger || null == status)
- return;
-
- int severity = status.getSeverity();
- Level level = Level.DEBUG;
- if (severity == IStatus.ERROR)
- level = Level.ERROR;
- else if (severity == IStatus.WARNING)
- level = Level.WARN;
- else if (severity == IStatus.INFO)
- level = Level.INFO;
- else if (severity == IStatus.CANCEL)
- level = Level.FATAL;
-
- plugin = formatText(plugin);
- String statusPlugin = formatText(status.getPlugin());
- String statusMessage = formatText(status.getMessage());
- StringBuffer message = new StringBuffer();
- if (plugin != null) {
- message.append(plugin);
- message.append(" - "); //$NON-NLS-1$
- }
- if (statusPlugin != null &&
- (plugin == null || !statusPlugin.equals(plugin))) {
- message.append(statusPlugin);
- message.append(" - "); //$NON-NLS-1$
- }
- message.append(status.getCode());
- if (statusMessage != null) {
- message.append(" - "); //$NON-NLS-1$
- message.append(statusMessage);
- }
- this.logger.log(level,message.toString(),status.getException());
- }
-
- static private String formatText(String text) {
- if (text != null) {
- text = text.trim();
- if (text.length() == 0) return null;
- }
- return text;
- }
-}
\ No newline at end of file
Deleted:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogManager.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogManager.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogManager.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,260 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.hibernate.eclipse.logging;
-
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.Category;
-import org.apache.log4j.Hierarchy;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.helpers.OptionConverter;
-import org.apache.log4j.spi.HierarchyEventListener;
-import org.apache.log4j.spi.LoggerFactory;
-import org.apache.log4j.spi.LoggerRepository;
-import org.apache.log4j.spi.RepositorySelector;
-import org.apache.log4j.spi.RootLogger;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.ILogListener;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Plugin;
-
-/**
- * PluginLogManager
- * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
- * @author Manoel Marques
- */
-public class PluginLogManager {
-
- private ILog log;
- private IPath stateLocation;
- private Hierarchy hierarchy;
- private HashMap<String, ILogListener> hookedPlugins = new HashMap<String,
ILogListener>();
- private LoggingHelper helper;
-
- private class PluginEventListener implements HierarchyEventListener {
-
- /**
- * Called when a new appender is added for a particular level.
- * Internally it checks if the appender is one of our custom ones
- * and sets its custom properties.
- * @param category level
- * @param appender appender added for this level
- */
- public void addAppenderEvent(Category cat, Appender appender) {
- if (appender instanceof PluginLogAppender) {
- ((PluginLogAppender)appender).setLog(log);
- }
- if (appender instanceof PluginFileAppender) {
- ((PluginFileAppender)appender).setStateLocation(stateLocation);
- }
- }
-
- /**
- * Called when a appender is removed from for a particular level.
- * Does nothing.
- * @param category level
- * @param appender appender added for this level
- */
- public void removeAppenderEvent(Category cat, Appender appender) {
- }
- }
-
- /**
- * Creates a new PluginLogManager. Saves the plug-in log and state location.
- * Creates a new Hierarchy and add a new PluginEventListener to it.
- * Configure the hierarchy with the properties passed.
- * Add this object to the list of active plug-in log managers.
- * @param plugin the plug-in object
- * @param properties log configuration properties
- */
- public PluginLogManager(Plugin plugin, LoggingHelper helper, URL log4jUrl) {
- this.log = plugin.getLog();
- this.stateLocation = plugin.getStateLocation();
- this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
- this.hierarchy.addHierarchyEventListener(new PluginEventListener());
- LogManager.setRepositorySelector(new RepositorySelector() {
-
- public LoggerRepository getLoggerRepository() {
- return hierarchy;
- }
-
- }, "hibernate-tools"); //$NON-NLS-1$
- OptionConverter.selectAndConfigure(log4jUrl, null, this.hierarchy);
- this.helper = helper;
- helper.addLogManager(this);
- }
-
- /**
- * Hooks a plug-in into this PluginLogManager. When the hooked plug-in uses the
- * Eclipse log API, it will be channeled to this logging framework.
- * @param id logger name (usually the the plug-in id)
- * @param pluginLog plug-in log
- */
- public boolean hookPlugin(String id, ILog pluginLog) {
- synchronized(this.hookedPlugins) {
- if (pluginLog == null || id == null || this.hookedPlugins.containsKey(id))
- return false;
-
- PluginLogListener listener = new PluginLogListener(pluginLog,getLogger(id));
- this.hookedPlugins.put(id,listener);
- }
- return true;
- }
-
- /**
- * Unhooks a plug-in from this PluginLogManager. The Eclipse log API
- * won't be channeled to this logging framework anymore.
- * @param id logger name (usually the the plug-in id)
- */
- public boolean unHookPlugin(String id) {
- synchronized(this.hookedPlugins) {
- if (id == null || !this.hookedPlugins.containsKey(id))
- return false;
-
- PluginLogListener listener = (PluginLogListener) this.hookedPlugins.get(id);
- listener.dispose();
- this.hookedPlugins.remove(id);
- }
- return true;
- }
-
- /**
- * Checks if this PluginLogManager is disabled for this level.
- * @param level level value
- * @return boolean true if it is disabled
- */
- public boolean isDisabled(int level) {
- return this.hierarchy.isDisabled(level);
- }
-
- /**
- * Enable logging for logging requests with level l or higher.
- * By default all levels are enabled.
- * @param level level object
- */
- public void setThreshold(Level level) {
- this.hierarchy.setThreshold(level);
- }
-
- /**
- * The string version of setThreshold(Level level)
- * @param level level string
- */
- public void setThreshold(String level) {
- this.hierarchy.setThreshold(level);
- }
-
- /**
- * Get the repository-wide threshold.
- * @return Level
- */
- public Level getThreshold() {
- return this.hierarchy.getThreshold();
- }
-
- /**
- * Returns a new logger instance named as the first parameter
- * using the default factory. If a logger of that name already exists,
- * then it will be returned. Otherwise, a new logger will be instantiated
- * and then linked with its existing ancestors as well as children.
- * @param name logger name
- * @return Logger
- */
- public Logger getLogger(String name) {
- return this.hierarchy.getLogger(name);
- }
-
- /**
- * The same as getLogger(String name) but using a factory instance instead of
- * a default factory.
- * @param name logger name
- * @param factory factory instance
- * @return Logger
- */
- public Logger getLogger(String name, LoggerFactory factory) {
- return this.hierarchy.getLogger(name,factory);
- }
-
- /**
- * Returns the root of this hierarchy.
- * @return Logger
- */
- public Logger getRootLogger() {
- return this.hierarchy.getRootLogger();
- }
-
- /**
- * Checks if this logger exists.
- * @return Logger
- */
- public Logger exists(String name) {
- return this.hierarchy.exists(name);
- }
-
- /**
- * Removes appenders and disposes the logger hierarchy
- *
- */
- public void shutdown() {
- internalShutdown();
- helper.removeLogManager(this);
- }
-
- /**
- * Used by LoggingHelper to shutdown without removing it from the LoggingHelper list
- *
- */
- void internalShutdown() {
- synchronized(this.hookedPlugins) {
- Iterator<String> it = this.hookedPlugins.keySet().iterator();
- while (it.hasNext()) {
- String id = it.next();
- PluginLogListener listener = (PluginLogListener) this.hookedPlugins.get(id);
- listener.dispose();
- }
- this.hookedPlugins.clear();
- }
- this.hierarchy.shutdown();
- }
-
- /**
- * Returns all the loggers in this manager.
- * @return Enumeration logger enumeration
- */
- public Enumeration<?> getCurrentLoggers() {
- return this.hierarchy.getCurrentLoggers();
- }
-
- /**
- * Resets configuration values to its defaults.
- *
- */
- public void resetConfiguration() {
- this.hierarchy.resetConfiguration();
- }
-}
\ No newline at end of file
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/.classpath
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/.classpath 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/.classpath 2010-03-30
13:36:44 UTC (rev 21136)
@@ -22,7 +22,7 @@
<classpathentry kind="lib"
path="lib/annotations/hibernate-entitymanager.jar"
sourcepath="D:/Temp/_hibernate/hibernate-entitymanager-3.4.0.GA-sources.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/javassist.jar"/>
<classpathentry kind="lib"
path="lib/annotations/hibernate-validator.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/hibernate/log4j-1.2.15.jar"/>
+ <classpathentry kind="lib" path="lib/hibernate/log4j-1.2.15.jar"
sourcepath="D:/Temp/_hibernate/log4j-1.2.15-sources.jar "/>
<classpathentry kind="lib" path="lib/hibernate/hibernate-jmx.jar"
sourcepath="D:/Temp/_hibernate/hibernate-jmx-3.3.2.GA-sources.jar "/>
<classpathentry kind="lib"
path="lib/hibernate/commons-collections-3.1.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/slf4j-api-1.5.8.jar"
sourcepath="D:/Temp/_hibernate/slf4j-api-1.5.8-sources.jar"/>
@@ -30,7 +30,7 @@
<classpathentry kind="lib"
path="lib/annotations/hibernate-commons-annotations.jar"
sourcepath="D:/Temp/_hibernate/hibernate-commons-annotations-3.1.0.GA-sources.jar
"/>
<classpathentry kind="lib"
path="lib/annotations/ejb3-persistence.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/c3p0-0.9.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/hibernate/commons-logging-1.0.4.jar"/>
+ <classpathentry kind="lib"
path="lib/hibernate/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/concurrent-1.3.2.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/connector.jar"/>
<classpathentry kind="lib"
path="lib/hibernate/ehcache-1.2.3.jar"/>
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/META-INF/MANIFEST.MF
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/META-INF/MANIFEST.MF 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/META-INF/MANIFEST.MF 2010-03-30
13:36:44 UTC (rev 21136)
@@ -55,10 +55,6 @@
org.hibernate.mediator.stubs,
org.hibernate.mediator.stubs.util,
org.hibernate.mediator.util,
- org.apache.log4j,
- org.apache.log4j.helpers,
- org.apache.log4j.spi,
- org.apache.commons.logging,
org.dom4j,
org.dom4j.io,
net.sf.cglib.core,
@@ -73,3 +69,4 @@
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: registered
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Activator: org.hibernate.mediator.MediatorPlugin
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/hibernate-log4j.properties
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/hibernate-log4j.properties)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/hibernate-log4j.properties
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/hibernate-log4j.properties 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,42 @@
+### This file is used to control the logging done by the hibernate tools eclipse plugins
+### You can modfiy these to be more or less verbose depending on your needs
+
+### Direct messages to Eclipse logging system (will be shown in Error Log)
+log4j.appender.eclipselog=org.hibernate.mediator.logging.PluginLogAppender
+log4j.appender.eclipselog.layout=org.apache.log4j.PatternLayout
+log4j.appender.eclipselog.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m
+
+### Direct messages from Eclipse loggin system to
.metadata/plugins/org.hibernate.eclipse/hibernate-tools.log
+log4j.appender.pluginlog=org.hibernate.mediator.logging.PluginFileAppender
+log4j.appender.pluginlog.File=hibernate-tools.log
+log4j.appender.pluginlog.MaxFileSize=1MB
+log4j.appender.pluginlog.MaxBackupIndex=1
+log4j.appender.pluginlog.layout=org.apache.log4j.PatternLayout
+log4j.appender.pluginlog.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c
%x - %m\n
+
+### set log levels - for more verbose logging change 'info' to 'debug'
###
+log4j.rootLogger=warn, eclipselog, pluginlog
+
+log4j.logger.org.hibernate=warn
+
+# Disable superflous PARSER errors.
+log4j.logger.org.hibernate.PARSER=none
+
+### log just the SQL
+#log4j.logger.org.hibernate.SQL=debug
+
+### log JDBC bind parameters ###
+#log4j.logger.org.hibernate.type=info
+
+### log schema export/update ###
+#log4j.logger.org.hibernate.tool.hbm2ddl=debug
+
+### log cache activity ###
+#log4j.logger.org.hibernate.cache=debug
+
+### log JDBC resource acquisition
+#log4j.logger.org.hibernate.jdbc=debug
+
+### enable the following line if you want to track down connection ###
+### leakages when using DriverManagerConnectionProvider ###
+#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/MediatorPlugin.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/MediatorPlugin.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/MediatorPlugin.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -1,19 +1,25 @@
/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.hibernate.mediator;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.hibernate.mediator.logging.LoggingHelper;
+import org.hibernate.mediator.logging.PluginLogManager;
import org.osgi.framework.BundleContext;
/**
@@ -26,7 +32,7 @@
// The shared instance
private static MediatorPlugin plugin;
-
+
/**
* The constructor
*/
@@ -40,20 +46,38 @@
public void start(BundleContext context) throws Exception {
super.start(context);
setPlugin(this);
+ configureLog4jHooks();
+ Log log = LogFactory.getLog(MediatorPlugin.class);
+ log.info("HibernateMediatorPlugin Started"); //$NON-NLS-1$
}
+ private void configureLog4jHooks() {
+ URL entry = getBundle().getEntry("hibernate-log4j.xml"); //$NON-NLS-1$
+ if (entry == null) {
+ entry = getBundle().getEntry("hibernate-log4j.properties"); //$NON-NLS-1$
+ }
+
+ if (entry == null) {
+ // should log this!
+ } else {
+ LoggingHelper helper = LoggingHelper.getDefault();
+ PluginLogManager manager = new PluginLogManager(this, helper, entry);
+ }
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ LoggingHelper.getDefault().stop(context);
setPlugin(null);
super.stop(context);
}
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public static MediatorPlugin getDefault() {
@@ -63,47 +87,40 @@
private static void setPlugin(MediatorPlugin plugin) {
MediatorPlugin.plugin = plugin;
}
-
+
/**
* Log message
- *
*/
private static void log(int severity, String message, Throwable e) {
getDefault().getLog().log(new Status(severity, PLUGIN_ID, message, e));
}
-
+
/**
* Short exception log
- *
*/
public static void logException(Throwable e) {
- log(IStatus.ERROR, e.getMessage(), e);
+ log(IStatus.ERROR, e.getMessage(), e);
}
-
+
/**
* Short error log call
- *
*/
public static void logError(String message) {
log(IStatus.ERROR, message, null);
}
-
+
/**
* Short warning log call
- *
*/
public static void logWarning(String message) {
log(IStatus.WARNING, message, null);
}
-
+
/**
* Short information log call
- *
*/
public static void logInfo(String message) {
log(IStatus.INFO, message, null);
}
-
-
}
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/Messages.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/Messages.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/Messages.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -19,8 +19,8 @@
//public static String JavaPage_no_info;
public static String JavaPage_not_allowed;
//public static String KnownConfigurations_could_not_write_state;
- //public static String KnownConfigurations_hibernate_log;
- //public static String KnownConfigurations_unknown;
+ public static String KnownConfigurations_hibernate_log;
+ public static String KnownConfigurations_unknown;
public static String DefaultExecutionContext_existing_classloader;
//public static String ClassNode_uninitialized_proxy;
//public static String ConfigurationNode_mapped_entities;
@@ -32,7 +32,7 @@
//public static String
StandAloneConsoleConfigurationPreferences_could_not_resolve_classpaths;
//public static String StandAloneConsoleConfigurationPreferences_errors_while_parsing;
public static String PluginFileAppender_missing_plugin_state_location;
- //public static String PluginLogAppender_missing_layout_for_appender;
+ public static String PluginLogAppender_missing_layout_for_appender;
public static String EntityPropertySource_identifier;
public static String EntityPropertySource_properties;
public static String DynamicSQLPreviewView_caused_by;
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingHelper.java
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/LoggingHelper.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingHelper.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingHelper.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.mediator.logging;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+public class LoggingHelper {
+
+ private static LoggingHelper helper;
+
+ private List<PluginLogManager> logManagers = new
ArrayList<PluginLogManager>();
+
+ public LoggingHelper() {
+ super();
+ }
+
+ synchronized public static LoggingHelper getDefault() {
+ if(helper==null) { helper = new LoggingHelper(); }
+ return helper;
+ }
+
+ /**
+ * Iterates over the list of active log managers and shutdowns each one
+ * @see Plugin#stop
+ */
+ public void stop(BundleContext context) throws Exception {
+ synchronized (this.logManagers) {
+ for (PluginLogManager logManager : logManagers) {
+ logManager.internalShutdown();
+ }
+ this.logManagers.clear();
+ }
+ }
+
+ /**
+ * Adds a log manager object to the list of active log managers
+ */
+ void addLogManager(PluginLogManager logManager) {
+ synchronized (this.logManagers) {
+ if (logManager != null)
+ this.logManagers.add(logManager);
+ }
+ }
+
+ /**
+ * Removes a log manager object from the list of active log managers
+ */
+ void removeLogManager(PluginLogManager logManager) {
+ synchronized (this.logManagers) {
+ if (logManager != null)
+ this.logManagers.remove(logManager);
+ }
+ }
+}
\ No newline at end of file
Added:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingStreamManager.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingStreamManager.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/LoggingStreamManager.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,57 @@
+package org.hibernate.mediator.logging;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.IConsoleManager;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.hibernate.mediator.Messages;
+
+public class LoggingStreamManager {
+
+ private static LoggingStreamManager instance;
+
+ public static synchronized LoggingStreamManager getInstance() {
+ if (instance == null) {
+ instance = new LoggingStreamManager();
+ }
+ return instance;
+ }
+
+ private Map<String, Object[]> loggingStreams = new HashMap<String,
Object[]>();
+
+ public MessageConsoleStream findLoggingStream(String name) {
+ Object[] console = loggingStreams.get(name);
+ if (console == null) {
+ console = new Object[2];
+ String secondaryId = Messages.KnownConfigurations_hibernate_log
+ + (name == null ? Messages.KnownConfigurations_unknown : name);
+ console[0] = new MessageConsole(secondaryId, null);
+ IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
+ consoleManager.addConsoles(new IConsole[] { (IConsole) console[0] });
+ console[1] = ((MessageConsole) console[0]).newMessageStream();
+ loggingStreams.put(name, console);
+ }
+ return (MessageConsoleStream) console[1];
+ }
+
+ public void removeLoggingStream(String consoleConfigName) {
+ Object[] object = loggingStreams.remove(consoleConfigName);
+ if (object != null) {
+ MessageConsole mc = (MessageConsole) object[0];
+ MessageConsoleStream stream = (MessageConsoleStream) object[1];
+ try {
+ stream.close();
+ } catch (IOException ie) {
+ // ignore
+ }
+ IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
+ consoleManager.removeConsoles(new IConsole[] { mc });
+ }
+ }
+
+}
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginFileAppender.java
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginFileAppender.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginFileAppender.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginFileAppender.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.mediator.logging;
+
+import java.io.IOException;
+
+import org.apache.log4j.Layout;
+import org.apache.log4j.RollingFileAppender;
+import org.apache.log4j.spi.LoggingEvent;
+import org.eclipse.core.runtime.IPath;
+import org.hibernate.mediator.Messages;
+
+/**
+ * PluginFileAppender
+ * This class is a custom Log4J appender that sends Log4J events to
+ * the Eclipse plug-in state location. It extends the RollingFileAppender class.
+ * @author Manoel Marques
+ */
+public class PluginFileAppender extends RollingFileAppender {
+
+ private IPath stateLocation;
+ private boolean activateOptionsPending;
+ private boolean translatePath = true;
+
+ /**
+ * Creates a new PluginFileAppender.
+ */
+ public PluginFileAppender() {
+ super();
+ }
+
+ /**
+ * Creates a new PluginFileAppender.
+ * @param layout layout instance.
+ * @param stateLocation IPath containing the plug-in state location
+ */
+ public PluginFileAppender(Layout layout,IPath stateLocation) {
+ super();
+ setLayout(layout);
+ setStateLocation(stateLocation);
+ }
+
+ /**
+ * Creates a new PluginFileAppender.
+ * @param layout layout instance.
+ * @param stateLocation IPath containing the plug-in state location
+ * @param file file name
+ * @param append true if file is to be appended
+ */
+ public PluginFileAppender(Layout layout,IPath stateLocation, String file, boolean
append)
+ throws IOException {
+ super();
+ setLayout(layout);
+ setStateLocation(stateLocation);
+ setFile(file);
+ setAppend(append);
+ activateOptions();
+ }
+
+ /**
+ * Creates a new PluginFileAppender.
+ * @param layout layout instance.
+ * @param stateLocation IPath containing the plug-in state location
+ * @param file file name
+ */
+ public PluginFileAppender(Layout layout,IPath stateLocation, String file) throws
IOException {
+ super();
+ setLayout(layout);
+ setStateLocation(stateLocation);
+ setFile(file);
+ activateOptions();
+ }
+
+ /**
+ * Sets the state location. If activateOptions call is pending, translate the file name
+ * and call activateOptions
+ * @param stateLocation IPath containing the plug-in state location
+ */
+ public void setStateLocation(IPath stateLocation) {
+ this.stateLocation = stateLocation;
+ if (this.stateLocation != null && this.activateOptionsPending) {
+ this.activateOptionsPending = false;
+ setFile(getFile());
+ activateOptions();
+ }
+ }
+
+ /**
+ * Sets the file name.Translate it before setting.
+ * @param file file name
+ */
+ public void setFile(String file) {
+ super.setFile(getTranslatedFileName(file));
+ }
+
+ /**
+ * Set file options and opens it, leaving ready to write.
+ * @param file file name
+ * @param append true if file is to be appended
+ * @param bufferedIO true if file is to buffered
+ * @param bufferSize buffer size
+ * @throws IOException - IO Error happend or the state location was not set
+ */
+ public void setFile(String fileName,boolean append,boolean bufferedIO,int bufferSize)
throws IOException {
+ if (this.stateLocation == null)
+ throw new IOException(Messages.PluginFileAppender_missing_plugin_state_location);
+
+ fileName = (this.translatePath) ? getTranslatedFileName(fileName) : fileName;
+ super.setFile(fileName,append,bufferedIO,bufferSize);
+ }
+
+ /**
+ * Finishes instance initialization. If state location was not set, set activate as
+ * pending and does nothing.
+ */
+ public void activateOptions() {
+ if (this.stateLocation == null) {
+ this.activateOptionsPending = true;
+ return;
+ }
+
+ // base class will call setFile, don't translate the name
+ // because it was already translated
+ this.translatePath = false;
+ super.activateOptions();
+ this.translatePath = true;
+ }
+
+ /**
+ * Any path part of a file is removed and the state location is added to the name
+ * to form a new path. If there is not state location, returns the name unmodified.
+ * @param file file name
+ * @return translated file name
+ */
+ private String getTranslatedFileName(String file) {
+
+ if (this.stateLocation == null || file == null)
+ return file;
+
+ file = file.trim();
+ if (file.length() == 0)
+ return file;
+
+ int index = file.lastIndexOf('/');
+ if (index == -1)
+ index = file.lastIndexOf('\\');
+
+ if (index != -1)
+ file = file.substring(index + 1);
+
+ IPath newPath = this.stateLocation.append(file);
+ return newPath.toString();
+ }
+
+ public void append(LoggingEvent event) {
+ super.append( event );
+ }
+}
\ No newline at end of file
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogAppender.java
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogAppender.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogAppender.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogAppender.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.mediator.logging;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.spi.ErrorCode;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.ThrowableInformation;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.ui.console.MessageConsoleStream;
+import org.hibernate.mediator.Messages;
+
+/**
+ * PluginLogAppender This class is a custom Log4J appender that sends Log4J events to the
Eclipse
+ * plug-in log.
+ *
+ * @author Manoel Marques
+ */
+public class PluginLogAppender extends AppenderSkeleton {
+
+ @SuppressWarnings("unused")
+ private ILog pluginLog;
+
+ /**
+ * Sets the Eclipse log instance
+ *
+ * @param log
+ * plug-in log
+ */
+ void setLog(ILog pluginLog) {
+ this.pluginLog = pluginLog;
+ }
+
+ /**
+ * Log event happened. Translates level to status instance codes: level > Level.ERROR
-
+ * Status.ERROR level > Level.WARN - Status.WARNING level > Level.DEBUG -
Status.INFO default -
+ * Status.OK
+ *
+ * @param event
+ * LoggingEvent instance
+ */
+ public void append(LoggingEvent event) {
+
+ if (this.layout == null) {
+ this.errorHandler.error(Messages.PluginLogAppender_missing_layout_for_appender
+ + this.name, null, ErrorCode.MISSING_LAYOUT);
+ return;
+ }
+
+ String text = this.layout.format(event);
+
+ Throwable thrown = null;
+ if (this.layout.ignoresThrowable()) {
+ ThrowableInformation info = event.getThrowableInformation();
+ if (info != null)
+ thrown = info.getThrowable();
+ }
+ /** /
+ Level level = event.getLevel();
+ int severity = IStatus.OK;
+
+ if (level.toInt() >= Priority.ERROR_INT)
+ severity = IStatus.ERROR;
+ else if (level.toInt() >= Priority.WARN_INT)
+ severity = IStatus.WARNING;
+ else if (level.toInt() >= Priority.DEBUG_INT)
+ severity = IStatus.INFO;
+
+ this.pluginLog.log(new Status(severity, this.pluginLog.getBundle().getSymbolicName(),
level
+ .toInt(), text, thrown));
+ /**/
+
+ Object peek = CurrentContext.peek();
+ MessageConsoleStream stream = LoggingStreamManager.getInstance().findLoggingStream(
+ (String) peek);
+ if (stream != null) {
+ stream.println(text);
+ if (thrown != null) {
+ StringWriter stringWriter = new StringWriter();
+ thrown.printStackTrace(new PrintWriter(stringWriter));
+ stream.println(stringWriter.getBuffer().toString());
+ }
+ }
+ }
+
+ /**
+ * Closes this appender
+ */
+ public void close() {
+ this.closed = true;
+ }
+
+ /**
+ * Checks if this appender requires layout
+ *
+ * @return true if layout is required.
+ */
+ public boolean requiresLayout() {
+ return true;
+ }
+}
\ No newline at end of file
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogListener.java
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogListener.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogListener.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogListener.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.mediator.logging;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * PluginLogListener
+ * This class is responsible for adding itself to the plug-in logging framework
+ * and translating plug-in log requests to Logger events.
+ * @author Manoel Marques
+ */
+public class PluginLogListener implements ILogListener {
+
+ private ILog log;
+ private Logger logger;
+
+ /**
+ * Creates a new PluginLogListener. Saves the plug-in log and logger instance.
+ * Adds itself to the plug-in log.
+ * @param plugin the plug-in object
+ * @param logger logger instance
+ */
+ public PluginLogListener(ILog log,Logger logger) {
+ this.log = log;
+ this.logger = logger;
+ log.addLogListener(this);
+ }
+
+ /**
+ * Removes itself from the plug-in log, reset instance variables.
+ */
+ public void dispose() {
+ if (this.log != null) {
+ this.log.removeLogListener(this);
+ this.log = null;
+ this.logger = null;
+ }
+ }
+
+ /**
+ * Log event happened.
+ * Translates status instance to Logger level and message.
+ * Status.ERROR - Level.ERROR
+ * Status.WARNING - Level.WARN
+ * Status.INFO - Level.INFO
+ * Status.CANCEL - Level.FATAL
+ * default - Level.DEBUG
+ * @param status Log Status
+ * @param plugin plug-in id
+ */
+ public void logging(IStatus status, String plugin) {
+ if (null == this.logger || null == status)
+ return;
+
+ int severity = status.getSeverity();
+ Level level = Level.DEBUG;
+ if (severity == IStatus.ERROR)
+ level = Level.ERROR;
+ else if (severity == IStatus.WARNING)
+ level = Level.WARN;
+ else if (severity == IStatus.INFO)
+ level = Level.INFO;
+ else if (severity == IStatus.CANCEL)
+ level = Level.FATAL;
+
+ plugin = formatText(plugin);
+ String statusPlugin = formatText(status.getPlugin());
+ String statusMessage = formatText(status.getMessage());
+ StringBuffer message = new StringBuffer();
+ if (plugin != null) {
+ message.append(plugin);
+ message.append(" - "); //$NON-NLS-1$
+ }
+ if (statusPlugin != null &&
+ (plugin == null || !statusPlugin.equals(plugin))) {
+ message.append(statusPlugin);
+ message.append(" - "); //$NON-NLS-1$
+ }
+ message.append(status.getCode());
+ if (statusMessage != null) {
+ message.append(" - "); //$NON-NLS-1$
+ message.append(statusMessage);
+ }
+ this.logger.log(level,message.toString(),status.getException());
+ }
+
+ static private String formatText(String text) {
+ if (text != null) {
+ text = text.trim();
+ if (text.length() == 0) return null;
+ }
+ return text;
+ }
+}
\ No newline at end of file
Copied:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogManager.java
(from rev 21120,
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/eclipse/logging/PluginLogManager.java)
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogManager.java
(rev 0)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/logging/PluginLogManager.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -0,0 +1,263 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.mediator.logging;
+
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Category;
+import org.apache.log4j.Hierarchy;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.helpers.OptionConverter;
+import org.apache.log4j.spi.HierarchyEventListener;
+import org.apache.log4j.spi.LoggerFactory;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.RepositorySelector;
+import org.apache.log4j.spi.RootLogger;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Plugin;
+import org.hibernate.mediator.logging.PluginFileAppender;
+import org.hibernate.mediator.logging.PluginLogAppender;
+import org.hibernate.mediator.logging.PluginLogListener;
+
+/**
+ * PluginLogManager
+ * This class encapsulates a Log4J Hierarchy and centralizes all Logger access.
+ * @author Manoel Marques
+ */
+public class PluginLogManager {
+
+ private ILog log;
+ private IPath stateLocation;
+ private Hierarchy hierarchy;
+ private HashMap<String, ILogListener> hookedPlugins = new HashMap<String,
ILogListener>();
+ private LoggingHelper helper;
+
+ private class PluginEventListener implements HierarchyEventListener {
+
+ /**
+ * Called when a new appender is added for a particular level.
+ * Internally it checks if the appender is one of our custom ones
+ * and sets its custom properties.
+ * @param category level
+ * @param appender appender added for this level
+ */
+ public void addAppenderEvent(Category cat, Appender appender) {
+ if (appender instanceof PluginLogAppender) {
+ ((PluginLogAppender)appender).setLog(log);
+ }
+ if (appender instanceof PluginFileAppender) {
+ ((PluginFileAppender)appender).setStateLocation(stateLocation);
+ }
+ }
+
+ /**
+ * Called when a appender is removed from for a particular level.
+ * Does nothing.
+ * @param category level
+ * @param appender appender added for this level
+ */
+ public void removeAppenderEvent(Category cat, Appender appender) {
+ }
+ }
+
+ /**
+ * Creates a new PluginLogManager. Saves the plug-in log and state location.
+ * Creates a new Hierarchy and add a new PluginEventListener to it.
+ * Configure the hierarchy with the properties passed.
+ * Add this object to the list of active plug-in log managers.
+ * @param plugin the plug-in object
+ * @param properties log configuration properties
+ */
+ public PluginLogManager(Plugin plugin, LoggingHelper helper, URL log4jUrl) {
+ this.log = plugin.getLog();
+ this.stateLocation = plugin.getStateLocation();
+ this.hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
+ this.hierarchy.addHierarchyEventListener(new PluginEventListener());
+ LogManager.setRepositorySelector(new RepositorySelector() {
+
+ public LoggerRepository getLoggerRepository() {
+ return hierarchy;
+ }
+
+ }, "hibernate-tools"); //$NON-NLS-1$
+ OptionConverter.selectAndConfigure(log4jUrl, null, this.hierarchy);
+ this.helper = helper;
+ helper.addLogManager(this);
+ }
+
+ /**
+ * Hooks a plug-in into this PluginLogManager. When the hooked plug-in uses the
+ * Eclipse log API, it will be channeled to this logging framework.
+ * @param id logger name (usually the the plug-in id)
+ * @param pluginLog plug-in log
+ */
+ public boolean hookPlugin(String id, ILog pluginLog) {
+ synchronized(this.hookedPlugins) {
+ if (pluginLog == null || id == null || this.hookedPlugins.containsKey(id))
+ return false;
+
+ PluginLogListener listener = new PluginLogListener(pluginLog,getLogger(id));
+ this.hookedPlugins.put(id,listener);
+ }
+ return true;
+ }
+
+ /**
+ * Unhooks a plug-in from this PluginLogManager. The Eclipse log API
+ * won't be channeled to this logging framework anymore.
+ * @param id logger name (usually the the plug-in id)
+ */
+ public boolean unHookPlugin(String id) {
+ synchronized(this.hookedPlugins) {
+ if (id == null || !this.hookedPlugins.containsKey(id))
+ return false;
+
+ PluginLogListener listener = (PluginLogListener) this.hookedPlugins.get(id);
+ listener.dispose();
+ this.hookedPlugins.remove(id);
+ }
+ return true;
+ }
+
+ /**
+ * Checks if this PluginLogManager is disabled for this level.
+ * @param level level value
+ * @return boolean true if it is disabled
+ */
+ public boolean isDisabled(int level) {
+ return this.hierarchy.isDisabled(level);
+ }
+
+ /**
+ * Enable logging for logging requests with level l or higher.
+ * By default all levels are enabled.
+ * @param level level object
+ */
+ public void setThreshold(Level level) {
+ this.hierarchy.setThreshold(level);
+ }
+
+ /**
+ * The string version of setThreshold(Level level)
+ * @param level level string
+ */
+ public void setThreshold(String level) {
+ this.hierarchy.setThreshold(level);
+ }
+
+ /**
+ * Get the repository-wide threshold.
+ * @return Level
+ */
+ public Level getThreshold() {
+ return this.hierarchy.getThreshold();
+ }
+
+ /**
+ * Returns a new logger instance named as the first parameter
+ * using the default factory. If a logger of that name already exists,
+ * then it will be returned. Otherwise, a new logger will be instantiated
+ * and then linked with its existing ancestors as well as children.
+ * @param name logger name
+ * @return Logger
+ */
+ public Logger getLogger(String name) {
+ return this.hierarchy.getLogger(name);
+ }
+
+ /**
+ * The same as getLogger(String name) but using a factory instance instead of
+ * a default factory.
+ * @param name logger name
+ * @param factory factory instance
+ * @return Logger
+ */
+ public Logger getLogger(String name, LoggerFactory factory) {
+ return this.hierarchy.getLogger(name,factory);
+ }
+
+ /**
+ * Returns the root of this hierarchy.
+ * @return Logger
+ */
+ public Logger getRootLogger() {
+ return this.hierarchy.getRootLogger();
+ }
+
+ /**
+ * Checks if this logger exists.
+ * @return Logger
+ */
+ public Logger exists(String name) {
+ return this.hierarchy.exists(name);
+ }
+
+ /**
+ * Removes appenders and disposes the logger hierarchy
+ *
+ */
+ public void shutdown() {
+ internalShutdown();
+ helper.removeLogManager(this);
+ }
+
+ /**
+ * Used by LoggingHelper to shutdown without removing it from the LoggingHelper list
+ *
+ */
+ void internalShutdown() {
+ synchronized(this.hookedPlugins) {
+ Iterator<String> it = this.hookedPlugins.keySet().iterator();
+ while (it.hasNext()) {
+ String id = it.next();
+ PluginLogListener listener = (PluginLogListener) this.hookedPlugins.get(id);
+ listener.dispose();
+ }
+ this.hookedPlugins.clear();
+ }
+ this.hierarchy.shutdown();
+ }
+
+ /**
+ * Returns all the loggers in this manager.
+ * @return Enumeration logger enumeration
+ */
+ public Enumeration<?> getCurrentLoggers() {
+ return this.hierarchy.getCurrentLoggers();
+ }
+
+ /**
+ * Resets configuration values to its defaults.
+ *
+ */
+ public void resetConfiguration() {
+ this.hierarchy.resetConfiguration();
+ }
+}
\ No newline at end of file
Modified:
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java
===================================================================
---
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java 2010-03-30
12:19:43 UTC (rev 21135)
+++
branches/hibernatetools-multiversion/hibernatetools/plugins/org.hibernate.mediator/src/org/hibernate/mediator/stubs/ConfigurationStubFactory.java 2010-03-30
13:36:44 UTC (rev 21136)
@@ -109,7 +109,7 @@
private Configuration buildAnnotationConfiguration() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Class<?> clazz = ReflectHelper
- .classForName("org.hibernate.cfg.AnnotationConfiguration",
ConfigurationStubFactory.class); //$NON-NLS-1$
+ .classForName("org.hibernate.cfg.AnnotationConfiguration", Object.class);
//$NON-NLS-1$
Configuration annotationConfig = (Configuration)clazz.newInstance();
return annotationConfig;
}
@@ -134,7 +134,7 @@
overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
}
Class<?> clazz = ReflectHelper.classForName(
- "org.hibernate.ejb.Ejb3Configuration", ConfigurationStubFactory.class);
//$NON-NLS-1$
+ "org.hibernate.ejb.Ejb3Configuration", Object.class); //$NON-NLS-1$
Object ejb3cfg = clazz.newInstance();
if (StringHelper.isNotEmpty(entityResolver)) {