Search in sources :

Example 6 with InfoScmResult

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

the class GitInfoCommandTckTest method testInfoCommandWithZeroShortRevision.

public void testInfoCommandWithZeroShortRevision() 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, 0);
    InfoScmResult result = provider.info(repository, new ScmFileSet(getRepositoryRoot()), commandParameters);
    assertNotNull(result);
    assertTrue("revision should be not empty, minimum 4 (see git help rev-parse --short)", result.getInfoItems().get(0).getRevision().length() >= 4);
}
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 7 with InfoScmResult

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

the class ChangeLogReport method getRevisionForTag.

/**
 * Resolves the given tag to the revision number.
 *
 * @param tag
 * @param repository
 * @param provider
 * @return
 * @throws ScmException
 */
private String getRevisionForTag(final String tag, final ScmRepository repository, final ScmProvider provider) throws ScmException {
    if (repository.getProvider().equals("svn")) {
        if (tag == null) {
            return "HEAD";
        }
        SvnInfoCommandExpanded infoCommand = new SvnInfoCommandExpanded();
        infoCommand.setLogger(new DefaultLog());
        InfoScmResult infoScmResult = infoCommand.executeInfoTagCommand((SvnScmProviderRepository) repository.getProviderRepository(), new ScmFileSet(basedir), tag, null, false, null);
        if (infoScmResult.getInfoItems().size() == 0) {
            throw new ScmException("There is no tag named '" + tag + "' in the Subversion repository.");
        }
        InfoItem infoItem = infoScmResult.getInfoItems().get(0);
        String revision = infoItem.getLastChangedRevision();
        getLog().info(String.format("Resolved tag '%s' to revision '%s'", tag, revision));
        return revision;
    }
    return tag;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) InfoItem(org.apache.maven.scm.command.info.InfoItem) ScmException(org.apache.maven.scm.ScmException) DefaultLog(org.apache.maven.scm.log.DefaultLog) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) SvnInfoCommandExpanded(org.apache.maven.scm.provider.svn.svnexe.command.info.SvnInfoCommandExpanded)

Example 8 with InfoScmResult

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

the class HgScmProvider method info.

/**
 * returns result of hg id -i
 * @since 1.5
 * @see org.apache.maven.scm.provider.AbstractScmProvider#info(org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
 */
@Override
public InfoScmResult info(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    HgInfoCommand infoCommand = new HgInfoCommand();
    infoCommand.setLogger(getLogger());
    return (InfoScmResult) infoCommand.execute(repository, fileSet, parameters);
}
Also used : HgInfoCommand(org.apache.maven.scm.provider.hg.command.info.HgInfoCommand) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult)

Example 9 with InfoScmResult

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

the class HgInfoCommand method executeCommand.

@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    String[] revCmd = new String[] { HgCommandConstants.REVNO_CMD, "-i" };
    HgInfoConsumer consumer = new HgInfoConsumer(getLogger());
    ScmResult scmResult = HgUtils.execute(consumer, getLogger(), fileSet.getBasedir(), revCmd);
    return new InfoScmResult(consumer.getInfoItems(), scmResult);
}
Also used : InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) ScmResult(org.apache.maven.scm.ScmResult) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult)

Example 10 with InfoScmResult

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

the class SvnInfoCommand method executeInfoCommand.

public InfoScmResult executeInfoCommand(SvnScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters, boolean recursive, String revision) throws ScmException {
    Commandline cl = createCommandLine(repository, fileSet, recursive, revision);
    SvnInfoConsumer consumer = new SvnInfoConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    if (getLogger().isInfoEnabled()) {
        getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
        }
    }
    int exitCode;
    try {
        exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new InfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
    }
    return new InfoScmResult(cl.toString(), consumer.getInfoItems());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) InfoScmResult(org.apache.maven.scm.command.info.InfoScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

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