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

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