@Test @EnabledOnOs(OS.WINDOWS) public void testGetRelativePathMixedCaseOnWindows() throws MojoExecutionException { JGitSourceReferencesProvider provider = new JGitSourceReferencesProvider(); File projectBasedir = new File("C:/bar/baz/test/me"); File repoRoot = new File("c:/bar/baz"); assertEquals("test/me", provider.getRelativePath(projectBasedir, repoRoot)); }
String getRelativePath(File subDir, File parentDir) throws MojoExecutionException { URI subDirUri; URI relativeUri; try { subDirUri = subDir.getCanonicalFile().toURI(); relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (relativeUri.equals(subDirUri)) { throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir); } String relative = relativeUri.getPath(); if (relative.startsWith("/")) { relative = relative.substring(1); } if (relative.endsWith("/")) { relative = relative.substring(0, relative.length() - 1); } return relative; }
JGitSourceReferencesProvider implements SourceReferencesProvider { String getRelativePath(File subDir, File parentDir) throws MojoExecutionException { URI subDirUri; URI relativeUri; try { subDirUri = subDir.getCanonicalFile().toURI(); relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (relativeUri.equals(subDirUri)) { throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir); } String relative = relativeUri.getPath(); if (relative.startsWith("/")) { relative = relative.substring(1); } if (relative.endsWith("/")) { relative = relative.substring(0, relative.length() - 1); } return relative; } }
JGitSourceReferencesProvider implements SourceReferencesProvider { String getRelativePath(File subDir, File parentDir) throws MojoExecutionException { URI subDirUri; URI relativeUri; try { subDirUri = subDir.getCanonicalFile().toURI(); relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (relativeUri.equals(subDirUri)) { throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir); } String relative = relativeUri.getPath(); if (relative.startsWith("/")) { relative = relative.substring(1); } if (relative.endsWith("/")) { relative = relative.substring(0, relative.length() - 1); } return relative; }  }
JGitSourceReferencesProvider implements SourceReferencesProvider { String getRelativePath(File subDir, File parentDir) throws MojoExecutionException { URI subDirUri; URI relativeUri; try { subDirUri = subDir.getCanonicalFile().toURI(); relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (relativeUri.equals(subDirUri)) { throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir); } String relative = relativeUri.getPath(); if (relative.startsWith("/")) { relative = relative.substring(1); } if (relative.endsWith("/")) { relative = relative.substring(0, relative.length() - 1); } return relative; }  @Override String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl); }
JGitSourceReferencesProvider implements SourceReferencesProvider { String getRelativePath(File subDir, File parentDir) throws MojoExecutionException { URI subDirUri; URI relativeUri; try { subDirUri = subDir.getCanonicalFile().toURI(); relativeUri = parentDir.getCanonicalFile().toURI().relativize(subDirUri); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } if (relativeUri.equals(subDirUri)) { throw new MojoExecutionException(subDir + " is not a subdir of " + parentDir); } String relative = relativeUri.getPath(); if (relative.startsWith("/")) { relative = relative.substring(1); } if (relative.endsWith("/")) { relative = relative.substring(0, relative.length() - 1); } return relative; }  @Override String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl);  }