Coverage Report - org.apache.maven.scm.provider.synergy.command.checkout.SynergyCheckOutCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
SynergyCheckOutCommand
0 %
0/41
0 %
0/20
16
 
 1  
 package org.apache.maven.scm.provider.synergy.command.checkout;
 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.ScmVersion;
 33  
 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
 34  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 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: SynergyCheckOutCommand.java 1067549 2011-02-05 23:13:10Z olamy $
 44  
  */
 45  0
 public class SynergyCheckOutCommand
 46  
     extends AbstractCheckOutCommand
 47  
     implements SynergyCommand
 48  
 {
 49  
 
 50  
     /** {@inheritDoc} */
 51  
     protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
 52  
                                                         ScmVersion version, boolean recursive )
 53  
         throws ScmException
 54  
     {
 55  0
         if ( fileSet.getFileList().size() != 0 )
 56  
         {
 57  0
             throw new ScmException( "This provider doesn't support checking out subsets of a project" );
 58  
         }
 59  
 
 60  0
         if ( getLogger().isDebugEnabled() )
 61  
         {
 62  0
             getLogger().debug( "executing checkout command..." );
 63  
         }
 64  
 
 65  0
         SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
 66  
 
 67  0
         if ( getLogger().isDebugEnabled() )
 68  
         {
 69  0
             getLogger().debug( fileSet.toString() );
 70  
         }
 71  
 
 72  0
         String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
 73  
 
 74  
         File waPath;
 75  
         try
 76  
         {
 77  0
             String projectSpec =
 78  
                 SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
 79  0
             if ( projectSpec != null )
 80  
             {
 81  0
                 if ( getLogger().isInfoEnabled() )
 82  
                 {
 83  0
                     getLogger().info( "A working project already exists [" + projectSpec + "]." );
 84  
                 }
 85  0
                 SynergyUtil.synchronize( getLogger(), projectSpec, ccmAddr );
 86  
             }
 87  
             else
 88  
             {
 89  0
                 SynergyUtil.checkoutProject( getLogger(), null, repo.getProjectSpec(), version,
 90  
                                              repo.getProjectPurpose(), repo.getProjectRelease(), ccmAddr );
 91  0
                 projectSpec =
 92  
                     SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
 93  0
                 if ( getLogger().isInfoEnabled() )
 94  
                 {
 95  0
                     getLogger().info( "A new working project [" + projectSpec + "] was created." );
 96  
                 }
 97  
             }
 98  0
             SynergyUtil.reconfigure( getLogger(), projectSpec, ccmAddr );
 99  0
             waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr );
 100  
 
 101  
         }
 102  
         finally
 103  
         {
 104  0
             SynergyUtil.stop( getLogger(), ccmAddr );
 105  0
         }
 106  
 
 107  0
         File source = new File( waPath, repo.getProjectName() );
 108  
 
 109  0
         if ( getLogger().isInfoEnabled() )
 110  
         {
 111  0
             getLogger().info(
 112  
                               "We will now copy files from Synergy Work Area [" + source
 113  
                                   + "] to expected folder [" + fileSet.getBasedir() + "]" );
 114  
         }
 115  
 
 116  
         // Move files to the expected folder
 117  
         try
 118  
         {
 119  0
             FileUtils.copyDirectoryStructure( source, fileSet.getBasedir() );
 120  
         }
 121  0
         catch ( IOException e1 )
 122  
         {
 123  0
             throw new ScmException( "Unable to copy directory structure", e1 );
 124  0
         }
 125  
 
 126  0
         if ( getLogger().isDebugEnabled() )
 127  
         {
 128  0
             getLogger().debug( "We will list content of checkout directory." );
 129  
         }
 130  
 
 131  
         // We need to list files in the directory
 132  0
         List<ScmFile> files = new ArrayList<ScmFile>();
 133  
         try
 134  
         {
 135  
             @SuppressWarnings( "unchecked" )
 136  0
             List<File> realFiles = FileUtils.getFiles( fileSet.getBasedir(), null, "_ccmwaid.inf" ); 
 137  0
             for (File f : realFiles) 
 138  
             {
 139  0
                 files.add( new ScmFile( f.getPath(), ScmFileStatus.CHECKED_OUT ) );
 140  
             }
 141  
         }
 142  0
         catch ( IOException e )
 143  
         {
 144  0
             throw new ScmException( "Unable to list files in checkout directory", e );
 145  0
         }
 146  
 
 147  0
         if ( getLogger().isDebugEnabled() )
 148  
         {
 149  0
             getLogger().debug( "checkout command end successfully ..." );
 150  
         }
 151  
 
 152  0
         return new CheckOutScmResult( files, new ScmResult( "multiple commandline", "OK", "OK", true ) );
 153  
     }
 154  
 
 155  
 }