001    package org.apache.maven.scm.provider.tfs.command;
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    
022    import java.util.Iterator;
023    
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFile;
026    import org.apache.maven.scm.ScmFileSet;
027    import org.apache.maven.scm.command.status.AbstractStatusCommand;
028    import org.apache.maven.scm.command.status.StatusScmResult;
029    import org.apache.maven.scm.provider.ScmProviderRepository;
030    import org.apache.maven.scm.provider.tfs.TfsScmProviderRepository;
031    import org.apache.maven.scm.provider.tfs.command.consumer.ChangedFileConsumer;
032    import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
033    
034    public class TfsStatusCommand
035        extends AbstractStatusCommand
036    {
037    
038        protected StatusScmResult executeStatusCommand( ScmProviderRepository r, ScmFileSet f )
039            throws ScmException
040        {
041            TfsScmProviderRepository tfsRepo = (TfsScmProviderRepository) r;
042    
043            TfsCommand command = createCommand( tfsRepo, f );
044            ChangedFileConsumer out = new ChangedFileConsumer( getLogger() );
045            ErrorStreamConsumer err = new ErrorStreamConsumer();
046            
047            int status = command.execute( out, err );
048            if ( status != 0 || err.hasBeenFed() )
049            {
050                return new StatusScmResult( command.getCommandString(), "Error code for TFS status command - " + status,
051                                            err.getOutput(), false );
052            }
053            Iterator<ScmFile> iter = out.getChangedFiles().iterator();
054            getLogger().debug( "Iterating" );
055            while ( iter.hasNext() )
056            {
057                ScmFile file = (ScmFile) iter.next();
058                getLogger().debug( file.getPath() + ":" + file.getStatus() );
059            }
060            return new StatusScmResult( command.getCommandString(), out.getChangedFiles() );
061        }
062    
063        public TfsCommand createCommand( TfsScmProviderRepository r, ScmFileSet f )
064        {
065            String url = r.getServerPath();
066            String workspace = r.getWorkspace();
067            TfsCommand command = new TfsCommand( "status", r, f, getLogger() );
068            if ( workspace != null && !workspace.trim().equals( "" ) )
069            {
070                command.addArgument( "-workspace:" + workspace );
071            }
072            command.addArgument( "-recursive" );
073            command.addArgument( "-format:detailed" );
074            command.addArgument( url );
075            return command;
076        }
077    }
078