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