Coverage Report - org.apache.maven.scm.provider.synergy.command.edit.SynergyEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
SynergyEditCommand
0 %
0/36
0 %
0/16
12
 
 1  
 package org.apache.maven.scm.provider.synergy.command.edit;
 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.Iterator;
 26  
 import java.util.LinkedList;
 27  
 import java.util.List;
 28  
 
 29  
 import org.apache.maven.scm.ScmException;
 30  
 import org.apache.maven.scm.ScmFile;
 31  
 import org.apache.maven.scm.ScmFileSet;
 32  
 import org.apache.maven.scm.ScmFileStatus;
 33  
 import org.apache.maven.scm.ScmResult;
 34  
 import org.apache.maven.scm.command.edit.AbstractEditCommand;
 35  
 import org.apache.maven.scm.command.edit.EditScmResult;
 36  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 37  
 import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
 38  
 import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
 39  
 import org.apache.maven.scm.provider.synergy.util.SynergyTaskManager;
 40  
 import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
 41  
 import org.codehaus.plexus.util.FileUtils;
 42  
 
 43  
 /**
 44  
  * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
 45  
  * @version $Id: SynergyEditCommand.java 1067549 2011-02-05 23:13:10Z olamy $
 46  
  */
 47  0
 public class SynergyEditCommand
 48  
     extends AbstractEditCommand
 49  
     implements SynergyCommand
 50  
 {
 51  
     /** {@inheritDoc} */
 52  
     protected ScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
 53  
         throws ScmException
 54  
     {
 55  0
         if ( getLogger().isDebugEnabled() )
 56  
         {
 57  0
             getLogger().debug( "executing edit command..." );
 58  
         }
 59  
 
 60  0
         SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
 61  
 
 62  0
         if ( getLogger().isDebugEnabled() )
 63  
         {
 64  0
             getLogger().debug( fileSet.toString() );
 65  
         }
 66  
 
 67  0
         String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
 68  
 
 69  
         try
 70  
         {
 71  0
             String projectSpec =
 72  
                 SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
 73  0
             File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr );
 74  0
             File sourcePath = new File( waPath, repo.getProjectName() );
 75  0
             if ( projectSpec == null )
 76  
             {
 77  0
                 throw new ScmException( "You should checkout project first" );
 78  
             }
 79  0
             int taskNum = SynergyUtil.createTask( getLogger(), "Maven SCM Synergy provider: edit command for project "
 80  
                 + repo.getProjectSpec(), repo.getProjectRelease(), true, ccmAddr );
 81  0
             if ( getLogger().isInfoEnabled() )
 82  
             {
 83  0
                 getLogger().info( "Task " + taskNum + " was created to perform checkout." );
 84  
             }
 85  0
             for ( Iterator<File> i = fileSet.getFileList().iterator(); i.hasNext(); )
 86  
             {
 87  0
                 File f = (File) i.next();
 88  0
                 File dest = f;
 89  0
                 File source = new File( sourcePath, SynergyUtil.removePrefix( fileSet.getBasedir(), f ) );
 90  0
                 List<File> list = new LinkedList<File>();
 91  0
                 list.add( source );
 92  0
                 SynergyUtil.checkoutFiles( getLogger(), list, ccmAddr );
 93  0
                 if ( !source.equals( dest ) )
 94  
                 {
 95  0
                     if ( getLogger().isDebugEnabled() )
 96  
                     {
 97  0
                         getLogger().debug( "Copy file [" + source + "] to expected folder [" + dest + "]." );
 98  
                     }
 99  
                     try
 100  
                     {
 101  0
                         FileUtils.copyFile( source, dest );
 102  
                     }
 103  0
                     catch ( IOException e )
 104  
                     {
 105  0
                         throw new ScmException( "Unable to copy file from Work Area", e );
 106  0
                     }
 107  
                 }
 108  0
             }
 109  
         }
 110  
         finally
 111  
         {
 112  0
             SynergyUtil.stop( getLogger(), ccmAddr );
 113  0
         }
 114  0
         List<ScmFile> scmFiles = new ArrayList<ScmFile>(fileSet.getFileList().size());
 115  0
         for (File f : fileSet.getFileList())
 116  
         {
 117  0
             scmFiles.add( new ScmFile( f.getPath(), ScmFileStatus.EDITED ) );
 118  
         }
 119  0
         return new EditScmResult( "", scmFiles );
 120  
     }
 121  
 
 122  
 }