001    package org.apache.maven.scm.provider.hg.command.add;
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    
022    import java.io.File;
023    
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFile;
026    import org.apache.maven.scm.ScmFileSet;
027    import org.apache.maven.scm.ScmFileStatus;
028    import org.apache.maven.scm.ScmResult;
029    import org.apache.maven.scm.command.Command;
030    import org.apache.maven.scm.command.add.AbstractAddCommand;
031    import org.apache.maven.scm.command.add.AddScmResult;
032    import org.apache.maven.scm.provider.ScmProviderRepository;
033    import org.apache.maven.scm.provider.hg.HgUtils;
034    import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
035    
036    /**
037     * Add no recursive.
038     *
039     * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
040     * @version $Id: HgAddCommand.java 1054126 2010-12-31 15:18:11Z olamy $
041     */
042    public class HgAddCommand
043        extends AbstractAddCommand
044        implements Command
045    {
046        /** {@inheritDoc} */
047        protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
048                                               boolean binary )
049            throws ScmException
050        {
051            //String[] addCmd = new String[] { ADD_CMD, NO_RECURSE_OPTION };
052            String[] addCmd = new String[] { HgCommandConstants.ADD_CMD, HgCommandConstants.VERBOSE_OPTION };
053            addCmd = HgUtils.expandCommandLine( addCmd, fileSet );
054    
055            File workingDir = fileSet.getBasedir();
056            HgAddConsumer consumer = new HgAddConsumer( getLogger(), workingDir );
057            ScmResult result = HgUtils.execute( consumer, getLogger(), workingDir, addCmd );
058    
059            AddScmResult addScmResult = new AddScmResult( consumer.getAddedFiles(), result );
060    
061            // add in bogus 'added' results for empty directories.  only need to do this because the maven scm unit test
062            // framework seems to think that this is the way we should behave.  it's pretty hacky. -rwd
063            for ( File workingFile : fileSet.getFileList() )
064            {
065                File file = new File( workingDir + "/" + workingFile.getPath() );
066                if ( file.isDirectory() && file.listFiles().length == 0 )
067                {
068                    addScmResult.getAddedFiles().add( new ScmFile( workingFile.getPath(), ScmFileStatus.ADDED ) );
069                }
070            }
071    
072            return addScmResult;
073        }
074    }