001package org.apache.maven.scm.provider.integrity.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
022import org.apache.maven.scm.ScmException;
023import org.apache.maven.scm.ScmFile;
024import org.apache.maven.scm.ScmFileSet;
025import org.apache.maven.scm.ScmResult;
026import org.apache.maven.scm.command.add.AbstractAddCommand;
027import org.apache.maven.scm.command.add.AddScmResult;
028import org.apache.maven.scm.provider.ScmProviderRepository;
029import org.apache.maven.scm.provider.integrity.Sandbox;
030import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
031
032import java.util.List;
033
034/**
035 * MKS Integrity implementation for Maven's AbstractAddCommand
036 *
037 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
038 * @version $Id: IntegrityAddCommand.java 1.4 2011/08/22 13:06:13EDT Cletus D'Souza (dsouza) Exp  $
039 * @since 1.6
040 */
041public class IntegrityAddCommand
042    extends AbstractAddCommand
043{
044    /**
045     * {@inheritDoc}
046     */
047    @Override
048    public AddScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
049                                           boolean binary )
050        throws ScmException
051    {
052        getLogger().info( "Attempting to add new files from directory " + fileSet.getBasedir().getAbsolutePath() );
053        IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
054        Sandbox siSandbox = iRepo.getSandbox();
055        String excludes = Sandbox.formatFilePatterns( fileSet.getExcludes() );
056        String includes = Sandbox.formatFilePatterns( fileSet.getIncludes() );
057        String msg = ( ( null == message || message.length() == 0 ) ? System.getProperty( "message" ) : message );
058        List<ScmFile> addedFiles = siSandbox.addNonMembers( excludes, includes, msg );
059        if ( siSandbox.getOverallAddSuccess() )
060        {
061            return new AddScmResult( "si add", addedFiles );
062        }
063        else
064        {
065            return new AddScmResult( addedFiles,
066                                     new ScmResult( "si add", "There was a problem adding files to the repository", "",
067                                                    false ) );
068        }
069    }
070
071}