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   */
41  public class HgAddCommand extends AbstractAddCommand implements Command {
42      /** {@inheritDoc} */
43      protected ScmResult executeAddCommand(
44              ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
45          // String[] addCmd = new String[] { ADD_CMD, NO_RECURSE_OPTION };
46          String[] addCmd = new String[] {HgCommandConstants.ADD_CMD, HgCommandConstants.VERBOSE_OPTION};
47          addCmd = HgUtils.expandCommandLine(addCmd, fileSet);
48  
49          File workingDir = fileSet.getBasedir();
50          HgAddConsumer consumer = new HgAddConsumer(workingDir);
51          ScmResult result = HgUtils.execute(consumer, workingDir, addCmd);
52  
53          AddScmResult addScmResult = new AddScmResult(consumer.getAddedFiles(), result);
54  
55          // add in bogus 'added' results for empty directories.  only need to do this because the maven scm unit test
56          // framework seems to think that this is the way we should behave.  it's pretty hacky. -rwd
57          for (File workingFile : fileSet.getFileList()) {
58              File file = new File(workingDir + "/" + workingFile.getPath());
59              if (file.isDirectory() && file.listFiles().length == 0) {
60                  addScmResult.getAddedFiles().add(new ScmFile(workingFile.getPath(), ScmFileStatus.ADDED));
61              }
62          }
63  
64          return addScmResult;
65      }
66  }