Search in sources :

Example 21 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class HgScmProvider method tag.

/**
 * {@inheritDoc}
 */
public TagScmResult tag(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    HgTagCommand command = new HgTagCommand();
    command.setLogger(getLogger());
    return (TagScmResult) command.execute(repository, fileSet, parameters);
}
Also used : HgTagCommand(org.apache.maven.scm.provider.hg.command.tag.HgTagCommand) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult)

Example 22 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class ClearCaseTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeTagCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("executing tag command...");
    }
    Commandline cl = createCommandLine(fileSet, tag);
    ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Creating label: " + tag);
        }
        Commandline newLabelCommandLine = createNewLabelCommandLine(fileSet, tag);
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Executing: " + newLabelCommandLine.getWorkingDirectory().getAbsolutePath() + ">>" + newLabelCommandLine.toString());
        }
        exitCode = CommandLineUtils.executeCommandLine(newLabelCommandLine, new CommandLineUtils.StringStreamConsumer(), stderr);
        if (exitCode == 0) {
            getLogger().debug("Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString());
            exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
        }
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing clearcase command.", ex);
    }
    if (exitCode != 0) {
        return new TagScmResult(cl.toString(), "The cleartool command failed.", stderr.getOutput(), false);
    }
    return new TagScmResult(cl.toString(), consumer.getCheckedInFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) ClearCaseCheckInConsumer(org.apache.maven.scm.provider.clearcase.command.checkin.ClearCaseCheckInConsumer) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 23 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class HgTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeTagCommand(ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    if (tag == null || StringUtils.isEmpty(tag.trim())) {
        throw new ScmException("tag must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support tagging subsets of a directory : " + fileSet.getFileList());
    }
    File workingDir = fileSet.getBasedir();
    // build the command
    String[] tagCmd = new String[] { HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION, scmTagParameters.getMessage(), tag };
    // keep the command about in string form for reporting
    StringBuilder cmd = joinCmd(tagCmd);
    HgTagConsumer consumer = new HgTagConsumer(getLogger());
    ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, tagCmd);
    HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
    if (result.isSuccess()) {
        if (repository.isPushChanges()) {
            if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
                String branchName = HgUtils.getCurrentBranchName(getLogger(), workingDir);
                boolean differentOutgoingBranch = HgUtils.differentOutgoingBranchFound(getLogger(), workingDir, branchName);
                String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null, repository.getURI() };
                result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
            }
        }
    } else {
        throw new ScmException("Error while executing command " + cmd.toString());
    }
    // do an inventory to return the files tagged (all of them)
    String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
    HgListConsumer listconsumer = new HgListConsumer(getLogger());
    result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
    if (result.isSuccess()) {
        List<ScmFile> files = listconsumer.getFiles();
        List<ScmFile> fileList = new ArrayList<ScmFile>();
        for (ScmFile f : files) {
            if (!f.getPath().endsWith(".hgtags")) {
                fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
            }
        }
        return new TagScmResult(fileList, result);
    } else {
        throw new ScmException("Error while executing command " + cmd.toString());
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) ArrayList(java.util.ArrayList) ScmFile(org.apache.maven.scm.ScmFile) HgListConsumer(org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) HgScmProviderRepository(org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)

Example 24 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class CvsJavaTagCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected TagScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsLogListener logListener = new CvsLogListener();
    CvsTagConsumer consumer = new CvsTagConsumer(getLogger());
    try {
        boolean isSuccess = CvsConnection.processCommand(cl.getArguments(), cl.getWorkingDirectory().getAbsolutePath(), logListener, getLogger());
        if (!isSuccess) {
            return new TagScmResult(cl.toString(), "The cvs tag command failed.", logListener.getStderr().toString(), false);
        }
        BufferedReader stream = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(logListener.getStdout().toString().getBytes())));
        String line;
        while ((line = stream.readLine()) != null) {
            consumer.consumeLine(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new TagScmResult(cl.toString(), "The cvs tag command failed.", logListener.getStderr().toString(), false);
    }
    return new TagScmResult(cl.toString(), consumer.getTaggedFiles());
}
Also used : CvsLogListener(org.apache.maven.scm.provider.cvslib.cvsjava.util.CvsLogListener) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) CvsTagConsumer(org.apache.maven.scm.provider.cvslib.command.tag.CvsTagConsumer) BufferedReader(java.io.BufferedReader) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) ScmException(org.apache.maven.scm.ScmException)

