2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.junit5;
18 import com.intellij.rt.execution.junit.JUnitStarter;
19 import org.junit.platform.engine.discovery.DiscoverySelectors;
20 import org.junit.platform.engine.discovery.PackageSelector;
21 import org.junit.platform.launcher.LauncherDiscoveryRequest;
22 import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
24 import java.io.BufferedReader;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.stream.Collectors;
32 public class JUnit5TestRunnerUtil {
34 public static LauncherDiscoveryRequest buildRequest(String[] suiteClassNames, String[] packageNameRef) {
35 if (suiteClassNames.length == 0) {
39 final LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request();
40 final List<String> lines = new ArrayList<>();
43 if (suiteClassNames.length == 1 && suiteClassNames[0].charAt(0) == '@') {
44 // all tests in the package specified
46 BufferedReader reader = new BufferedReader(new FileReader(suiteClassNames[0].substring(1)));
48 final String packageName = reader.readLine();
49 if (packageName == null) return null;
52 final String categoryName = reader.readLine();
55 while ((line = reader.readLine()) != null) {
58 packageNameRef[0] = packageName.length() == 0 ? "<default package>" : packageName;
59 return builder.selectors(DiscoverySelectors.selectPackage(packageName)).build();
65 catch (IOException e) {
71 Collections.addAll(lines, suiteClassNames);
74 final List<String> mappedLines = lines.stream().map(line -> line.replaceFirst(",", "#")).collect(Collectors.toList());
75 return builder.selectors(DiscoverySelectors.selectNames(mappedLines)).build();