Repository: tomee Updated Branches: refs/heads/master 912db4178 -> 3069db0ba
http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java index e212428..4dd2554 100644 --- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java +++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java @@ -1,63 +1,63 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.jul.formatter; - -import org.apache.juli.AsyncFileHandler; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.ConsoleHandler; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -public class AsyncConsoleHandler extends AsyncFileHandler { - private final ConsoleHandler delegate = new ConsoleHandler() {{ - setFormatter(new SingleLineFormatter()); // console -> dev. File uses plain old format - }}; - - protected void publishInternal(final LogRecord record) { - delegate.publish(record); - } - - // copy cause of classloading - private static class SingleLineFormatter extends Formatter { - private static final String SEP = System.getProperty("line.separator", "\n"); - - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") - @Override - public synchronized String format(final LogRecord record) { - final boolean exception = record.getThrown() != null; - final StringBuilder sbuf = new StringBuilder(); - sbuf.append(record.getLevel().getLocalizedName()); - sbuf.append(" - "); - sbuf.append(this.formatMessage(record)); - sbuf.append(SEP); - if (exception) { - try { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - record.getThrown().printStackTrace(pw); - pw.close(); - sbuf.append(sw.toString()); - } catch (final Exception ex) { - // no-op - } - } - return sbuf.toString(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.jul.formatter; + +import org.apache.juli.AsyncFileHandler; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +public class AsyncConsoleHandler extends AsyncFileHandler { + private final ConsoleHandler delegate = new ConsoleHandler() {{ + setFormatter(new SingleLineFormatter()); // console -> dev. File uses plain old format + }}; + + protected void publishInternal(final LogRecord record) { + delegate.publish(record); + } + + // copy cause of classloading + private static class SingleLineFormatter extends Formatter { + private static final String SEP = System.getProperty("line.separator", "\n"); + + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + @Override + public synchronized String format(final LogRecord record) { + final boolean exception = record.getThrown() != null; + final StringBuilder sbuf = new StringBuilder(); + sbuf.append(record.getLevel().getLocalizedName()); + sbuf.append(" - "); + sbuf.append(this.formatMessage(record)); + sbuf.append(SEP); + if (exception) { + try { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + record.getThrown().printStackTrace(pw); + pw.close(); + sbuf.append(sw.toString()); + } catch (final Exception ex) { + // no-op + } + } + return sbuf.toString(); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java index 5ee3a39..03c66c0 100644 --- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java +++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java @@ -1,48 +1,48 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.jul.formatter; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.LogRecord; - -public class SimpleTomEEFormatter extends java.util.logging.Formatter { - private static final String LN = System.getProperty("line.separator"); - - @SuppressWarnings("ThrowableResultOfMethodCallIgnored") - @Override - public synchronized String format(final LogRecord record) { - final Throwable thrown = record.getThrown(); - final StringBuilder sbuf = new StringBuilder(); - sbuf.append(record.getLevel().getLocalizedName()); - sbuf.append(" - "); - sbuf.append(formatMessage(record)); - sbuf.append(LN); - if (thrown != null) { - try { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - thrown.printStackTrace(pw); - pw.close(); - sbuf.append(sw.toString()); - } catch (final Exception ex) { - // no-op - } - } - return sbuf.toString(); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.jul.formatter; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.logging.LogRecord; + +public class SimpleTomEEFormatter extends java.util.logging.Formatter { + private static final String LN = System.getProperty("line.separator"); + + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") + @Override + public synchronized String format(final LogRecord record) { + final Throwable thrown = record.getThrown(); + final StringBuilder sbuf = new StringBuilder(); + sbuf.append(record.getLevel().getLocalizedName()); + sbuf.append(" - "); + sbuf.append(formatMessage(record)); + sbuf.append(LN); + if (thrown != null) { + try { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + thrown.printStackTrace(pw); + pw.close(); + sbuf.append(sw.toString()); + } catch (final Exception ex) { + // no-op + } + } + return sbuf.toString(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java index 39f8b4d..184ecea 100644 --- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java +++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java @@ -1,180 +1,180 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.jul.formatter.log; - -import org.apache.juli.logging.Log; - -import java.util.logging.ConsoleHandler; -import java.util.logging.Formatter; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; - -// DirectJDKLog copy since it is now package scoped -public class JULLogger implements Log { - /** - * Alternate config reader and console format - */ - private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter"; - private static final String SIMPLE_CFG = "org.apache.juli.JdkLoggerConfig"; //doesn't exist - private static final String FORMATTER = "org.apache.juli.formatter"; - - static { - if (System.getProperty("java.util.logging.config.class") == null && - System.getProperty("java.util.logging.config.file") == null) { - // default configuration - it sucks. Let's override at least the - // formatter for the console - try { - Class.forName(SIMPLE_CFG).newInstance(); - } catch (final Throwable t) { - // no-op - } - try { - final Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).newInstance(); - // it is also possible that the user modified jre/lib/logging.properties - - // but that's really stupid in most cases - final Logger root = Logger.getLogger(""); - final Handler[] handlers = root.getHandlers(); - for (final Handler handler : handlers) { - // I only care about console - that's what's used in default config anyway - if (handler instanceof ConsoleHandler) { - handler.setFormatter(fmt); - } - } - } catch (final Throwable t) { - // no-op maybe it wasn't included - the ugly default will be used. - } - } - } - - private final Logger logger; - - public JULLogger(final String name) { - logger = Logger.getLogger(name); - } - - @Override - public final boolean isErrorEnabled() { - return logger.isLoggable(Level.SEVERE); - } - - @Override - public final boolean isWarnEnabled() { - return logger.isLoggable(Level.WARNING); - } - - @Override - public final boolean isInfoEnabled() { - return logger.isLoggable(Level.INFO); - } - - @Override - public final boolean isDebugEnabled() { - return logger.isLoggable(Level.FINE); - } - - @Override - public final boolean isFatalEnabled() { - return logger.isLoggable(Level.SEVERE); - } - - @Override - public final boolean isTraceEnabled() { - return logger.isLoggable(Level.FINER); - } - - @Override - public final void debug(final Object message) { - log(Level.FINE, String.valueOf(message), null); - } - - @Override - public final void debug(final Object message, final Throwable t) { - log(Level.FINE, String.valueOf(message), t); - } - - @Override - public final void trace(final Object message) { - log(Level.FINER, String.valueOf(message), null); - } - - @Override - public final void trace(final Object message, final Throwable t) { - log(Level.FINER, String.valueOf(message), t); - } - - @Override - public final void info(final Object message) { - log(Level.INFO, String.valueOf(message), null); - } - - @Override - public final void info(final Object message, final Throwable t) { - log(Level.INFO, String.valueOf(message), t); - } - - @Override - public final void warn(final Object message) { - log(Level.WARNING, String.valueOf(message), null); - } - - @Override - public final void warn(final Object message, final Throwable t) { - log(Level.WARNING, String.valueOf(message), t); - } - - @Override - public final void error(final Object message) { - log(Level.SEVERE, String.valueOf(message), null); - } - - @Override - public final void error(final Object message, final Throwable t) { - log(Level.SEVERE, String.valueOf(message), t); - } - - @Override - public final void fatal(final Object message) { - log(Level.SEVERE, String.valueOf(message), null); - } - - @Override - public final void fatal(final Object message, final Throwable t) { - log(Level.SEVERE, String.valueOf(message), t); - } - - private void log(final Level level, final String msg, final Throwable ex) { - if (logger.isLoggable(level)) { - // Hack (?) to get the stack trace. - final Throwable dummyException = new Throwable(); - final StackTraceElement[] locations = dummyException.getStackTrace(); - // Caller will be the third element - String cname = "unknown"; - String method = "unknown"; - if (locations != null && locations.length > 3) { - final StackTraceElement caller = locations[3]; - cname = caller.getClassName(); - method = caller.getMethodName(); - } - if (ex == null) { - logger.logp(level, cname, method, msg); - } else { - logger.logp(level, cname, method, msg, ex); - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.jul.formatter.log; + +import org.apache.juli.logging.Log; + +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.Logger; + +// DirectJDKLog copy since it is now package scoped +public class JULLogger implements Log { + /** + * Alternate config reader and console format + */ + private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter"; + private static final String SIMPLE_CFG = "org.apache.juli.JdkLoggerConfig"; //doesn't exist + private static final String FORMATTER = "org.apache.juli.formatter"; + + static { + if (System.getProperty("java.util.logging.config.class") == null && + System.getProperty("java.util.logging.config.file") == null) { + // default configuration - it sucks. Let's override at least the + // formatter for the console + try { + Class.forName(SIMPLE_CFG).newInstance(); + } catch (final Throwable t) { + // no-op + } + try { + final Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).newInstance(); + // it is also possible that the user modified jre/lib/logging.properties - + // but that's really stupid in most cases + final Logger root = Logger.getLogger(""); + final Handler[] handlers = root.getHandlers(); + for (final Handler handler : handlers) { + // I only care about console - that's what's used in default config anyway + if (handler instanceof ConsoleHandler) { + handler.setFormatter(fmt); + } + } + } catch (final Throwable t) { + // no-op maybe it wasn't included - the ugly default will be used. + } + } + } + + private final Logger logger; + + public JULLogger(final String name) { + logger = Logger.getLogger(name); + } + + @Override + public final boolean isErrorEnabled() { + return logger.isLoggable(Level.SEVERE); + } + + @Override + public final boolean isWarnEnabled() { + return logger.isLoggable(Level.WARNING); + } + + @Override + public final boolean isInfoEnabled() { + return logger.isLoggable(Level.INFO); + } + + @Override + public final boolean isDebugEnabled() { + return logger.isLoggable(Level.FINE); + } + + @Override + public final boolean isFatalEnabled() { + return logger.isLoggable(Level.SEVERE); + } + + @Override + public final boolean isTraceEnabled() { + return logger.isLoggable(Level.FINER); + } + + @Override + public final void debug(final Object message) { + log(Level.FINE, String.valueOf(message), null); + } + + @Override + public final void debug(final Object message, final Throwable t) { + log(Level.FINE, String.valueOf(message), t); + } + + @Override + public final void trace(final Object message) { + log(Level.FINER, String.valueOf(message), null); + } + + @Override + public final void trace(final Object message, final Throwable t) { + log(Level.FINER, String.valueOf(message), t); + } + + @Override + public final void info(final Object message) { + log(Level.INFO, String.valueOf(message), null); + } + + @Override + public final void info(final Object message, final Throwable t) { + log(Level.INFO, String.valueOf(message), t); + } + + @Override + public final void warn(final Object message) { + log(Level.WARNING, String.valueOf(message), null); + } + + @Override + public final void warn(final Object message, final Throwable t) { + log(Level.WARNING, String.valueOf(message), t); + } + + @Override + public final void error(final Object message) { + log(Level.SEVERE, String.valueOf(message), null); + } + + @Override + public final void error(final Object message, final Throwable t) { + log(Level.SEVERE, String.valueOf(message), t); + } + + @Override + public final void fatal(final Object message) { + log(Level.SEVERE, String.valueOf(message), null); + } + + @Override + public final void fatal(final Object message, final Throwable t) { + log(Level.SEVERE, String.valueOf(message), t); + } + + private void log(final Level level, final String msg, final Throwable ex) { + if (logger.isLoggable(level)) { + // Hack (?) to get the stack trace. + final Throwable dummyException = new Throwable(); + final StackTraceElement[] locations = dummyException.getStackTrace(); + // Caller will be the third element + String cname = "unknown"; + String method = "unknown"; + if (locations != null && locations.length > 3) { + final StackTraceElement caller = locations[3]; + cname = caller.getClassName(); + method = caller.getMethodName(); + } + if (ex == null) { + logger.logp(level, cname, method, msg); + } else { + logger.logp(level, cname, method, msg, ex); + } + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java index fe274f8..0f86f37 100644 --- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java +++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java @@ -1,116 +1,116 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.jul.formatter.log; - -import org.apache.juli.logging.Log; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.concurrent.atomic.AtomicReference; - -public final class ReloadableLog { - - public static final Class<?>[] INTERFACES = new Class<?>[]{Log.class}; - - private ReloadableLog() { - // no-op - } - - public static Log newLog(final String name, final String factory) { - return Log.class.cast(Proxy.newProxyInstance( - ReloadableLog.class.getClassLoader(), INTERFACES, new ReloadableLogHandler(factory, name))); - } - - private static final class ReloadableLogHandler implements InvocationHandler { - private static final String LOG4J_IMPL = "org.apache.tomee.loader.log.Log4jLog"; - private static final String LOG4J2_IMPL = "org.apache.tomee.loader.log.Log4j2Log"; - private static final String SLF4J_IMPL = "org.apache.tomee.loader.log.Slf4jLog"; - private static final String MAVEN_IMPL = "org.apache.openejb.maven.util.TomEEMavenLog"; - - private volatile String factory; - private final String name; - private final AtomicReference<Log> delegate = new AtomicReference<>(); - private volatile boolean done = false; - - public ReloadableLogHandler(final String factory, final String name) { - this.factory = factory; - this.name = name; - initDelegate(); - } - - private Log initDelegate() { - if (done) { - return delegate.get(); - } - - try { - if (factory == null) { - final String f = TomEELog.getLoggerClazz(); - if (f != null) { - factory = f; - } - - final Log log = delegate.get(); - if (factory == null && log != null) { - return log; - } - } - switch (factory) { - case "org.apache.openejb.util.Log4jLogStreamFactory": - delegate.set(newInstance(LOG4J_IMPL)); - break; - case "org.apache.openejb.util.Log4j2LogStreamFactory": - delegate.set(newInstance(LOG4J2_IMPL)); - break; - case "org.apache.openejb.util.Slf4jLogStreamFactory": - delegate.set(newInstance(SLF4J_IMPL)); - break; - case "org.apache.openejb.maven.util.MavenLogStreamFactory": - delegate.set(newInstance(MAVEN_IMPL)); - break; - default: - delegate.set(new JULLogger(name)); - } - done = true; - } catch (final Throwable the) { - if (delegate.get() == null) { - delegate.set(new JULLogger(name)); - } - } - return delegate.get(); - } - - private Log newInstance(final String impl) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { - return Log.class.cast(Thread.currentThread() - .getContextClassLoader() - .loadClass(impl) - .getConstructor(String.class) - .newInstance(name)); - } - - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { - try { - return method.invoke(initDelegate(), args); - } catch (final InvocationTargetException ite) { - throw ite.getCause(); - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.jul.formatter.log; + +import org.apache.juli.logging.Log; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.concurrent.atomic.AtomicReference; + +public final class ReloadableLog { + + public static final Class<?>[] INTERFACES = new Class<?>[]{Log.class}; + + private ReloadableLog() { + // no-op + } + + public static Log newLog(final String name, final String factory) { + return Log.class.cast(Proxy.newProxyInstance( + ReloadableLog.class.getClassLoader(), INTERFACES, new ReloadableLogHandler(factory, name))); + } + + private static final class ReloadableLogHandler implements InvocationHandler { + private static final String LOG4J_IMPL = "org.apache.tomee.loader.log.Log4jLog"; + private static final String LOG4J2_IMPL = "org.apache.tomee.loader.log.Log4j2Log"; + private static final String SLF4J_IMPL = "org.apache.tomee.loader.log.Slf4jLog"; + private static final String MAVEN_IMPL = "org.apache.openejb.maven.util.TomEEMavenLog"; + + private volatile String factory; + private final String name; + private final AtomicReference<Log> delegate = new AtomicReference<>(); + private volatile boolean done = false; + + public ReloadableLogHandler(final String factory, final String name) { + this.factory = factory; + this.name = name; + initDelegate(); + } + + private Log initDelegate() { + if (done) { + return delegate.get(); + } + + try { + if (factory == null) { + final String f = TomEELog.getLoggerClazz(); + if (f != null) { + factory = f; + } + + final Log log = delegate.get(); + if (factory == null && log != null) { + return log; + } + } + switch (factory) { + case "org.apache.openejb.util.Log4jLogStreamFactory": + delegate.set(newInstance(LOG4J_IMPL)); + break; + case "org.apache.openejb.util.Log4j2LogStreamFactory": + delegate.set(newInstance(LOG4J2_IMPL)); + break; + case "org.apache.openejb.util.Slf4jLogStreamFactory": + delegate.set(newInstance(SLF4J_IMPL)); + break; + case "org.apache.openejb.maven.util.MavenLogStreamFactory": + delegate.set(newInstance(MAVEN_IMPL)); + break; + default: + delegate.set(new JULLogger(name)); + } + done = true; + } catch (final Throwable the) { + if (delegate.get() == null) { + delegate.set(new JULLogger(name)); + } + } + return delegate.get(); + } + + private Log newInstance(final String impl) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { + return Log.class.cast(Thread.currentThread() + .getContextClassLoader() + .loadClass(impl) + .getConstructor(String.class) + .newInstance(name)); + } + + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + try { + return method.invoke(initDelegate(), args); + } catch (final InvocationTargetException ite) { + throw ite.getCause(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java index 91ff914..ac34d3b 100644 --- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java +++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java @@ -1,80 +1,80 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.jul.formatter; - -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.junit.Test; - -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -import static org.junit.Assert.assertEquals; - -public class SimpleTomEEFormatterTest { - private static final String LINE_SEPARATOR_KEY = "line.separator"; - - @Test - public void formatNullThrown() throws Exception { - final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); - try { - final String lineSeparatorValue = "\n"; - final String logMessage = "An example log record"; - final Level level = Level.FINEST; - - System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); - final LogRecord logRecordInput = new LogRecord(level, logMessage); - logRecordInput.setThrown(null); - - final Formatter formatter = new SimpleTomEEFormatter(); - final String actualFormatOutput = formatter.format(logRecordInput); - - final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n"; - - assertEquals(expectedFormatOutput, actualFormatOutput); - } finally { - System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); - } - } - - @Test - public void formatNotNullThrown() throws Exception { - final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); - - try { - final String lineSeparatorValue = "\n"; - final String logMessage = "An example log record"; - final Level level = Level.CONFIG; - final String exceptionMessage = "An example exception"; - final Throwable thrown = new Exception(exceptionMessage); - - System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); - final LogRecord logRecordInput = new LogRecord(level, logMessage); - logRecordInput.setThrown(thrown); - - final Formatter formatter = new SimpleTomEEFormatter(); - final String actualFormatOutput = formatter.format(logRecordInput); - - final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + lineSeparatorValue + ExceptionUtils.getStackTrace(thrown); - - assertEquals(expectedFormatOutput, actualFormatOutput); - } finally { - System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); - } - } - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.jul.formatter; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.junit.Test; + +import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +import static org.junit.Assert.assertEquals; + +public class SimpleTomEEFormatterTest { + private static final String LINE_SEPARATOR_KEY = "line.separator"; + + @Test + public void formatNullThrown() throws Exception { + final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); + try { + final String lineSeparatorValue = "\n"; + final String logMessage = "An example log record"; + final Level level = Level.FINEST; + + System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); + final LogRecord logRecordInput = new LogRecord(level, logMessage); + logRecordInput.setThrown(null); + + final Formatter formatter = new SimpleTomEEFormatter(); + final String actualFormatOutput = formatter.format(logRecordInput); + + final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n"; + + assertEquals(expectedFormatOutput, actualFormatOutput); + } finally { + System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); + } + } + + @Test + public void formatNotNullThrown() throws Exception { + final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY); + + try { + final String lineSeparatorValue = "\n"; + final String logMessage = "An example log record"; + final Level level = Level.CONFIG; + final String exceptionMessage = "An example exception"; + final Throwable thrown = new Exception(exceptionMessage); + + System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue); + final LogRecord logRecordInput = new LogRecord(level, logMessage); + logRecordInput.setThrown(thrown); + + final Formatter formatter = new SimpleTomEEFormatter(); + final String actualFormatOutput = formatter.format(logRecordInput); + + final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + lineSeparatorValue + ExceptionUtils.getStackTrace(thrown); + + assertEquals(expectedFormatOutput, actualFormatOutput); + } finally { + System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty); + } + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProvider.java b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProvider.java index 0e2e7f0..4ed8b9e 100644 --- a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProvider.java +++ b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProvider.java @@ -1,46 +1,46 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.myfaces; - -import org.apache.myfaces.config.DefaultFacesConfigurationProvider; -import org.apache.myfaces.config.element.FacesConfig; -import org.apache.openejb.loader.IO; - -import javax.faces.context.ExternalContext; -import java.io.InputStream; - -public class TomEEFacesConfigurationProvider extends DefaultFacesConfigurationProvider { - @Override - public FacesConfig getWebAppFacesConfig(final ExternalContext ectx) { - final InputStream stream = ectx.getResourceAsStream("/WEB-INF/faces-config.xml"); - if (stream != null && isEmpty(stream)) { - return new org.apache.myfaces.config.impl.digester.elements.FacesConfig(); - } - // we can't just check the emptyness after the exception - // because otherwise an exception is logged because of the parser error handler - return super.getWebAppFacesConfig(ectx); - } - - private static boolean isEmpty(final InputStream stream) { - try { - final String content = IO.slurp(stream); - return content.trim().length() == 0; - } catch (final Exception e) { - return false; - } - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.myfaces; + +import org.apache.myfaces.config.DefaultFacesConfigurationProvider; +import org.apache.myfaces.config.element.FacesConfig; +import org.apache.openejb.loader.IO; + +import javax.faces.context.ExternalContext; +import java.io.InputStream; + +public class TomEEFacesConfigurationProvider extends DefaultFacesConfigurationProvider { + @Override + public FacesConfig getWebAppFacesConfig(final ExternalContext ectx) { + final InputStream stream = ectx.getResourceAsStream("/WEB-INF/faces-config.xml"); + if (stream != null && isEmpty(stream)) { + return new org.apache.myfaces.config.impl.digester.elements.FacesConfig(); + } + // we can't just check the emptyness after the exception + // because otherwise an exception is logged because of the parser error handler + return super.getWebAppFacesConfig(ectx); + } + + private static boolean isEmpty(final InputStream stream) { + try { + final String content = IO.slurp(stream); + return content.trim().length() == 0; + } catch (final Exception e) { + return false; + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProviderFactory.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProviderFactory.java b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProviderFactory.java index e37ad1f..1d098c5 100644 --- a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProviderFactory.java +++ b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigurationProviderFactory.java @@ -1,72 +1,72 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tomee.myfaces; - -import org.apache.myfaces.shared.util.ClassUtils; -import org.apache.myfaces.spi.FacesConfigurationProvider; -import org.apache.myfaces.spi.ServiceProviderFinderFactory; -import org.apache.myfaces.spi.impl.DefaultFacesConfigurationProviderFactory; - -import javax.faces.FacesException; -import javax.faces.context.ExternalContext; -import java.lang.reflect.InvocationTargetException; -import java.security.PrivilegedActionException; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -// fork to be able to not fail on empty faces-config.xml -public class TomEEFacesConfigurationProviderFactory extends DefaultFacesConfigurationProviderFactory { - public static final String FACES_CONFIGURATION_PROVIDER = FacesConfigurationProvider.class.getName(); - public static final String FACES_CONFIGURATION_PROVIDER_LIST = FacesConfigurationProvider.class.getName()+".LIST"; - public static final String FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY = FacesConfigurationProvider.class.getName() + ".INSTANCE"; - - private Logger getLogger() { - return Logger.getLogger(DefaultFacesConfigurationProviderFactory.class.getName()); - } - - @Override - public FacesConfigurationProvider getFacesConfigurationProvider(final ExternalContext externalContext) { - FacesConfigurationProvider returnValue = (FacesConfigurationProvider) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY); - if (returnValue == null) { - final ExternalContext extContext = externalContext; - try { - returnValue = resolveFacesConfigurationProviderFromService(extContext); - externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY, returnValue); - } catch (final ClassNotFoundException | NoClassDefFoundError e) { - // ignore - } catch (final InstantiationException | InvocationTargetException | IllegalAccessException e) { - getLogger().log(Level.SEVERE, "", e); - } catch (final PrivilegedActionException e) { - throw new FacesException(e); - } - } - - - return returnValue; - } - - private FacesConfigurationProvider resolveFacesConfigurationProviderFromService(final ExternalContext externalContext) - throws ClassNotFoundException, NoClassDefFoundError, InstantiationException, IllegalAccessException, InvocationTargetException, PrivilegedActionException { - List<String> classList = (List<String>) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_LIST); - if (classList == null) { - classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).getServiceProviderList(FACES_CONFIGURATION_PROVIDER); - externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_LIST, classList); - } - return ClassUtils.buildApplicationObject(FacesConfigurationProvider.class, classList, new TomEEFacesConfigurationProvider()); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomee.myfaces; + +import org.apache.myfaces.shared.util.ClassUtils; +import org.apache.myfaces.spi.FacesConfigurationProvider; +import org.apache.myfaces.spi.ServiceProviderFinderFactory; +import org.apache.myfaces.spi.impl.DefaultFacesConfigurationProviderFactory; + +import javax.faces.FacesException; +import javax.faces.context.ExternalContext; +import java.lang.reflect.InvocationTargetException; +import java.security.PrivilegedActionException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +// fork to be able to not fail on empty faces-config.xml +public class TomEEFacesConfigurationProviderFactory extends DefaultFacesConfigurationProviderFactory { + public static final String FACES_CONFIGURATION_PROVIDER = FacesConfigurationProvider.class.getName(); + public static final String FACES_CONFIGURATION_PROVIDER_LIST = FacesConfigurationProvider.class.getName()+".LIST"; + public static final String FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY = FacesConfigurationProvider.class.getName() + ".INSTANCE"; + + private Logger getLogger() { + return Logger.getLogger(DefaultFacesConfigurationProviderFactory.class.getName()); + } + + @Override + public FacesConfigurationProvider getFacesConfigurationProvider(final ExternalContext externalContext) { + FacesConfigurationProvider returnValue = (FacesConfigurationProvider) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY); + if (returnValue == null) { + final ExternalContext extContext = externalContext; + try { + returnValue = resolveFacesConfigurationProviderFromService(extContext); + externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY, returnValue); + } catch (final ClassNotFoundException | NoClassDefFoundError e) { + // ignore + } catch (final InstantiationException | InvocationTargetException | IllegalAccessException e) { + getLogger().log(Level.SEVERE, "", e); + } catch (final PrivilegedActionException e) { + throw new FacesException(e); + } + } + + + return returnValue; + } + + private FacesConfigurationProvider resolveFacesConfigurationProviderFromService(final ExternalContext externalContext) + throws ClassNotFoundException, NoClassDefFoundError, InstantiationException, IllegalAccessException, InvocationTargetException, PrivilegedActionException { + List<String> classList = (List<String>) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_LIST); + if (classList == null) { + classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).getServiceProviderList(FACES_CONFIGURATION_PROVIDER); + externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_LIST, classList); + } + return ClassUtils.buildApplicationObject(FacesConfigurationProvider.class, classList, new TomEEFacesConfigurationProvider()); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigurationProviderFactory ---------------------------------------------------------------------- diff --git a/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigurationProviderFactory b/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigurationProviderFactory index 8d058c7..e5b0160 100644 --- a/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigurationProviderFactory +++ b/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigurationProviderFactory @@ -1 +1 @@ -org.apache.tomee.myfaces.TomEEFacesConfigurationProviderFactory +org.apache.tomee.myfaces.TomEEFacesConfigurationProviderFactory http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-webaccess/src/main/java/readme.txt ---------------------------------------------------------------------- diff --git a/tomee/tomee-webaccess/src/main/java/readme.txt b/tomee/tomee-webaccess/src/main/java/readme.txt index 59bd2de..f3a6d76 100644 --- a/tomee/tomee-webaccess/src/main/java/readme.txt +++ b/tomee/tomee-webaccess/src/main/java/readme.txt @@ -1,6 +1,6 @@ -If there is at least one file (Java or not) in src/main/java, -then all files in src/main/groovy will be found. -If, however, src/main/java is empty, then src/main/groovy will be ignored. -You can get around this by placing an empty file in src/main/java just so that src/main/groovy -will be recognized. The same is true for src/test/java and src/test/groovy. +If there is at least one file (Java or not) in src/main/java, +then all files in src/main/groovy will be found. +If, however, src/main/java is empty, then src/main/groovy will be ignored. +You can get around this by placing an empty file in src/main/java just so that src/main/groovy +will be recognized. The same is true for src/test/java and src/test/groovy. This is actually a workaround for GRECLIPSE-1221. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-webaccess/src/main/webapp/app/js/view/growl.js ---------------------------------------------------------------------- diff --git a/tomee/tomee-webaccess/src/main/webapp/app/js/view/growl.js b/tomee/tomee-webaccess/src/main/webapp/app/js/view/growl.js index 7510997..a147ed9 100644 --- a/tomee/tomee-webaccess/src/main/webapp/app/js/view/growl.js +++ b/tomee/tomee-webaccess/src/main/webapp/app/js/view/growl.js @@ -1,70 +1,70 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -(function () { - 'use strict'; - - var deps = ['app/js/templates', 'lib/underscore']; - define(deps, function (templates, underscore) { - - var GrowlContainerView = Backbone.View.extend({ - el: 'body', - render: function () { - if (this.options.isRendered) { - return this; - } - - var me = this; - var container = $(templates.getValue('growl-container', {})); - me.$el.append(container[0]); - me.containerEl = $(container[0]); - - // render it only once - this.options.isRendered = true; - return this; - } - }); - var container = new GrowlContainerView({}); - - function showNotification(messageType, messageText) { - container.render(); - - var alert = $(templates.getValue('growl', { - messageType: messageType, - messageText: messageText - })); - - container.containerEl.append(alert[0]); - alert.fadeIn(); - var faceOutCallback = function () { - alert.fadeOut(null, function () { - try { - alert.remove(); - } catch (ignore) { /* noop */ - } - }); - }; - var faceOut = underscore.debounce(faceOutCallback, 5000); - faceOut(); - } - - return { - showNotification: showNotification - }; - }); -}()); +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function () { + 'use strict'; + + var deps = ['app/js/templates', 'lib/underscore']; + define(deps, function (templates, underscore) { + + var GrowlContainerView = Backbone.View.extend({ + el: 'body', + render: function () { + if (this.options.isRendered) { + return this; + } + + var me = this; + var container = $(templates.getValue('growl-container', {})); + me.$el.append(container[0]); + me.containerEl = $(container[0]); + + // render it only once + this.options.isRendered = true; + return this; + } + }); + var container = new GrowlContainerView({}); + + function showNotification(messageType, messageText) { + container.render(); + + var alert = $(templates.getValue('growl', { + messageType: messageType, + messageText: messageText + })); + + container.containerEl.append(alert[0]); + alert.fadeIn(); + var faceOutCallback = function () { + alert.fadeOut(null, function () { + try { + alert.remove(); + } catch (ignore) { /* noop */ + } + }); + }; + var faceOut = underscore.debounce(faceOutCallback, 5000); + faceOut(); + } + + return { + showNotification: showNotification + }; + }); +}()); http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-webaccess/src/test/java/readme.txt ---------------------------------------------------------------------- diff --git a/tomee/tomee-webaccess/src/test/java/readme.txt b/tomee/tomee-webaccess/src/test/java/readme.txt index 59bd2de..f3a6d76 100644 --- a/tomee/tomee-webaccess/src/test/java/readme.txt +++ b/tomee/tomee-webaccess/src/test/java/readme.txt @@ -1,6 +1,6 @@ -If there is at least one file (Java or not) in src/main/java, -then all files in src/main/groovy will be found. -If, however, src/main/java is empty, then src/main/groovy will be ignored. -You can get around this by placing an empty file in src/main/java just so that src/main/groovy -will be recognized. The same is true for src/test/java and src/test/groovy. +If there is at least one file (Java or not) in src/main/java, +then all files in src/main/groovy will be found. +If, however, src/main/java is empty, then src/main/groovy will be ignored. +You can get around this by placing an empty file in src/main/java just so that src/main/groovy +will be recognized. The same is true for src/test/java and src/test/groovy. This is actually a workaround for GRECLIPSE-1221. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/3069db0b/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/installer/InstallerServlet.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/installer/InstallerServlet.java b/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/installer/InstallerServlet.java index d5cf64b..8bf7aac 100644 --- a/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/installer/InstallerServlet.java +++ b/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/installer/InstallerServlet.java @@ -1,81 +1,81 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.tomee.webapp.installer; - -import org.apache.tomee.installer.Installer; -import org.apache.tomee.installer.Paths; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -public class InstallerServlet extends HttpServlet { - - private String escape(final String str) { - if (str == null) { - return ""; - } - return str.replaceAll("\"", "\\\\\"").replaceAll("\\\\", "\\\\\\\\"); - } - - private String getJsonList(final List<Map<String, String>> list) { - final StringBuffer sb = new StringBuffer(); - for (final Map<String, String> entry : list) { - sb.append(String.format("{\"key\": \"%s\", \"value\": \"%s\"},", - entry.get("key"), escape(entry.get("value")) - )); - } - if (!list.isEmpty()) { - sb.deleteCharAt(sb.length() - 1); - } - return "[" + sb.toString() + "]"; - } - - @Override - protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { - final ServletContext ctx = req.getServletContext(); - final String rootPath = ctx.getRealPath("/"); - final Runner installer = new Runner(new Installer(new Paths(new File(rootPath)))); - resp.setContentType("application/json"); - resp.getOutputStream().print(getJsonList(installer.execute(false))); - } - - @Override - protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { - final ServletContext ctx = req.getServletContext(); - final String rootPath = ctx.getRealPath("/"); - final Runner installer = new Runner(new Installer(new Paths(new File(rootPath)))); - if (req.getParameter("catalinaBaseDir") != null && "".equals(req.getParameter("catalinaBaseDir").trim())) { - installer.setCatalinaBaseDir(req.getParameter("catalinaBaseDir").trim()); - } - if (req.getParameter("catalinaHome") != null && "".equals(req.getParameter("catalinaHome").trim())) { - installer.setCatalinaHome(req.getParameter("catalinaHome").trim()); - } - if (req.getParameter("serverXmlFile") != null && "".equals(req.getParameter("serverXmlFile").trim())) { - installer.setServerXmlFile(req.getParameter("serverXmlFile").trim()); - } - resp.setContentType("application/json"); - resp.getOutputStream().print(getJsonList(installer.execute(true))); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomee.webapp.installer; + +import org.apache.tomee.installer.Installer; +import org.apache.tomee.installer.Paths; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class InstallerServlet extends HttpServlet { + + private String escape(final String str) { + if (str == null) { + return ""; + } + return str.replaceAll("\"", "\\\\\"").replaceAll("\\\\", "\\\\\\\\"); + } + + private String getJsonList(final List<Map<String, String>> list) { + final StringBuffer sb = new StringBuffer(); + for (final Map<String, String> entry : list) { + sb.append(String.format("{\"key\": \"%s\", \"value\": \"%s\"},", + entry.get("key"), escape(entry.get("value")) + )); + } + if (!list.isEmpty()) { + sb.deleteCharAt(sb.length() - 1); + } + return "[" + sb.toString() + "]"; + } + + @Override + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + final ServletContext ctx = req.getServletContext(); + final String rootPath = ctx.getRealPath("/"); + final Runner installer = new Runner(new Installer(new Paths(new File(rootPath)))); + resp.setContentType("application/json"); + resp.getOutputStream().print(getJsonList(installer.execute(false))); + } + + @Override + protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { + final ServletContext ctx = req.getServletContext(); + final String rootPath = ctx.getRealPath("/"); + final Runner installer = new Runner(new Installer(new Paths(new File(rootPath)))); + if (req.getParameter("catalinaBaseDir") != null && "".equals(req.getParameter("catalinaBaseDir").trim())) { + installer.setCatalinaBaseDir(req.getParameter("catalinaBaseDir").trim()); + } + if (req.getParameter("catalinaHome") != null && "".equals(req.getParameter("catalinaHome").trim())) { + installer.setCatalinaHome(req.getParameter("catalinaHome").trim()); + } + if (req.getParameter("serverXmlFile") != null && "".equals(req.getParameter("serverXmlFile").trim())) { + installer.setServerXmlFile(req.getParameter("serverXmlFile").trim()); + } + resp.setContentType("application/json"); + resp.getOutputStream().print(getJsonList(installer.execute(true))); + } +}
