Skip to content

Commit a81397f

Browse files
committed
Clarify logging
1 parent c3585ae commit a81397f

File tree

12 files changed

+57
-19
lines changed

12 files changed

+57
-19
lines changed

src/main/org/apache/tools/ant/DefaultLogger.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* any messages that get logged.
3737
*
3838
*/
39-
public class DefaultLogger implements BuildLogger {
39+
public class DefaultLogger implements BuildLogger, Logger {
4040
/**
4141
* Size of left-hand column for right-justified task name.
4242
* @see #messageLogged(BuildEvent)
@@ -326,7 +326,7 @@ protected void printMessage(final String message,
326326
*
327327
* @param message Message being logged. Should not be <code>null</code>.
328328
*/
329-
protected void log(String message) {
329+
public void log(String message) {
330330
}
331331

332332
/**
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
package org.apache.tools.ant;
19+
20+
/**
21+
* A generic logger interface.
22+
*/
23+
public interface Logger {
24+
/**
25+
* Log a message.
26+
*
27+
* @param message String to be logged
28+
*/
29+
void log(String message);
30+
}

src/main/org/apache/tools/ant/Project.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* file paths at runtime.
6363
*
6464
*/
65-
public class Project implements ResourceFactory {
65+
public class Project implements ResourceFactory, Logger {
6666
/** Message priority of &quot;error&quot;. */
6767
public static final int MSG_ERR = 0;
6868
/** Message priority of &quot;warning&quot;. */

src/main/org/apache/tools/ant/ProjectComponent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Provides common facilities.
2323
*
2424
*/
25-
public abstract class ProjectComponent implements Cloneable {
25+
public abstract class ProjectComponent implements Cloneable, Logger {
2626

2727
// CheckStyle:VisibilityModifier OFF - bc
2828
/**

src/main/org/apache/tools/ant/Task.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ protected void handleErrorFlush(String output) {
270270
handleErrorOutput(output);
271271
}
272272

273-
/**
274-
* Logs a message with the default (INFO) priority.
275-
*
276-
* @param msg The message to be logged. Should not be <code>null</code>.
277-
*/
278-
public void log(String msg) {
279-
log(msg, Project.MSG_INFO);
280-
}
281-
282273
/**
283274
* Logs a message with the given priority. This delegates
284275
* the actual logging to the project.
@@ -287,6 +278,7 @@ public void log(String msg) {
287278
* @param msgLevel The message priority at which this message is to
288279
* be logged.
289280
*/
281+
@Override
290282
public void log(String msg, int msgLevel) {
291283
if (getProject() == null) {
292284
super.log(msg, msgLevel);

src/main/org/apache/tools/ant/listener/MailLogger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public Values starttls(boolean starttls) {
307307
* @param message the message being logger
308308
*/
309309
@Override
310-
protected void log(String message) {
310+
public void log(String message) {
311311
buffer.append(message).append(System.lineSeparator());
312312
}
313313

src/main/org/apache/tools/ant/taskdefs/XSLTLogger.java

+2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
/**
2222
* Interface to log messages for XSLT
2323
* @since Ant 1.5
24+
* @deprecated replaced by Logger
2425
*/
26+
@Deprecated
2527
public interface XSLTLogger {
2628
/**
2729
* Log a message.

src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.xml.transform.stream.StreamSource;
5151

5252
import org.apache.tools.ant.BuildException;
53+
import org.apache.tools.ant.Logger;
5354
import org.apache.tools.ant.Project;
5455
import org.apache.tools.ant.taskdefs.XSLTLiaison4;
5556
import org.apache.tools.ant.taskdefs.XSLTLogger;
@@ -100,7 +101,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
100101
/** stylesheet to use for transformation */
101102
private Resource stylesheet;
102103

103-
private XSLTLogger logger;
104+
private Logger logger;
104105

105106
/** possible resolver for publicIds */
106107
private EntityResolver entityResolver;
@@ -514,10 +515,20 @@ public void addParam(final String name, final Object value) {
514515
* Set a logger.
515516
* @param l a logger.
516517
*/
517-
public void setLogger(final XSLTLogger l) {
518+
public void setLogger(final Logger l) {
518519
logger = l;
519520
}
520521

522+
/**
523+
* Set a logger.
524+
* @param l a logger.
525+
* @deprecated XSLTLogger replaced by Logger
526+
*/
527+
@Deprecated
528+
public void setLogger(final XSLTLogger l) {
529+
logger = (Logger) l;
530+
}
531+
521532
/**
522533
* Log an error.
523534
* @param e the exception to log.

src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public EchoTestLogger() {
9797
/**
9898
* {@inheritDoc}
9999
*/
100-
protected void log(String message) {
100+
@Override
101+
public void log(String message) {
101102
this.lastLoggedMessage = message;
102103
}
103104

src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class DefaultCompilerAdapterTest {
5050

5151
private static class LogCapturingJavac extends Javac {
5252
private StringBuilder sb = new StringBuilder();
53+
@Override
5354
public void log(String msg, int msgLevel) {
5455
sb.append(msg);
5556
}

src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public int execute() {
6363
};
6464
}
6565

66+
@Override
6667
public void log(String msg, int msgLevel) {
6768
}
6869
}

src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
import javax.xml.transform.TransformerFactoryConfigurationError;
3434

3535
import org.apache.tools.ant.BuildException;
36+
import org.apache.tools.ant.Logger;
3637
import org.apache.tools.ant.taskdefs.XSLTLiaison;
37-
import org.apache.tools.ant.taskdefs.XSLTLogger;
3838
import org.apache.tools.ant.util.JAXPUtils;
3939
import org.junit.After;
4040
import org.junit.Test;
4141

4242
/**
4343
* TraX XSLTLiaison testcase
4444
*/
45-
public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements XSLTLogger {
45+
public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements Logger {
4646

4747
@After
4848
public void tearDown() {

0 commit comments

Comments
 (0)