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.optional.jsp.compilers;
  18. import java.io.File;
  19. import java.util.Enumeration;
  20. import java.util.Vector;
  21. import org.apache.tools.ant.Project;
  22. import org.apache.tools.ant.taskdefs.optional.jsp.JspC;
  23. import org.apache.tools.ant.types.CommandlineJava;
  24. /**
  25. * This is the default implementation for the JspCompilerAdapter interface.
  26. * This is currently very light on the ground since only one compiler type is
  27. * supported.
  28. *
  29. */
  30. public abstract class DefaultJspCompilerAdapter
  31. implements JspCompilerAdapter {
  32. private static String lSep = System.getProperty("line.separator");
  33. /**
  34. * Logs the compilation parameters, adds the files to compile and logs the
  35. * "niceSourceList"
  36. */
  37. protected void logAndAddFilesToCompile(JspC jspc,
  38. Vector compileList,
  39. CommandlineJava cmd) {
  40. jspc.log("Compilation " + cmd.describeJavaCommand(),
  41. Project.MSG_VERBOSE);
  42. StringBuffer niceSourceList = new StringBuffer("File");
  43. if (compileList.size() != 1) {
  44. niceSourceList.append("s");
  45. }
  46. niceSourceList.append(" to be compiled:");
  47. niceSourceList.append(lSep);
  48. Enumeration e = compileList.elements();
  49. while (e.hasMoreElements()) {
  50. String arg = (String) e.nextElement();
  51. cmd.createArgument().setValue(arg);
  52. niceSourceList.append(" " + arg + lSep);
  53. }
  54. jspc.log(niceSourceList.toString(), Project.MSG_VERBOSE);
  55. }
  56. /**
  57. * our owner
  58. */
  59. protected JspC owner;
  60. /**
  61. * set the owner
  62. */
  63. public void setJspc(JspC owner) {
  64. this.owner = owner;
  65. }
  66. /** get the owner
  67. * @return the owner; should never be null
  68. */
  69. public JspC getJspc() {
  70. return owner;
  71. }
  72. /**
  73. * add an argument oneple to the argument list, if the value aint null
  74. *
  75. * @param argument The argument
  76. */
  77. protected void addArg(CommandlineJava cmd, String argument) {
  78. if (argument != null && argument.length() != 0) {
  79. cmd.createArgument().setValue(argument);
  80. }
  81. }
  82. /**
  83. * add an argument tuple to the argument list, if the value aint null
  84. *
  85. * @param argument The argument
  86. * @param value the parameter
  87. */
  88. protected void addArg(CommandlineJava cmd, String argument, String value) {
  89. if (value != null) {
  90. cmd.createArgument().setValue(argument);
  91. cmd.createArgument().setValue(value);
  92. }
  93. }
  94. /**
  95. * add an argument tuple to the arg list, if the file parameter aint null
  96. *
  97. * @param argument The argument
  98. * @param file the parameter
  99. */
  100. protected void addArg(CommandlineJava cmd, String argument, File file) {
  101. if (file != null) {
  102. cmd.createArgument().setValue(argument);
  103. cmd.createArgument().setFile(file);
  104. }
  105. }
  106. /**
  107. * ask if compiler can sort out its own dependencies
  108. * @return true if the compiler wants to do its own
  109. * depends
  110. */
  111. public boolean implementsOwnDependencyChecking() {
  112. return false;
  113. }
  114. /**
  115. * get our project
  116. * @return owner project data
  117. */
  118. public Project getProject() {
  119. return getJspc().getProject();
  120. }
  121. }