001package org.apache.maven.scm.provider.svn.svnexe.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.ScmFileSet; 024import org.apache.maven.scm.command.status.AbstractStatusCommand; 025import org.apache.maven.scm.command.status.StatusScmResult; 026import org.apache.maven.scm.provider.ScmProviderRepository; 027import org.apache.maven.scm.provider.svn.command.SvnCommand; 028import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; 029import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils; 030import org.codehaus.plexus.util.cli.CommandLineException; 031import org.codehaus.plexus.util.cli.CommandLineUtils; 032import org.codehaus.plexus.util.cli.Commandline; 033 034/** 035 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 036 * 037 */ 038public class SvnStatusCommand 039 extends AbstractStatusCommand 040 implements SvnCommand 041{ 042 /** {@inheritDoc} */ 043 protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet ) 044 throws ScmException 045 { 046 Commandline cl = createCommandLine( (SvnScmProviderRepository) repo, fileSet ); 047 048 SvnStatusConsumer consumer = new SvnStatusConsumer( getLogger(), fileSet.getBasedir() ); 049 050 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); 051 052 if ( getLogger().isInfoEnabled() ) 053 { 054 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) ); 055 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); 056 } 057 058 int exitCode; 059 060 try 061 { 062 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() ); 063 } 064 catch ( CommandLineException ex ) 065 { 066 throw new ScmException( "Error while executing command.", ex ); 067 } 068 069 if ( exitCode != 0 ) 070 { 071 return new StatusScmResult( cl.toString(), "The svn 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( SvnScmProviderRepository repository, ScmFileSet fileSet ) 082 { 083 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( fileSet.getBasedir(), repository ); 084 085 cl.createArg().setValue( "status" ); 086 087 return cl; 088 } 089}