Skip to content

Commit

Permalink
Clarify logging
Browse files Browse the repository at this point in the history
  • Loading branch information
twogee committed Nov 12, 2021
1 parent c3585ae commit a81397f
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/DefaultLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* any messages that get logged.
*
*/
public class DefaultLogger implements BuildLogger {
public class DefaultLogger implements BuildLogger, Logger {
/**
* Size of left-hand column for right-justified task name.
* @see #messageLogged(BuildEvent)
Expand Down Expand Up @@ -326,7 +326,7 @@ protected void printMessage(final String message,
*
* @param message Message being logged. Should not be <code>null</code>.
*/
protected void log(String message) {
public void log(String message) {
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/main/org/apache/tools/ant/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant;

/**
* A generic logger interface.
*/
public interface Logger {
/**
* Log a message.
*
* @param message String to be logged
*/
void log(String message);
}
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* file paths at runtime.
*
*/
public class Project implements ResourceFactory {
public class Project implements ResourceFactory, Logger {
/** Message priority of &quot;error&quot;. */
public static final int MSG_ERR = 0;
/** Message priority of &quot;warning&quot;. */
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/ProjectComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Provides common facilities.
*
*/
public abstract class ProjectComponent implements Cloneable {
public abstract class ProjectComponent implements Cloneable, Logger {

// CheckStyle:VisibilityModifier OFF - bc
/**
Expand Down
10 changes: 1 addition & 9 deletions src/main/org/apache/tools/ant/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,6 @@ protected void handleErrorFlush(String output) {
handleErrorOutput(output);
}

/**
* Logs a message with the default (INFO) priority.
*
* @param msg The message to be logged. Should not be <code>null</code>.
*/
public void log(String msg) {
log(msg, Project.MSG_INFO);
}

/**
* Logs a message with the given priority. This delegates
* the actual logging to the project.
Expand All @@ -287,6 +278,7 @@ public void log(String msg) {
* @param msgLevel The message priority at which this message is to
* be logged.
*/
@Override
public void log(String msg, int msgLevel) {
if (getProject() == null) {
super.log(msg, msgLevel);
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/listener/MailLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public Values starttls(boolean starttls) {
* @param message the message being logger
*/
@Override
protected void log(String message) {
public void log(String message) {
buffer.append(message).append(System.lineSeparator());
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
/**
* Interface to log messages for XSLT
* @since Ant 1.5
* @deprecated replaced by Logger
*/
@Deprecated
public interface XSLTLogger {
/**
* Log a message.
Expand Down
15 changes: 13 additions & 2 deletions src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import javax.xml.transform.stream.StreamSource;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Logger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.XSLTLiaison4;
import org.apache.tools.ant.taskdefs.XSLTLogger;
Expand Down Expand Up @@ -100,7 +101,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
/** stylesheet to use for transformation */
private Resource stylesheet;

private XSLTLogger logger;
private Logger logger;

/** possible resolver for publicIds */
private EntityResolver entityResolver;
Expand Down Expand Up @@ -514,10 +515,20 @@ public void addParam(final String name, final Object value) {
* Set a logger.
* @param l a logger.
*/
public void setLogger(final XSLTLogger l) {
public void setLogger(final Logger l) {
logger = l;
}

/**
* Set a logger.
* @param l a logger.
* @deprecated XSLTLogger replaced by Logger
*/
@Deprecated
public void setLogger(final XSLTLogger l) {
logger = (Logger) l;
}

/**
* Log an error.
* @param e the exception to log.
Expand Down
3 changes: 2 additions & 1 deletion src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public EchoTestLogger() {
/**
* {@inheritDoc}
*/
protected void log(String message) {
@Override
public void log(String message) {
this.lastLoggedMessage = message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DefaultCompilerAdapterTest {

private static class LogCapturingJavac extends Javac {
private StringBuilder sb = new StringBuilder();
@Override
public void log(String msg, int msgLevel) {
sb.append(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public int execute() {
};
}

@Override
public void log(String msg, int msgLevel) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
import javax.xml.transform.TransformerFactoryConfigurationError;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Logger;
import org.apache.tools.ant.taskdefs.XSLTLiaison;
import org.apache.tools.ant.taskdefs.XSLTLogger;
import org.apache.tools.ant.util.JAXPUtils;
import org.junit.After;
import org.junit.Test;

/**
* TraX XSLTLiaison testcase
*/
public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements XSLTLogger {
public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements Logger {

@After
public void tearDown() {
Expand Down

0 comments on commit a81397f

Please sign in to comment.