1 package org.apache.maven.surefire.group.match;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class SingleGroupMatcher
23 implements GroupMatcher
24 {
25
26 private String enabled;
27
28 private Class<?> enabledClass;
29
30 public SingleGroupMatcher( String enabled )
31 {
32 this.enabled = enabled.endsWith( ".class" ) ? enabled.substring( 0, enabled.length() - 6 ) : enabled;
33 }
34
35 @Override
36 public int hashCode()
37 {
38 final int prime = 31;
39 int result = 1;
40 result = prime * result + ( ( enabled == null ) ? 0 : enabled.hashCode() );
41 return result;
42 }
43
44 @Override
45 public boolean equals( Object obj )
46 {
47 if ( this == obj )
48 {
49 return true;
50 }
51 if ( obj == null )
52 {
53 return false;
54 }
55 if ( getClass() != obj.getClass() )
56 {
57 return false;
58 }
59 SingleGroupMatcher other = (SingleGroupMatcher) obj;
60 if ( enabled == null )
61 {
62 if ( other.enabled != null )
63 {
64 return false;
65 }
66 }
67 else if ( !enabled.equals( other.enabled ) )
68 {
69 return false;
70 }
71 return true;
72 }
73
74 @Override
75 public String toString()
76 {
77 return "*" + enabled;
78 }
79
80 public boolean enabled( Class<?>... cats )
81 {
82 if ( cats != null )
83 {
84 for ( Class<?> cls : cats )
85 {
86 if ( enabledClass != null && enabledClass.isAssignableFrom( cls ) )
87 {
88 return true;
89 }
90
91 String name = cls.getName();
92 if ( name.endsWith( enabled ) )
93 {
94 return true;
95 }
96 }
97 }
98
99 return false;
100 }
101
102 public boolean enabled( String... cats )
103 {
104 if ( enabled == null )
105 {
106 return true;
107 }
108
109 for ( String cat : cats )
110 {
111 if ( cat == null || cat.trim().length() < 1 )
112 {
113 continue;
114 }
115
116
117 if ( cat.endsWith( enabled ) )
118 {
119 return true;
120 }
121 }
122
123 return false;
124 }
125
126 public void loadGroupClasses( ClassLoader cloader )
127 {
128 try
129 {
130 enabledClass = cloader.loadClass( enabled );
131 }
132 catch ( ClassNotFoundException e )
133 {
134 throw new RuntimeException( "Unable to load category: " + enabled, e );
135 }
136 }
137
138 }