Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tycho-4.0.x] Print the name and version of used ECJ compiler #2617

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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<Map.Entry<String, String>> customCompilerArgumentEntries = config
.getCustomCompilerArgumentsEntries();
Expand All @@ -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;
Expand Down