FileUtils { public static List<Resource> scanForFeatureFiles(List<String> paths, ClassLoader cl) { if (paths == null) { return Collections.EMPTY_LIST; } List<Resource> list = new ArrayList(); for (String path : paths) { boolean classpath = isClassPath(path); list.addAll(scanForFeatureFiles(classpath, path, cl)); } return list; } private  FileUtils(); static final boolean isClassPath(String text); static final boolean isFilePath(String text); static final boolean isThisPath(String text); static final boolean isJsonFile(String text); static final boolean isJavaScriptFile(String text); static final boolean isYamlFile(String text); static final boolean isXmlFile(String text); static final boolean isTextFile(String text); static final boolean isCsvFile(String text); static final boolean isGraphQlFile(String text); static final boolean isFeatureFile(String text); static ScriptValue readFile(String text, ScenarioContext context); static String removePrefix(String text); static Feature parseFeatureAndCallTag(String path); static Resource toResource(String path, ScenarioContext context); static String readFileAsString(String path, ScenarioContext context); static InputStream readFileAsStream(String path, ScenarioContext context); static String toPackageQualifiedName(String path); static String toString(File file); static String toString(InputStream is); static String toPrettyString(String raw); static byte[] toBytes(InputStream is); static String toString(byte[] bytes); static byte[] toBytes(String string); static void copy(File src, File dest); static void writeToFile(File file, byte[] data); static void writeToFile(File file, String data); static InputStream toInputStream(String text); static String removeFileExtension(String path); static String replaceFileExtension(String path, String extension); static String getKarateVersion(); static void renameFileIfZeroBytes(String fileName); static String toStandardPath(String path); static String toRelativeClassPath(Path path, ClassLoader cl); static File getDirContaining(Class clazz); static Path getPathContaining(Class clazz); static File getFileRelativeTo(Class clazz, String path); static String toRelativeClassPath(Class clazz); static Path fromRelativeClassPath(String relativePath, ClassLoader cl); static Path fromRelativeClassPath(String relativePath, Path parentPath); static List<Resource> scanForFeatureFilesOnClassPath(ClassLoader cl); static List<Resource> scanForFeatureFiles(List<String> paths, ClassLoader cl); static List<Resource> scanForFeatureFiles(List<String> paths, Class clazz); static boolean isJarPath(URI uri); static Path urlToPath(URL url, String relativePath); static List<URL> getAllClassPathUrls(ClassLoader classLoader); static List<Resource> scanForFeatureFiles(boolean classpath, String searchPath, ClassLoader cl); static String getBuildDir(); static boolean isOsWindows(); static boolean isOsMacOsX(); static String getOsName(); static OsType getOsType(); static OsType getOsType(String name); static final Charset UTF8; static final byte[] EMPTY_BYTES; static final String CLASSPATH_COLON; static final String THIS_COLON; static final String FILE_COLON; static final String SRC_TEST_JAVA; static final String SRC_TEST_RESOURCES; }
@Test public void testScanFileWithLineNumber() { String relativePath = "classpath:com/intuit/karate/test/test.feature:3"; List<Resource> files = FileUtils.scanForFeatureFiles(Collections.singletonList(relativePath), getClass().getClassLoader()); assertEquals(1, files.size()); assertEquals(3, files.get(0).getLine()); }
@Test public void testScanFilePath() { String relativePath = "classpath:com/intuit/karate/test"; List<Resource> files = FileUtils.scanForFeatureFiles(true, relativePath, getClass().getClassLoader()); assertEquals(1, files.size()); }
@Test public void testGetClasspathAbsolute() { File file = new File("src/test/java/com/intuit/karate/multi-scenario.feature").getAbsoluteFile(); String scan = "classpath:" + file.getPath(); List<Resource> resources = FileUtils.scanForFeatureFiles(Collections.singletonList(scan), ClassLoader.getSystemClassLoader()); assertEquals(1, resources.size()); assertEquals(file, resources.get(0).getPath().toFile()); }