001    package org.apache.maven.scm.provider.starteam.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    
022    import org.apache.maven.scm.ScmException;
023    import org.apache.maven.scm.ScmFileSet;
024    import org.apache.maven.scm.command.status.AbstractStatusCommand;
025    import org.apache.maven.scm.command.status.StatusScmResult;
026    import org.apache.maven.scm.provider.ScmProviderRepository;
027    import org.apache.maven.scm.provider.starteam.command.StarteamCommand;
028    import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
029    import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
030    import org.codehaus.plexus.util.cli.CommandLineUtils;
031    import org.codehaus.plexus.util.cli.Commandline;
032    
033    /**
034     * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
035     *
036     */
037    public class StarteamStatusCommand
038        extends AbstractStatusCommand
039        implements StarteamCommand
040    {
041        // ----------------------------------------------------------------------
042        // AbstractStatusCommand Implementation
043        // ----------------------------------------------------------------------
044    
045        /** {@inheritDoc} */
046        protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
047            throws ScmException
048        {
049            if ( getLogger().isInfoEnabled() )
050            {
051                getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
052            }
053    
054            if ( fileSet.getFileList().size() != 0 )
055            {
056                throw new ScmException( "This provider doesn't support checking status of a subsets of a directory" );
057            }
058    
059            StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
060    
061            StarteamStatusConsumer consumer = new StarteamStatusConsumer( getLogger(), fileSet.getBasedir() );
062    
063            CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
064    
065            Commandline cl = createCommandLine( repository, fileSet );
066    
067            int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
068    
069            if ( exitCode != 0 )
070            {
071                return new StatusScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
072            }
073    
074            return new StatusScmResult( cl.toString(), consumer.getChangedFiles() );
075        }
076    
077        // ----------------------------------------------------------------------
078        //
079        // ----------------------------------------------------------------------
080    
081        public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet workingDirectory )
082        {
083            return StarteamCommandLineUtils.createStarteamCommandLine( "hist", null, workingDirectory, repo );
084        }
085    }