You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultExcludes.java 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2003-2004 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;
  18. import org.apache.tools.ant.Task;
  19. import org.apache.tools.ant.Project;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.DirectoryScanner;
  22. /**
  23. * Alters the default excludes for the <strong>entire</strong> build..
  24. *
  25. * @author Gus Heck &lt;gus.heck@olin.edu&gt;
  26. *
  27. * @since Ant 1.6
  28. *
  29. * @ant.task category="utility"
  30. */
  31. public class DefaultExcludes extends Task {
  32. private String add = "";
  33. private String remove = "";
  34. private boolean defaultrequested = false;
  35. private boolean echo = false;
  36. // by default, messages are always displayed
  37. private int logLevel = Project.MSG_WARN;
  38. /**
  39. * Does the work.
  40. *
  41. * @exception BuildException if something goes wrong with the build
  42. */
  43. public void execute() throws BuildException {
  44. if (!defaultrequested && add.equals("") && remove.equals("") && !echo) {
  45. throw new BuildException("<defaultexcludes> task must set "
  46. + "at least one attribute (echo=\"false\""
  47. + " doesn't count since that is the default");
  48. }
  49. if (defaultrequested) {
  50. DirectoryScanner.resetDefaultExcludes();
  51. }
  52. if (!add.equals("")) {
  53. DirectoryScanner.addDefaultExclude(add);
  54. }
  55. if (!remove.equals("")) {
  56. DirectoryScanner.removeDefaultExclude(remove);
  57. }
  58. if (echo) {
  59. StringBuffer message
  60. = new StringBuffer("Current Default Excludes:\n");
  61. String[] excludes = DirectoryScanner.getDefaultExcludes();
  62. for (int i = 0; i < excludes.length; i++) {
  63. message.append(" " + excludes[i] + "\n");
  64. }
  65. log(message.toString(), logLevel);
  66. }
  67. }
  68. /**
  69. * go back to standard default patterns
  70. *
  71. * @param def if true go back to default patterns
  72. */
  73. public void setDefault(boolean def) {
  74. defaultrequested = def;
  75. }
  76. /**
  77. * Pattern to add to the default excludes
  78. *
  79. * @param add Sets the value for the pattern to exclude.
  80. */
  81. public void setAdd(String add) {
  82. this.add = add;
  83. }
  84. /**
  85. * Pattern to remove from the default excludes.
  86. *
  87. * @param remove Sets the value for the pattern that
  88. * should no longer be excluded.
  89. */
  90. public void setRemove(String remove) {
  91. this.remove = remove;
  92. }
  93. /**
  94. * If true, echo the default excludes.
  95. *
  96. * @param echo whether or not to echo the contents of
  97. * the default excludes.
  98. */
  99. public void setEcho(boolean echo) {
  100. this.echo = echo;
  101. }
  102. }