pax_global_header00006660000000000000000000000064116764317170014527gustar00rootroot0000000000000052 comment=666d7c33055599659e30935daf649e49df717b39 gossip-gossip-1.8/000077500000000000000000000000001167643171700142055ustar00rootroot00000000000000gossip-gossip-1.8/README.md000066400000000000000000000076671167643171700155040ustar00rootroot00000000000000Description ----------- [SLF4j][1] Gossip Provider Features -------- * Small footprint ~75k (even smaller for gossip-bootstrap-slf4j ~20k) * Profile-based configuration * Profile activation triggers * Multiple source inputs * Console and rolling file listeners * ANSI color rendering * Internal logging * SLF4j support, helpers and utilities Synopsis -------- Need a small fast logging provider for [SLF4j][1]? Don't want to pull in the kitchen sink with [Log4j][2]? Hate [JUL][3]? If you answered yes to any (or all) of the questions above, then Gossip might be the logging provider for you! If you don't mind some additional byte-code weight, then you should probably look at [LOGBack][5]. This is the recommended SLF4j provider when byte-code size is not an issue. If you think that [JUL][3] is the best logging system ever, please exit the universe as soon as possible. License ------- [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Optional Dependencies --------------------- * [jANSI][4] - For ANSI colored output Configuration ------------- Configuration of Gossip is handled via standard property files. The [bootstrap configuration](http://github.com/jdillon/gossip/blob/master/gossip-core/src/main/resources/org/sonatype/gossip/bootstrap.properties) attempts to read: 1. META-INF/org.sonatype.gossip/config.properties (as resource) 2. -Dgossip.configuration (value of as file/url) 3. ~/.gossip/config.properties (as file) Bootstrap or Internal Logging ----------------------------- Gossip provides some minimal SLF4j components to be used: * Before the proper logging was created * In environments where only the very basic control over logging is required The gossip-bootstrap artifact contains, [org.sonatype.gossip.Log](https://github.com/jdillon/gossip/blob/master/gossip-bootstrap/src/main/java/org/sonatype/gossip/Log.java) which is a SLF4j LoggerFactory-like class that produces real SLF4j Logger instances. This can be used in cases where the configuration/installation of SLF4j is not ready yet, and can be converted to use the desired SLF4j provider using Log.configure(ILoggerFactory). Gossip internal loggers are delegates, so once the "real" SLF4j provider is configured they will be updated to use the target logging systems Logger implementations. For users that want to use standard SLF4j but need a little more control over the logging system than slf4j-simple provides, the gossip-bootstrap-slf4j module provides bindings to use the internal Log as a real SLF4j binding. Log has a few parameters controlled by system properties: * org.sonatype.gossip.Log.threshold = [TRACE|DEBUG|INFO|WARN|ERROR] * org.sonatype.gossip.Log.stream = [OUT|ERR] * org.sonatype.gossip.Log.pattern (see [PatternRenderer](https://github.com/jdillon/gossip/blob/master/gossip-bootstrap/src/main/java/org/sonatype/gossip/render/PatternRenderer.java) for details) In addition, these are configurable runtime via method calls. Gossip uses this internal logging system when booting up to provide its gossip-slf4j bindings. Extra Components ---------------- To avoid bloating out core with optional/extra components, [gossip-extra](https://github.com/jdillon/gossip/blob/master/gossip-extra) is here to hold on to stuff which you might want, but which is not required by the core. General Support and Helpers --------------------------- In addition to providing SLF4j bindings, Gossip also contains some helpers classes for using SLF4j in general. These can be found in [gossip-support](https://github.com/jdillon/gossip/blob/master/gossip-support). Building -------- ### Requirements * [Maven](http://maven.apache.org) 2+ * [Java](http://java.sun.com/) 5+ Check out and build: git clone git://github.com/jdillon/gossip.git cd gossip mvn install [1]: http://slf4j.org [2]: http://logging.apache.org/log4j [3]: http://download.oracle.com/javase/1.5.0/docs/api/java/util/logging/package-summary.html [4]: http://jansi.fusesource.org/ [5]: http://logback.qos.ch gossip-gossip-1.8/gossip-bootstrap-slf4j/000077500000000000000000000000001167643171700205445ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/pom.xml000066400000000000000000000030661167643171700220660ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-bootstrap-slf4j Gossip Bootstrap SLF4j SLF4j bindings for Gossip Bootstrap. org.sonatype.gossip gossip-bootstrap junit junit test gossip-gossip-1.8/gossip-bootstrap-slf4j/src/000077500000000000000000000000001167643171700213335ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/000077500000000000000000000000001167643171700222575ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/000077500000000000000000000000001167643171700232005ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/000077500000000000000000000000001167643171700237675ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/000077500000000000000000000000001167643171700250115ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/impl/000077500000000000000000000000001167643171700257525ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/impl/StaticLoggerBinder.java000066400000000000000000000033601167643171700323320ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.spi.LoggerFactoryBinder; import org.sonatype.gossip.Log; /** * Gossip Bootstrap logger binder for SLF4J. * * @author Jason Dillon * @since 1.6 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticLoggerBinder implements LoggerFactoryBinder { public static String REQUESTED_API_VERSION = "1.6.0"; // to avoid constant folding by the compiler, this field must *not* be final private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder(); /** * @return {@link #SINGLETON} */ public static StaticLoggerBinder getSingleton() { return SINGLETON; } private final ILoggerFactory factory = new ILoggerFactory() { public Logger getLogger(final String name) { return Log.getLogger(name); } }; public ILoggerFactory getLoggerFactory() { Log.configure(factory); return factory; } public String getLoggerFactoryClassStr() { return factory.getClass().getName(); } }gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/impl/StaticMDCBinder.java000066400000000000000000000023121167643171700315120ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.helpers.BasicMDCAdapter; import org.slf4j.spi.MDCAdapter; /** * Gossip MDC binder for SLF4J. * * @author Jason Dillon * @since 1.6 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticMDCBinder { public static final StaticMDCBinder SINGLETON = new StaticMDCBinder(); private final BasicMDCAdapter adapter = new BasicMDCAdapter(); public MDCAdapter getMDCA() { return adapter; } public String getMDCAdapterClassStr() { return adapter.getClass().getName(); } }gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/impl/StaticMarkerBinder.java000066400000000000000000000025031167643171700323320ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.IMarkerFactory; import org.slf4j.helpers.BasicMarkerFactory; import org.slf4j.spi.MarkerFactoryBinder; /** * Gossip Bootstrap marker binder for SLF4J. * * @author Jason Dillon * @since 1.6 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticMarkerBinder implements MarkerFactoryBinder { public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder(); private final IMarkerFactory factory = new BasicMarkerFactory(); public IMarkerFactory getMarkerFactory() { return factory; } public String getMarkerFactoryClassStr() { return factory.getClass().getName(); } }gossip-gossip-1.8/gossip-bootstrap-slf4j/src/main/java/org/slf4j/impl/package-info.java000066400000000000000000000013011167643171700311340ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Gossip Bootstrap SLF4j bindings. * * @since 1.6 */ package org.slf4j.impl;gossip-gossip-1.8/gossip-bootstrap/000077500000000000000000000000001167643171700175245ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/pom.xml000066400000000000000000000031131167643171700210370ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-bootstrap Gossip Bootstrap Contains just enough Gossip to allow the internal org.sonatype.gossip.Log to function. org.slf4j slf4j-api junit junit test gossip-gossip-1.8/gossip-bootstrap/src/000077500000000000000000000000001167643171700203135ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/000077500000000000000000000000001167643171700212375ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/000077500000000000000000000000001167643171700221605ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/000077500000000000000000000000001167643171700227475ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/000077500000000000000000000000001167643171700246115ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/000077500000000000000000000000001167643171700261155ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/Event.java000066400000000000000000000053061167643171700300450ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import java.io.Serializable; import java.util.Arrays; /** * Gossip logging event container. * * @author Jason Dillon * @since 1.0 */ public final class Event implements Serializable { private static final long serialVersionUID = 1; private static final boolean traceEnable; static { traceEnable = Boolean.getBoolean(Event.class.getName() + ".traceEnable"); } private final Logger logger; private final Level level; private final String message; private final Throwable cause; private final long timeStamp; private final String threadName; private final StackTraceElement[] trace; public Event(final Logger logger, final Level level, final String message, final Throwable cause) { this.logger = logger; this.level = level; this.message = message; this.cause = cause; this.timeStamp = System.currentTimeMillis(); this.threadName = Thread.currentThread().getName(); // Trace here is for where the log message came from, not where the optional cause came from this.trace = traceEnable ? new Throwable().getStackTrace() : null; } public String getName() { return logger.getName(); } public Level getLevel() { return level; } public String getMessage() { return message; } public Throwable getCause() { return cause; } public long getTimeStamp() { return timeStamp; } public String getThreadName() { return threadName; } public StackTraceElement[] getTrace() { return trace; } @Override public String toString() { return "Event{" + "logger=" + logger + ", level=" + level + ", message='" + message + '\'' + ", cause=" + cause + ", timeStamp=" + timeStamp + ", threadName='" + threadName + '\'' + ", trace=" + (trace == null ? null : Arrays.asList(trace)) + '}'; } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/Level.java000066400000000000000000000125621167643171700300350ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import org.slf4j.spi.LocationAwareLogger; /** * Gossip logging level. * * @author Jason Dillon * @since 1.6 */ public enum Level { ALL(-1000), // -1000 TRACE(LocationAwareLogger.TRACE_INT), // 0 DEBUG(LocationAwareLogger.DEBUG_INT), // 10 INFO(LocationAwareLogger.INFO_INT), // 20 WARN(LocationAwareLogger.WARN_INT), // 30 ERROR(LocationAwareLogger.ERROR_INT), // 40 OFF(1000); // 1000 public final int id; private Level(final int id) { this.id = id; } /** * @since 1.8 */ public boolean isEnabled(final Logger logger) { assert logger != null; switch (this) { case ALL: return true; case TRACE: return logger.isTraceEnabled(); case DEBUG: return logger.isDebugEnabled(); case INFO: return logger.isInfoEnabled(); case WARN: return logger.isWarnEnabled(); case ERROR: return logger.isErrorEnabled(); default: return false; } } /** * @since 1.8 */ public void log(final Logger logger, final String msg) { assert logger != null; switch (this) { case TRACE: logger.trace(msg); break; case DEBUG: logger.debug(msg); break; case INFO: logger.info(msg); break; case WARN: logger.warn(msg); break; case ERROR: logger.error(msg); break; default: throw new UnsupportedOperationException(); } } /** * @since 1.8 */ public void log(final Logger logger, final String format, final Object arg) { assert logger != null; switch (this) { case TRACE: logger.trace(format, arg); break; case DEBUG: logger.debug(format, arg); break; case INFO: logger.info(format, arg); break; case WARN: logger.warn(format, arg); break; case ERROR: logger.error(format, arg); break; default: throw new UnsupportedOperationException(); } } /** * @since 1.8 */ public void log(final Logger logger, final String format, final Object arg1, final Object arg2) { assert logger != null; switch (this) { case TRACE: logger.trace(format, arg1, arg2); break; case DEBUG: logger.debug(format, arg1, arg2); break; case INFO: logger.info(format, arg1, arg2); break; case WARN: logger.warn(format, arg1, arg2); break; case ERROR: logger.error(format, arg1, arg2); break; default: throw new UnsupportedOperationException(); } } /** * @since 1.8 */ public void log(final Logger logger, final String format, final Object... args) { assert logger != null; switch (this) { case TRACE: logger.trace(format, args); break; case DEBUG: logger.debug(format, args); break; case INFO: logger.info(format, args); break; case WARN: logger.warn(format, args); break; case ERROR: logger.error(format, args); break; default: throw new UnsupportedOperationException(); } } /** * @since 1.8 */ public void log(final Logger logger, final String msg, final Throwable cause) { assert logger != null; switch (this) { case TRACE: logger.trace(msg, cause); break; case DEBUG: logger.debug(msg, cause); break; case INFO: logger.info(msg, cause); break; case WARN: logger.warn(msg, cause); break; case ERROR: logger.error(msg, cause); break; default: throw new UnsupportedOperationException(); } } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/Log.java000066400000000000000000000134301167643171700275020ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.sonatype.gossip.LoggerDelegateFactory.LoggerDelegateAware; import org.sonatype.gossip.render.PatternRenderer; import org.sonatype.gossip.render.Renderer; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; /** * Provides internal logging support for Gossip. * * @author Jason Dillon * @since 1.0 */ public final class Log { private final static Map delegates = new HashMap(); private static final String INTERNAL_PREFIX = "org.sonatype.gossip"; private static volatile Level threshold; private static final Level internalThreshold; private static volatile Renderer renderer; private static volatile PrintStream stream; private static boolean configured; private static ILoggerFactory configuredFactory; private static enum StreamType { OUT, ERR } static { final String baseName = Log.class.getName(); String thresholdName = System.getProperty(baseName + ".threshold"); threshold = thresholdName != null ? Level.valueOf(thresholdName.toUpperCase()) : Level.WARN; String internalThresholdName = System.getProperty(baseName + ".internalThreshold"); internalThreshold = internalThresholdName != null ? Level.valueOf(internalThresholdName.toUpperCase()) : Level.WARN; // Use a pattern renderer by default, user can install whatever they want later PatternRenderer renderer = new PatternRenderer(); String pattern = System.getProperty(baseName + ".pattern", PatternRenderer.DEFAULT_PATTERN); renderer.setPattern(pattern); Log.renderer = renderer; StreamType streamType = StreamType.OUT; String streamName = System.getProperty(baseName + ".stream"); if (streamName != null) { streamType = StreamType.valueOf(streamName.toUpperCase()); } switch (streamType) { case ERR: stream = System.err; break; default: case OUT: stream = System.out; break; } } /** * @since 1.6 */ public static Level getThreshold() { return threshold; } /** * @since 1.6 */ public static void setThreshold(final Level threshold) { if (threshold == null) { throw new NullPointerException(); } Log.threshold = threshold; } /** * @since 1.6 */ public static Renderer getRenderer() { return renderer; } /** * @since 1.6 */ public static void setRenderer(final Renderer renderer) { if (renderer == null) { throw new NullPointerException(); } Log.renderer = renderer; } /** * @since 1.6 */ public static PrintStream getStream() { return stream; } /** * @since 1.6 */ public static void setStream(final PrintStream stream) { if (stream == null) { throw new NullPointerException(); } Log.stream = stream; } public static synchronized void configure(final ILoggerFactory factory) { if (factory == null) { throw new NullPointerException(); } if (!configured) { configuredFactory = factory; // Replace all logger delegates with real loggers for (Map.Entry entry : delegates.entrySet()) { Logger logger = configuredFactory.getLogger(entry.getKey()); entry.getValue().setDelegate(logger); } delegates.clear(); configured = true; } } public static synchronized Logger getLogger(final String name) { assert name != null; // Gossip loggers will always be internal if (name.startsWith(INTERNAL_PREFIX)) { return new LoggerImpl(name); } if (!configured) { Logger delegate = LoggerDelegateFactory.create(new LoggerImpl(name)); delegates.put(name, (LoggerDelegateAware)delegate); return delegate; } return configuredFactory.getLogger(name); } public static Logger getLogger(final Class type) { assert type != null; return getLogger(type.getName()); } private static class LoggerImpl extends LoggerSupport { private LoggerImpl(final String name) { super(name); } @Override protected boolean isEnabled(final Level l) { assert l != null; Level threshold = getThreshold(); if (getName().startsWith(INTERNAL_PREFIX)) { threshold = Log.internalThreshold; } return threshold.id <= l.id; } @Override protected void doLog(final Event event) { final PrintStream out = getStream(); synchronized (out) { out.print(getRenderer().render(event)); out.flush(); } } } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/LoggerDelegateFactory.java000066400000000000000000000046011167643171700331630ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import org.slf4j.Marker; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** * Creates {@link Logger} delegates. * * @author Jason Dillon * @since 1.6 */ public final class LoggerDelegateFactory { /** * Returns {@link Logger} instances delegating to the given logger. Returned instances also implement {@link LoggerDelegateAware} * to allow inspection/replacement of the delegate logger. */ public static Logger create(final Logger target) { return (Logger) Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[]{ Logger.class, LoggerDelegateAware.class }, new DelegateHandler(target)); } public static interface LoggerDelegateAware { Logger getDelegate(); void setDelegate(Logger delegate); } private static class DelegateHandler implements InvocationHandler, LoggerDelegateAware { private Logger delegate; private DelegateHandler(final Logger delegate) { setDelegate(delegate); } public Logger getDelegate() { return delegate; } public void setDelegate(final Logger delegate) { if (delegate == null) { throw new NullPointerException(); } this.delegate = delegate; } public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getDeclaringClass() == LoggerDelegateAware.class) { return method.invoke(this, args); } return method.invoke(getDelegate(), args); } } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/LoggerSupport.java000066400000000000000000000152761167643171700316070ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import org.slf4j.helpers.FormattingTuple; import org.slf4j.helpers.MarkerIgnoringBase; import org.slf4j.helpers.MessageFormatter; import java.io.Serializable; import static org.sonatype.gossip.Level.DEBUG; import static org.sonatype.gossip.Level.ERROR; import static org.sonatype.gossip.Level.INFO; import static org.sonatype.gossip.Level.TRACE; import static org.sonatype.gossip.Level.WARN; /** * Support for the Gossip {@link Logger} implementation. * * @author Jason Dillon * @since 1.0 */ public abstract class LoggerSupport extends MarkerIgnoringBase implements org.slf4j.Logger, Serializable { private static final long serialVersionUID = 1; protected LoggerSupport(final String name) { this.name = name; } protected LoggerSupport() { // nop } @Override public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getClass().getSimpleName()); if (name != null) { buff.append("[").append(name).append("]"); } buff.append(String.format("@%x", System.identityHashCode(this))); return buff.toString(); } @Override public final int hashCode() { if (name == null) { return System.identityHashCode(this); } return name.hashCode(); } @Override public final boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } Logger that = (Logger) obj; return !(name != null ? !name.equals(that.getName()) : that.getName() != null); } protected abstract boolean isEnabled(final Level level); protected abstract void doLog(Event event); protected void doLog(final Level level, final String message, final Throwable cause) { doLog(new Event(this, level, message, cause)); } private void log(final Level level, final FormattingTuple tuple) { doLog(level, tuple.getMessage(), tuple.getThrowable()); } private void log(final Level level, final String msg) { if (isEnabled(level)) { doLog(level, msg, null); } } private void log(final Level level, final String format, final Object arg) { if (isEnabled(level)) { log(level, MessageFormatter.format(format, arg)); } } private void log(final Level level, final String format, final Object arg1, final Object arg2) { if (isEnabled(level)) { log(level, MessageFormatter.format(format, arg1, arg2)); } } private void log(final Level level, final String format, final Object[] args) { if (isEnabled(level)) { log(level, MessageFormatter.arrayFormat(format, args)); } } // // TRACE // public final boolean isTraceEnabled() { return isEnabled(TRACE); } public final void trace(final String msg) { log(TRACE, msg); } public final void trace(final String format, final Object arg) { log(TRACE, format, arg); } public final void trace(final String format, final Object arg1, final Object arg2) { log(TRACE, format, arg1, arg2); } public final void trace(final String format, final Object... args) { log(TRACE, format, args); } public final void trace(final String msg, final Throwable cause) { log(TRACE, msg, cause); } // // DEBUG // public final boolean isDebugEnabled() { return isEnabled(DEBUG); } public final void debug(final String msg) { log(DEBUG, msg); } public final void debug(final String format, final Object arg) { log(DEBUG, format, arg); } public final void debug(final String format, final Object arg1, final Object arg2) { log(DEBUG, format, arg1, arg2); } public final void debug(final String format, final Object... args) { log(DEBUG, format, args); } public final void debug(final String msg, final Throwable cause) { log(DEBUG, msg, cause); } // // INFO // public final boolean isInfoEnabled() { return isEnabled(INFO); } public final void info(final String msg) { log(INFO, msg); } public final void info(final String format, final Object arg) { log(INFO, format, arg); } public final void info(final String format, final Object arg1, final Object arg2) { log(INFO, format, arg1, arg2); } public final void info(final String format, final Object... args) { log(INFO, format, args); } public final void info(final String msg, final Throwable cause) { log(INFO, msg, cause); } // // WARN // public final boolean isWarnEnabled() { return isEnabled(WARN); } public final void warn(final String msg) { log(WARN, msg); } public final void warn(final String format, final Object arg) { log(WARN, format, arg); } public final void warn(final String format, final Object... args) { log(WARN, format, args); } public final void warn(final String format, final Object arg1, final Object arg2) { log(WARN, format, arg1, arg2); } public final void warn(final String msg, final Throwable cause) { log(WARN, msg, cause); } // // ERROR // public final boolean isErrorEnabled() { return isEnabled(ERROR); } public final void error(final String msg) { log(ERROR, msg); } public final void error(final String format, final Object arg) { log(ERROR, format, arg); } public final void error(final String format, final Object arg1, final Object arg2) { log(ERROR, format, arg1, arg2); } public final void error(final String format, final Object... args) { log(ERROR, format, args); } public final void error(final String msg, final Throwable cause) { log(ERROR, msg, cause); } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/render/000077500000000000000000000000001167643171700273745ustar00rootroot00000000000000gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/render/PatternRenderer.java000066400000000000000000000224311167643171700333450ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.render; import org.sonatype.gossip.Event; /** * Renders events based on a pattern. * *

* Pattern syntax: *

 *   ((token)*(text)*)+
 * 
* *

Tokens:

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
%%A percent sign
%dTime-stamp
%cShort logger name
%CFull logger name
%lLevel
%tThread name
%mMessage
%xCause
%nNewline
%TQualified class name of the caller issuing the logging request
%MThe method name where the logging request was issued
%FThe file name where the logging request was issued
%LThe line number from where the logging request was issued
* * @author Jason Dillon * @since 1.0 */ public class PatternRenderer implements Renderer { private static final String NEWLINE = System.getProperty("line.separator"); /** * @since 1.6 */ public static final String DEFAULT_PATTERN = "[%l] %c - %m%n%x"; private String pattern; public PatternRenderer() { this(DEFAULT_PATTERN); } /** * @since 1.6 */ public PatternRenderer(final String pattern) { setPattern(pattern); } @Override public String toString() { return "PatternRenderer{" + "pattern=" + pattern + '}'; } public String getPattern() { return pattern; } public void setPattern(final String pattern) { if (pattern == null) { throw new NullPointerException(); } this.pattern = pattern; } public String render(final Event event) { if (event == null) { throw new NullPointerException(); } final String _pattern = getPattern(); final StringBuilder buff = new StringBuilder(); int len = _pattern.length(); for (int i=0; i < len; i++) { char c = _pattern.charAt(i); if (c == '%') { if (i + 1 >= len) { throw new IllegalArgumentException("Invalid pattern: " + _pattern); } char t = _pattern.charAt(++i); switch (t) { case '%': buff.append(t); break; case 'd': renderTimeStamp(event, buff); break; case 'c': renderName(event, buff, true); break; case 'C': renderName(event, buff, false); break; case 'l': renderLevel(event, buff); break; case 't': renderThreadName(event, buff); break; case 'T': renderTraceClass(event, buff); break; case 'F': renderTraceFile(event, buff); break; case 'M': renderTraceMethod(event, buff); break; case 'L': renderTraceLine(event, buff); break; case 'm': renderMessage(event, buff); break; case 'x': renderCause(event, buff); break; // TODO: Maybe try and add MDC support here? Probably %X{foo} case 'n': renderNewLine(buff); break; default: throw new IllegalArgumentException("Invalid pattern token: " + t); } } else { buff.append(c); } } return buff.toString(); } protected void renderNewLine(final StringBuilder buff) { assert buff != null; buff.append(NEWLINE); } protected void renderTimeStamp(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; buff.append(event.getTimeStamp()); } protected void renderLevel(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; buff.append(event.getLevel().name()); } protected void renderName(final Event event, final StringBuilder buff, final boolean shortName) { assert event != null; assert buff != null; String name = event.getName(); if (name != null) { if (shortName) { int i = name.lastIndexOf("."); if (i != -1) { name = name.substring(i + 1, name.length()); } } buff.append(name); } else { buff.append(""); } } protected void renderThreadName(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; buff.append(event.getThreadName()); } protected void renderMessage(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; buff.append(event.getMessage()); } protected void renderCause(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; Throwable cause = event.getCause(); if (cause != null) { buff.append(cause); buff.append(NEWLINE); while (cause != null) { for (StackTraceElement e : cause.getStackTrace()) { buff.append(" at ").append(e.getClassName()).append(".").append(e.getMethodName()); buff.append(" (").append(getLocation(e)).append(")"); buff.append(NEWLINE); } cause = cause.getCause(); if (cause != null) { buff.append("Caused by ").append(cause.getClass().getName()).append(": "); buff.append(cause.getMessage()); buff.append(NEWLINE); } } } } protected void renderTraceFile(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; StackTraceElement[] trace = event.getTrace(); if (trace != null) { buff.append(trace[0].getFileName()); } } protected void renderTraceClass(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; StackTraceElement[] trace = event.getTrace(); if (trace != null) { buff.append(trace[0].getClassName()); } } protected void renderTraceMethod(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; StackTraceElement[] trace = event.getTrace(); if (trace != null) { buff.append(trace[0].getMethodName()); } } protected void renderTraceLine(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; StackTraceElement[] trace = event.getTrace(); if (trace != null) { buff.append(trace[0].getLineNumber()); } } protected String getLocation(final StackTraceElement e) { assert e != null; if (e.isNativeMethod()) { return "Native Method"; } else if (e.getFileName() == null) { return "Unknown Source"; } else if (e.getLineNumber() >= 0) { return String.format("%s:%s", e.getFileName(), e.getLineNumber()); } else { return e.getFileName(); } } }gossip-gossip-1.8/gossip-bootstrap/src/main/java/org/sonatype/gossip/render/Renderer.java000066400000000000000000000017521167643171700320120ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.render; import org.sonatype.gossip.Event; /** * Log event renderer. * * @author Jason Dillon * @since 1.0 */ public interface Renderer { /** * Render an event as a string. * * @param event The event to render. * @return The rendered event. */ String render(Event event); }gossip-gossip-1.8/gossip-core/000077500000000000000000000000001167643171700164375ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/pom.xml000066400000000000000000000042611167643171700177570ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-core Gossip Core org.sonatype.gossip gossip-bootstrap junit junit test org.codehaus.modello modello-maven-plugin src/main/mdo/gossip.mdo 1.0.0 java xsd gossip-gossip-1.8/gossip-core/src/000077500000000000000000000000001167643171700172265ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/000077500000000000000000000000001167643171700201525ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/000077500000000000000000000000001167643171700210735ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/000077500000000000000000000000001167643171700216625ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/000077500000000000000000000000001167643171700235245ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/000077500000000000000000000000001167643171700250305ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/ConfigurationException.java000066400000000000000000000024061167643171700323630ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; /** * Thrown to indicate a failure has occurred while configuring Gossip. * * @author Jason Dillon * @since 1.0 */ public class ConfigurationException extends RuntimeException { ///CLOVER:OFF private static final long serialVersionUID = 1; public ConfigurationException() {} public ConfigurationException(final String message) { super(message); } public ConfigurationException(final String message, final Throwable cause) { super(message, cause); } public ConfigurationException(final Throwable cause) { super(cause); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/Configurator.java000066400000000000000000000163051167643171700303420ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import org.sonatype.gossip.listener.ConsoleListener; import org.sonatype.gossip.model.ListenerNode; import org.sonatype.gossip.model.LoggerNode; import org.sonatype.gossip.model.Model; import org.sonatype.gossip.model.ModelMerger; import org.sonatype.gossip.model.ProfileNode; import org.sonatype.gossip.model.SourceNode; import org.sonatype.gossip.model.TriggerNode; import org.sonatype.gossip.source.Source; import org.sonatype.gossip.source.URLSource; import org.sonatype.gossip.trigger.AlwaysTrigger; import java.net.URL; import java.util.HashMap; import java.util.Map; /** * Configures Gossip. * * @author Jason Dillon * @since 1.0 */ public final class Configurator { private static final String BOOTSTRAP_RESOURCE = "bootstrap.properties"; private final Logger log = Log.getLogger(getClass()); public EffectiveProfile configure() { log.debug("Configuring"); EffectiveProfile profile = new EffectiveProfile(); try { // Load the bootstrap configuration Model bootstrap = loadBootstrap(); // Resolve sources and merge Model config = resolve(bootstrap); // Configure the active profiles configureActiveProfiles(profile, config); } catch (Throwable t) { log.error("Failed to configure; using fall-back provider", t); } if (profile.getProfiles().isEmpty()) { log.debug("No profiles were activated; using fall-back"); ProfileNode p = createFallbackProfile(); profile.addProfile(p); } return profile; } private Model resolve(final Model bootstrap) { assert bootstrap != null; Model config = new Model(); ModelMerger merger = new ModelMerger(); Map hints = new HashMap(); for (SourceNode source : bootstrap.getSources()) { try { Source loader = source.create(); merger.merge(config, loader.load(), true, hints); } catch (Exception e) { log.error("Failed to resolve source: " + source, e); } } resolveIncludes(config); return config; } private void resolveIncludes(final Model model) { assert model != null; // Process profile includes for (ProfileNode profile : model.getProfiles()) { log.trace("Processing includes for: {}", profile); for (String include : profile.getIncludes()) { ProfileNode includedProfile = model.findProfile(include); if (includedProfile == null) { log.warn("Unable to include non-existent profile: {}", includedProfile); continue; } log.debug("Including {} profile into: {}", include, profile); // FIXME: This should really be in ModelMerger for (Object name : includedProfile.getProperties().keySet()) { if (!profile.getProperties().containsKey(name)) { profile.getProperties().put(name, includedProfile.getProperties().get(name)); log.trace("Appending property: {}", name); } } for (LoggerNode logger : includedProfile.getLoggers()) { if (!profile.getLoggers().contains(logger)) { profile.getLoggers().add(logger); log.trace("Appending logger: {}", logger); } } for (ListenerNode listener : includedProfile.getListeners()) { if (!profile.getListeners().contains(listener)) { profile.getListeners().add(listener); log.trace("Appending listener: {}", listener); } } for (TriggerNode trigger : includedProfile.getTriggers()) { if (!profile.getTriggers().contains(trigger)) { profile.getTriggers().add(trigger); log.trace("Appending trigger: {}", trigger); } } } } } private void configureActiveProfiles(final EffectiveProfile profile, final Model model) throws Exception { assert profile != null; assert model != null; log.debug("Activating profiles"); for (ProfileNode node : model.getProfiles()) { if (isProfileActive(node)) { log.debug("Active profile: {}", node); profile.addProfile(node); } } // If no profiles were activated, look for a "default" profile, if it exists then use it if (profile.getProfiles().isEmpty()) { ProfileNode node = model.findProfile("default"); if (node != null) { log.debug("Using default profile: {}", node); profile.addProfile(node); } } } private boolean isProfileActive(final ProfileNode profile) { assert profile != null; log.trace("Checking if profile is active: {}", profile); for (TriggerNode trigger : profile.getTriggers()) { try { if (trigger.create().isActive()) { log.debug("Active trigger: {}", trigger); return true; } } catch (Exception e) { log.error("Failed to evaluate trigger: " + trigger, e); } } return false; } private ProfileNode createFallbackProfile() { ProfileNode p = new ProfileNode(); p.setName("fall-back"); TriggerNode trigger = new TriggerNode(); trigger.setType(AlwaysTrigger.class); p.getTriggers().add(trigger); ListenerNode listenerNode = new ListenerNode(); listenerNode.setType(ConsoleListener.class); p.getListeners().add(listenerNode); return p; } private Model loadBootstrap() throws Exception { URL url = getClass().getResource(BOOTSTRAP_RESOURCE); // This should really never happen unless something is messed up, but don't toss an exception, let the fallback provider kick-in assert url != null : "Unable to load bootstrap resource: " + BOOTSTRAP_RESOURCE; log.trace("Using bootstrap URL: {}", url); URLSource source = new URLSource(); source.setUrl(url); return source.load(); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/EffectiveProfile.java000066400000000000000000000067301167643171700311220ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.Logger; import org.sonatype.gossip.listener.Listener; import org.sonatype.gossip.model.ListenerNode; import org.sonatype.gossip.model.LoggerNode; import org.sonatype.gossip.model.ProfileNode; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Effective profile. This handles what is currently configured and activated. * The meat of event dispatching is done here. * * @author Jason Dillon * @since 1.0 */ public final class EffectiveProfile { private static final Logger log = Log.getLogger(EffectiveProfile.class); private final List profiles = new ArrayList(); private Map loggers; public List getProfiles() { return profiles; } public void addProfile(final ProfileNode node) { assert node != null; getProfiles().add(node); } public Map loggers() { if (loggers == null) { log.trace("Loading effective logger table"); Map map = new HashMap(); for (ProfileNode profile : getProfiles()) { for (LoggerNode node : profile.getLoggers()) { map.put(node.getName(), node); } } this.loggers = map; } return loggers; } private Listener[] listeners; /** * @since 2.5 */ public Listener[] getListeners() { if (this.listeners == null) { log.trace("Building listener dispatch table"); List listeners = new ArrayList(); for (ProfileNode profile : getProfiles()) { for (ListenerNode listener : profile.getListeners()) { try { log.trace("Adding listener: {}", listener); listeners.add(listener.create()); } catch (Exception e) { log.error("Failed to create listener: " + listener, e); } } } this.listeners = listeners.toArray(new Listener[listeners.size()]); } return this.listeners; } public void dispatch(final Event event) { assert event != null; Listener[] listeners = getListeners(); log.trace("Dispatching event to {} listener(s): {}", listeners.length, event); int i=0; for (Listener listener : listeners) { log.trace("Dispatching to listener[{}]: {}", i++, listener); try { listener.onEvent(event); } catch (Throwable t) { log.error("Listener execution failed; ignoring", t); } } } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/Gossip.java000066400000000000000000000213701167643171700271420ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.sonatype.gossip.model.LoggerNode; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * Factory to produce Gossip {@link Logger} instances. * * @author Jason Dillon * @since 1.0 */ public final class Gossip implements ILoggerFactory { private static final Logger log = Log.getLogger(Gossip.class); private static final Gossip INSTANCE = new Gossip(); public static Gossip getInstance() { return INSTANCE; } /** * Map {@link Logger} names to {@link LoggerImpl} or {@link ProvisionNode}. */ private final Map loggers = new HashMap(); private final LoggerImpl root = new LoggerImpl(LoggerImpl.ROOT_NAME, Level.WARN); private final EffectiveProfile effectiveProfile; private Gossip() { if (log.isTraceEnabled()) { //noinspection ThrowableInstanceNeverThrown log.trace("Initializing", new Throwable("INIT MARKER")); } effectiveProfile = new Configurator().configure(); prime(); } public LoggerImpl getRoot() { return root; } public EffectiveProfile getEffectiveProfile() { return effectiveProfile; } private void prime() { log.trace("Priming"); // Include the root logger in the list loggers.put(root.getName(), root); // Prime the loggers we have configured for (Map.Entry entry : getEffectiveProfile().loggers().entrySet()) { String name = entry.getKey(); LoggerNode node = entry.getValue(); LoggerImpl logger; if (LoggerImpl.ROOT_TOKEN.equals(name)) { logger = root; } else { logger = getLogger(name); } logger.setLevel(node.asLevel()); } } public LoggerImpl getLogger(final String name) { if (name == null) { throw new NullPointerException(); } LoggerImpl logger; synchronized (loggers) { Object obj = loggers.get(name); if (obj == null) { logger = new LoggerImpl(name); loggers.put(name, logger); log.trace("Created logger: {}", logger); updateParents(logger); } else if (obj instanceof ProvisionNode) { ProvisionNode node = (ProvisionNode)obj; logger = new LoggerImpl(name); loggers.put(name, logger); log.trace("Replaced provision node with logger: {}", logger); updateChildren(node, logger); updateParents(logger); } else if (obj instanceof LoggerImpl) { logger = (LoggerImpl)obj; log.trace("Using cached logger: {}", logger); } else { throw new InternalError(); } } return logger; } /** * @since 1.4 */ public Collection getLoggerNames() { synchronized (loggers) { return Collections.unmodifiableSet(loggers.keySet()); } } public final class LoggerImpl extends LoggerSupport implements Loggerish { public static final String ROOT_TOKEN="*"; public static final String ROOT_NAME=ROOT_LOGGER_NAME; private Level level; private Level cachedLevel; private LoggerImpl parent; private LoggerImpl(final String name, final Level level) { super(name); this.level = level; } private LoggerImpl(final String name) { this(name, null); } public LoggerImpl getParent() { return parent; } public Level getLevel() { return level; } public void setLevel(final Level level) { // level can be null this.level = level; this.cachedLevel = level; invalidateCache(); } private void invalidateCache() { // Update any children's cached level, forcing them to re-evaluate and cache if needed for (Map.Entry entry : loggers.entrySet()) { if (entry.getKey().startsWith(getName() + ".")) { Object obj = entry.getValue(); if (obj instanceof LoggerImpl) { LoggerImpl logger = (LoggerImpl)obj; if (logger.level == null) { logger.cachedLevel = null; } } } } } public Level findEffectiveLevel() { for (LoggerImpl logger = this; logger != null; logger=logger.parent) { if (logger.level != null) { return logger.level; } } return Level.OFF; } public Level getEffectiveLevel() { // If we don't have a cached level, then find and cache it if (cachedLevel == null) { cachedLevel = findEffectiveLevel(); } return cachedLevel; } @Override protected boolean isEnabled(final Level level) { assert level != null; return getEffectiveLevel().id <= level.id; } @Override protected void doLog(final Event event) { getEffectiveProfile().dispatch(event); } @Override public String toString() { return "Logger[" + getName() + "]@" + System.identityHashCode(this); } } // // NOTE: The following was borrowed and massaged from Log4j // /** * Marker interface for the {@link #loggers} map. */ private interface Loggerish { // Empty } private final class ProvisionNode extends ArrayList implements Loggerish { private ProvisionNode(final LoggerImpl logger) { assert logger != null; add(logger); } } private void updateParents(final LoggerImpl logger) { assert logger != null; String name = logger.getName(); int length = name.length(); boolean parentFound = false; // if name = "w.x.y.z", loop through "w.x.y", "w.x" and "w", but not "w.x.y.z" for (int i = name.lastIndexOf('.', length - 1); i >= 0; i = name.lastIndexOf('.', i - 1)) { String key = name.substring(0, i); Object obj = loggers.get(key); // Create a provision node for a future parent. if (obj == null) { ProvisionNode node = new ProvisionNode(logger); loggers.put(key, node); } else if (obj instanceof LoggerImpl) { parentFound = true; logger.parent = (LoggerImpl) obj; // no need to update the ancestors of the closest ancestor break; } else if (obj instanceof ProvisionNode) { ((ProvisionNode) obj).add(logger); } else { throw new InternalError(); } } // If we could not find any existing parents, then link with root. if (!parentFound) { logger.parent = root; } } private void updateChildren(final ProvisionNode node, final LoggerImpl logger) { assert node != null; assert logger != null; final int last = node.size(); for (int i = 0; i < last; i++) { LoggerImpl l = (LoggerImpl) node.get(i); // Unless this child already points to a correct (lower) parent, // make cat.parent point to l.parent and l.parent to cat. if (!l.parent.getName().startsWith(logger.getName())) { logger.parent = l.parent; l.parent = logger; } } } } gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/MissingPropertyException.java000066400000000000000000000021171167643171700327310ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; /** * Thrown to indicate a required configuration property is missing. * * @author Jason Dillon * @since 1.0 */ public class MissingPropertyException extends ConfigurationException { ///CLOVER:OFF private static final long serialVersionUID = 1; public MissingPropertyException(final String name) { super(String.format("Missing required configuration property: %s", name)); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/000077500000000000000000000000001167643171700266555ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/ConsoleListener.java000066400000000000000000000036771167643171700326450ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.listener; import org.sonatype.gossip.Event; import java.io.PrintStream; /** * Writes events to console. * * @author Jason Dillon * @since 1.0 */ public class ConsoleListener extends ListenerSupport { public static enum Stream { OUT, ERR } private Stream stream; public ConsoleListener() { setStream(Stream.OUT); } public Stream getStream() { return stream; } public void setStream(final Stream stream) { assert stream != null; this.stream = stream; } public void onEvent(final Event event) { assert event != null; if (!isLoggable(event)) return; Stream stream = getStream(); PrintStream out; switch (stream) { case OUT: out = System.out; break; case ERR: out = System.err; break; default: throw new InternalError(); } synchronized (out) { out.print(render(event)); out.flush(); } } @Override public String toString() { return getClass().getSimpleName() + "{" + "stream=" + stream + ", threshold=" + getThreshold() + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/CountingWriter.java000066400000000000000000000031241167643171700325030ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.listener; import java.io.FilterWriter; import java.io.IOException; import java.io.Writer; /** * Writer which counts the number of bytes written. * * @author Jason Dillon * @since 1.0 */ public class CountingWriter extends FilterWriter { private long count = 0; public CountingWriter(final Writer out) { super(out); } public long size() { return count; } public void reset() { count = 0; } @Override public void write(final int c) throws IOException { super.write(c); count++; } @Override public void write(final char[] cbuf, final int off, final int len) throws IOException { super.write(cbuf, off, len); count += len - off; } @Override public void write(final String str, final int off, final int len) throws IOException { super.write(str, off, len); count += str.length(); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/FileListener.java000066400000000000000000000107761167643171700321200ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.listener; import org.sonatype.gossip.Event; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Writes events to a file. * * @author Jason Dillon * @since 1.0 */ public class FileListener extends ListenerSupport { public static final int DEFAULT_BUFFER_SIZE = 8192; private static final Pattern PATTERN = Pattern.compile("\\$\\{([^}]+)\\}"); private File file; private boolean append; private int bufferSize = DEFAULT_BUFFER_SIZE; private RollingStrategy rollingStrategy; private CountingWriter writer; public File getFile() { return file; } public void setFile(final File file) { this.file = file; } public void setFile(final String fileName) { assert fileName != null; setFile(new File(evaluate(fileName.trim()))); } public boolean isAppend() { return append; } public void setAppend(final boolean append) { this.append = append; } public int getBufferSize() { return bufferSize; } public void setBufferSize(final int n) { this.bufferSize = n; } public RollingStrategy getRollingStrategy() { return rollingStrategy; } public void setRollingStrategy(final RollingStrategy s) { this.rollingStrategy = s; } public CountingWriter getWriter() { return writer; } protected CountingWriter createWriter() throws IOException { if (writer != null) { writer.close(); } File file = getFile(); File dir = file.getParentFile(); if (dir != null && !dir.isDirectory() && !dir.mkdirs()) { log.warn("Unable to create directory structure for: {}", file); } log.trace("Creating writer for file: {}", file); Writer writer = new FileWriter(file, isAppend()); // Maybe buffer if (bufferSize > 0) { log.trace("Using buffer size: {}", bufferSize); writer = new BufferedWriter(writer, bufferSize); } return new CountingWriter(writer); } public void onEvent(final Event event) throws Exception { assert event != null; if (!isLoggable(event)) return; if (writer == null) { writer = createWriter(); } else { // Maybe roll the file if (rollingStrategy != null && rollingStrategy.roll(this)) { // Rebuild the writer after a roll writer = createWriter(); } } synchronized (writer) { writer.write(render(event)); writer.flush(); } } protected String evaluate(String input) { if (input != null) { Matcher matcher = PATTERN.matcher(input); while (matcher.find()) { Object rep = getProperty(matcher.group(1)); if (rep != null) { input = input.replace(matcher.group(0), rep.toString()); matcher.reset(input); } } } return input; } protected Object getProperty(final String name) { assert name != null; return System.getProperty(name); } @Override public String toString() { return getClass().getSimpleName() + "{" + "append=" + append + ", bufferSize=" + bufferSize + ", file=" + file + ", rollingStrategy=" + rollingStrategy + ", threshold=" + getThreshold() + '}'; } /** * Interface for file rolling strategy's. */ public static interface RollingStrategy { boolean roll(FileListener listener); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/Listener.java000066400000000000000000000020021167643171700312770ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.listener; import org.sonatype.gossip.Event; /** * {@link Event} listener. * * @author Jason Dillon * @since 1.0 */ public interface Listener { /** * Handle an event. * * @param event The event to handle. * @throws Exception Failed to handled event. */ void onEvent(Event event) throws Exception; }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/ListenerSupport.java000066400000000000000000000046411167643171700327070ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.listener; import org.slf4j.Logger; import org.sonatype.gossip.Event; import org.sonatype.gossip.Gossip; import org.sonatype.gossip.Level; import org.sonatype.gossip.Log; import org.sonatype.gossip.render.PatternRenderer; import org.sonatype.gossip.render.Renderer; /** * Support for {@link Listener} implementations. * * @author Jason Dillon * @since 1.0 */ public abstract class ListenerSupport implements Listener { protected final Logger log = Log.getLogger(getClass()); private Renderer renderer; private Level threshold = Level.TRACE; public Renderer getRenderer() { return renderer; } protected Renderer createRenderer() { return new PatternRenderer(); } public void setRenderer(final Renderer renderer) { this.renderer = renderer; } public Level getThreshold() { return threshold; } public void setThreshold(final Level threshold) { this.threshold = threshold; } public void setThreshold(final String threshold) { assert threshold != null; setThreshold(Level.valueOf(threshold)); } /** * Returns false if the given event does not match the threshold. * * @param event The event to evaluate.1 * @return True if the event is loggable. */ protected final boolean isLoggable(final Event event) { assert event != null; return threshold == null || event.getLevel().id >= threshold.id; } protected String render(final Event event) { assert event != null; Renderer renderer = getRenderer(); if (renderer == null) { renderer = createRenderer(); setRenderer(renderer); } return renderer.render(event); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/listener/package-info.java000066400000000000000000000012771167643171700320530ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Event listeners. * * @since 1.0 */ package org.sonatype.gossip.listener;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/000077500000000000000000000000001167643171700261305ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/ComponentFactory.java000066400000000000000000000064721167643171700322760ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model; import org.slf4j.Logger; import org.sonatype.gossip.Log; import org.sonatype.gossip.listener.Listener; import org.sonatype.gossip.model.io.props.Context; import org.sonatype.gossip.model.io.props.ContextConfigurator; import org.sonatype.gossip.source.Source; import org.sonatype.gossip.trigger.Trigger; /** * Constructs components from model nodes. * * @author Jason Dillon * @since 1.0 */ public class ComponentFactory { private static Logger log = Log.getLogger(ComponentFactory.class); public static Source create(final SourceNode node) throws Exception { return (Source) build(node); } public static Trigger create(final TriggerNode node) throws Exception { return (Trigger) build(node); } public static Listener create(final ListenerNode node) throws Exception { return (Listener) build(node); } // // Helpers // private static Class loadClass(final String className) throws ClassNotFoundException { assert className != null; Class type; try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); log.trace("Using class-loader: {}", cl); if (cl == null) { // HACK: Sometimes the TCL is null (ick) but this probably not right either cl = ClassLoader.getSystemClassLoader(); } type = cl.loadClass(className); } catch (ClassNotFoundException e) { // HACK: This is needed as a fallback on Maven 2.0.x and 2.2.x which does not have the TCL setup as expected log.trace("Falling back to Class.forName..."); type = Class.forName(className); } log.trace("Loaded class: {}", type); return type; } private static Object build(final FactoryNode node) throws Exception { assert node != null; return build(node.getType(), node.getConfiguration()); } public static Object build(final String className, final Object config) throws Exception { assert className != null; Class type = loadClass(className); Object obj = type.newInstance(); if (config != null) { // // TODO: Support the Xpp3 configuration... w/o requiring it on the classpath for this class to function // if (config instanceof Context) { new ContextConfigurator().configure(obj, (Context)config); } else { log.error("Unsupported configuration type: " + config.getClass().getName()); } } log.trace("Created: {}", obj); return obj; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/ModelMerger.java000066400000000000000000000056671167643171700312130ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; /** * Handles merging {@link Model} objects. * * @author Jason Dillon * @since 1.0 */ public class ModelMerger { public void merge(Model target, Model source, boolean sourceDominant, Map hints) { assert target != null; if (source == null) { return; } Map context = new HashMap(); if (hints != null) { context.putAll(hints); } mergeModel(target, source, sourceDominant, context); } protected void mergeModel(Model target, Model source, boolean sourceDominant, Map context) { mergeModel_Properties(target, source, sourceDominant, context); mergeModel_Profiles(target, source, sourceDominant, context); } protected void mergeModel_Properties(Model target, Model source, boolean sourceDominant, Map context) { Properties merged = new Properties(); if (sourceDominant) { merged.putAll(target.getProperties()); merged.putAll(source.getProperties()); } else { merged.putAll(source.getProperties()); merged.putAll(target.getProperties()); } target.setProperties(merged); } protected void mergeModel_Profiles(Model target, Model source, boolean sourceDominant, Map context) { List src = source.getProfiles(); if (!src.isEmpty()) { List profiles = target.getProfiles(); Map merged = new LinkedHashMap((src.size() + profiles.size()) * 2); for (ProfileNode element : profiles) { Object key = element.getName(); merged.put(key, element); } for (ProfileNode element : src) { Object key = element.getName(); if (sourceDominant || !merged.containsKey(key)) { merged.put(key, element); } } target.setProfiles(new ArrayList(merged.values())); } } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/000077500000000000000000000000001167643171700265375ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/package-info.java000066400000000000000000000012711167643171700317270ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Model I/O. * * @since 1.0 */ package org.sonatype.gossip.model.io;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/props/000077500000000000000000000000001167643171700277025ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/props/Context.java000066400000000000000000000134511167643171700321750ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model.io.props; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.Set; /** * Container for Gossip configuration details. * * @author Jason Dillon * @since 1.0 */ public final class Context implements Cloneable { private static final String NEWLINE = System.getProperty("line.separator"); private final Map store; private String prefix; private Context parent; private Context(final Map store, final String prefix) { assert store != null; this.store = store; this.prefix = prefix; } @Override public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getClass().getSimpleName()); buff.append("[").append(NEWLINE); if (prefix != null) { for (Map.Entry entry : store.entrySet()) { if (entry.getKey().startsWith(prefix)) { buff.append(" "). append(entry.getKey()).append("=").append(entry.getValue()). append(",").append(NEWLINE); } } } buff.append("]"); return buff.toString(); } @Override public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(); } } public String key(final String name) { assert name != null; if (prefix != null) { return prefix + "." + name; } return name; } public boolean contains(final String name) { assert name != null; return store.containsKey(key(name)); } public String set(final String name, final String value) { assert name != null; assert value != null; return store.put(key(name), value); } public String get(final String name, final String defaultValue) { assert name != null; // defaultValue can be null String value = store.get(key(name)); if (value == null) { value = defaultValue; } return value; } public String get(final String name) { return get(name, null); } public int size() { if (prefix == null) { return store.size(); } int c = 0; for (String key : store.keySet()) { if (key.startsWith(prefix)) { c++; } } return c; } public Set names() { if (prefix == null) { return Collections.unmodifiableSet(store.keySet()); } Set matching = new HashSet(); int l = prefix.length(); for (String key : store.keySet()) { if (key.startsWith(prefix + ".")) { // Strip off the prefix key = key.substring(l + 1, key.length()); matching.add(key); } } return Collections.unmodifiableSet(matching); } // // Children // public Context parent() { if (parent == null) { throw new IllegalStateException("Parent is not bound"); } return parent; } public Context child(final String prefix) { assert prefix != null; Context child = (Context) clone(); child.parent = this; if (child.prefix != null) { child.prefix += "." + prefix; } else { child.prefix = prefix; } return child; } // // Helpers // @SuppressWarnings({"unchecked"}) public static Context create(final URL input) throws IOException { assert input != null; InputStream in = input.openStream(); Properties props; try { props = new Properties(); if (input.getFile().toLowerCase().endsWith(".xml")) { props.loadFromXML(in); } props.load(in); } finally { in.close(); } Context ctx = new Context((Map)props, null); return ctx; } public static Properties asProperties(final Context ctx) { assert ctx != null; Properties props = new Properties(); for (Iterator iter = ctx.names().iterator(); iter.hasNext();) { String key = (String)iter.next(); String value = ctx.get(key); props.setProperty(key, value); } return props; } public Properties toProperties() { return asProperties(this); } public String[] split(final String name, boolean trim) { String[] strings = this.get(name, "").split(","); if (trim) { strings = trim(strings); } return strings; } public static String[] trim(final String[] strings) { for (int i=0; iJason Dillon * @since 1.0 */ public class ContextConfigurator { private static final Logger log = Log.getLogger(ContextConfigurator.class); public void configure(final Object target, final Context config) throws Exception { assert target != null; assert config != null; for (String name : config.names()) { // Get the first element of the name for the key int i = name.indexOf("."); if (i != -1) { name = name.substring(0, i); } String value = config.get(name); // Attempt to set the simple value if (!maybeSet(target, name, value)) { // otherwise assume the value is class to build and inject Object obj = ComponentFactory.build(value, config.child(name)); Class type = obj.getClass(); name = getSetterName(name); // find a method suitable to call for (Method method : target.getClass().getMethods()) { if (method.getName().equals(name)) { Class[] args = method.getParameterTypes(); if (args.length == 1) { for (Class arg : args) { if (arg.isAssignableFrom(type)) { method.invoke(target, obj); break; } } } } } } } } private boolean maybeSet(final Object target, final String name, final String text) { assert target != null; assert name != null; assert text != null; try { Method setter = selectSetter(target.getClass(), getSetterName(name)); if (setter != null) { Class type = setter.getParameterTypes()[0]; log.trace("Setting '{}={}' via: {}", new Object[] { name, text, setter }); Object value = null; if (type.isEnum()) { //noinspection unchecked value = selectEnum(type, text); } else if (type != String.class) { PropertyEditor editor = PropertyEditorManager.findEditor(type); if (editor != null) { editor.setAsText(text); value = editor.getValue(); } else { log.trace("Unable to convert value {} to {}", text, type); return false; } } if (value != null) { log.trace("Converted value: {}", value); } else { value = text; } setter.invoke(target, value); return true; } else { log.trace("Missing setter for: {}", text); } } catch (Exception e) { log.error("Failed to set '{}={}'", new Object[] { name, text, e }); } return false; } private Enum selectEnum(final Class type, final String name) { assert type != null; assert name != null; for (Enum n : type.getEnumConstants()) { if (n.name().equalsIgnoreCase(name)) { return n; } } throw new IllegalArgumentException("No enum const " + type + "." + name); } private Method selectSetter(final Class type, final String name) { assert type != null; assert name != null; Map setters = new HashMap(); for (Method method : type.getMethods()) { if (method.getName().equals(name) && method.getParameterTypes().length == 1) { setters.put(method.getParameterTypes()[0], method); } } Method setter = null; if (setters.size() == 1) { setter = setters.entrySet().iterator().next().getValue(); } else if (setters.size() > 1) { // Prefer the string setter if if there is one setter = setters.get(String.class); } return setter; } private String getSetterName(final String name) { assert name != null && name.length() != 0; return new StringBuilder(name.length() + 3) .append("set") .append(Character.toTitleCase(name.charAt(0))) .append(name.substring(1)) .toString(); } }GossipPropertiesReader.java000066400000000000000000000167441167643171700351460ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/props/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model.io.props; import org.slf4j.Logger; import org.sonatype.gossip.ConfigurationException; import org.sonatype.gossip.Log; import org.sonatype.gossip.model.ListenerNode; import org.sonatype.gossip.model.LoggerNode; import org.sonatype.gossip.model.Model; import org.sonatype.gossip.model.ProfileNode; import org.sonatype.gossip.model.SourceNode; import org.sonatype.gossip.model.TriggerNode; import java.io.IOException; import java.net.URL; import java.util.Arrays; /** * Reads a Gossip {@link Model} from a properties file. * * @author Jason Dillon * @since 1.0 */ public class GossipPropertiesReader { private static final String EXPECTED_VERSION = "1.0.0"; private static final String SOURCES = "sources"; private static final String SOURCE_DOT = "source."; private static final String PROFILES = "profiles"; private static final String PROFILE_DOT = "profile."; private static final String INCLUDES = "includes"; private static final String PROPERTIES = "properties"; private static final String LOGGER = "logger"; private static final String TRIGGERS = "triggers"; private static final String TRIGGER_DOT = "trigger."; private static final String LISTENERS = "listeners"; private static final String LISTENER_DOT = "listener."; private static final Logger log = Log.getLogger(GossipPropertiesReader.class); // // TODO: Support XML properties format // public Model read(final URL url) throws IOException { assert url != null; Model model = new Model(); Context ctx = Context.create(url); // Validate the version String tmp = ctx.get("version"); if (!EXPECTED_VERSION.equals(tmp)) { throw new ConfigurationException("Invalid configuration version: " + tmp + ", expected: " + EXPECTED_VERSION); } model.setProperties(ctx.child(PROPERTIES).toProperties()); configureSourceNodes(model, ctx); configureProfileNodes(model, ctx); return model; } private void configureSourceNodes(final Model model, final Context ctx) { assert model != null; assert ctx != null; if (!ctx.contains(SOURCES)) { return; } for (String name : ctx.split(SOURCES, true)) { if (name.length() == 0) { throw new ConfigurationException("Source name is blank"); } log.trace("Configuring source: {}", name); SourceNode node = createSourceNode(name, ctx.get(SOURCE_DOT + name), ctx.child(SOURCE_DOT + name)); model.getSources().add(node); } } private SourceNode createSourceNode(final String id, final String type, final Context ctx) { assert type != null; assert ctx != null; log.trace("Configuring source: {} -> {}", type, ctx); SourceNode node = new SourceNode(); node.setId(id); node.setType(type); node.setConfiguration(ctx); log.trace("Created: {}", node); return node; } private void configureProfileNodes(final Model model, final Context ctx) { assert model != null; assert ctx != null; if (!ctx.contains(PROFILES)) { return; } for (String name : ctx.split(PROFILES, true)) { if (name.length() == 0) { throw new ConfigurationException("Profile name is blank"); } ProfileNode node = createProfileNode(name, ctx.child(PROFILE_DOT + name)); model.getProfiles().add(node); } } private ProfileNode createProfileNode(final String name, final Context ctx) { assert name != null; assert ctx != null; log.trace("Configuring profile: {} -> {}", name, ctx); ProfileNode node = new ProfileNode(); node.setId(name); node.setName(name); node.setProperties(ctx.child(PROPERTIES).toProperties()); configureLoggerNodes(node, ctx.child(LOGGER)); configureTriggerNodes(node, ctx); configureListenerNodes(node, ctx); String includes = ctx.get(INCLUDES); if (includes != null) { String[] profiles = Context.trim(includes.split(",")); node.setIncludes(Arrays.asList(profiles)); } log.trace("Created: {}", node); return node; } private void configureLoggerNodes(final ProfileNode profile, final Context ctx) { assert profile != null; assert ctx != null; for (String name : ctx.names()) { name = name.trim(); String value = ctx.get(name); LoggerNode node = new LoggerNode(); node.setId(name); node.setName(name); node.setLevel(value); log.trace("Created: {}", node); profile.getLoggers().add(node); } } private void configureTriggerNodes(final ProfileNode profile, final Context ctx) { assert profile != null; assert ctx != null; if (!ctx.contains(TRIGGERS)) { return; } for (String name : ctx.split(TRIGGERS, true)) { if (name.length() == 0) { throw new ConfigurationException("Trigger name is blank"); } TriggerNode node = createTriggerNode(name, ctx.get(TRIGGER_DOT + name), ctx.child(TRIGGER_DOT + name)); profile.getTriggers().add(node); } } private TriggerNode createTriggerNode(final String id, final String type, final Context ctx) { assert type != null; assert ctx != null; log.trace("Configuring trigger: {} -> {}", type, ctx); TriggerNode node = new TriggerNode(); node.setId(id); node.setType(type); node.setConfiguration(ctx); log.trace("Created: {}", node); return node; } private void configureListenerNodes(final ProfileNode profile, final Context ctx) { assert profile != null; assert ctx != null; if (!ctx.contains(LISTENERS)) { return; } for (String name : ctx.split(LISTENERS, true)) { if (name.length() == 0) { throw new ConfigurationException("Listener name is blank"); } ListenerNode listener = createListenerNode(name, ctx.get(LISTENER_DOT + name), ctx.child(LISTENER_DOT + name)); profile.getListeners().add(listener); } } private ListenerNode createListenerNode(final String id, final String type, final Context ctx) { assert type != null; assert ctx != null; log.trace("Configuring listener: {} -> {}", type, ctx); ListenerNode node = new ListenerNode(); node.setId(id); node.setType(type); node.setConfiguration(ctx); log.trace("Created: {}", node); return node; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/io/props/package-info.java000066400000000000000000000013121167643171700330660ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Properties model I/O. * * @since 1.0 */ package org.sonatype.gossip.model.io.props;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/model/package-info.java000066400000000000000000000013001167643171700313110ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Configuration model. * * @since 1.0 */ package org.sonatype.gossip.model;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/package-info.java000066400000000000000000000012661167643171700302240ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Core components. * * @since 1.0 */ package org.sonatype.gossip;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/000077500000000000000000000000001167643171700263305ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/FileSource.java000066400000000000000000000030311167643171700312300ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.MissingPropertyException; import org.sonatype.gossip.model.Model; import java.io.File; /** * Local file configuration source. * * @author Jason Dillon * @since 1.0 */ public class FileSource extends SourceSupport { private File file; public void setFile(final File file) { this.file = file; } public void setFile(final String fileName) { assert fileName != null; setFile(new File(fileName)); } public File getFile() { return file; } public Model load() throws Exception { if (file == null) { throw new MissingPropertyException("file"); } return load(file); } @Override public String toString() { return getClass().getSimpleName() + "{" + "file=" + file + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/HomeDirectorySource.java000066400000000000000000000030461167643171700331340ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.MissingPropertyException; import org.sonatype.gossip.model.Model; import java.io.File; /** * Home-directory configuration source. * * @author Jason Dillon * @since 1.0 */ public class HomeDirectorySource extends SourceSupport { private String path; public void setPath(final String path) { this.path = path; } public String getPath() { return path; } public Model load() throws Exception { if (path == null) { throw new MissingPropertyException("path"); } File homeDir = new File(System.getProperty("user.home")); File file = new File(homeDir, path); return load(file); } @Override public String toString() { return getClass().getSimpleName() + "{" + "path='" + path + '\'' + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/ResourceSource.java000066400000000000000000000066651167643171700321600ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.MissingPropertyException; import org.sonatype.gossip.model.Model; import java.net.URL; import static org.sonatype.gossip.source.ResourceSource.ClassLoaderType.*; /** * Resource-based configuration source. * * @author Jason Dillon * @since 1.0 */ public class ResourceSource extends SourceSupport { public static enum ClassLoaderType { TCL, INTERNAL, SYSTEM; } private String name; private ClassLoaderType classLoaderType = TCL; private ClassLoader classLoader; public String getName() { return name; } public void setName(final String name) { this.name = name; } public void setClassLoaderType(final ClassLoaderType type) { assert type != null; this.classLoaderType = type; } public ClassLoaderType getClassLoaderType() { return classLoaderType; } public ClassLoader getClassLoader() { if (classLoader == null) { switch (classLoaderType) { case TCL: classLoader = Thread.currentThread().getContextClassLoader(); break; case INTERNAL: classLoader = getClass().getClassLoader(); break; case SYSTEM: classLoader = ClassLoader.getSystemClassLoader(); break; } } return classLoader; } public void setClassLoader(final ClassLoader cl) { this.classLoader = cl; } public Model load() throws Exception { if (name == null) { throw new MissingPropertyException("name"); } Model model = null; ClassLoader cl = getClassLoader(); assert cl != null; log.trace("Loading resource for name: {}, CL: {} ({})", new Object[] { name, cl, classLoaderType }); URL url = cl.getResource(name); // HACK: This is needed as a fallback on Maven 2.0.x and 2.2.x which does not have the TCL setup as expected if (url == null) { cl = getClass().getClassLoader(); log.trace("Configured CL failed, trying {}: {}", ClassLoaderType.INTERNAL, cl); url = cl.getResource(name); } if (url == null) { log.trace("Unable to load; missing resource: {}", name); } else { log.trace("Loaded resource: {}", url); model = load(url); } return model; } @Override public String toString() { return getClass().getSimpleName() + "{" + "name='" + name + '\'' + ", classLoaderType='" + classLoaderType + '\'' + ", classLoader=" + classLoader + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/Source.java000066400000000000000000000017611167643171700304400ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.model.Model; /** * Model source. * * @author Jason Dillon * @since 1.0 */ public interface Source { /** * Load a configuration model. * * @return The loaded model. * @throws Exception Failed to load the model. */ Model load() throws Exception; }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/SourceSupport.java000066400000000000000000000033131167643171700320300ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.slf4j.Logger; import org.sonatype.gossip.Log; import org.sonatype.gossip.model.Model; import org.sonatype.gossip.model.io.props.GossipPropertiesReader; import java.io.File; import java.net.URL; /** * Support for {@link Source} components. * * @author Jason Dillon * @since 1.0 */ public abstract class SourceSupport implements Source { protected final Logger log = Log.getLogger(getClass()); protected Model load(final URL url) throws Exception { assert url != null; log.debug("Loading model from: {}", url); // HACK: FOr now just assume we are doing properties, support xpp3 optionally in the future GossipPropertiesReader reader = new GossipPropertiesReader(); return reader.read(url); } protected Model load(final File file) throws Exception { assert file != null; if (!file.exists()) { log.trace("File does not exist; skipping: {}", file); return null; } return load(file.toURI().toURL()); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/SystemPropertySource.java000066400000000000000000000043551167643171700334140ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.ConfigurationException; import org.sonatype.gossip.MissingPropertyException; import org.sonatype.gossip.model.Model; import java.io.File; import java.net.MalformedURLException; import java.net.URL; /** * System-property configuration source. * * @author Jason Dillon * @since 1.0 */ public class SystemPropertySource extends SourceSupport { public SystemPropertySource() {} public SystemPropertySource(final String name) { setName(name); } private String name; public void setName(final String name) { this.name = name; } public String getName() { return name; } public Model load() throws Exception { if (name == null) { throw new MissingPropertyException("name"); } String value = System.getProperty(name); if (value == null) { log.trace("Unable to load; property not set: {}", name); return null; } URL url = null; try { url = new URL(value); } catch (MalformedURLException e) { File file = new File(value); if (file.exists()) { url = file.toURI().toURL(); } } if (url == null) { throw new ConfigurationException("Unable to load; unable to resolve target: " + value); } return load(url); } @Override public String toString() { return getClass().getSimpleName() + "{" + "name='" + name + '\'' + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/URLSource.java000066400000000000000000000031071167643171700310170ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.sonatype.gossip.MissingPropertyException; import org.sonatype.gossip.model.Model; import java.net.MalformedURLException; import java.net.URL; /** * URL configuration source. * * @author Jason Dillon * @since 1.0 */ public class URLSource extends SourceSupport { private URL url; public void setUrl(final URL url) { this.url = url; } public void setUrl(final String location) throws MalformedURLException { assert location != null; setUrl(new URL(location)); } public URL getUrl() { return url; } public Model load() throws Exception { if (url == null) { throw new MissingPropertyException("url"); } return load(url); } @Override public String toString() { return getClass().getSimpleName() + "{" + "url=" + url + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/source/package-info.java000066400000000000000000000013031167643171700315140ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Configuration sources. * * @since 1.0 */ package org.sonatype.gossip.source;gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/000077500000000000000000000000001167643171700264735ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/AlwaysTrigger.java000066400000000000000000000015601167643171700321240ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.trigger; /** * Always triggers. * * @author Jason Dillon * @since 1.0 */ public class AlwaysTrigger implements Trigger { public boolean isActive() { return true; } }EnvironmentVariableTrigger.java000066400000000000000000000017211167643171700345560ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.trigger; /** * Triggers activation based on a environment variable. * * @author Jason Dillon * @since 1.0 */ public class EnvironmentVariableTrigger extends NameValueTriggerSupport { @Override protected String resolve() { return System.getenv(getName()); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/NameValueTriggerSupport.java000066400000000000000000000055421167643171700341420ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.trigger; import org.slf4j.Logger; import org.sonatype.gossip.Log; /** * Support for triggers which expect a name and value for configuration. * * @author Jason Dillon * @since 1.0 */ public abstract class NameValueTriggerSupport implements Trigger { protected transient Logger log = Log.getLogger(getClass()); private String name; private String value; private boolean trim = true; private boolean ignoreCase = true; public void setName(final String name) { this.name = name; } public String getName() { return name; } public void setValue(final String value) { this.value = value; } public String getValue() { return value; } public void setTrim(final boolean flag) { this.trim = flag; } public boolean isTrim() { return trim; } public void setIgnoreCase(final boolean flag) { this.ignoreCase = flag; } public boolean isIgnoreCase() { return ignoreCase; } protected abstract String resolve(); public boolean isActive() { assert name != null; // value can be null; String have = resolve(); if (log.isTraceEnabled()) { log.trace("Checking active state; name={}, expect={}, found={}", new Object[] { name, value, have }); } // If not set, its not active if (have == null) { return false; } // We are set, but no value, so set means active if (value == null) { return true; } String want = value; // Trim if asked if (trim) { want = want.trim(); have = have.trim(); } // Else value needs to equal our value if (ignoreCase) { return want.equalsIgnoreCase(have); } else { return want.equals(have); } } @Override public String toString() { return getClass().getSimpleName() + "{" + "name='" + name + '\'' + ", value='" + value + '\'' + ", trim=" + trim + ", ignoreCase=" + ignoreCase + '}'; } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/SystemPropertyTrigger.java000066400000000000000000000017171167643171700337210ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.trigger; /** * Triggers activation when a system property is set. * * @author Jason Dillon * @since 1.0 */ public class SystemPropertyTrigger extends NameValueTriggerSupport { @Override protected String resolve() { return System.getProperty(getName()); } }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/Trigger.java000066400000000000000000000016421167643171700307440ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.trigger; /** * Profile trigger. * * @author Jason Dillon * @since 1.0 */ public interface Trigger { /** * Determine if a profile is active. * * @return True if the profile is active. */ boolean isActive(); }gossip-gossip-1.8/gossip-core/src/main/java/org/sonatype/gossip/trigger/package-info.java000066400000000000000000000013121167643171700316570ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Profile activation triggers. * * @since 1.0 */ package org.sonatype.gossip.trigger;gossip-gossip-1.8/gossip-core/src/main/mdo/000077500000000000000000000000001167643171700207315ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/mdo/gossip.mdo000066400000000000000000000327171167643171700227500ustar00rootroot00000000000000 gossip Gossip 1.0.0 package org.sonatype.gossip.model field version Model 1.0.0+ version 1.0.0+ true String properties 1.0.0+ Properties String * sources 1.0.0+ SourceNode * profiles 1.0.0+ ProfileNode * 1.0.0+ Node 1.0.0+ id 1.0.0+ false String 1.0.0+ 1.0.0+ ProfileNode 1.0.0+ Node name 1.0.0+ true String properties 1.0.0+ Properties String * includes 1.0.0+ String * loggers 1.0.0+ LoggerNode * triggers 1.0.0+ TriggerNode * listeners 1.0.0+ ListenerNode * 1.0.0+ 1.0.0+ LoggerNode 1.0.0+ Node name 1.0.0+ true String level 1.0.0+ true String 1.0.0+ 1.0.0+ 1.0.0+ FactoryNode 1.0.0+ Node type 1.0.0+ true String configuration 1.0.0+ DOM 1.0.0+ 1.0.0+ 1.0.0+ SourceNode 1.0.0+ FactoryNode 1.0.0+ TriggerNode 1.0.0+ FactoryNode 1.0.0+ ListenerNode 1.0.0+ FactoryNode 1.0.0+ gossip-gossip-1.8/gossip-core/src/main/resources/000077500000000000000000000000001167643171700221645ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/resources/org/000077500000000000000000000000001167643171700227535ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/resources/org/sonatype/000077500000000000000000000000001167643171700246155ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/resources/org/sonatype/gossip/000077500000000000000000000000001167643171700261215ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/main/resources/org/sonatype/gossip/bootstrap.properties000066400000000000000000000026061167643171700322600ustar00rootroot00000000000000# # Copyright (c) 2009-2011 the original author or authors. # # Licensed 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. # version=1.0.0 ## ## Defines the standard sources for loading additional configuration ## sources=classpath, homedir, sysprop #source.defaults=org.sonatype.gossip.source.ResourceSource #source.defaults.classLoaderType=INTERNAL #source.defaults.name=org/sonatype/gossip/default.properties # And look for something in the classpath source.classpath=org.sonatype.gossip.source.ResourceSource source.classpath.name=META-INF/org.sonatype.gossip/config.properties # Allow -Dgossip.configuration=whatever to be used to load configuration source.sysprop=org.sonatype.gossip.source.SystemPropertySource source.sysprop.name=gossip.configuration # Try to load configuration from ~/.gossip/config.properties source.homedir=org.sonatype.gossip.source.HomeDirectorySource source.homedir.path=.gossip/config.properties gossip-gossip-1.8/gossip-core/src/test/000077500000000000000000000000001167643171700202055ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/000077500000000000000000000000001167643171700211265ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/000077500000000000000000000000001167643171700217155ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/000077500000000000000000000000001167643171700235575ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/000077500000000000000000000000001167643171700250635ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/model/000077500000000000000000000000001167643171700261635ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/model/ModelTest.java000066400000000000000000000036651167643171700307400ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * Tests for {@link Model}. * * @author Jason Dillon */ public class ModelTest { @Test public void testLoggerNodeIdentity() { LoggerNode node1 = new LoggerNode(); node1.setName("foo"); LoggerNode node2 = new LoggerNode(); node2.setName("bar"); LoggerNode node3 = new LoggerNode(); node3.setName("foo"); List list = new ArrayList(); list.add(node1); assertTrue(list.contains(node1)); assertFalse(list.contains(node2)); assertTrue(list.contains(node3)); } @Test public void testListenerNodeIdenityer() { ListenerNode node1 = new ListenerNode(); node1.setType("foo"); ListenerNode node2 = new ListenerNode(); node2.setType("bar"); ListenerNode node3 = new ListenerNode(); node3.setType("foo"); List list = new ArrayList(); list.add(node1); assertTrue(list.contains(node1)); assertFalse(list.contains(node2)); assertTrue(list.contains(node3)); } }gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/model/io/000077500000000000000000000000001167643171700265725ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/model/io/props/000077500000000000000000000000001167643171700277355ustar00rootroot00000000000000GossipPropertiesReaderTest.java000066400000000000000000000023001167643171700360200ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/model/io/props/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.model.io.props; import org.junit.Test; import org.sonatype.gossip.model.Model; import java.io.IOException; import java.net.URL; /** * Tests for {@link GossipPropertiesReader}. * * @author Jason Dillon */ public class GossipPropertiesReaderTest { @Test public void testLoad() throws IOException { URL url = getClass().getResource("gossip1.properties"); GossipPropertiesReader reader = new GossipPropertiesReader(); Model model = reader.read(url); System.out.println(model); } }gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/source/000077500000000000000000000000001167643171700263635ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/source/SystemPropertySourceTest.java000066400000000000000000000036001167643171700342770ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.junit.Test; import org.sonatype.gossip.ConfigurationException; import org.sonatype.gossip.model.Model; import static org.junit.Assert.*; /** * Tests for the {@link org.sonatype.gossip.source.SystemPropertySource} class. * * @author Jason Dillon */ public class SystemPropertySourceTest { @Test public void test1() throws Exception { SystemPropertySource s = new SystemPropertySource(); String name = "foo.bar"; s.setName(name); System.setProperty(name, "no such file anywhere I hope"); try { s.load(); fail(); } catch (ConfigurationException e) { // expected } } @Test public void test2() throws Exception { SystemPropertySource s = new SystemPropertySource(); String name = "foo.bar"; s.setName(name); System.getProperties().remove(name); Model model = s.load(); assertNull(model); } @Test public void test3() throws Exception { try { SystemPropertySource s = new SystemPropertySource(); s.load(); fail(); } catch (ConfigurationException expected) {} } }gossip-gossip-1.8/gossip-core/src/test/java/org/sonatype/gossip/source/URLSourceTest.java000066400000000000000000000023161167643171700317130ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.source; import org.junit.Test; import org.sonatype.gossip.model.Model; import java.net.URL; import static org.junit.Assert.*; /** * Tests for the {@link org.sonatype.gossip.source.URLSource} class. * * @author Jason Dillon */ public class URLSourceTest { @Test public void test1() throws Exception { URLSource s = new URLSource(); URL url = getClass().getResource("config1.properties"); assertNotNull(url); s.setUrl(url); Model model = s.load(); assertNotNull(model); } }gossip-gossip-1.8/gossip-core/src/test/resources/000077500000000000000000000000001167643171700222175ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/000077500000000000000000000000001167643171700230065ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/000077500000000000000000000000001167643171700246505ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/000077500000000000000000000000001167643171700261545ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/model/000077500000000000000000000000001167643171700272545ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/model/io/000077500000000000000000000000001167643171700276635ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/model/io/props/000077500000000000000000000000001167643171700310265ustar00rootroot00000000000000gossip1.properties000066400000000000000000000020021167643171700344440ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/model/io/props# # Copyright (c) 2009-2011 the original author or authors. # # Licensed 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. # version=1.0.0 profiles=config1 profile.config1.triggers=0 profile.config1.trigger.0=org.sonatype.gossip.model.trigger.AlwaysTrigger profile.config1.filters=0 profile.config1.filter.0=org.sonatype.gossip.model.filter.ConsoleWriter profile.config1.filter.0.name=SYSOUT profile.config1.filter.0.renderer=org.sonatype.gossip.model.render.SimpleRenderer profile.config1.logger.foo=DEBUG profile.config1.logger.bar=ERROR gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/source/000077500000000000000000000000001167643171700274545ustar00rootroot00000000000000gossip-gossip-1.8/gossip-core/src/test/resources/org/sonatype/gossip/source/config1.properties000066400000000000000000000020021167643171700331120ustar00rootroot00000000000000# # Copyright (c) 2009-2011 the original author or authors. # # Licensed 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. # version=1.0.0 profiles=config1 profile.config1.triggers=0 profile.config1.trigger.0=org.sonatype.gossip.model.trigger.AlwaysTrigger profile.config1.filters=0 profile.config1.filter.0=org.sonatype.gossip.model.filter.ConsoleWriter profile.config1.filter.0.name=SYSOUT profile.config1.filter.0.renderer=org.sonatype.gossip.model.render.SimpleRenderer profile.config1.logger.foo=DEBUG profile.config1.logger.bar=ERROR gossip-gossip-1.8/gossip-extra/000077500000000000000000000000001167643171700166325ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/pom.xml000066400000000000000000000032361167643171700201530ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-extra Gossip Extra org.sonatype.gossip gossip-core junit junit test org.fusesource.jansi jansi 1.5 true gossip-gossip-1.8/gossip-extra/src/000077500000000000000000000000001167643171700174215ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/000077500000000000000000000000001167643171700203455ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/000077500000000000000000000000001167643171700212665ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/000077500000000000000000000000001167643171700220555ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/000077500000000000000000000000001167643171700237175ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/000077500000000000000000000000001167643171700252235ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/000077500000000000000000000000001167643171700263465ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/listener/000077500000000000000000000000001167643171700301735ustar00rootroot00000000000000FileSizeRollingStrategy.java000066400000000000000000000065571167643171700355600ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/listener/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.extra.listener; import org.slf4j.Logger; import org.sonatype.gossip.Log; import org.sonatype.gossip.listener.CountingWriter; import org.sonatype.gossip.listener.FileListener; import org.sonatype.gossip.listener.FileListener.RollingStrategy; import java.io.File; /** * A file-size {@link RollingStrategy}. * * @author Jason Dillon * @since 1.6 */ public class FileSizeRollingStrategy implements RollingStrategy { private static final Logger log = Log.getLogger(FileSizeRollingStrategy.class); private long maximumFileSize = 10*1024*1024; private int maximumBackupIndex = 1; public int getMaximumBackupIndex() { return maximumBackupIndex; } public void setMaximumBackupIndex(final int n) { this.maximumBackupIndex = n; } public long getMaximumFileSize() { return maximumFileSize; } public void setMaximumFileSize(final long n) { this.maximumFileSize = n; } public boolean roll(final FileListener listener) { assert listener != null; CountingWriter writer = listener.getWriter(); if (writer.size() > maximumFileSize) { return false; } // // This was copied from Log4j's RollingFileAppender and massaged a bit, probably needs more work on Windows // File source = listener.getFile(); File target; boolean renameSucceeded = true; // If maxBackups <= 0, then there is no file renaming to be done. if (maximumBackupIndex > 0) { // Delete the oldest file, to keep Windows happy. File file = new File(source.getPath() + '.' + maximumBackupIndex); if (file.exists()) { renameSucceeded = file.delete(); } // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2} for (int i=maximumBackupIndex-1; i >= 1 && renameSucceeded; i--) { file = new File(source.getPath() + "." + i); if (file.exists()) { target = new File(source.getPath() + '.' + (i + 1)); log.debug("Renaming file {} to {}", file, target); renameSucceeded = file.renameTo(target); } } if (renameSucceeded) { // Rename fileName to fileName.1 target = new File(source.getPath() + "." + 1); file = new File(source.getPath()); log.debug("Renaming file {} to {}", file, target); renameSucceeded = file.renameTo(target); if (!renameSucceeded) { return false; } } } return true; } }gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/listener/package-info.java000066400000000000000000000013141167643171700333610ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Extra Event listeners. * * @since 1.6 */ package org.sonatype.gossip.extra.listener;gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/render/000077500000000000000000000000001167643171700276255ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/render/ColorRenderer.java000066400000000000000000000067101167643171700332410ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.extra.render; import org.sonatype.gossip.Event; import org.sonatype.gossip.render.PatternRenderer; import static org.fusesource.jansi.Ansi.Attribute.*; import static org.fusesource.jansi.Ansi.Color.*; import static org.fusesource.jansi.Ansi.*; /** * Renders events with ANSI colors. * * @author Jason Dillon * @since 1.6 */ public class ColorRenderer extends PatternRenderer { @Override protected void renderLevel(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; switch (event.getLevel()) { case TRACE: case DEBUG: buff.append(ansi().a(INTENSITY_BOLD).fg(YELLOW).a(event.getLevel().name()).reset()); break; case INFO: buff.append(ansi().a(INTENSITY_BOLD).fg(GREEN).a(event.getLevel().name()).reset()); break; case WARN: case ERROR: buff.append(ansi().a(INTENSITY_BOLD).fg(RED).a(event.getLevel().name()).reset()); break; default: throw new InternalError(); } } @Override protected void renderName(final Event event, final StringBuilder buff, final boolean shortName) { StringBuilder tmp = new StringBuilder(); super.renderName(event, tmp, shortName); buff.append(ansi().fg(GREEN).a(tmp).reset()); } @Override protected void renderCause(final Event event, final StringBuilder buff) { assert event != null; assert buff != null; Throwable cause = event.getCause(); if (cause == null) { return; } buff.append(ansi().a(INTENSITY_BOLD).fg(RED).a(cause.getClass().getName()).reset()); if (cause.getMessage() != null) { buff.append(": "); buff.append(ansi().a(INTENSITY_BOLD).fg(RED).a(cause.getMessage()).reset()); } renderNewLine(buff); while (cause != null) { for (StackTraceElement e : cause.getStackTrace()) { buff.append(" "); buff.append(ansi().a(INTENSITY_BOLD).a("at").reset().a(" ").a(e.getClassName()).a(".").a(e.getMethodName())); buff.append(ansi().a(" (").a(INTENSITY_BOLD).a(getLocation(e)).reset().a(")")); renderNewLine(buff); } cause = cause.getCause(); if (cause != null) { buff.append(ansi().a(INTENSITY_BOLD).a("Caused by").reset().a(" ").a(cause.getClass().getName())); if (cause.getMessage() != null) { buff.append(": "); buff.append(ansi().a(INTENSITY_BOLD).fg(RED).a(cause.getMessage()).reset()); } renderNewLine(buff); } } } }gossip-gossip-1.8/gossip-extra/src/main/java/org/sonatype/gossip/extra/render/package-info.java000066400000000000000000000013121167643171700330110ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Extra Event renderers. * * @since 1.6 */ package org.sonatype.gossip.extra.render;gossip-gossip-1.8/gossip-extra/src/test/000077500000000000000000000000001167643171700204005ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/000077500000000000000000000000001167643171700213215ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/000077500000000000000000000000001167643171700221105ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/sonatype/000077500000000000000000000000001167643171700237525ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/sonatype/gossip/000077500000000000000000000000001167643171700252565ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/sonatype/gossip/extra/000077500000000000000000000000001167643171700264015ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/sonatype/gossip/extra/listener/000077500000000000000000000000001167643171700302265ustar00rootroot00000000000000FileSizeRollingStrategyTest.java000066400000000000000000000103661167643171700364440ustar00rootroot00000000000000gossip-gossip-1.8/gossip-extra/src/test/java/org/sonatype/gossip/extra/listener/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.extra.listener; import static org.junit.Assert.assertEquals; import org.junit.Ignore; /** * Tests for {@link FileSizeRollingStrategy}. * * @author Jason Dillon */ public class ColorRendererTest { @Test public void test1() throws Exception { Logger log = Gossip.getInstance().getLogger("foo"); Event e = new Event(log, Level.DEBUG, "foo bar baz", null); ColorRenderer r = new ColorRenderer(); String text = r.render(e); System.out.println(text); } }gossip-gossip-1.8/gossip-slf4j/000077500000000000000000000000001167643171700165315ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/pom.xml000066400000000000000000000027121167643171700200500ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-slf4j Gossip SLF4j org.sonatype.gossip gossip-core junit junit test gossip-gossip-1.8/gossip-slf4j/src/000077500000000000000000000000001167643171700173205ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/000077500000000000000000000000001167643171700202445ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/java/000077500000000000000000000000001167643171700211655ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/java/org/000077500000000000000000000000001167643171700217545ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/000077500000000000000000000000001167643171700227765ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/impl/000077500000000000000000000000001167643171700237375ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/impl/StaticLoggerBinder.java000066400000000000000000000032531167643171700303200ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.ILoggerFactory; import org.slf4j.spi.LoggerFactoryBinder; import org.sonatype.gossip.Gossip; import org.sonatype.gossip.Log; /** * Gossip logger binder for SLF4J. * * @author Jason Dillon * @since 1.0 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticLoggerBinder implements LoggerFactoryBinder { /** * @since 1.1 */ public static String REQUESTED_API_VERSION = "1.6.0"; // to avoid constant folding by the compiler, this field must *not* be final private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder(); /** * @since 1.1 * @return {@link #SINGLETON} */ public static StaticLoggerBinder getSingleton() { return SINGLETON; } private final ILoggerFactory factory = Gossip.getInstance(); public ILoggerFactory getLoggerFactory() { Log.configure(factory); return factory; } public String getLoggerFactoryClassStr() { return Gossip.class.getName(); } }gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/impl/StaticMDCBinder.java000066400000000000000000000023121167643171700274770ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.helpers.BasicMDCAdapter; import org.slf4j.spi.MDCAdapter; /** * Gossip MDC binder for SLF4J. * * @author Jason Dillon * @since 1.0 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticMDCBinder { public static final StaticMDCBinder SINGLETON = new StaticMDCBinder(); private final BasicMDCAdapter adapter = new BasicMDCAdapter(); public MDCAdapter getMDCA() { return adapter; } public String getMDCAdapterClassStr() { return adapter.getClass().getName(); } }gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/impl/StaticMarkerBinder.java000066400000000000000000000024711167643171700303230ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.slf4j.impl; import org.slf4j.IMarkerFactory; import org.slf4j.helpers.BasicMarkerFactory; import org.slf4j.spi.MarkerFactoryBinder; /** * Gossip marker binder for SLF4J. * * @author Jason Dillon * @since 1.0 */ @SuppressWarnings({"UnusedDeclaration"}) public final class StaticMarkerBinder implements MarkerFactoryBinder { public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder(); private final IMarkerFactory factory = new BasicMarkerFactory(); public IMarkerFactory getMarkerFactory() { return factory; } public String getMarkerFactoryClassStr() { return factory.getClass().getName(); } }gossip-gossip-1.8/gossip-slf4j/src/main/java/org/slf4j/impl/package-info.java000066400000000000000000000012671167643171700271340ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Gossip SLF4j bindings. * * @since 1.0 */ package org.slf4j.impl;gossip-gossip-1.8/gossip-slf4j/src/test/000077500000000000000000000000001167643171700202775ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/test/java/000077500000000000000000000000001167643171700212205ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/test/java/org/000077500000000000000000000000001167643171700220075ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/test/java/org/sonatype/000077500000000000000000000000001167643171700236515ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/test/java/org/sonatype/gossip/000077500000000000000000000000001167643171700251555ustar00rootroot00000000000000gossip-gossip-1.8/gossip-slf4j/src/test/java/org/sonatype/gossip/GossipTest.java000066400000000000000000000026761167643171700301370ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip; import org.junit.Test; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; /** * Tests for the {@link Gossip} class. * * @author Jason Dillon */ public class GossipTest { @Test public void testBasic() throws Exception { ILoggerFactory factory = LoggerFactory.getILoggerFactory(); assertNotNull(factory); assertEquals(Gossip.class.getName(), factory.getClass().getName()); Logger log = LoggerFactory.getLogger(getClass()); assertNotNull(log); log.trace("trace"); log.debug("debug"); log.info("info"); log.warn("warn"); log.error("error"); } }gossip-gossip-1.8/gossip-support/000077500000000000000000000000001167643171700172235ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/pom.xml000066400000000000000000000030401167643171700205350ustar00rootroot00000000000000 4.0.0 org.sonatype.gossip gossip 1.8 gossip-support Gossip Support Support, helper and utilities. org.sonatype.gossip gossip-bootstrap junit junit test gossip-gossip-1.8/gossip-support/src/000077500000000000000000000000001167643171700200125ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/000077500000000000000000000000001167643171700207365ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/000077500000000000000000000000001167643171700216575ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/org/000077500000000000000000000000001167643171700224465ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/000077500000000000000000000000001167643171700243105ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/000077500000000000000000000000001167643171700256145ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/000077500000000000000000000000001167643171700273305ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/DC.java000066400000000000000000000157541167643171700304750ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.slf4j.MDC; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; /** * Diagnostic context; provides map and stack facilities. * * @author Jason Dillon * @since 1.6 */ public class DC { /** * The key in which we publish our contents to in the Slf4j MDC. */ public static final String KEY = getProperty("key", "DC"); /** * String prefixed to MDC value when there is content to publish. * * @since 1.7 */ public static final String PREFIX = getProperty("prefix", ","); /** * String used to separate the stack and context values when both are present. * * @since 1.7 */ public static final String SEPARATOR = getProperty("separator", ","); /** * Container for thread diagnostic context state. * * @since 1.7 */ public static class State { private final Map map; private final LinkedList stack; private State() { this.map = new HashMap(); this.stack = new LinkedList(); } private State(final State source) { this(); checkNotNull(source); this.map.putAll(source.map); this.stack.addAll(source.stack); } @Override public String toString() { return "State{" + "map=" + map + ", stack=" + stack + '}'; } } private static InheritableThreadLocal stateHolder = new InheritableThreadLocal() { @Override protected State initialValue() { return new State(); } @Override protected State childValue(final State parentValue) { return new State(parentValue); } }; private static State state() { return stateHolder.get(); } /** * Helper to get {@link State#map}. */ private static Map map() { return state().map; } /** * Helper to get {@link State#stack}. */ private static LinkedList stack() { return state().stack; } /** * Get a copy of the state for the current thread. * * @since 1.7 */ public static State getState() { return new State(state()); } /** * Set the state for the current thread. * * @since 1.7 */ public static void setState(final State state) { checkNotNull(state); stateHolder.set(state); update(); } /** * Reset the current threads state. * * @since 1.7 */ public static void reset() { stateHolder.remove(); MDC.remove(KEY); } /** * Render the current threads state. * * @since 1.7 */ public static StringBuilder render() { State state = state(); StringBuilder buff = new StringBuilder(); // Append the stack if there is one if (!state.stack.isEmpty()) { buff.append(state.stack); } if (!state.map.isEmpty()) { // Append the context if there is some if (buff.length() != 0) { buff.append(SEPARATOR); } buff.append(state.map); } return buff; } /** * Updates and publishes the rendered state to the Slf4j MDC. */ private static void update() { StringBuilder buff = render(); if (buff.length() != 0) { buff.insert(0, PREFIX); MDC.put(KEY, buff.toString()); } else { reset(); } } // Context operations public static void put(final Object key, final Object value) { checkNotNull(key); map().put(key.toString(), String.valueOf(value)); update(); } public static void put(final Class key, final Object value) { checkNotNull(key); put(key.getSimpleName(), value); } /** * @since 1.8 */ public static interface RestoreHandle { /** * Restore previously set value or remove if previously unset. */ void restore(); } /** * @since 1.8 */ public static RestoreHandle install(final Object key, final Object value) { checkNotNull(key); final String _key = String.valueOf(key); final Map map = map(); final boolean exists = map.containsKey(_key); final Object prev = map().put(_key, String.valueOf(value)); update(); return new RestoreHandle() { public void restore() { if (exists) { map.put(_key, String.valueOf(prev)); } else { map.remove(_key); } update(); } }; } /** * @since 1.8 */ public static RestoreHandle install(final Class key, final Object value) { checkNotNull(key); return install(key.getSimpleName(), value); } public static String get(final Object key) { checkNotNull(key); return map().get(key.toString()); } public static String get(final Class key) { checkNotNull(key); return get(key.getSimpleName()); } public static void remove(final Object key) { checkNotNull(key); map().remove(key.toString()); update(); } public static void remove(final Class key) { checkNotNull(key); remove(key.getSimpleName()); } // Stack Operations public static void push(final Object value) { checkNotNull(value); stack().addFirst(value.toString()); update(); } public static String pop() { String value = stack().removeFirst(); update(); return value; } public static String peek() { return stack().peek(); } // Misc Helpers private static String getProperty(final String name, final String defaultValue) { return System.getProperty(DC.class.getName() + "." + name, defaultValue); } private static T checkNotNull(final T reference) { if (reference == null) { throw new NullPointerException(); } return reference; } }gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/LoggingOutputStream.java000066400000000000000000000120701167643171700341560ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.slf4j.Logger; import org.sonatype.gossip.Level; import java.io.IOException; import java.io.OutputStream; /** * {@link OutputStream} which logs lines to a {@link Logger}. * * @author Jim Moore * @author Jason Dillon * @since 1.8 * * @link https://github.com/apache/log4j/blob/trunk/contribs/JimMoore/LoggingOutputStream.java */ public class LoggingOutputStream extends OutputStream { protected static final String LINE_SEPERATOR = System.getProperty("line.separator"); /** * Used to maintain the contract of {@link #close()}. */ protected boolean hasBeenClosed = false; /** * The internal buffer where data is stored. */ protected byte[] buf; /** * The number of valid bytes in the buffer. This value is always in the range 0 through buf.length; elements buf[0] * through buf[count-1] contain valid byte data. */ protected int count; /** * Remembers the size of the buffer for speed. */ private int bufLength; /** * The default number of bytes in the buffer. =2048 */ public static final int DEFAULT_BUFFER_LENGTH = 2048; protected Logger logger; protected Level level; public LoggingOutputStream(final Logger logger, final Level level) { if (logger == null) { throw new NullPointerException(); } if (level == null) { throw new NullPointerException(); } this.level = level; this.logger = logger; bufLength = DEFAULT_BUFFER_LENGTH; buf = new byte[DEFAULT_BUFFER_LENGTH]; count = 0; } /** * Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it * closes the output stream. A closed stream cannot perform output operations and cannot be reopened. */ public void close() { flush(); hasBeenClosed = true; } /** * Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The * byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored. * * @param b the byte to write * @throws IOException if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed. */ public void write(final int b) throws IOException { if (hasBeenClosed) { throw new IOException("The stream has been closed."); } // don't log nulls if (b == 0) { return; } // would this be writing past the buffer? if (count == bufLength) { // grow the buffer final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH; final byte[] newBuf = new byte[newBufLength]; System.arraycopy(buf, 0, newBuf, 0, bufLength); buf = newBuf; bufLength = newBufLength; } buf[count] = (byte) b; count++; } /** * Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it * is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should * immediately be written to their intended destination. */ public void flush() { if (count == 0) { return; } // don't print out blank lines; flushing from PrintStream puts out these if (count == LINE_SEPERATOR.length()) { if (((char) buf[0]) == LINE_SEPERATOR.charAt(0) && ((count == 1) || // <- Unix & Mac, -> Windows ((count == 2) && ((char) buf[1]) == LINE_SEPERATOR.charAt(1)))) { reset(); return; } } final byte[] theBytes = new byte[count]; System.arraycopy(buf, 0, theBytes, 0, count); level.log(logger, new String(theBytes)); reset(); } private void reset() { // not resetting the buffer -- assuming that if it grew that it // will likely grow similarly again count = 0; } } gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/MuxLoggerFactory.java000066400000000000000000000045521167643171700334420ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.slf4j.Logger; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** * Factory to produce a multiplexing {@link Logger}. * * @author Jason Dillon * @since 1.6 */ public class MuxLoggerFactory { /** * @param loggers The first logger will be responsible for all methods which return values, otherwise all loggers are invoked in order. */ public static Logger create(final Logger... loggers) { return (Logger) Proxy.newProxyInstance(Logger.class.getClassLoader(), new Class[]{Logger.class}, new Handler(loggers)); } private static class Handler implements InvocationHandler { private final Logger[] loggers; private Handler(final Logger[] loggers) { assert loggers != null; assert loggers.length > 0; this.loggers = loggers; } public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { assert proxy != null; assert method != null; if (method.getDeclaringClass().equals(Object.class)) { return method.invoke(this, args); } else { // For methods that return something, pick the first logger (mostly name + isEnabled() muck) if (method.getReturnType() != Void.TYPE) { return method.invoke(loggers[0], args); } // Else invoke them all for (Logger logger : loggers) { method.invoke(logger, args); } return null; // void } } } }gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/PrintStreamLogger.java000066400000000000000000000055411167643171700336100ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.slf4j.Logger; import org.sonatype.gossip.Event; import org.sonatype.gossip.Level; import org.sonatype.gossip.LoggerSupport; import org.sonatype.gossip.render.PatternRenderer; import org.sonatype.gossip.render.Renderer; import java.io.PrintStream; /** * Adapts a {@link PrintStream} to a {@link Logger} interface. * * @author Jason Dillon * @since 1.6 */ public class PrintStreamLogger extends LoggerSupport { private final PrintStream stream; private volatile Level threshold; private volatile Renderer renderer; public PrintStreamLogger(final PrintStream stream, final Level threshold) { if (stream == null) { throw new NullPointerException(); } // threshold can be null this.stream = stream; this.threshold = threshold; setRenderer(createRenderer()); } public PrintStreamLogger(final PrintStream stream) { this(stream, null); } /** * Returns a default {@link PatternRenderer}. */ protected Renderer createRenderer() { return new PatternRenderer(); } public PrintStream getStream() { return stream; } public Level getThreshold() { if (threshold == null) { return Level.TRACE; } return threshold; } public void setThreshold(final Level threshold) { // null will reset to default this.threshold = threshold; } public Renderer getRenderer() { return renderer; } public void setRenderer(final Renderer renderer) { if (renderer == null) { throw new NullPointerException(); } this.renderer = renderer; } public void setName(final String name) { // null will reset to default this.name = name; } protected boolean isEnabled(final Level level) { assert level != null; return getThreshold().id <= level.id; } @Override protected void doLog(final Event event) { assert event != null; final PrintStream out = getStream(); synchronized (out) { out.print(getRenderer().render(event)); out.flush(); } } }gossip-gossip-1.8/gossip-support/src/main/java/org/sonatype/gossip/support/package-info.java000066400000000000000000000013151167643171700325170ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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. */ /** * Support, helper and utilities. * * @since 1.6 */ package org.sonatype.gossip.support;gossip-gossip-1.8/gossip-support/src/test/000077500000000000000000000000001167643171700207715ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/000077500000000000000000000000001167643171700217125ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/000077500000000000000000000000001167643171700225015ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/000077500000000000000000000000001167643171700243435ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/gossip/000077500000000000000000000000001167643171700256475ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/gossip/support/000077500000000000000000000000001167643171700273635ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/gossip/support/DCTest.java000066400000000000000000000015621167643171700313600ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.junit.Ignore; import org.junit.Test; /** * Tests for {@link DC}. */ public class DCTest { @Test @Ignore public void makeSomeRealTests() { // FIXME: Reminder to make tests for this } } gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/gossip/support/MuxLoggerFactoryTest.java000066400000000000000000000016161167643171700343330ustar00rootroot00000000000000/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.junit.Ignore; import org.junit.Test; /** * Tests for {@link MuxLoggerFactory}. */ public class MuxLoggerFactoryTest { @Test @Ignore public void makeSomeRealTests() { // FIXME: Reminder to make tests for this } } PrintStreamLoggerTest.java000066400000000000000000000032321167643171700344170ustar00rootroot00000000000000gossip-gossip-1.8/gossip-support/src/test/java/org/sonatype/gossip/support/** * Copyright (c) 2009-2011 the original author or authors. * * Licensed 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.sonatype.gossip.support; import org.junit.Test; import org.sonatype.gossip.Level; /** * Tests for {@link PrintStreamLogger}. */ public class PrintStreamLoggerTest { // Not really tests, more like helpers for manual verification... @Test public void testSimple() { PrintStreamLogger log = new PrintStreamLogger(System.out); System.out.println("LOG: " + log); log.info("Test"); } @Test public void testWithName() { PrintStreamLogger log = new PrintStreamLogger(System.out); log.setName("foo"); System.out.println("LOG: " + log); log.info("Test"); } @Test public void testWithLevel() { PrintStreamLogger log = new PrintStreamLogger(System.out); log.setThreshold(Level.WARN); System.out.println("LOG: " + log); log.info("Test"); log.error("Test"); } @Test public void testWithCause() { PrintStreamLogger log = new PrintStreamLogger(System.out); log.error("oops", new Throwable()); } } gossip-gossip-1.8/header.txt000066400000000000000000000011001167643171700161660ustar00rootroot00000000000000Copyright (c) 2009-2011 the original author or authors. Licensed 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.gossip-gossip-1.8/pom.xml000066400000000000000000000264061167643171700155320ustar00rootroot00000000000000 4.0.0 org.sonatype.forge forge-parent 9 org.sonatype.gossip gossip Gossip 1.8 pom Gossip is a plugin for SLF4j which has simple and flexible configuration. Sonatype http://sonatype.org The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo http://github.com/jdillon/gossip scm:git:git://github.com/jdillon/gossip.git scm:git:ssh://git@github.com/jdillon/gossip.git http://github.com/jdillon/gossip Hudson https://builds.sonatype.org/job/gossip/ jdillon Jason Dillon jason@planet57.com Build Master Developer UTF-8 UTF-8 org.slf4j slf4j-api 1.6.1 junit junit 4.8.2 test org.sonatype.gossip gossip-bootstrap 1.8 org.sonatype.gossip gossip-bootstrap-slf4j 1.8 org.sonatype.gossip gossip-support 1.8 org.sonatype.gossip gossip-core 1.8 org.sonatype.gossip gossip-slf4j 1.8 org.sonatype.gossip gossip-extra 1.8 gossip-bootstrap gossip-bootstrap-slf4j gossip-support gossip-core gossip-slf4j gossip-extra install ${project.basedir}/src/main/resources false **/* ${project.basedir}/src/main/filtered-resources true **/* ${project.basedir}/src/test/resources false **/* ${project.basedir}/src/test/filtered-resources true **/* org.apache.maven.plugins maven-surefire-plugin true once -ea false ${project.build.directory} **/Abstract*.java **/Test*.java **/*Test.java TRACE TRACE org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.apache.maven.plugins maven-source-plugin jar-no-fork true org.codehaus.mojo animal-sniffer-maven-plugin check org.codehaus.mojo.signature java15 1.0 org.apache.maven.plugins maven-release-plugin true false deploy -B -Prelease com.mycila.maven-license-plugin maven-license-plugin true true
${project.basedir}/header.txt
false **/pom.xml **/*.xml **/*.xsd **/*.xjb **/*.mdo **/*.properties **/*.java **/*.groovy **/*.scala **/*.aj **/*.js **/*.css **/target/** JAVADOC_STYLE XML_STYLE XML_STYLE
no-maven-descriptor org.apache.maven.plugins maven-jar-plugin false