From abe4f55d80678d5774a97db45399cd58fdb692aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 9 Jul 2023 07:32:38 +0200 Subject: [PATCH] Print the name and version of used ECJ compiler (cherry picked from commit 094e0fb1ddc0541471900eecbdcd257bba7c8917) --- .../tycho/compiler/jdt/JDTCompiler.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java index 583aed351f..8376a62980 100644 --- a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java +++ b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JDTCompiler.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.StringJoiner; +import java.util.jar.JarFile; +import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -54,6 +56,7 @@ import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.tycho.compiler.jdt.copied.LibraryInfo; +import org.osgi.framework.Constants; /** * See https://help.eclipse.org/ganymede/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_options.htm @@ -75,6 +78,8 @@ public class JDTCompiler extends AbstractCompiler { static final Pattern LINE_PATTERN = Pattern .compile("(?:(\\d*)\\. )?(ERROR|WARNING) in (.*?)( \\(at line (\\d+)\\))?\\s*"); + static final String COMPILER_NAME = getCompilerName(); + @Requirement private JdkLibraryInfoProvider jdkLibInfoProvider; @@ -103,7 +108,7 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil } getLogger().info("Compiling " + sourceFiles.length + " " + "source file" + (sourceFiles.length == 1 ? "" : "s") - + " to " + destinationDir.getAbsolutePath()); + + " to " + destinationDir.getAbsolutePath() + " using " + COMPILER_NAME + ""); Collection> customCompilerArgumentEntries = config .getCustomCompilerArgumentsEntries(); @@ -122,6 +127,30 @@ public CompilerResult performCompile(CompilerConfiguration config) throws Compil return messages; } + private static String getCompilerName() { + + try { + URL location = Main.class.getProtectionDomain().getCodeSource().getLocation(); + File file = new File(location.toURI()); + try (JarFile jarFile = new JarFile(file)) { + Manifest manifest = jarFile.getManifest(); + String name = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME); + String version = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION); + if (name != null && version != null) { + return name + " " + version; + } + if (version != null) { + return "Eclipse Compiler for Java(TM) " + version; + } + if (name != null) { + return name; + } + } + } catch (Exception e) { + } + return "Unknown Compiler"; + } + private boolean requireFork(CompilerConfiguration config, CustomCompilerConfiguration custom) { if (config.isFork()) { return true;