1 | |
package org.apache.maven.surefire.junitcore; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Properties; |
25 | |
import org.apache.maven.surefire.booter.ProviderParameterNames; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
class JUnitCoreParameters |
31 | |
{ |
32 | |
private final String parallel; |
33 | |
|
34 | |
private final Boolean perCoreThreadCount; |
35 | |
|
36 | |
private final int threadCount; |
37 | |
|
38 | |
private final int threadCountSuites; |
39 | |
|
40 | |
private final int threadCountClasses; |
41 | |
|
42 | |
private final int threadCountMethods; |
43 | |
|
44 | |
private final int parallelTestsTimeoutInSeconds; |
45 | |
|
46 | |
private final int parallelTestsTimeoutForcedInSeconds; |
47 | |
|
48 | |
private final Boolean useUnlimitedThreads; |
49 | |
|
50 | |
public static final String PARALLEL_KEY = ProviderParameterNames.PARALLEL_PROP; |
51 | |
|
52 | |
public static final String PERCORETHREADCOUNT_KEY = "perCoreThreadCount"; |
53 | |
|
54 | |
public static final String THREADCOUNT_KEY = ProviderParameterNames.THREADCOUNT_PROP; |
55 | |
|
56 | |
public static final String THREADCOUNTSUITES_KEY = ProviderParameterNames.THREADCOUNTSUITES_PROP; |
57 | |
|
58 | |
public static final String THREADCOUNTCLASSES_KEY = ProviderParameterNames.THREADCOUNTCLASSES_PROP; |
59 | |
|
60 | |
public static final String THREADCOUNTMETHODS_KEY = ProviderParameterNames.THREADCOUNTMETHODS_PROP; |
61 | |
|
62 | |
public static final String USEUNLIMITEDTHREADS_KEY = "useUnlimitedThreads"; |
63 | |
|
64 | |
public static final String PARALLEL_TIMEOUT_KEY = ProviderParameterNames.PARALLEL_TIMEOUT_PROP; |
65 | |
|
66 | |
public static final String PARALLEL_TIMEOUTFORCED_KEY = ProviderParameterNames.PARALLEL_TIMEOUTFORCED_PROP; |
67 | |
|
68 | |
public JUnitCoreParameters( Properties properties ) |
69 | 119 | { |
70 | 119 | parallel = properties.getProperty( PARALLEL_KEY, "none" ).toLowerCase(); |
71 | 119 | perCoreThreadCount = Boolean.valueOf( properties.getProperty( PERCORETHREADCOUNT_KEY, "true" ) ); |
72 | 119 | threadCount = Integer.valueOf( properties.getProperty( THREADCOUNT_KEY, "0" ) ); |
73 | 119 | threadCountMethods = Integer.valueOf( properties.getProperty( THREADCOUNTMETHODS_KEY, "0" ) ); |
74 | 119 | threadCountClasses = Integer.valueOf( properties.getProperty( THREADCOUNTCLASSES_KEY, "0" ) ); |
75 | 119 | threadCountSuites = Integer.valueOf( properties.getProperty( THREADCOUNTSUITES_KEY, "0" ) ); |
76 | 119 | useUnlimitedThreads = Boolean.valueOf( properties.getProperty( USEUNLIMITEDTHREADS_KEY, "false" ) ); |
77 | 119 | parallelTestsTimeoutInSeconds = Integer.valueOf( properties.getProperty( PARALLEL_TIMEOUT_KEY, "0" ) ); |
78 | 119 | parallelTestsTimeoutForcedInSeconds = Integer.valueOf( properties.getProperty( PARALLEL_TIMEOUTFORCED_KEY, "0" ) ); |
79 | 119 | } |
80 | |
|
81 | |
private static Collection<String> lowerCase( String... elements ) |
82 | |
{ |
83 | 804 | ArrayList<String> lowerCase = new ArrayList<String>(); |
84 | 3728 | for ( String element : elements ) |
85 | |
{ |
86 | 2924 | lowerCase.add( element.toLowerCase() ); |
87 | |
} |
88 | 804 | return lowerCase; |
89 | |
} |
90 | |
|
91 | |
private boolean isAllParallel() |
92 | |
{ |
93 | 968 | return "all".equals( parallel ); |
94 | |
} |
95 | |
|
96 | |
public boolean isParallelMethod() |
97 | |
{ |
98 | 301 | return isAllParallel() |
99 | |
|| lowerCase( "both", "methods", "suitesAndMethods", "classesAndMethods" ).contains( parallel ); |
100 | |
} |
101 | |
|
102 | |
public boolean isParallelClasses() |
103 | |
{ |
104 | 311 | return isAllParallel() |
105 | |
|| lowerCase( "both", "classes", "suitesAndClasses", "classesAndMethods" ).contains( parallel ); |
106 | |
} |
107 | |
|
108 | |
public boolean isParallelSuites() |
109 | |
{ |
110 | 356 | return isAllParallel() || lowerCase( "suites", "suitesAndClasses", "suitesAndMethods" ).contains( parallel ); |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
@Deprecated |
117 | |
public boolean isParallelBoth() |
118 | |
{ |
119 | 0 | return isParallelMethod() && isParallelClasses(); |
120 | |
} |
121 | |
|
122 | |
public Boolean isPerCoreThreadCount() |
123 | |
{ |
124 | 180 | return perCoreThreadCount; |
125 | |
} |
126 | |
|
127 | |
public int getThreadCount() |
128 | |
{ |
129 | 152 | return threadCount; |
130 | |
} |
131 | |
|
132 | |
public int getThreadCountMethods() |
133 | |
{ |
134 | 96 | return threadCountMethods; |
135 | |
} |
136 | |
|
137 | |
public int getThreadCountClasses() |
138 | |
{ |
139 | 108 | return threadCountClasses; |
140 | |
} |
141 | |
|
142 | |
public int getThreadCountSuites() |
143 | |
{ |
144 | 132 | return threadCountSuites; |
145 | |
} |
146 | |
|
147 | |
public Boolean isUseUnlimitedThreads() |
148 | |
{ |
149 | 179 | return useUnlimitedThreads; |
150 | |
} |
151 | |
|
152 | |
public int getParallelTestsTimeoutInSeconds() |
153 | |
{ |
154 | 0 | return parallelTestsTimeoutInSeconds; |
155 | |
} |
156 | |
|
157 | |
public int getParallelTestsTimeoutForcedInSeconds() |
158 | |
{ |
159 | 0 | return parallelTestsTimeoutForcedInSeconds; |
160 | |
} |
161 | |
|
162 | |
public boolean isNoThreading() |
163 | |
{ |
164 | 4 | return !isAnyParallelitySelected(); |
165 | |
} |
166 | |
|
167 | |
public boolean isAnyParallelitySelected() |
168 | |
{ |
169 | 100 | return isParallelSuites() || isParallelClasses() || isParallelMethod(); |
170 | |
} |
171 | |
|
172 | |
@Override |
173 | |
public String toString() |
174 | |
{ |
175 | 1 | return "parallel='" + parallel + '\'' + ", perCoreThreadCount=" + perCoreThreadCount + ", threadCount=" |
176 | |
+ threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads + ", threadCountSuites=" + threadCountSuites |
177 | |
+ ", threadCountClasses=" + threadCountClasses + ", threadCountMethods=" + threadCountMethods; |
178 | |
} |
179 | |
} |