Coverage Report - org.apache.maven.scm.provider.synergy.command.add.SynergyAddCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
SynergyAddCommand
0 %
0/33
0 %
0/18
13
 
 1  
 package org.apache.maven.scm.provider.synergy.command.add;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.IOException;
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 import org.apache.maven.scm.ScmException;
 28  
 import org.apache.maven.scm.ScmFile;
 29  
 import org.apache.maven.scm.ScmFileSet;
 30  
 import org.apache.maven.scm.ScmFileStatus;
 31  
 import org.apache.maven.scm.ScmResult;
 32  
 import org.apache.maven.scm.command.add.AbstractAddCommand;
 33  
 import org.apache.maven.scm.command.add.AddScmResult;
 34  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 35  
 import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
 36  
 import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
 37  
 import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
 38  
 import org.codehaus.plexus.util.FileUtils;
 39  
 
 40  
 /**
 41  
  * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
 42  
  * @version $Id: SynergyAddCommand.java 1067549 2011-02-05 23:13:10Z olamy $
 43  
  */
 44  0
 public class SynergyAddCommand
 45  
     extends AbstractAddCommand
 46  
     implements SynergyCommand
 47  
 {
 48  
     /** {@inheritDoc} */
 49  
     protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
 50  
                                            boolean binary )
 51  
         throws ScmException
 52  
     {
 53  0
         if ( getLogger().isDebugEnabled() )
 54  
         {
 55  0
             getLogger().debug( "executing add command..." );
 56  
         }
 57  
 
 58  0
         SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
 59  
 
 60  0
         if ( getLogger().isDebugEnabled() )
 61  
         {
 62  0
             getLogger().debug( "basedir: " + fileSet.getBasedir() );
 63  
         }
 64  
 
 65  0
         if ( message == null || message.equals( "" ) )
 66  
         {
 67  0
             message = "Maven SCM Synergy provider: adding file(s) to project " + repo.getProjectSpec();
 68  
         }
 69  
 
 70  0
         String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
 71  
 
 72  
         try
 73  
         {
 74  0
             int taskNum = SynergyUtil.createTask( getLogger(), message, repo.getProjectRelease(), true, ccmAddr );
 75  0
             String projectSpec =
 76  
                 SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
 77  0
             if ( projectSpec == null )
 78  
             {
 79  0
                 throw new ScmException( "You should checkout a working project first" );
 80  
             }
 81  0
             File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr );
 82  0
             File destPath = new File( waPath, repo.getProjectName() );
 83  0
             for ( File source : fileSet.getFileList() )
 84  
             {
 85  0
                 File dest = new File( destPath, SynergyUtil.removePrefix( fileSet.getBasedir(), source ) );
 86  0
                 if ( !source.equals( dest ) )
 87  
                 {
 88  0
                     if ( getLogger().isDebugEnabled() )
 89  
                     {
 90  0
                         getLogger().debug( "Copy file [" + source + "] to Synergy Work Area [" + dest + "]." );
 91  
                     }
 92  
                     try
 93  
                     {
 94  0
                         FileUtils.copyFile( source, dest );
 95  
                     }
 96  0
                     catch ( IOException e )
 97  
                     {
 98  0
                         throw new ScmException( "Unable to copy file in Work Area", e );
 99  0
                     }
 100  
                 }
 101  0
                 SynergyUtil.create( getLogger(), dest, message, ccmAddr );
 102  0
             }
 103  0
             SynergyUtil.checkinTask( getLogger(), taskNum, message, ccmAddr );
 104  
 
 105  
         }
 106  
         finally
 107  
         {
 108  0
             SynergyUtil.stop( getLogger(), ccmAddr );
 109  0
         }
 110  0
         List<ScmFile> scmFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
 111  0
         for (File f : fileSet.getFileList())
 112  
         {
 113  0
             scmFiles.add( new ScmFile( f.getPath(), ScmFileStatus.ADDED ) );
 114  
         }
 115  0
         return new AddScmResult( "", scmFiles );
 116  
     }
 117  
 
 118  
 
 119  
 }