1 package org.apache.maven.surefire.booter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.PrintStream;
23 import java.util.Collections;
24 import java.util.Iterator;
25
26 import org.apache.maven.surefire.util.CloseableIterator;
27 import org.apache.maven.surefire.util.TestsToRun;
28
29 import static org.apache.maven.surefire.booter.CommandReader.getReader;
30 import static org.apache.maven.surefire.util.ReflectionUtils.loadClass;
31
32
33
34
35
36
37
38
39
40
41
42
43
44 final class LazyTestsToRun
45 extends TestsToRun
46 {
47 private final PrintStream originalOutStream;
48
49
50
51
52
53
54 LazyTestsToRun( PrintStream originalOutStream )
55 {
56 super( Collections.<Class<?>>emptySet() );
57
58 this.originalOutStream = originalOutStream;
59 }
60
61 private final class BlockingIterator
62 implements Iterator<Class<?>>
63 {
64 private final Iterator<String> it = getReader().getIterableClasses( originalOutStream ).iterator();
65
66 @Override
67 public boolean hasNext()
68 {
69 return it.hasNext();
70 }
71
72 @Override
73 public Class<?> next()
74 {
75 return findClass( it.next() );
76 }
77
78 @Override
79 public void remove()
80 {
81 throw new UnsupportedOperationException();
82 }
83 }
84
85
86
87
88 @Override
89 public Iterator<Class<?>> iterated()
90 {
91 return newWeakIterator();
92 }
93
94
95
96
97
98
99 @Override
100 public Iterator<Class<?>> iterator()
101 {
102 return new BlockingIterator();
103 }
104
105
106
107
108
109 @Override
110 public String toString()
111 {
112 return "LazyTestsToRun";
113 }
114
115
116
117
118
119 @Override
120 public boolean allowEagerReading()
121 {
122 return false;
123 }
124
125 private static Class<?> findClass( String clazz )
126 {
127 return loadClass( Thread.currentThread().getContextClassLoader(), clazz );
128 }
129
130
131
132
133
134 private Iterator<Class<?>> newWeakIterator()
135 {
136 final Iterator<String> it = getReader().iterated();
137 return new CloseableIterator<Class<?>>()
138 {
139 @Override
140 protected boolean isClosed()
141 {
142 return LazyTestsToRun.this.isFinished();
143 }
144
145 @Override
146 protected boolean doHasNext()
147 {
148 return it.hasNext();
149 }
150
151 @Override
152 protected Class<?> doNext()
153 {
154 return findClass( it.next() );
155 }
156
157 @Override
158 protected void doRemove()
159 {
160 }
161
162 @Override
163 public void remove()
164 {
165 throw new UnsupportedOperationException( "unsupported remove" );
166 }
167 };
168 }
169 }