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