From 27a9b822e59388e76380fc4dec25c03e6d229f79 Mon Sep 17 00:00:00 2001 From: Leonid Bushuev Date: Fri, 15 Feb 2019 18:43:24 +0100 Subject: [PATCH] Any compatibility error message (related to IDEA-207341) --- .../intellij/rt/ant/execution/AntMain2.java | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java b/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java index dc072a08b7c9..939e6749e7fb 100644 --- a/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java +++ b/java/java-runtime/src/com/intellij/rt/ant/execution/AntMain2.java @@ -20,24 +20,39 @@ import java.lang.reflect.InvocationTargetException; public final class AntMain2 { public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - IdeaAntLogger2.guardStreams(); - // as we build classpath ourselves, and ensure all libraries are added to classpath, - // preferred way for us to run ant will be using the traditional ant entry point, via the "Main" class try { - final Class antMain = Class.forName("org.apache.tools.ant.Main"); - antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args}); - return; + IdeaAntLogger2.guardStreams(); + + // as we build classpath ourselves, and ensure all libraries are added to classpath, + // preferred way for us to run ant will be using the traditional ant entry point, via the "Main" class + try { + final Class antMain = Class.forName("org.apache.tools.ant.Main"); + antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args}); + return; + } + catch (ClassNotFoundException e) { + // ignore + } + + // fallback: try the newer approach, launcher + // This approach is less preferred in our case, but still... + // From the ant documentation: "You should start the launcher with the most minimal classpath possible, generally just the ant-launcher.jar." + final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher"); + antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args}); } - catch (ClassNotFoundException e) { - // ignore + catch (UnsupportedClassVersionError ucv) { + String jreVersion = System.getProperty("java.version"); + String message = "\nThe version of the executed Ant is not compatible with the JRE version " + jreVersion + ". " + + "\nTo use Ant with this Java version, download an older version of Ant, " + + "unpack it and specify the path to it on the 'Execution' tab in the 'Build File Properties' dialog " + + "(accessible via the 'Ant Build' tool window -> Properties button)."; + throw new IllegalStateException(message) { + public synchronized Throwable fillInStackTrace() { + return this; + } + }; } - - // fallback: try the newer approach, launcher - // This approach is less preferred in our case, but still... - // From the ant documentation: "You should start the launcher with the most minimal classpath possible, generally just the ant-launcher.jar." - final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher"); - antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args}); } }