Skip to content

Commit 3ab39cd

Browse files
Restore AbstractCompiler#getLogger() method
We need preserve a compatibility for some time.
1 parent 49a464d commit 3ab39cd

File tree

5 files changed

+156
-22
lines changed

5 files changed

+156
-22
lines changed

plexus-compiler-api/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<groupId>org.codehaus.plexus</groupId>
1919
<artifactId>plexus-utils</artifactId>
2020
</dependency>
21+
<dependency>
22+
<groupId>org.eclipse.sisu</groupId>
23+
<artifactId>org.eclipse.sisu.plexus</artifactId>
24+
<scope>provided</scope>
25+
</dependency>
2126
<dependency>
2227
<groupId>org.slf4j</groupId>
2328
<artifactId>slf4j-api</artifactId>

plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
4040
*/
4141
public abstract class AbstractCompiler implements Compiler {
42-
protected Logger log = LoggerFactory.getLogger(getClass());
42+
private final Logger log = LoggerFactory.getLogger(getClass());
43+
44+
private final org.codehaus.plexus.logging.Logger plexusLogger;
45+
4346
protected static final String EOL = System.lineSeparator();
4447

4548
protected static final String PS = System.getProperty("path.separator");
@@ -68,6 +71,25 @@ protected AbstractCompiler(
6871
this.outputFileEnding = outputFileEnding;
6972

7073
this.outputFile = outputFile;
74+
75+
this.plexusLogger = new PlexusLoggerWrapper(log);
76+
}
77+
78+
/**
79+
*
80+
* @return a Logger
81+
*/
82+
protected Logger getLog() {
83+
return log;
84+
}
85+
86+
/**
87+
* @return a plexus Logger
88+
* @deprecated please use {@link #getLog()}
89+
*/
90+
@Deprecated
91+
protected org.codehaus.plexus.logging.Logger getLogger() {
92+
return plexusLogger;
7193
}
7294

7395
// ----------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.codehaus.plexus.compiler;
2+
3+
import org.slf4j.Logger;
4+
5+
class PlexusLoggerWrapper implements org.codehaus.plexus.logging.Logger {
6+
7+
private final Logger log;
8+
9+
PlexusLoggerWrapper(Logger log) {
10+
this.log = log;
11+
}
12+
13+
@Override
14+
public void debug(String message) {
15+
log.debug(message);
16+
}
17+
18+
@Override
19+
public void debug(String message, Throwable throwable) {
20+
log.debug(message, throwable);
21+
}
22+
23+
@Override
24+
public boolean isDebugEnabled() {
25+
return log.isDebugEnabled();
26+
}
27+
28+
@Override
29+
public void info(String message) {
30+
log.info(message);
31+
}
32+
33+
@Override
34+
public void info(String message, Throwable throwable) {
35+
log.info(message, throwable);
36+
}
37+
38+
@Override
39+
public boolean isInfoEnabled() {
40+
return log.isInfoEnabled();
41+
}
42+
43+
@Override
44+
public void warn(String message) {
45+
log.warn(message);
46+
}
47+
48+
@Override
49+
public void warn(String message, Throwable throwable) {
50+
log.warn(message, throwable);
51+
}
52+
53+
@Override
54+
public boolean isWarnEnabled() {
55+
return log.isWarnEnabled();
56+
}
57+
58+
@Override
59+
public void error(String message) {
60+
log.error(message);
61+
}
62+
63+
@Override
64+
public void error(String message, Throwable throwable) {
65+
log.error(message, throwable);
66+
}
67+
68+
@Override
69+
public boolean isErrorEnabled() {
70+
return log.isErrorEnabled();
71+
}
72+
73+
@Override
74+
public void fatalError(String message) {
75+
log.error(message);
76+
}
77+
78+
@Override
79+
public void fatalError(String message, Throwable throwable) {
80+
log.error(message, throwable);
81+
}
82+
83+
@Override
84+
public boolean isFatalErrorEnabled() {
85+
return log.isErrorEnabled();
86+
}
87+
88+
@Override
89+
public int getThreshold() {
90+
return 0;
91+
}
92+
93+
@Override
94+
public void setThreshold(int threshold) {
95+
// not implemented
96+
}
97+
98+
@Override
99+
public org.codehaus.plexus.logging.Logger getChildLogger(String name) {
100+
return null;
101+
}
102+
103+
@Override
104+
public String getName() {
105+
return log.getName();
106+
}
107+
}

plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
229229
JavaCompiler compiler = getEcj();
230230
boolean success = false;
231231
if (compiler != null) {
232-
log.debug("Using JSR-199 EclipseCompiler");
232+
getLog().debug("Using JSR-199 EclipseCompiler");
233233
// ECJ JSR-199 compiles against the latest Java version it supports if no source
234234
// version is given explicitly. BatchCompiler uses 1.3 as default. So check
235235
// whether a source version is specified, and if not supply 1.3 explicitly.
236236
if (!haveSourceOrReleaseArgument(args)) {
237-
log.debug("ecj: no source level nor release specified, defaulting to Java 1.3");
237+
getLog().debug("ecj: no source level nor release specified, defaulting to Java 1.3");
238238
args.add("-source");
239239
args.add("1.3");
240240
}
@@ -286,17 +286,17 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
286286
try {
287287
charset = Charset.forName(encoding);
288288
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
289-
log.warn("ecj: invalid or unsupported character set '" + encoding + "', using default");
289+
getLog().warn("ecj: invalid or unsupported character set '" + encoding + "', using default");
290290
// charset remains null
291291
}
292292
}
293293
if (charset == null) {
294294
charset = Charset.defaultCharset();
295295
}
296-
if (log.isDebugEnabled()) {
297-
log.debug("ecj: using character set " + charset.displayName());
298-
log.debug("ecj command line: " + args);
299-
log.debug("ecj input source files: " + allSources);
296+
if (getLog().isDebugEnabled()) {
297+
getLog().debug("ecj: using character set " + charset.displayName());
298+
getLog().debug("ecj command line: " + args);
299+
getLog().debug("ecj input source files: " + allSources);
300300
}
301301

302302
try (StandardJavaFileManager manager =
@@ -308,19 +308,19 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
308308
} catch (RuntimeException e) {
309309
throw new EcjFailureException(e.getLocalizedMessage());
310310
}
311-
log.debug(sw.toString());
311+
getLog().debug(sw.toString());
312312
} else {
313313
// Use the BatchCompiler and send all errors to xml temp file.
314314
File errorF = null;
315315
try {
316316
errorF = File.createTempFile("ecjerr-", ".xml");
317-
log.debug("Using legacy BatchCompiler; error file " + errorF);
317+
getLog().debug("Using legacy BatchCompiler; error file " + errorF);
318318

319319
args.add("-log");
320320
args.add(errorF.toString());
321321
args.addAll(allSources);
322322

323-
log.debug("ecj command line: " + args);
323+
getLog().debug("ecj command line: " + args);
324324

325325
success = BatchCompiler.compile(
326326
args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
@@ -341,7 +341,7 @@ public void setTaskName(String s) {}
341341
@Override
342342
public void worked(int i, int i1) {}
343343
});
344-
log.debug(sw.toString());
344+
getLog().debug(sw.toString());
345345

346346
if (errorF.length() < 80) {
347347
throw new EcjFailureException(sw.toString());
@@ -524,7 +524,7 @@ private JavaCompiler getEcj() {
524524
}
525525
}
526526
}
527-
log.debug("Cannot find org.eclipse.jdt.internal.compiler.tool.EclipseCompiler");
527+
getLog().debug("Cannot find org.eclipse.jdt.internal.compiler.tool.EclipseCompiler");
528528
return null;
529529
}
530530

