View Javadoc

1   package org.apache.maven.surefire.junitcore;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Properties;
23  import org.apache.maven.surefire.booter.ProviderParameterNames;
24  
25  /**
26   * @author Kristian Rosenvold
27   */
28  class JUnitCoreParameters
29  {
30      private final String parallel;
31  
32      private final Boolean perCoreThreadCount;
33  
34      private final int threadCount;
35  
36      private final Boolean useUnlimitedThreads;
37  
38      public static final String PARALLEL_KEY = ProviderParameterNames.PARALLEL_PROP;
39  
40      public static final String PERCORETHREADCOUNT_KEY = "perCoreThreadCount";
41  
42      public static final String THREADCOUNT_KEY = ProviderParameterNames.THREADCOUNT_PROP;
43  
44      public static final String USEUNLIMITEDTHREADS_KEY = "useUnlimitedThreads";
45  
46      public JUnitCoreParameters( Properties properties )
47      {
48          this.parallel = properties.getProperty( PARALLEL_KEY, "none" ).toLowerCase();
49          this.perCoreThreadCount = Boolean.valueOf( properties.getProperty( PERCORETHREADCOUNT_KEY, "true" ) );
50          this.threadCount = Integer.valueOf( properties.getProperty( THREADCOUNT_KEY, "2" ) );
51          this.useUnlimitedThreads = Boolean.valueOf( properties.getProperty( USEUNLIMITEDTHREADS_KEY, "false" ) );
52      }
53  
54      public boolean isParallelMethod()
55      {
56          return "methods".equals( parallel );
57      }
58  
59      public boolean isParallelClasses()
60      {
61          return "classes".equals( parallel );
62      }
63  
64      public boolean isParallelBoth()
65      {
66          return "both".equals( parallel );
67      }
68  
69      public Boolean isPerCoreThreadCount()
70      {
71          return perCoreThreadCount;
72      }
73  
74      public int getThreadCount()
75      {
76          return threadCount;
77      }
78  
79      public Boolean isUseUnlimitedThreads()
80      {
81          return useUnlimitedThreads;
82      }
83  
84      public boolean isNoThreading()
85      {
86          return !( isParallelClasses() || isParallelMethod() || isParallelBoth() );
87      }
88  
89      public boolean isAnyParallelitySelected()
90      {
91          return !isNoThreading();
92      }
93  
94      @Override
95      public String toString()
96      {
97          return "parallel='" + parallel + '\'' + ", perCoreThreadCount=" + perCoreThreadCount + ", threadCount="
98              + threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads;
99      }
100 }