PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/ant-1.8.2/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 445 lines | 178 code | 48 blank | 219 comment | 11 complexity | 356fd67df75934941c58fd8f5f8abd5f MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package org.apache.tools.ant.taskdefs;
  19. import java.io.File;
  20. import java.util.Enumeration;
  21. import java.util.StringTokenizer;
  22. import org.apache.tools.ant.DirectoryScanner;
  23. import org.apache.tools.ant.Project;
  24. import org.apache.tools.ant.Task;
  25. import org.apache.tools.ant.types.FileSet;
  26. import org.apache.tools.ant.types.PatternSet;
  27. import org.apache.tools.ant.types.selectors.AndSelector;
  28. import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
  29. import org.apache.tools.ant.types.selectors.ContainsSelector;
  30. import org.apache.tools.ant.types.selectors.DateSelector;
  31. import org.apache.tools.ant.types.selectors.DependSelector;
  32. import org.apache.tools.ant.types.selectors.DepthSelector;
  33. import org.apache.tools.ant.types.selectors.DifferentSelector;
  34. import org.apache.tools.ant.types.selectors.ExtendSelector;
  35. import org.apache.tools.ant.types.selectors.FileSelector;
  36. import org.apache.tools.ant.types.selectors.FilenameSelector;
  37. import org.apache.tools.ant.types.selectors.MajoritySelector;
  38. import org.apache.tools.ant.types.selectors.NoneSelector;
  39. import org.apache.tools.ant.types.selectors.NotSelector;
  40. import org.apache.tools.ant.types.selectors.OrSelector;
  41. import org.apache.tools.ant.types.selectors.PresentSelector;
  42. import org.apache.tools.ant.types.selectors.SelectSelector;
  43. import org.apache.tools.ant.types.selectors.SelectorContainer;
  44. import org.apache.tools.ant.types.selectors.SizeSelector;
  45. import org.apache.tools.ant.types.selectors.TypeSelector;
  46. import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
  47. /**
  48. * This is an abstract task that should be used by all those tasks that
  49. * require to include or exclude files based on pattern matching.
  50. *
  51. * @since Ant 1.1
  52. */
  53. public abstract class MatchingTask extends Task implements SelectorContainer {
  54. // CheckStyle:VisibilityModifier OFF - bc
  55. protected FileSet fileset = new FileSet();
  56. // CheckStyle:VisibilityModifier ON
  57. /** {@inheritDoc}. */
  58. public void setProject(Project project) {
  59. super.setProject(project);
  60. fileset.setProject(project);
  61. }
  62. /**
  63. * add a name entry on the include list
  64. * @return a NameEntry object to be configured
  65. */
  66. public PatternSet.NameEntry createInclude() {
  67. return fileset.createInclude();
  68. }
  69. /**
  70. * add a name entry on the include files list
  71. * @return an NameEntry object to be configured
  72. */
  73. public PatternSet.NameEntry createIncludesFile() {
  74. return fileset.createIncludesFile();
  75. }
  76. /**
  77. * add a name entry on the exclude list
  78. * @return an NameEntry object to be configured
  79. */
  80. public PatternSet.NameEntry createExclude() {
  81. return fileset.createExclude();
  82. }
  83. /**
  84. * add a name entry on the include files list
  85. * @return an NameEntry object to be configured
  86. */
  87. public PatternSet.NameEntry createExcludesFile() {
  88. return fileset.createExcludesFile();
  89. }
  90. /**
  91. * add a set of patterns
  92. * @return PatternSet object to be configured
  93. */
  94. public PatternSet createPatternSet() {
  95. return fileset.createPatternSet();
  96. }
  97. /**
  98. * Sets the set of include patterns. Patterns may be separated by a comma
  99. * or a space.
  100. *
  101. * @param includes the string containing the include patterns
  102. */
  103. public void setIncludes(String includes) {
  104. fileset.setIncludes(includes);
  105. }
  106. // CheckStyle:MethodNameCheck OFF - bc
  107. /**
  108. * Set this to be the items in the base directory that you want to be
  109. * included. You can also specify "*" for the items (ie: items="*")
  110. * and it will include all the items in the base directory.
  111. *
  112. * @param itemString the string containing the files to include.
  113. */
  114. public void XsetItems(String itemString) {
  115. log("The items attribute is deprecated. "
  116. + "Please use the includes attribute.", Project.MSG_WARN);
  117. if (itemString == null || itemString.equals("*")
  118. || itemString.equals(".")) {
  119. createInclude().setName("**");
  120. } else {
  121. StringTokenizer tok = new StringTokenizer(itemString, ", ");
  122. while (tok.hasMoreTokens()) {
  123. String pattern = tok.nextToken().trim();
  124. if (pattern.length() > 0) {
  125. createInclude().setName(pattern + "/**");
  126. }
  127. }
  128. }
  129. }
  130. /**
  131. * Sets the set of exclude patterns. Patterns may be separated by a comma
  132. * or a space.
  133. *
  134. * @param excludes the string containing the exclude patterns
  135. */
  136. public void setExcludes(String excludes) {
  137. fileset.setExcludes(excludes);
  138. }
  139. /**
  140. * List of filenames and directory names to not include. They should be
  141. * either , or " " (space) separated. The ignored files will be logged.
  142. *
  143. * @param ignoreString the string containing the files to ignore.
  144. */
  145. public void XsetIgnore(String ignoreString) {
  146. log("The ignore attribute is deprecated."
  147. + "Please use the excludes attribute.", Project.MSG_WARN);
  148. if (ignoreString != null && ignoreString.length() > 0) {
  149. StringTokenizer tok = new StringTokenizer(ignoreString, ", ",
  150. false);
  151. while (tok.hasMoreTokens()) {
  152. createExclude().setName("**/" + tok.nextToken().trim() + "/**");
  153. }
  154. }
  155. }
  156. // CheckStyle:VisibilityModifier ON
  157. /**
  158. * Sets whether default exclusions should be used or not.
  159. *
  160. * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
  161. * should be used, "false"|"off"|"no" when they
  162. * shouldn't be used.
  163. */
  164. public void setDefaultexcludes(boolean useDefaultExcludes) {
  165. fileset.setDefaultexcludes(useDefaultExcludes);
  166. }
  167. /**
  168. * Returns the directory scanner needed to access the files to process.
  169. * @param baseDir the base directory to use with the fileset
  170. * @return a directory scanner
  171. */
  172. protected DirectoryScanner getDirectoryScanner(File baseDir) {
  173. fileset.setDir(baseDir);
  174. return fileset.getDirectoryScanner(getProject());
  175. }
  176. /**
  177. * Sets the name of the file containing the includes patterns.
  178. *
  179. * @param includesfile A string containing the filename to fetch
  180. * the include patterns from.
  181. */
  182. public void setIncludesfile(File includesfile) {
  183. fileset.setIncludesfile(includesfile);
  184. }
  185. /**
  186. * Sets the name of the file containing the includes patterns.
  187. *
  188. * @param excludesfile A string containing the filename to fetch
  189. * the include patterns from.
  190. */
  191. public void setExcludesfile(File excludesfile) {
  192. fileset.setExcludesfile(excludesfile);
  193. }
  194. /**
  195. * Sets case sensitivity of the file system
  196. *
  197. * @param isCaseSensitive "true"|"on"|"yes" if file system is case
  198. * sensitive, "false"|"off"|"no" when not.
  199. */
  200. public void setCaseSensitive(boolean isCaseSensitive) {
  201. fileset.setCaseSensitive(isCaseSensitive);
  202. }
  203. /**
  204. * Sets whether or not symbolic links should be followed.
  205. *
  206. * @param followSymlinks whether or not symbolic links should be followed
  207. */
  208. public void setFollowSymlinks(boolean followSymlinks) {
  209. fileset.setFollowSymlinks(followSymlinks);
  210. }
  211. /**
  212. * Indicates whether there are any selectors here.
  213. *
  214. * @return whether any selectors are in this container
  215. */
  216. public boolean hasSelectors() {
  217. return fileset.hasSelectors();
  218. }
  219. /**
  220. * Gives the count of the number of selectors in this container
  221. *
  222. * @return the number of selectors in this container
  223. */
  224. public int selectorCount() {
  225. return fileset.selectorCount();
  226. }
  227. /**
  228. * Returns the set of selectors as an array.
  229. * @param p the current project
  230. * @return an array of selectors in this container
  231. */
  232. public FileSelector[] getSelectors(Project p) {
  233. return fileset.getSelectors(p);
  234. }
  235. /**
  236. * Returns an enumerator for accessing the set of selectors.
  237. *
  238. * @return an enumerator that goes through each of the selectors
  239. */
  240. public Enumeration selectorElements() {
  241. return fileset.selectorElements();
  242. }
  243. /**
  244. * Add a new selector into this container.
  245. *
  246. * @param selector the new selector to add
  247. */
  248. public void appendSelector(FileSelector selector) {
  249. fileset.appendSelector(selector);
  250. }
  251. /* Methods below all add specific selectors */
  252. /**
  253. * add a "Select" selector entry on the selector list
  254. * @param selector the selector to add
  255. */
  256. public void addSelector(SelectSelector selector) {
  257. fileset.addSelector(selector);
  258. }
  259. /**
  260. * add an "And" selector entry on the selector list
  261. * @param selector the selector to add
  262. */
  263. public void addAnd(AndSelector selector) {
  264. fileset.addAnd(selector);
  265. }
  266. /**
  267. * add an "Or" selector entry on the selector list
  268. * @param selector the selector to add
  269. */
  270. public void addOr(OrSelector selector) {
  271. fileset.addOr(selector);
  272. }
  273. /**
  274. * add a "Not" selector entry on the selector list
  275. * @param selector the selector to add
  276. */
  277. public void addNot(NotSelector selector) {
  278. fileset.addNot(selector);
  279. }
  280. /**
  281. * add a "None" selector entry on the selector list
  282. * @param selector the selector to add
  283. */
  284. public void addNone(NoneSelector selector) {
  285. fileset.addNone(selector);
  286. }
  287. /**
  288. * add a majority selector entry on the selector list
  289. * @param selector the selector to add
  290. */
  291. public void addMajority(MajoritySelector selector) {
  292. fileset.addMajority(selector);
  293. }
  294. /**
  295. * add a selector date entry on the selector list
  296. * @param selector the selector to add
  297. */
  298. public void addDate(DateSelector selector) {
  299. fileset.addDate(selector);
  300. }
  301. /**
  302. * add a selector size entry on the selector list
  303. * @param selector the selector to add
  304. */
  305. public void addSize(SizeSelector selector) {
  306. fileset.addSize(selector);
  307. }
  308. /**
  309. * add a selector filename entry on the selector list
  310. * @param selector the selector to add
  311. */
  312. public void addFilename(FilenameSelector selector) {
  313. fileset.addFilename(selector);
  314. }
  315. /**
  316. * add an extended selector entry on the selector list
  317. * @param selector the selector to add
  318. */
  319. public void addCustom(ExtendSelector selector) {
  320. fileset.addCustom(selector);
  321. }
  322. /**
  323. * add a contains selector entry on the selector list
  324. * @param selector the selector to add
  325. */
  326. public void addContains(ContainsSelector selector) {
  327. fileset.addContains(selector);
  328. }
  329. /**
  330. * add a present selector entry on the selector list
  331. * @param selector the selector to add
  332. */
  333. public void addPresent(PresentSelector selector) {
  334. fileset.addPresent(selector);
  335. }
  336. /**
  337. * add a depth selector entry on the selector list
  338. * @param selector the selector to add
  339. */
  340. public void addDepth(DepthSelector selector) {
  341. fileset.addDepth(selector);
  342. }
  343. /**
  344. * add a depends selector entry on the selector list
  345. * @param selector the selector to add
  346. */
  347. public void addDepend(DependSelector selector) {
  348. fileset.addDepend(selector);
  349. }
  350. /**
  351. * add a regular expression selector entry on the selector list
  352. * @param selector the selector to add
  353. */
  354. public void addContainsRegexp(ContainsRegexpSelector selector) {
  355. fileset.addContainsRegexp(selector);
  356. }
  357. /**
  358. * add a type selector entry on the type list
  359. * @param selector the selector to add
  360. * @since ant 1.6
  361. */
  362. public void addDifferent(DifferentSelector selector) {
  363. fileset.addDifferent(selector);
  364. }
  365. /**
  366. * add a type selector entry on the type list
  367. * @param selector the selector to add
  368. * @since ant 1.6
  369. */
  370. public void addType(TypeSelector selector) {
  371. fileset.addType(selector);
  372. }
  373. /**
  374. * add the modified selector
  375. * @param selector the selector to add
  376. * @since ant 1.6
  377. */
  378. public void addModified(ModifiedSelector selector) {
  379. fileset.addModified(selector);
  380. }
  381. /**
  382. * add an arbitary selector
  383. * @param selector the selector to add
  384. * @since Ant 1.6
  385. */
  386. public void add(FileSelector selector) {
  387. fileset.add(selector);
  388. }
  389. /**
  390. * Accessor for the implicit fileset.
  391. * @return the implicit fileset
  392. * @since Ant 1.5.2
  393. */
  394. protected final FileSet getImplicitFileSet() {
  395. return fileset;
  396. }
  397. }