001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.svn.svnexe.command.status; 020 021import org.apache.maven.scm.ScmException; 022import org.apache.maven.scm.ScmFileSet; 023import org.apache.maven.scm.command.status.AbstractStatusCommand; 024import org.apache.maven.scm.command.status.StatusScmResult; 025import org.apache.maven.scm.provider.ScmProviderRepository; 026import org.apache.maven.scm.provider.svn.command.SvnCommand; 027import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; 028import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils; 029import org.codehaus.plexus.util.Os; 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 extends AbstractStatusCommand implements SvnCommand { 039 /** {@inheritDoc} */ 040 protected StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException { 041 Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet); 042 043 SvnStatusConsumer consumer = new SvnStatusConsumer(fileSet.getBasedir()); 044 045 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); 046 047 if (logger.isInfoEnabled()) { 048 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl)); 049 050 if (Os.isFamily(Os.FAMILY_WINDOWS)) { 051 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath()); 052 } 053 } 054 055 int exitCode; 056 057 try { 058 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr); 059 } catch (CommandLineException ex) { 060 throw new ScmException("Error while executing command.", ex); 061 } 062 063 if (exitCode != 0) { 064 return new StatusScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false); 065 } 066 067 return new StatusScmResult(cl.toString(), consumer.getChangedFiles()); 068 } 069 070 // ---------------------------------------------------------------------- 071 // 072 // ---------------------------------------------------------------------- 073 074 public static Commandline createCommandLine(SvnScmProviderRepository repository, ScmFileSet fileSet) { 075 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository); 076 077 cl.createArg().setValue("status"); 078 079 return cl; 080 } 081}