1 package org.apache.maven.surefire.testset;
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.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 /**
27 * Information about the requested test.
28 *
29 * @author Kristian Rosenvold
30 */
31 public class TestRequest
32 {
33 private final List<File> suiteXmlFiles;
34
35 private final File testSourceDirectory;
36
37 private final TestListResolver requestedTests;
38
39 private final int rerunFailingTestsCount;
40
41 public TestRequest( List suiteXmlFiles, File testSourceDirectory, TestListResolver requestedTests )
42 {
43 this( createFiles( suiteXmlFiles ), testSourceDirectory, requestedTests, 0 );
44 }
45
46 public TestRequest( List suiteXmlFiles, File testSourceDirectory, TestListResolver requestedTests,
47 int rerunFailingTestsCount )
48 {
49 this.suiteXmlFiles = createFiles( suiteXmlFiles );
50 this.testSourceDirectory = testSourceDirectory;
51 this.requestedTests = requestedTests;
52 this.rerunFailingTestsCount = rerunFailingTestsCount;
53 }
54
55 /**
56 * Represents suitexmlfiles that define the test-run request
57 *
58 * @return A list of java.io.File objects.
59 */
60 public List<File> getSuiteXmlFiles()
61 {
62 return suiteXmlFiles;
63 }
64
65 /**
66 * Test source directory, normally ${project.build.testSourceDirectory}
67 *
68 * @return A file pointing to test sources
69 */
70 public File getTestSourceDirectory()
71 {
72 return testSourceDirectory;
73 }
74
75 /**
76 * A specific test request issued with -Dtest= from the command line.
77 *
78 * @return filter
79 */
80 public TestListResolver getTestListResolver()
81 {
82 return requestedTests;
83 }
84
85 /**
86 * How many times to rerun failing tests, issued with -Dsurefire.rerunFailingTestsCount from the command line.
87 *
88 * @return The int parameter to indicate how many times to rerun failing tests
89 */
90 public int getRerunFailingTestsCount()
91 {
92 return rerunFailingTestsCount;
93 }
94
95 private static List<File> createFiles( List suiteXmlFiles )
96 {
97 if ( suiteXmlFiles != null )
98 {
99 List<File> files = new ArrayList<File>();
100 Object element;
101 for ( Object suiteXmlFile : suiteXmlFiles )
102 {
103 element = suiteXmlFile;
104 files.add( element instanceof String ? new File( (String) element ) : (File) element );
105 }
106 return files;
107 }
108 return null;
109 }
110
111 }