View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.svn.svnexe.command.status;
20  
21  import org.apache.maven.scm.ScmException;
22  import org.apache.maven.scm.ScmFileSet;
23  import org.apache.maven.scm.command.status.AbstractStatusCommand;
24  import org.apache.maven.scm.command.status.StatusScmResult;
25  import org.apache.maven.scm.provider.ScmProviderRepository;
26  import org.apache.maven.scm.provider.svn.command.SvnCommand;
27  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
28  import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
29  import org.codehaus.plexus.util.Os;
30  import org.codehaus.plexus.util.cli.CommandLineException;
31  import org.codehaus.plexus.util.cli.CommandLineUtils;
32  import org.codehaus.plexus.util.cli.Commandline;
33  
34  /**
35   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
36   *
37   */
38  public class SvnStatusCommand extends AbstractStatusCommand implements SvnCommand {
39      /** {@inheritDoc} */
40      protected StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFileSet fileSet) throws ScmException {
41          Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet);
42  
43          SvnStatusConsumer consumer = new SvnStatusConsumer(fileSet.getBasedir());
44  
45          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
46  
47          if (logger.isInfoEnabled()) {
48              logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
49  
50              if (Os.isFamily(Os.FAMILY_WINDOWS)) {
51                  logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
52              }
53          }
54  
55          int exitCode;
56  
57          try {
58              exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
59          } catch (CommandLineException ex) {
60              throw new ScmException("Error while executing command.", ex);
61          }
62  
63          if (exitCode != 0) {
64              return new StatusScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
65          }
66  
67          return new StatusScmResult(cl.toString(), consumer.getChangedFiles());
68      }
69  
70      // ----------------------------------------------------------------------
71      //
72      // ----------------------------------------------------------------------
73  
74      public static Commandline createCommandLine(SvnScmProviderRepository repository, ScmFileSet fileSet) {
75          Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository);
76  
77          cl.createArg().setValue("status");
78  
79          return cl;
80      }
81  }