Any compatibility error message (related to IDEA-207341)

This commit is contained in:
Leonid Bushuev
2019-02-15 18:43:24 +01:00
parent 6a0f48c0b7
commit 27a9b822e5
@@ -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});
}
}