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