JGitSourceReferencesProvider implements SourceReferencesProvider { @Override public String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl) throws MojoExecutionException { File basedir = project.getBasedir().getAbsoluteFile(); FileRepositoryBuilder builder = new FileRepositoryBuilder().readEnvironment().findGitDir(basedir) .setMustExist(true); Repository repo; Git git; try { repo = builder.build(); git = Git.wrap(repo); } catch (IOException e) { throw new MojoExecutionException("IO exception trying to create git repo ", e); } ObjectId head = resolveHead(repo); StringBuilder result = new StringBuilder(scmUrl.getUrl()); result.append(";path=\""); result.append(getRelativePath(basedir, repo.getWorkTree())); result.append("\""); String tag = findTagForHead(git, head); if (tag != null) { result.append(";tag=\""); result.append(tag); result.append("\""); } result.append(";commitId="); result.append(head.getName()); return result.toString(); }  @Override String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl);  }
@Test public void testGetSourceReferencesHeader() throws MojoExecutionException { JGitSourceReferencesProvider provider = new JGitSourceReferencesProvider(); MavenProject mockProject = new MavenProject(); ScmUrl scmUrl = new ScmUrl(properties("scm:git:foo")); mockProject.setFile(new File("src/test/resources/pom.xml").getAbsoluteFile()); String sourceRef = provider.getSourceReferencesHeader(mockProject, scmUrl); assertTrue(sourceRef.startsWith("scm:git:foo;path=\"tycho-extras/tycho-sourceref-jgit/src/test/resources\"")); }
@Test public void testGetSourceReferencesHeader() throws MojoExecutionException { JGitSourceReferencesProvider provider = new JGitSourceReferencesProvider(); MavenProject mockProject = new MavenProject(); ScmUrl scmUrl = new ScmUrl(properties("scm:git:foo")); mockProject.setFile(new File("src/test/resources/pom.xml").getAbsoluteFile()); String sourceRef = provider.getSourceReferencesHeader(mockProject, scmUrl); assertTrue(sourceRef.startsWith("scm:git:foo;path=\"tycho-sourceref-jgit/src/test/resources\"")); }