View Javadoc

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 org.apache.maven.scm.ScmException;
23  import org.apache.maven.scm.ScmFile;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmResult;
26  import org.apache.maven.scm.command.unedit.AbstractUnEditCommand;
27  import org.apache.maven.scm.command.unedit.UnEditScmResult;
28  import org.apache.maven.scm.provider.ScmProviderRepository;
29  import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
30  import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
31  import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
32  import org.codehaus.plexus.util.FileUtils;
33  
34  import java.io.File;
35  import java.io.IOException;
36  import java.util.Iterator;
37  
38  /**
39   * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
40   */
41  public class SynergyUnEditCommand
42      extends AbstractUnEditCommand
43      implements SynergyCommand
44  {
45      protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
46          throws ScmException
47      {
48          getLogger().debug( "executing unedit command..." );
49  
50          SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
51          getLogger().debug( "basedir: " + fileSet.getBasedir() );
52  
53          String CCM_ADDR = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
54  
55          try
56          {
57              String project_spec =
58                  SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), CCM_ADDR );
59              if ( project_spec == null )
60              {
61                  throw new ScmException( "You should checkout project first" );
62              }
63              File WAPath = SynergyUtil.getWorkArea( getLogger(), project_spec, CCM_ADDR );
64              File destPath = new File( WAPath, repo.getProjectName() );
65              for ( Iterator i = fileSet.getFileList().iterator(); i.hasNext(); )
66              {
67                  ScmFile f = (ScmFile) i.next();
68                  File source = new File( fileSet.getBasedir(), f.getPath() );
69                  File dest = new File( destPath, f.getPath() );
70                  SynergyUtil.delete( getLogger(), dest, CCM_ADDR, true );
71                  if ( !source.equals( dest ) )
72                  {
73                      getLogger().debug( "Copy file [" + dest + "] to [" + source + "]." );
74                      try
75                      {
76                          FileUtils.copyFile( dest, source );
77                      }
78                      catch ( IOException e )
79                      {
80                          throw new ScmException( "Unable to restore file in output folder", e );
81                      }
82                  }
83              }
84          }
85          finally
86          {
87              SynergyUtil.stop( getLogger(), CCM_ADDR );
88          }
89  
90          return new UnEditScmResult( "", fileSet.getFileList() );
91      }
92  
93  }