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.hg.command.add;
20  
21  import java.io.File;
22  
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFile;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.ScmFileStatus;
27  import org.apache.maven.scm.ScmResult;
28  import org.apache.maven.scm.command.Command;
29  import org.apache.maven.scm.command.add.AbstractAddCommand;
30  import org.apache.maven.scm.command.add.AddScmResult;
31  import org.apache.maven.scm.provider.ScmProviderRepository;
32  import org.apache.maven.scm.provider.hg.HgUtils;
33  import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
34  
35  /**
36   * Add no recursive.
37   *
38   * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
39   */
40  public class HgAddCommand extends AbstractAddCommand implements Command {
41      /**
42       * {@inheritDoc}
43       */
44      protected ScmResult executeAddCommand(
45              ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
46          // String[] addCmd = new String[] { ADD_CMD, NO_RECURSE_OPTION };
47          String[] addCmd = new String[] {HgCommandConstants.ADD_CMD, HgCommandConstants.VERBOSE_OPTION};
48          addCmd = HgUtils.expandCommandLine(addCmd, fileSet);
49  
50          File workingDir = fileSet.getBasedir();
51          HgAddConsumer consumer = new HgAddConsumer(workingDir);
52          ScmResult result = HgUtils.execute(consumer, workingDir, addCmd);
53  
54          AddScmResult addScmResult = new AddScmResult(consumer.getAddedFiles(), result);
55  
56          // add in bogus 'added' results for empty directories.  only need to do this because the maven scm unit test
57          // framework seems to think that this is the way we should behave.  it's pretty hacky. -rwd
58          for (File workingFile : fileSet.getFileList()) {
59              File file = new File(workingDir + "/" + workingFile.getPath());
60              if (file.isDirectory() && file.listFiles().length == 0) {
61                  addScmResult.getAddedFiles().add(new ScmFile(workingFile.getPath(), ScmFileStatus.ADDED));
62              }
63          }
64  
65          return addScmResult;
66      }
67  }