From 14b58d0a85e7a302f35590067f1442d5a1a104d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 13 Nov 2022 18:48:35 +0100 Subject: [PATCH] describe compiler configuration on run --- .../plexus/compiler/AbstractCompiler.java | 5 +- .../compiler/CompilerConfiguration.java | 52 +++++++++++++++++++ .../src/main/it/simple-javac-fork/pom.xml | 7 ++- .../plexus/compiler/ajc/AspectJCompiler.java | 6 +++ .../compiler/csharp/CSharpCompiler.java | 6 +++ .../compiler/eclipse/EclipseJavaCompiler.java | 10 ++++ .../compiler/j2objc/J2ObjCCompiler.java | 8 ++- .../JavacCompilerWithErrorProne.java | 6 +++ .../plexus/compiler/javac/JavacCompiler.java | 6 +++ 9 files changed, 100 insertions(+), 6 deletions(-) diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java index 2a64b691..1f6a7d1f 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/AbstractCompiler.java @@ -74,6 +74,8 @@ protected AbstractCompiler( CompilerOutputStyle compilerOutputStyle, String inpu // // ---------------------------------------------------------------------- + public abstract String getCompilerId(); + public CompilerResult performCompile(CompilerConfiguration configuration) throws CompilerException { @@ -308,7 +310,8 @@ protected void logCompiling( String[] sourceFiles, CompilerConfiguration config config.getWorkingDirectory().toPath().relativize( new File( config.getOutputLocation() ).toPath() ).toString(); getLogger().info( "Compiling " + ( sourceFiles == null ? "" : ( sourceFiles.length + " source file" + ( sourceFiles.length == 1 ? " " : "s " ) ) ) + - "to " + to ); + "with " + getCompilerId() + " [" + config.describe() + "]" + + " to " + to ); } } } diff --git a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java index a65fe20f..7387855a 100644 --- a/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java +++ b/plexus-compiler-api/src/main/java/org/codehaus/plexus/compiler/CompilerConfiguration.java @@ -24,6 +24,8 @@ * SOFTWARE. */ +import org.codehaus.plexus.util.StringUtils; + import java.io.File; import java.util.AbstractMap; import java.util.ArrayList; @@ -812,4 +814,54 @@ public void setImplicitOption( String implicitOption ) { this.implicitOption = implicitOption; } + + public String describe() + { + List params = new ArrayList<>(); + + if ( isFork() ) + { + params.add( "forked" ); + } + + // base options: debug, optimize, verbose, deprecation + if ( isDebug() ) + { + if ( StringUtils.isNotEmpty( getDebugLevel() ) ) + { + params.add( "debug:" + getDebugLevel() ); + } + else + { + params.add( "debug" ); + } + } + if ( isOptimize() ) + { + params.add( "optimize" ); + } + if ( isVerbose() ) + { + params.add( "verbose" ); + } + if ( isShowDeprecation() ) + { + params.add( "deprecation" ); + } + + // target bytecode options: release or target, module-path + if ( !StringUtils.isEmpty( getReleaseVersion() ) ) + { + params.add( "release " + getReleaseVersion() ); + } + else if ( !StringUtils.isEmpty( getTargetVersion() ) ) + { + params.add( "target " + getTargetVersion() ); + } + if ( getModulepathEntries() != null && !getModulepathEntries().isEmpty() ) + { + params.add( "module-path" ); + } + return String.join( " ", params ); + } } diff --git a/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml b/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml index d72b91ab..df34466f 100644 --- a/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml +++ b/plexus-compiler-its/src/main/it/simple-javac-fork/pom.xml @@ -24,16 +24,15 @@ 4.0.0 org.codehaus.plexus.compiler.it - simple-javac + simple-javac-forked 1.0-SNAPSHOT - Test for default configuration + Test for default configuration with forked=true UTF-8 UTF-8 - 11 - 11 + 11 @pom.version@ diff --git a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java index ae1a7daf..8efcf201 100644 --- a/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java +++ b/plexus-compilers/plexus-compiler-aspectj/src/main/java/org/codehaus/plexus/compiler/ajc/AspectJCompiler.java @@ -303,6 +303,12 @@ public AspectJCompiler() super( CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE, "", ".class", null ); } + @Override + public String getCompilerId() + { + return "aspectj"; + } + public CompilerResult performCompile( CompilerConfiguration config ) throws CompilerException { diff --git a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java index dc6e01ef..41785ddd 100644 --- a/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java +++ b/plexus-compilers/plexus-compiler-csharp/src/main/java/org/codehaus/plexus/compiler/csharp/CSharpCompiler.java @@ -84,6 +84,12 @@ public CSharpCompiler() // Compiler Implementation // ---------------------------------------------------------------------- + @Override + public String getCompilerId() + { + return "csharp"; + } + public boolean canUpdateTarget( CompilerConfiguration configuration ) throws CompilerException { diff --git a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java index f12891f4..b147b118 100644 --- a/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java +++ b/plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java @@ -72,6 +72,12 @@ public EclipseJavaCompiler() // ---------------------------------------------------------------------- boolean errorsAsWarnings = false; + @Override + public String getCompilerId() + { + return "eclipse"; + } + @Override public CompilerResult performCompile( CompilerConfiguration config ) throws CompilerException @@ -371,6 +377,10 @@ public void report( Diagnostic diagnostic ) args.add( errorF.toString() ); args.addAll( allSources ); + String to = ( config.getWorkingDirectory() == null ) ? config.getOutputLocation() : + config.getWorkingDirectory().toPath().relativize( new File( config.getOutputLocation() ).toPath() ).toString(); + getLogger().info( "Compiling with " + config.describe( "eclipse" ) + + " to " + to ); getLogger().debug( "ecj command line: " + args ); success = BatchCompiler.compile( args.toArray( new String[args.size()] ), devNull, devNull, diff --git a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java index 2621968a..2bb8cf9a 100644 --- a/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java +++ b/plexus-compilers/plexus-compiler-j2objc/src/main/java/org/codehaus/plexus/compiler/j2objc/J2ObjCCompiler.java @@ -51,7 +51,7 @@ * Maître * */ -@Component( role = Compiler.class, hint = "j2objc ") +@Component( role = Compiler.class, hint = "j2objc") public class J2ObjCCompiler extends AbstractCompiler { @@ -98,6 +98,12 @@ public J2ObjCCompiler() // Compiler Implementation // ---------------------------------------------------------------------- + @Override + public String getCompilerId() + { + return "j2objc"; + } + public boolean canUpdateTarget( CompilerConfiguration configuration ) throws CompilerException { diff --git a/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java index 5c2348bc..74282b67 100644 --- a/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java +++ b/plexus-compilers/plexus-compiler-javac-errorprone/src/main/java/org/codehaus/plexus/compiler/javac/errorprone/JavacCompilerWithErrorProne.java @@ -44,6 +44,12 @@ public class JavacCompilerWithErrorProne extends JavacCompiler { + @Override + public String getCompilerId() + { + return "javac-with-errorprone"; + } + private static class NonDelegatingClassLoader extends URLClassLoader { diff --git a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java index b53e52c0..8650d3cb 100644 --- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java +++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java @@ -123,6 +123,12 @@ public JavacCompiler() // Compiler Implementation // ---------------------------------------------------------------------- + @Override + public String getCompilerId() + { + return "javac"; + } + @Override public CompilerResult performCompile( CompilerConfiguration config ) throws CompilerException