1 | |
package org.apache.maven.scm.provider.synergy.command.remove; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
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 | |
|
40 | |
|
41 | |
|
42 | 0 | public class SynergyRemoveCommand |
43 | |
extends AbstractRemoveCommand |
44 | |
implements SynergyCommand |
45 | |
{ |
46 | |
|
47 | |
protected ScmResult executeRemoveCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message ) |
48 | |
throws ScmException |
49 | |
{ |
50 | 0 | if ( getLogger().isDebugEnabled() ) |
51 | |
{ |
52 | 0 | getLogger().debug( "executing remove command..." ); |
53 | |
} |
54 | |
|
55 | 0 | SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository; |
56 | |
|
57 | 0 | if ( getLogger().isDebugEnabled() ) |
58 | |
{ |
59 | 0 | getLogger().debug( "basedir: " + fileSet.getBasedir() ); |
60 | |
} |
61 | |
|
62 | 0 | String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null ); |
63 | |
|
64 | |
try |
65 | |
{ |
66 | 0 | String projectSpec = |
67 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
68 | 0 | if ( projectSpec == null ) |
69 | |
{ |
70 | 0 | throw new ScmException( "You should checkout a working project first" ); |
71 | |
} |
72 | 0 | File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr ); |
73 | 0 | File destPath = new File( waPath, repo.getProjectName() ); |
74 | 0 | for ( File f : fileSet.getFileList() ) |
75 | |
{ |
76 | 0 | File source = new File( fileSet.getBasedir(), f.getPath() ); |
77 | 0 | File dest = new File( destPath, f.getPath() ); |
78 | 0 | SynergyUtil.delete( getLogger(), dest, ccmAddr, false ); |
79 | 0 | if ( !source.equals( dest ) ) |
80 | |
{ |
81 | 0 | if ( getLogger().isDebugEnabled() ) |
82 | |
{ |
83 | 0 | getLogger().debug( "Delete file [" + source + "]." ); |
84 | |
} |
85 | 0 | dest.delete(); |
86 | |
} |
87 | 0 | } |
88 | |
} |
89 | |
finally |
90 | |
{ |
91 | 0 | SynergyUtil.stop( getLogger(), ccmAddr ); |
92 | 0 | } |
93 | 0 | List<ScmFile> scmFiles = new ArrayList<ScmFile>(); |
94 | 0 | for (File file : fileSet.getFileList()) |
95 | |
{ |
96 | 0 | scmFiles.add( new ScmFile( file.getPath(), ScmFileStatus.DELETED ) ); |
97 | |
} |
98 | 0 | return new StatusScmResult( "", scmFiles ); |
99 | |
} |
100 | |
|
101 | |
} |