@@ -618,7 +618,7 @@ private String decodeVersion(String versionSpec) {
618618
}
619619

620620
if (versionSpec.equals("1.9")) {
621-
log.warn("Version 9 should be specified as 9, not 1.9");
621+
getLog().warn("Version 9 should be specified as 9, not 1.9");
622622
return "9";
623623
}
624624
return versionSpec;

plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil
154154
try {
155155
executable = getJavacExecutable();
156156
} catch (IOException e) {
157-
if (log.isWarnEnabled()) {
158-
log.warn("Unable to autodetect 'javac' path, using 'javac' from the environment.");
157+
if (getLog().isWarnEnabled()) {
158+
getLog().warn("Unable to autodetect 'javac' path, using 'javac' from the environment.");
159159
}
160160
executable = "javac";
161161
}
@@ -541,7 +541,7 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
541541

542542
List<CompilerMessage> messages;
543543

544-
if (log.isDebugEnabled()) {
544+
if (getLog().isDebugEnabled()) {
545545
String debugFileName = StringUtils.isEmpty(config.getDebugFileName()) ? "javac" : config.getDebugFileName();
546546

547547
File commandLineFile = new File(
@@ -555,8 +555,8 @@ protected CompilerResult compileOutOfProcess(CompilerConfiguration config, Strin
555555
Runtime.getRuntime().exec(new String[] {"chmod", "a+x", commandLineFile.getAbsolutePath()});
556556
}
557557
} catch (IOException e) {
558-
if (log.isWarnEnabled()) {
559-
log.warn("Unable to write '" + commandLineFile.getName() + "' debug script file", e);
558+
if (getLog().isWarnEnabled()) {
559+
getLog().warn("Unable to write '" + commandLineFile.getName() + "' debug script file", e);
560560
}
561561
}
562562
}
@@ -587,8 +587,8 @@ CompilerResult compileInProcess(String[] args, CompilerConfiguration config) thr
587587
final Thread thread = Thread.currentThread();
588588
final ClassLoader contextClassLoader = thread.getContextClassLoader();
589589
thread.setContextClassLoader(javacClass.getClassLoader());
590-
if (log.isDebugEnabled()) {
591-
log.debug("ttcl changed run compileInProcessWithProperClassloader");
590+
if (getLog().isDebugEnabled()) {
591+
getLog().debug("ttcl changed run compileInProcessWithProperClassloader");
592592
}
593593
try {
594594
return compileInProcessWithProperClassloader(javacClass, args);
@@ -880,7 +880,7 @@ private File createFileWithArguments(String[] args, String outputDirectory) thro
880880
PrintWriter writer = null;
881881
try {
882882
File tempFile;
883-
if (log.isDebugEnabled()) {
883+
if (getLog().isDebugEnabled()) {
884884
tempFile = File.createTempFile(JavacCompiler.class.getName(), "arguments", new File(outputDirectory));
885885
} else {
886886
tempFile = File.createTempFile(JavacCompiler.class.getName(), "arguments");

0 commit comments

Comments
 (0)