Example 25 with TagScmResult

use of org.apache.maven.scm.command.tag.TagScmResult in project maven-scm by apache.

the class IntegrityTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
@Override
public TagScmResult executeTagCommand(ScmProviderRepository repository, ScmFileSet fileSet, String tagName, ScmTagParameters scmTagParameters) throws ScmException {
    getLogger().info("Attempting to checkpoint project associated with sandbox " + fileSet.getBasedir().getAbsolutePath());
    TagScmResult result;
    String message = scmTagParameters.getMessage();
    IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
    try {
        // First validate the checkpoint label string by evaluating the groovy script
        String chkptLabel = evalGroovyExpression(tagName);
        Project.validateTag(chkptLabel);
        String msg = ((null == message || message.length() == 0) ? System.getProperty("message") : message);
        // Get information about the Project
        Project siProject = iRepo.getProject();
        // Ensure this is not a build project configuration
        if (!siProject.isBuild()) {
            Response res = siProject.checkpoint(msg, chkptLabel);
            int exitCode = res.getExitCode();
            boolean success = (exitCode == 0 ? true : false);
            WorkItem wi = res.getWorkItem(siProject.getConfigurationPath());
            String chkpt = wi.getResult().getField("resultant").getItem().getId();
            getLogger().info("Successfully checkpointed project " + siProject.getConfigurationPath() + " with label '" + chkptLabel + "', new revision is " + chkpt);
            result = new TagScmResult(res.getCommandString(), wi.getResult().getMessage(), "Exit Code: " + exitCode, success);
        } else {
            getLogger().error("Cannot checkpoint a build project configuration: " + siProject.getConfigurationPath() + "!");
            result = new TagScmResult("si checkpoint", "Cannot checkpoint a build project configuration!", "", false);
        }
    } catch (CompilationFailedException cfe) {
        getLogger().error("Groovy Compilation Exception: " + cfe.getMessage());
        result = new TagScmResult("si checkpoint", cfe.getMessage(), "", false);
    } catch (APIException aex) {
        ExceptionHandler eh = new ExceptionHandler(aex);
        getLogger().error("MKS API Exception: " + eh.getMessage());
        getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
        result = new TagScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
    } catch (Exception e) {
        getLogger().error("Failed to checkpoint project! " + e.getMessage());
        result = new TagScmResult("si checkpoint", e.getMessage(), "", false);
    }
    return result;
}
Also used : Response(com.mks.api.response.Response) ExceptionHandler(org.apache.maven.scm.provider.integrity.ExceptionHandler) Project(org.apache.maven.scm.provider.integrity.Project) APIException(com.mks.api.response.APIException) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) WorkItem(com.mks.api.response.WorkItem) ScmException(org.apache.maven.scm.ScmException) APIException(com.mks.api.response.APIException) CompilationFailedException(org.codehaus.groovy.control.CompilationFailedException)

Aggregations

TagScmResult (org.apache.maven.scm.command.tag.TagScmResult)32 File (java.io.File)12 ScmException (org.apache.maven.scm.ScmException)11 ArrayList (java.util.ArrayList)6 ScmFile (org.apache.maven.scm.ScmFile)6 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)6 Commandline (org.codehaus.plexus.util.cli.Commandline)5 ScmFileSet (org.apache.maven.scm.ScmFileSet)4 IOException (java.io.IOException)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 AccuRevInfo (org.apache.maven.scm.provider.accurev.AccuRevInfo)3 CommandParameters (org.apache.maven.scm.CommandParameters)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 ScmResult (org.apache.maven.scm.ScmResult)2 ScmTag (org.apache.maven.scm.ScmTag)2 ScmTagParameters (org.apache.maven.scm.ScmTagParameters)2 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)2 AccuRevScmProviderRepository (org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepository)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 CvsTagConsumer (org.apache.maven.scm.provider.cvslib.command.tag.CvsTagConsumer)2