001package org.apache.maven.scm.provider.jazz.command.status;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.scm.ScmException;
023import org.apache.maven.scm.ScmFile;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.command.status.AbstractStatusCommand;
026import org.apache.maven.scm.command.status.StatusScmResult;
027import org.apache.maven.scm.provider.ScmProviderRepository;
028import org.apache.maven.scm.provider.jazz.command.JazzConstants;
029import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
030import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
031
032//
033// See the following links for additional information on the RTC "status" command:
034// RTC 2.0.0.2:
035// http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
036// RTC 3.0:
037// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
038// RTC 3.0.1:
039// http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_status.html
040//
041
042/**
043 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
044 */
045public class JazzStatusCommand
046    extends AbstractStatusCommand
047{
048    /**
049     * {@inheritDoc}
050     */
051    public StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
052        throws ScmException
053    {
054        if ( getLogger().isDebugEnabled() )
055        {
056            getLogger().debug( "Executing status command..." );
057        }
058
059        JazzStatusConsumer statusConsumer = new JazzStatusConsumer( repo, getLogger() );
060        ErrorConsumer errConsumer = new ErrorConsumer( getLogger() );
061
062        JazzScmCommand statusCmd = createStatusCommand( repo, fileSet );
063        int status = statusCmd.execute( statusConsumer, errConsumer );
064        if ( status != 0 || errConsumer.hasBeenFed() )
065        {
066            return new StatusScmResult( statusCmd.getCommandString(),
067                                        "Error code for Jazz SCM status command - " + status, errConsumer.getOutput(),
068                                        false );
069        }
070
071        if ( getLogger().isDebugEnabled() )
072        {
073            if ( !statusConsumer.getChangedFiles().isEmpty() )
074            {
075                getLogger().debug( "Iterating over \"Status\" results" );
076                for ( ScmFile file : statusConsumer.getChangedFiles() )
077                {
078                    getLogger().debug( file.getPath() + " : " + file.getStatus() );
079                }
080            }
081            else
082            {
083                getLogger().debug( "There are no differences" );
084            }
085        }
086
087        return new StatusScmResult( statusCmd.getCommandString(), statusConsumer.getChangedFiles() );
088    }
089
090    public JazzScmCommand createStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
091    {
092        JazzScmCommand command =
093            new JazzScmCommand( JazzConstants.CMD_STATUS, null, repo, false, fileSet, getLogger() );
094
095        command.addArgument( JazzConstants.ARG_STATUS_WIDE_PRINT_OUT );
096        return command;
097    }
098}