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 public TestListResolver getTestListResolver()
79 {
80 return requestedTests;
81 }
82
83 /**
84 * How many times to rerun failing tests, issued with -Dsurefire.rerunFailingTestsCount from the command line.
85 *
86 * @return The int parameter to indicate how many times to rerun failing tests
87 */
88 public int getRerunFailingTestsCount()
89 {
90 return rerunFailingTestsCount;
91 }
92
93 private static List<File> createFiles( List suiteXmlFiles )
94 {
95 if ( suiteXmlFiles != null )
96 {
97 List<File> files = new ArrayList<File>();
98 Object element;
99 for ( Object suiteXmlFile : suiteXmlFiles )
100 {
101 element = suiteXmlFile;
102 files.add( element instanceof String ? new File( (String) element ) : (File) element );
103 }
104 return files;
105 }
106 return null;
107 }
108
109 }