1. /*
  2. * Copyright 2001-2002,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.optional.sitraka;
  18. import java.util.Vector;
  19. /**
  20. * Filters information from coverage, somewhat similar to a <tt>FileSet</tt>.
  21. *
  22. */
  23. public class Filters {
  24. /** default regexp to exclude everything */
  25. public static final String DEFAULT_EXCLUDE = "*.*():E";
  26. /** say whether we should use the default excludes or not */
  27. protected boolean defaultExclude = true;
  28. /** user defined filters */
  29. protected Vector filters = new Vector();
  30. public Filters() {
  31. }
  32. /**
  33. * Automatically exclude all classes and methods
  34. * unless included in nested elements; optional, default true.
  35. */
  36. public void setDefaultExclude(boolean value) {
  37. defaultExclude = value;
  38. }
  39. /**
  40. * include classes and methods in the analysis
  41. */
  42. public void addInclude(Include incl) {
  43. filters.addElement(incl);
  44. }
  45. /**
  46. * exclude classes and methods from the analysis
  47. */
  48. public void addExclude(Exclude excl) {
  49. filters.addElement(excl);
  50. }
  51. public String toString() {
  52. StringBuffer buf = new StringBuffer();
  53. final int size = filters.size();
  54. if (defaultExclude) {
  55. buf.append(DEFAULT_EXCLUDE);
  56. if (size > 0) {
  57. buf.append(',');
  58. }
  59. }
  60. for (int i = 0; i < size; i++) {
  61. buf.append(filters.elementAt(i).toString());
  62. if (i < size - 1) {
  63. buf.append(',');
  64. }
  65. }
  66. return buf.toString();
  67. }
  68. /**
  69. * an includes or excludes element
  70. */
  71. public abstract static class FilterElement {
  72. protected String clazz;
  73. protected String method = "*"; // default is all methods
  74. protected boolean enabled = true; // default is enable
  75. /**
  76. * this one is deprecated.
  77. * @ant.task ignore="true"
  78. */
  79. public void setName(String value) {
  80. clazz = value;
  81. }
  82. /**
  83. * The classname mask as a simple regular expression;
  84. * optional, defaults to "*"
  85. */
  86. public void setClass(String value) {
  87. clazz = value;
  88. }
  89. /**
  90. * The method mask as a simple regular expression;
  91. * optional, defaults to "*"
  92. */
  93. public void setMethod(String value) {
  94. method = value;
  95. }
  96. /**
  97. * enable or disable the filter; optional, default true
  98. */
  99. public void setEnabled(boolean value) {
  100. enabled = value;
  101. }
  102. public String toString() {
  103. return clazz + "." + method + "()";
  104. }
  105. }
  106. public static class Include extends FilterElement {
  107. public String toString() {
  108. return super.toString() + ":I" + (enabled ? "" : "#");
  109. }
  110. }
  111. public static class Exclude extends FilterElement {
  112. public String toString() {
  113. return super.toString() + ":E" + (enabled ? "" : "#");
  114. }
  115. }
  116. }