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.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2003-2004,2006 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. import org.apache.tools.ant.util.StringUtils;
  23. /**
  24. * Alters the default excludes for the <strong>entire</strong> build..
  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:");
  60. message.append(StringUtils.LINE_SEP);
  61. String[] excludes = DirectoryScanner.getDefaultExcludes();
  62. for (int i = 0; i < excludes.length; i++) {
  63. message.append(" ");
  64. message.append(excludes[i]);
  65. message.append(StringUtils.LINE_SEP);
  66. }
  67. log(message.toString(), logLevel);
  68. }
  69. }
  70. /**
  71. * go back to standard default patterns
  72. *
  73. * @param def if true go back to default patterns
  74. */
  75. public void setDefault(boolean def) {
  76. defaultrequested = def;
  77. }
  78. /**
  79. * Pattern to add to the default excludes
  80. *
  81. * @param add Sets the value for the pattern to exclude.
  82. */
  83. public void setAdd(String add) {
  84. this.add = add;
  85. }
  86. /**
  87. * Pattern to remove from the default excludes.
  88. *
  89. * @param remove Sets the value for the pattern that
  90. * should no longer be excluded.
  91. */
  92. public void setRemove(String remove) {
  93. this.remove = remove;
  94. }
  95. /**
  96. * If true, echo the default excludes.
  97. *
  98. * @param echo whether or not to echo the contents of
  99. * the default excludes.
  100. */
  101. public void setEcho(boolean echo) {
  102. this.echo = echo;
  103. }
  104. }