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