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 public boolean hasNext()
67 {
68 return it.hasNext();
69 }
70
71 public Class<?> next()
72 {
73 return findClass( it.next() );
74 }
75
76 public void remove()
77 {
78 throw new UnsupportedOperationException();
79 }
80 }
81
82
83
84
85 @Override
86 public Iterator<Class<?>> iterated()
87 {
88 return newWeakIterator();
89 }
90
91
92
93
94
95
96 public Iterator<Class<?>> iterator()
97 {
98 return new BlockingIterator();
99 }
100
101
102
103
104
105 public String toString()
106 {
107 return "LazyTestsToRun";
108 }
109
110
111
112
113
114 public boolean allowEagerReading()
115 {
116 return false;
117 }
118
119 private static Class<?> findClass( String clazz )
120 {
121 return loadClass( Thread.currentThread().getContextClassLoader(), clazz );
122 }
123
124
125
126
127
128 private Iterator<Class<?>> newWeakIterator()
129 {
130 final Iterator<String> it = getReader().iterated();
131 return new CloseableIterator<Class<?>>()
132 {
133 @Override
134 protected boolean isClosed()
135 {
136 return LazyTestsToRun.this.isFinished();
137 }
138
139 @Override
140 protected boolean doHasNext()
141 {
142 return it.hasNext();
143 }
144
145 @Override
146 protected Class<?> doNext()
147 {
148 return findClass( it.next() );
149 }
150
151 @Override
152 protected void doRemove()
153 {
154 }
155
156 public void remove()
157 {
158 throw new UnsupportedOperationException( "unsupported remove" );
159 }
160 };
161 }
162 }