1. /*
  2. * Copyright 2001-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.Method;
  19. import org.apache.tools.ant.AntClassLoader;
  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 WebLogic
  25. *
  26. * @since Ant 1.4
  27. */
  28. public class WLRmic extends DefaultRmicAdapter {
  29. public boolean execute() throws BuildException {
  30. getRmic().log("Using WebLogic rmic", Project.MSG_VERBOSE);
  31. Commandline cmd = setupRmicCommand(new String[] {"-noexit"});
  32. AntClassLoader loader = null;
  33. try {
  34. // Create an instance of the rmic
  35. Class c = null;
  36. if (getRmic().getClasspath() == null) {
  37. c = Class.forName("weblogic.rmic");
  38. } else {
  39. loader
  40. = getRmic().getProject().createClassLoader(getRmic().getClasspath());
  41. c = Class.forName("weblogic.rmic", true, loader);
  42. }
  43. Method doRmic = c.getMethod("main",
  44. new Class [] {String[].class});
  45. doRmic.invoke(null, new Object[] {cmd.getArguments()});
  46. return true;
  47. } catch (ClassNotFoundException ex) {
  48. throw new BuildException("Cannot use WebLogic rmic, as it is not "
  49. + "available. A common solution is to "
  50. + "set the environment variable "
  51. + "CLASSPATH.", getRmic().getLocation());
  52. } catch (Exception ex) {
  53. if (ex instanceof BuildException) {
  54. throw (BuildException) ex;
  55. } else {
  56. throw new BuildException("Error starting WebLogic rmic: ", ex,
  57. getRmic().getLocation());
  58. }
  59. } finally {
  60. if (loader != null) {
  61. loader.cleanup();
  62. }
  63. }
  64. }
  65. /**
  66. * Get the suffix for the rmic stub classes
  67. */
  68. public String getStubClassSuffix() {
  69. return "_WLStub";
  70. }
  71. /**
  72. * Get the suffix for the rmic skeleton classes
  73. */
  74. public String getSkelClassSuffix() {
  75. return "_WLSkel";
  76. }
  77. }