FileUtils { public static String toPackageQualifiedName(String path) { path = removePrefix(path); path = path.replace('/', '.'); if (path.contains(":\\")) { path = removePrefix(path); } if (path.indexOf('\\') != -1) { path = path.replace('\\', '.'); } String packagePath = path.replace("..", ""); if (packagePath.startsWith(".")) { packagePath = packagePath.substring(1); } if (packagePath.endsWith(DOT_FEATURE)) { packagePath = packagePath.substring(0, packagePath.length() - 8); } return packagePath; } 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 testWindowsFileNames() { String path = "com/intuit/karate/cucumber/scenario.feature"; String fixed = FileUtils.toPackageQualifiedName(path); assertEquals("com.intuit.karate.cucumber.scenario", fixed); path = "file:C:\\Users\\Karate\\scenario.feature"; fixed = FileUtils.toPackageQualifiedName(path); assertEquals("Users.Karate.scenario", fixed); path = "file:../Karate/scenario.feature"; fixed = FileUtils.toPackageQualifiedName(path); assertEquals("Karate.scenario", fixed); }