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 java.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFile;
28  import org.apache.maven.scm.ScmFileSet;
29  import org.apache.maven.scm.ScmFileStatus;
30  import org.apache.maven.scm.ScmResult;
31  import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
32  import org.apache.maven.scm.command.status.StatusScmResult;
33  import org.apache.maven.scm.provider.ScmProviderRepository;
34  import org.apache.maven.scm.provider.synergy.command.SynergyCommand;
35  import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository;
36  import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
37  
38  /**
39   * @author <a href="mailto:julien.henry@capgemini.com">Julien Henry</a>
40   *
41   */
42  public class SynergyRemoveCommand
43      extends AbstractRemoveCommand
44      implements SynergyCommand
45  {
46      /** {@inheritDoc} */
47      protected ScmResult executeRemoveCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message )
48          throws ScmException
49      {
50          if ( getLogger().isDebugEnabled() )
51          {
52              getLogger().debug( "executing remove command..." );
53          }
54  
55          SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository;
56  
57          if ( getLogger().isDebugEnabled() )
58          {
59              getLogger().debug( "basedir: " + fileSet.getBasedir() );
60          }
61  
62          String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null );
63  
64          try
65          {
66              String projectSpec =
67                  SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr );
68              if ( projectSpec == null )
69              {
70                  throw new ScmException( "You should checkout a working project first" );
71              }
72              File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr );
73              File destPath = new File( waPath, repo.getProjectName() );
74              for ( File f : fileSet.getFileList() )
75              {
76                  File source = new File( fileSet.getBasedir(), f.getPath() );
77                  File dest = new File( destPath, f.getPath() );
78                  SynergyUtil.delete( getLogger(), dest, ccmAddr, false );
79                  if ( !source.equals( dest ) )
80                  {
81                      if ( getLogger().isDebugEnabled() )
82                      {
83                          getLogger().debug( "Delete file [" + source + "]." );
84                      }
85                      dest.delete();
86                  }
87              }
88          }
89          finally
90          {
91              SynergyUtil.stop( getLogger(), ccmAddr );
92          }
93          List<ScmFile> scmFiles = new ArrayList<ScmFile>();
94          for ( File file : fileSet.getFileList() )
95          {
96              scmFiles.add( new ScmFile( file.getPath(), ScmFileStatus.DELETED ) );
97          }
98          return new StatusScmResult( "", scmFiles );
99      }
100 
101 }