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.ide;
  18. import java.io.File;
  19. import org.apache.tools.ant.BuildException;
  20. import org.apache.tools.ant.types.PatternSet;
  21. /**
  22. * Export packages from the Visual Age for Java workspace.
  23. * The packages are specified similar to all other MatchingTasks.
  24. * Since the VA Workspace is not file based, this task is simulating
  25. * a directory hierarchy for the workspace:
  26. * The 'root' contains all project 'dir's, and the projects contain
  27. * their respective package 'dir's.
  28. * Example:
  29. * <blockquote>
  30. * <vajexport destdir="C:/builddir/source">
  31. *  <include name="/MyVAProject/org/foo/subsystem1/**" />
  32. *  <exclude name="/MyVAProject/org/foo/subsystem1/test/**"/>
  33. * </vajexport>
  34. * </blockquote>
  35. * exports all packages in the project MyVAProject which start with
  36. * 'org.foo.subsystem1' except of these starting with
  37. * 'org.foo.subsystem1.test'.
  38. *
  39. * <p>Parameters:
  40. * <table border="1" cellpadding="2" cellspacing="0">
  41. * <tr>
  42. * <td valign="top"><b>Attribute</b></td>
  43. * <td valign="top"><b>Description</b></td>
  44. * <td align="center" valign="top"><b>Required</b></td>
  45. * </tr>
  46. * <tr>
  47. * <td valign="top">destdir</td>
  48. * <td valign="top">location to store the exported files</td>
  49. * <td align="center" valign="top">Yes</td>
  50. * <tr>
  51. * <td valign="top">exportSources</td>
  52. * <td valign="top">export Java sources, defaults to "yes"</td>
  53. * <td align="center" valign="top">No</td>
  54. * </tr>
  55. * <tr>
  56. * <td valign="top">exportResources</td>
  57. * <td valign="top">export resource files, defaults to "yes"</td>
  58. * <td align="center" valign="top">No</td>
  59. * </tr>
  60. * <tr>
  61. * <td valign="top">exportClasses</td>
  62. * <td valign="top">export class files, defaults to "no"</td>
  63. * <td align="center" valign="top">No</td>
  64. * </tr>
  65. * <tr>
  66. * <td valign="top">exportDebugInfo</td>
  67. * <td valign="top">include debug info in exported class files,
  68. * defaults to "no"</td>
  69. * <td align="center" valign="top">No</td>
  70. * </tr>
  71. * <tr>
  72. * <td valign="top">defaultexcludes</td>
  73. * <td valign="top">use default excludes when exporting,
  74. * defaults to "yes".
  75. * Default excludes are: IBM/**,
  76. * Java class libraries/**, Sun class libraries/**,
  77. * JSP Page Compile Generated Code/**, Visual Age*/**</td>
  78. * <td align="center" valign="top">No</td>
  79. * </tr>
  80. * <tr>
  81. * <td valign="top">overwrite</td>
  82. * <td valign="top">overwrite existing files, defaults to "yes"</td>
  83. * <td align="center" valign="top">No</td>
  84. * </tr>
  85. * <tr>
  86. * <td valign="top">remote</td>
  87. * <td valign="top">remote tool server to run this command against
  88. * (format: <servername> : <port no>)</td>
  89. * <td align="center" valign="top">No</td>
  90. * </tr>
  91. * <tr>
  92. * <td valign="top">haltonerror</td>
  93. * <td valign="top">stop the build process if an error occurs,
  94. * defaults to "yes"</td>
  95. * <td align="center" valign="top">No</td>
  96. * </tr>
  97. * </table>
  98. *
  99. */
  100. public class VAJExport extends VAJTask {
  101. //set set... method comments for description
  102. protected File destDir;
  103. protected boolean exportSources = true;
  104. protected boolean exportResources = true;
  105. protected boolean exportClasses = false;
  106. protected boolean exportDebugInfo = false;
  107. protected boolean useDefaultExcludes = true;
  108. protected boolean overwrite = true;
  109. protected PatternSet patternSet = new PatternSet();
  110. /**
  111. * add a name entry on the exclude list
  112. */
  113. public PatternSet.NameEntry createExclude() {
  114. return patternSet.createExclude();
  115. }
  116. /**
  117. * add a name entry on the include list
  118. */
  119. public PatternSet.NameEntry createInclude() {
  120. return patternSet.createInclude();
  121. }
  122. /**
  123. * do the export
  124. */
  125. public void execute() throws BuildException {
  126. // first off, make sure that we've got a destdir
  127. if (destDir == null) {
  128. throw new BuildException("destdir attribute must be set!");
  129. }
  130. // delegate the export to the VAJUtil object.
  131. try {
  132. getUtil().exportPackages(destDir,
  133. patternSet.getIncludePatterns(getProject()),
  134. patternSet.getExcludePatterns(getProject()),
  135. exportClasses, exportDebugInfo,
  136. exportResources, exportSources,
  137. useDefaultExcludes, overwrite);
  138. } catch (BuildException ex) {
  139. if (haltOnError) {
  140. throw ex;
  141. } else {
  142. log(ex.toString());
  143. }
  144. }
  145. }
  146. /**
  147. * Sets whether default exclusions should be used or not; default true.
  148. *
  149. * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
  150. * should be used, "false"|"off"|"no" when they
  151. * shouldn't be used.
  152. */
  153. public void setDefaultexcludes(boolean useDefaultExcludes) {
  154. this.useDefaultExcludes = useDefaultExcludes;
  155. }
  156. /**
  157. * Set the destination directory into which the selected
  158. * items should be exported; required.
  159. */
  160. public void setDestdir(File destDir) {
  161. this.destDir = destDir;
  162. }
  163. /**
  164. * Sets the set of exclude patterns. Patterns may be separated by a comma
  165. * or a space. Currently only patterns denoting packages are
  166. * supported
  167. *
  168. * @param excludes the string containing the exclude patterns
  169. */
  170. public void setExcludes(String excludes) {
  171. patternSet.setExcludes(excludes);
  172. }
  173. /**
  174. * optional flag to export the class files; default false.
  175. */
  176. public void setExportClasses(boolean doExport) {
  177. exportClasses = doExport;
  178. }
  179. /**
  180. * optional flag to export the debug info; default false.
  181. * debug info
  182. */
  183. public void setExportDebugInfo(boolean doExport) {
  184. exportDebugInfo = doExport;
  185. }
  186. /**
  187. * optional flag to export the resource file; default true.
  188. */
  189. public void setExportResources(boolean doExport) {
  190. exportResources = doExport;
  191. }
  192. /**
  193. * optional flag to export the Java files; default true.
  194. */
  195. public void setExportSources(boolean doExport) {
  196. exportSources = doExport;
  197. }
  198. /**
  199. * Sets the set of include patterns. Patterns may be separated by a comma
  200. * or a space. Currently only patterns denoting packages are
  201. * supported
  202. *
  203. * @param includes the string containing the include patterns
  204. */
  205. public void setIncludes(String includes) {
  206. patternSet.setIncludes(includes);
  207. }
  208. /**
  209. * if Overwrite is set, files will be overwritten during export
  210. */
  211. public void setOverwrite(boolean doOverwrite) {
  212. overwrite = doOverwrite;
  213. }
  214. }