Skip to content

Commit 874fd43

Browse files
committed
Clean up logging in ANT task
1 parent 2bf6e18 commit 874fd43

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/main/java/de/thetaphi/forbiddenapis/ant/AntTask.java

+23-21
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ public class AntTask extends Task {
7272

7373
@Override
7474
public void execute() throws BuildException {
75+
final Logger log = new Logger() {
76+
@Override
77+
public void error(String msg) {
78+
log(msg, Project.MSG_ERR);
79+
}
80+
81+
@Override
82+
public void warn(String msg) {
83+
// ANT has no real log levels printed, so prefix with "WARNING":
84+
log("WARNING: " + msg, Project.MSG_WARN);
85+
}
86+
87+
@Override
88+
public void info(String msg) {
89+
log(msg, Project.MSG_INFO);
90+
}
91+
};
92+
7593
AntClassLoader antLoader = null;
7694
try {
7795
final ClassLoader loader;
@@ -90,23 +108,7 @@ public void execute() throws BuildException {
90108
if (failOnMissingClasses) options.add(FAIL_ON_MISSING_CLASSES);
91109
if (failOnViolation) options.add(FAIL_ON_VIOLATION);
92110
if (failOnUnresolvableSignatures) options.add(FAIL_ON_UNRESOLVABLE_SIGNATURES);
93-
final Checker checker = new Checker(new Logger() {
94-
@Override
95-
public void error(String msg) {
96-
log(msg, Project.MSG_ERR);
97-
}
98-
99-
@Override
100-
public void warn(String msg) {
101-
// ANT has no real log levels printed, so prefix with "WARNING":
102-
log("WARNING: " + msg, Project.MSG_WARN);
103-
}
104-
105-
@Override
106-
public void info(String msg) {
107-
log(msg, Project.MSG_INFO);
108-
}
109-
}, loader, options);
111+
final Checker checker = new Checker(log, loader, options);
110112

111113
if (!checker.isSupportedJDK) {
112114
final String msg = String.format(Locale.ENGLISH,
@@ -115,7 +117,7 @@ public void info(String msg) {
115117
if (failOnUnsupportedJava) {
116118
throw new BuildException(msg);
117119
} else {
118-
log("WARNING: " + msg, Project.MSG_WARN);
120+
log.warn(msg);
119121
return;
120122
}
121123
}
@@ -156,7 +158,7 @@ public void info(String msg) {
156158
throw new BuildException("No API signatures found; use signaturesFile=, <signaturesFileSet/>, <bundledSignatures/> or inner text to define those!");
157159
}
158160

159-
log("Loading classes to check...", Project.MSG_INFO);
161+
log.info("Loading classes to check...");
160162
try {
161163
@SuppressWarnings("unchecked")
162164
final Iterator<Resource> iter = classFiles.iterator();
@@ -172,8 +174,8 @@ public void info(String msg) {
172174
}
173175
if (!foundClass) {
174176
if (ignoreEmptyFileset) {
175-
log("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.", Project.MSG_WARN);
176-
log("Scanned 0 class files.", Project.MSG_INFO);
177+
log.warn("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.");
178+
log.info("Scanned 0 class files.");
177179
return;
178180
} else {
179181
throw new BuildException("There is no <fileset/> or other resource collection given, or the collection does not contain any class files to check.");

0 commit comments

Comments
 (0)