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