Coverage Report - org.apache.maven.scm.provider.synergy.command.unedit.SynergyUnEditCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
SynergyUnEditCommand
0 %
0/31
0 %
0/14
11
 
 1  
 package org.apache.maven.scm.provider.synergy.command.unedit;
 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.List;
 27  
 
 28  
 import org.apache.maven.scm.ScmException;
 29  
 import org.apache.maven.scm.ScmFile;
 30  
 import org.apache.maven.scm.ScmFileSet;
 31  
 import org.apache.maven.scm.ScmFileStatus;
 32  
 import org.apache.maven.scm.ScmResult;
 33  
 import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
 34  
 import org.apache.maven.scm.command.unedit.UnEditScmResult;
 35  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 36  
 import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
 37  
 import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
 38  
 import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
 39  
 import org.codehaus.plexus.util.FileUtils;
 40  
 
 41  
 /**
 42  
  * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
 43  
  * @version $Id: SynergyUnEditCommand.java 1067549 2011-02-05 23:13:10Z olamy $
 44  
  */
 45  0
 public class SynergyUnEditCommand
 46  
     extends AbstractUnEditCommand
 47  
     implements SynergyCommand
 48  
 {
 49  
     /** {@inheritDoc} */
 50  
     protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
 51  
         throws ScmException
 52  
     {
 53  0
         if ( getLogger().isDebugEnabled() )
 54  
         {
 55  0
             getLogger().debug( "executing unedit 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
         String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
 66  
 
 67  
         try
 68  
         {
 69  0
             String projectSpec =
 70  
                 SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
 71  0
             if ( projectSpec == null )
 72  
             {
 73  0
                 throw new ScmException( "You should checkout a working project first" );
 74  
             }
 75  0
             File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr );
 76  0
             File destPath = new File( waPath, repo.getProjectName() );
 77  0
             for ( Iterator<File> i = fileSet.getFileList().iterator(); i.hasNext(); )
 78  
             {
 79  0
                 File f = i.next();
 80  0
                 File source = new File( fileSet.getBasedir(), f.getPath() );
 81  0
                 File dest = new File( destPath, f.getPath() );
 82  0
                 SynergyUtil.delete( getLogger(), dest, ccmAddr, true );
 83  0
                 if ( !source.equals( dest ) )
 84  
                 {
 85  0
                     if ( getLogger().isDebugEnabled() )
 86  
                     {
 87  0
                         getLogger().debug( "Copy file [" + dest + "] to [" + source + "]." );
 88  
                     }
 89  
                     try
 90  
                     {
 91  0
                         FileUtils.copyFile( dest, source );
 92  
                     }
 93  0
                     catch ( IOException e )
 94  
                     {
 95  0
                         throw new ScmException( "Unable to restore file in output folder", e );
 96  0
                     }
 97  
                 }
 98  0
             }
 99  
         }
 100  
         finally
 101  
         {
 102  0
             SynergyUtil.stop( getLogger(), ccmAddr );
 103  0
         }
 104  0
         List<ScmFile> files = new ArrayList<ScmFile>();
 105  0
         for (File f : fileSet.getFileList())
 106  
         {
 107  0
             files.add( new ScmFile(f.getPath(), ScmFileStatus.UNKNOWN) );
 108  
         }
 109  0
         return new UnEditScmResult( "", files );
 110  
     }
 111  
 
 112  
 }