/*
 * Copyright 2014 - 2020 Rafael Winterhalter
 *
 * 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 net.bytebuddy.build;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

An API that can be implemented by logging build systems to allow plugins to log information without depending on a build system-specific logging API.
/** * An API that can be implemented by logging build systems to allow plugins to log information without depending on * a build system-specific logging API. */
public interface BuildLogger {
Returns true if the debug log level is enabled.
Returns:true if the debug log level is enabled.
/** * Returns {@code true} if the debug log level is enabled. * * @return {@code true} if the debug log level is enabled. */
boolean isDebugEnabled();
Logs a message on the debug level.
Params:
  • message – The message to log.
/** * Logs a message on the debug level. * * @param message The message to log. */
void debug(String message);
Logs a message on the debug level.
Params:
  • message – The message to log.
  • throwable – A throwable that is attached to the message.
/** * Logs a message on the debug level. * * @param message The message to log. * @param throwable A throwable that is attached to the message. */
void debug(String message, Throwable throwable);
Returns true if the info log level is enabled.
Returns:true if the info log level is enabled.
/** * Returns {@code true} if the info log level is enabled. * * @return {@code true} if the info log level is enabled. */
boolean isInfoEnabled();
Logs a message on the info level.
Params:
  • message – The message to log.
/** * Logs a message on the info level. * * @param message The message to log. */
void info(String message);
Logs a message on the info level.
Params:
  • message – The message to log.
  • throwable – A throwable that is attached to the message.
/** * Logs a message on the info level. * * @param message The message to log. * @param throwable A throwable that is attached to the message. */
void info(String message, Throwable throwable);
Returns true if the warn log level is enabled.
Returns:true if the warn log level is enabled.
/** * Returns {@code true} if the warn log level is enabled. * * @return {@code true} if the warn log level is enabled. */
boolean isWarnEnabled();
Logs a message on the warn level.
Params:
  • message – The message to log.
/** * Logs a message on the warn level. * * @param message The message to log. */
void warn(String message);
Logs a message on the warn level.
Params:
  • message – The message to log.
  • throwable – A throwable that is attached to the message.
/** * Logs a message on the warn level. * * @param message The message to log. * @param throwable A throwable that is attached to the message. */
void warn(String message, Throwable throwable);
Returns true if the error log level is enabled.
Returns:true if the error log level is enabled.
/** * Returns {@code true} if the error log level is enabled. * * @return {@code true} if the error log level is enabled. */
boolean isErrorEnabled();
Logs a message on the error level.
Params:
  • message – The message to log.
/** * Logs a message on the error level. * * @param message The message to log. */
void error(String message);
Logs a message on the error level.
Params:
  • message – The message to log.
  • throwable – A throwable that is attached to the message.
/** * Logs a message on the error level. * * @param message The message to log. * @param throwable A throwable that is attached to the message. */
void error(String message, Throwable throwable);
A non-operational build logger that discards all statements.
/** * A non-operational build logger that discards all statements. */
enum NoOp implements BuildLogger {
The singleton instance.
/** * The singleton instance. */
INSTANCE;
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isDebugEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isInfoEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isWarnEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isErrorEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message, Throwable throwable) { /* empty */ } }
An abstract adapter implementation for a build logger.
/** * An abstract adapter implementation for a build logger. */
abstract class Adapter implements BuildLogger {
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isDebugEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isInfoEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isWarnEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message, Throwable throwable) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isErrorEnabled() { return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message) { /* empty */ }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message, Throwable throwable) { /* empty */ } }
A build logger that writes all statements to a PrintStream.
/** * A build logger that writes all statements to a {@link PrintStream}. */
@HashCodeAndEqualsPlugin.Enhance class StreamWriting implements BuildLogger {
The target for writing statements.
/** * The target for writing statements. */
private final PrintStream printStream;
Creates a new stream writing build logger.
Params:
  • printStream – The target for writing statements.
/** * Creates a new stream writing build logger. * * @param printStream The target for writing statements. */
public StreamWriting(PrintStream printStream) { this.printStream = printStream; }
Creates a build logger that writes to System.out.
Returns:A build logger that writes to System.out.
/** * Creates a build logger that writes to {@link System#out}. * * @return A build logger that writes to {@link System#out}. */
public static BuildLogger toSystemOut() { return new StreamWriting(System.out); }
Creates a build logger that writes to System.err.
Returns:A build logger that writes to System.err.
/** * Creates a build logger that writes to {@link System#err}. * * @return A build logger that writes to {@link System#err}. */
public static BuildLogger toSystemError() { return new StreamWriting(System.err); }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isDebugEnabled() { return true; }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message) { printStream.print(message); }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message, Throwable throwable) { synchronized (printStream) { printStream.print(message); throwable.printStackTrace(printStream); } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isInfoEnabled() { return true; }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message) { printStream.print(message); }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message, Throwable throwable) { synchronized (printStream) { printStream.print(message); throwable.printStackTrace(printStream); } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isWarnEnabled() { return true; }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message) { printStream.print(message); }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message, Throwable throwable) { synchronized (printStream) { printStream.print(message); throwable.printStackTrace(printStream); } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isErrorEnabled() { return true; }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message) { printStream.print(message); }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message, Throwable throwable) { synchronized (printStream) { printStream.print(message); throwable.printStackTrace(printStream); } } }
A compound build logger.
/** * A compound build logger. */
@HashCodeAndEqualsPlugin.Enhance class Compound implements BuildLogger {
The build loggers to delegate to.
/** * The build loggers to delegate to. */
private final List<BuildLogger> buildLoggers;
Creates a new compound build logger.
Params:
  • buildLogger – The build loggers to delegate to.
/** * Creates a new compound build logger. * * @param buildLogger The build loggers to delegate to. */
public Compound(BuildLogger... buildLogger) { this(Arrays.asList(buildLogger)); }
Creates a new compound build logger.
Params:
  • buildLoggers – The build loggers to delegate to.
/** * Creates a new compound build logger. * * @param buildLoggers The build loggers to delegate to. */
public Compound(List<? extends BuildLogger> buildLoggers) { this.buildLoggers = new ArrayList<BuildLogger>(); for (BuildLogger buildLogger : buildLoggers) { if (buildLogger instanceof Compound) { this.buildLoggers.addAll(((Compound) buildLogger).buildLoggers); } else if (!(buildLogger instanceof NoOp)) { this.buildLoggers.add(buildLogger); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isDebugEnabled() { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isDebugEnabled()) { return true; } } return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isDebugEnabled()) { buildLogger.debug(message); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public void debug(String message, Throwable throwable) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isDebugEnabled()) { buildLogger.debug(message, throwable); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isInfoEnabled() { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isInfoEnabled()) { return true; } } return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isInfoEnabled()) { buildLogger.info(message); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public void info(String message, Throwable throwable) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isInfoEnabled()) { buildLogger.info(message, throwable); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isWarnEnabled() { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isWarnEnabled()) { return true; } } return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isWarnEnabled()) { buildLogger.warn(message); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public void warn(String message, Throwable throwable) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isWarnEnabled()) { buildLogger.warn(message, throwable); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public boolean isErrorEnabled() { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isErrorEnabled()) { return true; } } return false; }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isErrorEnabled()) { buildLogger.error(message); } } }
{@inheritDoc}
/** * {@inheritDoc} */
public void error(String message, Throwable throwable) { for (BuildLogger buildLogger : buildLoggers) { if (buildLogger.isErrorEnabled()) { buildLogger.error(message, throwable); } } } } }