diff --git a/CONTRIBUTORS b/CONTRIBUTORS index bdbab8637..6964599bb 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -33,6 +33,7 @@ Benjamin Burgess Ben Galbraith Benoit Moussaud Bernd Dutkowski +Bernhard Rosenkraenzer Brad Clark Brant Langer Gurganus Brian Curnow diff --git a/WHATSNEW b/WHATSNEW index 7ded7aa87..eb78fbff8 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -229,6 +229,9 @@ Other changes: * A new can be used like wget's --cut-dirs option to strip leading directories from file names. + * now supports the GNU project's gcjh compiler. + Bugzilla Report 50149. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== diff --git a/contributors.xml b/contributors.xml index 9b7e03251..06be2cd3b 100644 --- a/contributors.xml +++ b/contributors.xml @@ -156,6 +156,10 @@ Bernd Dutkowski + + Bernhard + Rosenkraenzer + Brad Clark diff --git a/docs/manual/Tasks/javah.html b/docs/manual/Tasks/javah.html index b29041e9f..01b0d917d 100644 --- a/docs/manual/Tasks/javah.html +++ b/docs/manual/Tasks/javah.html @@ -40,6 +40,9 @@ name="implementationvalues">Here are the choices of the attribute:

  • default - the default compiler (kaffeh or sun) for the platform.
  • sun (the standard compiler of the JDK)
  • kaffeh (the native standard compiler of Kaffe)
  • +
  • gcjh (the native standard compiler + of gcj and gij) since Ant 1.8.2
  • Note: if you are using this task to work on multiple files diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javah/Gcjh.java b/src/main/org/apache/tools/ant/taskdefs/optional/javah/Gcjh.java new file mode 100644 index 000000000..712bb76ab --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javah/Gcjh.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.optional.javah; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.optional.Javah; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.JavaEnvUtils; + +/** + * Adapter to the native gcjh compiler. + * + * @since Ant 1.8.2 + */ +public class Gcjh implements JavahAdapter { + + public static final String IMPLEMENTATION_NAME = "gcjh"; + + /** + * Performs the actual compilation. + */ + public boolean compile(Javah javah) throws BuildException { + Commandline cmd = setupGcjhCommand(javah); + try { + Execute.runCommand(javah, cmd.getCommandline()); + return true; + } catch (BuildException e) { + if (e.getMessage().indexOf("failed with return code") == -1) { + throw e; + } + } + return false; + } + + private Commandline setupGcjhCommand(Javah javah) { + Commandline cmd = new Commandline(); + cmd.setExecutable(JavaEnvUtils.getJdkExecutable("gcjh")); + + if (javah.getDestdir() != null) { + cmd.createArgument().setValue("-d"); + cmd.createArgument().setFile(javah.getDestdir()); + } + + if (javah.getOutputfile() != null) { + cmd.createArgument().setValue("-o"); + cmd.createArgument().setFile(javah.getOutputfile()); + } + + Path cp = new Path(javah.getProject()); + if (javah.getBootclasspath() != null) { + cp.append(javah.getBootclasspath()); + } + cp = cp.concatSystemBootClasspath("ignore"); + if (javah.getClasspath() != null) { + cp.append(javah.getClasspath()); + } + if (cp.size() > 0) { + cmd.createArgument().setValue("--classpath"); + cmd.createArgument().setPath(cp); + } + + if (!javah.getOld()) { + cmd.createArgument().setValue("-jni"); + } + + cmd.addArguments(javah.getCurrentArgs()); + + javah.logAndAddFiles(cmd); + return cmd; + } + +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java index bbb2edaa3..d98b42763 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java @@ -42,6 +42,8 @@ public class JavahAdapterFactory { public static String getDefault() { if (JavaEnvUtils.isKaffe()) { return Kaffeh.IMPLEMENTATION_NAME; + } else if (JavaEnvUtils.isGij()) { + return Gcjh.IMPLEMENTATION_NAME; } return SunJavah.IMPLEMENTATION_NAME; } @@ -82,6 +84,9 @@ public class JavahAdapterFactory { if ((JavaEnvUtils.isKaffe() && choice == null) || Kaffeh.IMPLEMENTATION_NAME.equals(choice)) { return new Kaffeh(); + } else if ((JavaEnvUtils.isGij() && choice == null) + || Gcjh.IMPLEMENTATION_NAME.equals(choice)) { + return new Gcjh(); } else if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) { return new SunJavah(); } else if (choice != null) { diff --git a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java index b58b2ec78..535312723 100644 --- a/src/main/org/apache/tools/ant/util/JavaEnvUtils.java +++ b/src/main/org/apache/tools/ant/util/JavaEnvUtils.java @@ -91,6 +91,8 @@ public final class JavaEnvUtils { /** Whether this is the Kaffe VM */ private static boolean kaffeDetected; + /** Whether this is the GNU VM (gcj/gij) */ + private static boolean gijDetected; /** array of packages in the runtime */ private static Vector jrePackages; @@ -138,6 +140,13 @@ public final class JavaEnvUtils { } catch (Throwable t) { // swallow as this simply doesn't seem to be Kaffe } + gijDetected = false; + try { + Class.forName("gnu.gcj.Core"); + gijDetected = true; + } catch (Throwable t) { + // swallow as this simply doesn't seem to be gcj/gij + } } /** @@ -198,6 +207,15 @@ public final class JavaEnvUtils { return kaffeDetected; } + /** + * Checks whether the current Java VM is the GNU interpreter gij + * or we are running in a gcj precompiled binary. + * @return true if the current Java VM is gcj/gij. + */ + public static boolean isGij() { + return gijDetected; + } + /** * Finds an executable that is part of a JRE installation based on * the java.home system property.