View Javadoc

1   package org.apache.maven.scm.provider.synergy.command.remove;
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.remove.AbstractRemoveCommand;
27  import org.apache.maven.scm.command.status.StatusScmResult;
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  
33  import java.io.File;
34  import java.util.Iterator;
35  
36  /**
37   * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
38   */
39  public class SynergyRemoveCommand
40      extends AbstractRemoveCommand
41      implements SynergyCommand
42  {
43      protected ScmResult executeRemoveCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message )
44          throws ScmException
45      {
46          getLogger().debug( "executing remove command..." );
47  
48          SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
49          getLogger().debug( "basedir: " + fileSet.getBasedir() );
50  
51          String CCM_ADDR = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
52  
53          try
54          {
55              String project_spec =
56                  SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), CCM_ADDR );
57              if ( project_spec == null )
58              {
59                  throw new ScmException( "You should checkout project first" );
60              }
61              File WAPath = SynergyUtil.getWorkArea( getLogger(), project_spec, CCM_ADDR );
62              File destPath = new File( WAPath, repo.getProjectName() );
63              for ( Iterator i = fileSet.getFileList().iterator(); i.hasNext(); )
64              {
65                  ScmFile f = (ScmFile) i.next();
66                  File source = new File( fileSet.getBasedir(), f.getPath() );
67                  File dest = new File( destPath, f.getPath() );
68                  SynergyUtil.delete( getLogger(), dest, CCM_ADDR, false );
69                  if ( !source.equals( dest ) )
70                  {
71                      getLogger().debug( "Delete file [" + source + "]." );
72                      dest.delete();
73                  }
74              }
75          }
76          finally
77          {
78              SynergyUtil.stop( getLogger(), CCM_ADDR );
79          }
80  
81          return new StatusScmResult( "", fileSet.getFileList() );
82      }
83  
84  }