1. /*
  2. * Copyright 2001-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.rmic;
  18. import java.lang.reflect.Constructor;
  19. import java.lang.reflect.Method;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.Project;
  22. import org.apache.tools.ant.types.Commandline;
  23. /**
  24. * The implementation of the rmic for Kaffe
  25. *
  26. * @since Ant 1.4
  27. */
  28. public class KaffeRmic extends DefaultRmicAdapter {
  29. public boolean execute() throws BuildException {
  30. getRmic().log("Using Kaffe rmic", Project.MSG_VERBOSE);
  31. Commandline cmd = setupRmicCommand();
  32. try {
  33. Class c = Class.forName("kaffe.rmi.rmic.RMIC");
  34. Constructor cons = c.getConstructor(new Class[] {String[].class});
  35. Object rmic = cons.newInstance(new Object[] {cmd.getArguments()});
  36. Method doRmic = c.getMethod("run", null);
  37. Boolean ok = (Boolean) doRmic.invoke(rmic, null);
  38. return ok.booleanValue();
  39. } catch (ClassNotFoundException ex) {
  40. throw new BuildException("Cannot use Kaffe rmic, as it is not "
  41. + "available. A common solution is to "
  42. + "set the environment variable "
  43. + "JAVA_HOME or CLASSPATH.",
  44. getRmic().getLocation());
  45. } catch (Exception ex) {
  46. if (ex instanceof BuildException) {
  47. throw (BuildException) ex;
  48. } else {
  49. throw new BuildException("Error starting Kaffe rmic: ",
  50. ex, getRmic().getLocation());
  51. }
  52. }
  53. }
  54. }