Search in sources :

Example 1 with InfoScmResult

use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.

the class JGitInfoCommand method executeCommand.

@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    Git git = null;
    try {
        File basedir = fileSet.getBasedir();
        git = Git.open(basedir);
        ObjectId objectId = git.getRepository().resolve("HEAD");
        InfoItem infoItem = new InfoItem();
        infoItem.setRevision(StringUtils.trim(objectId.name()));
        infoItem.setURL(basedir.getPath());
        return new InfoScmResult(Collections.singletonList(infoItem), new ScmResult("JGit.resolve(HEAD)", "", objectId.toString(), true));
    } catch (Exception e) {
        throw new ScmException("JGit resolve failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : InfoItem(org.apache.maven.scm.command.info.InfoItem) ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) ScmResult(org.apache.maven.scm.ScmResult) ObjectId(org.eclipse.jgit.lib.ObjectId) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) File(java.io.File) ScmException(org.apache.maven.scm.ScmException)

Example 2 with InfoScmResult

use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.

the class GitInfoCommand method executeCommand.

@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    GitInfoConsumer consumer = new GitInfoConsumer(getLogger(), fileSet);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    Commandline cli = createCommandLine(repository, fileSet, parameters);
    int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr, getLogger());
    if (exitCode != 0) {
        return new InfoScmResult(cli.toString(), "The git rev-parse command failed.", stderr.getOutput(), false);
    }
    return new InfoScmResult(cli.toString(), consumer.getInfoItems());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult)

Example 3 with InfoScmResult

use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.

the class GitInfoCommandTckTest method testInfoCommandWithNegativeShortRevision.

public void testInfoCommandWithNegativeShortRevision() throws Exception {
    GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
    assertNotNull(repository);
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setInt(CommandParameter.SCM_SHORT_REVISION_LENGTH, GitInfoCommand.NO_REVISION_LENGTH);
    InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), commandParameters);
    assertNotNull(result);
    assertEquals("revision should not be short", "cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767", result.getInfoItems().get(0).getRevision());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmProviderRepository(org.apache.maven.scm.provider.ScmProviderRepository) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandParameters(org.apache.maven.scm.CommandParameters)

Example 4 with InfoScmResult

use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.

the class GitInfoCommandTckTest method testInfoCommandWithShortRevision.

public void testInfoCommandWithShortRevision() throws Exception {
    GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
    assertNotNull(repository);
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setInt(CommandParameter.SCM_SHORT_REVISION_LENGTH, 6);
    InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), commandParameters);
    assertNotNull(result);
    assertEquals("revision must be short, exactly 6 digits ", "cd3c0d", result.getInfoItems().get(0).getRevision());
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmProviderRepository(org.apache.maven.scm.provider.ScmProviderRepository) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandParameters(org.apache.maven.scm.CommandParameters)

Example 5 with InfoScmResult

use of org.apache.maven.scm.command.info.InfoScmResult in project maven-scm by apache.

the class GitInfoCommandTckTest method testInfoCommand.

public void testInfoCommand() throws Exception {
    GitScmTestUtils.initRepo("src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy());
    ScmProvider provider = getScmManager().getProviderByUrl(getScmUrl());
    ScmProviderRepository repository = provider.makeProviderScmRepository(getRepositoryRoot());
    assertNotNull(repository);
    InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), new CommandParameters());
    assertNotNull(result);
    assertEquals("cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767", result.getInfoItems().get(0).getRevision());
// 
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) ScmFileSet(org.apache.maven.scm.ScmFileSet) ScmProviderRepository(org.apache.maven.scm.provider.ScmProviderRepository) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandParameters(org.apache.maven.scm.CommandParameters)

Aggregations

InfoScmResult (org.apache.maven.scm.command.info.InfoScmResult)13 ScmFileSet (org.apache.maven.scm.ScmFileSet)7 CommandParameters (org.apache.maven.scm.CommandParameters)5 ScmException (org.apache.maven.scm.ScmException)5 ScmProvider (org.apache.maven.scm.provider.ScmProvider)4 ScmProviderRepository (org.apache.maven.scm.provider.ScmProviderRepository)4 File (java.io.File)3 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)3 ScmResult (org.apache.maven.scm.ScmResult)2 InfoItem (org.apache.maven.scm.command.info.InfoItem)2 SvnCommandLineUtils (org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils)2 ScmRepositoryException (org.apache.maven.scm.repository.ScmRepositoryException)2 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)2 Commandline (org.codehaus.plexus.util.cli.Commandline)2 RemoteInfoScmResult (org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult)1 DefaultLog (org.apache.maven.scm.log.DefaultLog)1 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)1 HgInfoCommand (org.apache.maven.scm.provider.hg.command.info.HgInfoCommand)1 SvnInfoCommand (org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommand)1 SvnInfoCommandExpanded (org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommandExpanded)1