InputFileUtils { public static String getRelativePath(InputFile file, FileSystem fs) { try { return fs.baseDir().toPath().toAbsolutePath().relativize(Paths.get(file.uri())).toString().replace('\\', '/'); } catch (IllegalArgumentException caught) { return file.filename(); } } private  InputFileUtils(); static InputStream getInputStream(InputFile file); static File getFile(InputFile file); static String getAbsolutePath(InputFile file); static String getRelativePath(InputFile file, FileSystem fs);  }
@Test public void testDifferentFileSystem() throws Exception { if (!System.getProperty("os.name").toLowerCase().startsWith("win")) return; SensorContextTester context = TestProjectSensorContext.createContext(); InputFile f1 = context.fileSystem().inputFile(context.fileSystem().predicates().hasFilename("test1.p")); Assert.assertEquals(InputFileUtils.getRelativePath(f1, new DefaultFileSystem(new File("X:\\"))), "test1.p"); }