1 | |
package org.apache.maven.scm.provider.synergy.command.unedit; |
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.io.IOException; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.List; |
27 | |
|
28 | |
import org.apache.maven.scm.ScmException; |
29 | |
import org.apache.maven.scm.ScmFile; |
30 | |
import org.apache.maven.scm.ScmFileSet; |
31 | |
import org.apache.maven.scm.ScmFileStatus; |
32 | |
import org.apache.maven.scm.ScmResult; |
33 | |
import org.apache.maven.scm.command.unedit.AbstractUnEditCommand; |
34 | |
import org.apache.maven.scm.command.unedit.UnEditScmResult; |
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 | |
|
43 | |
|
44 | |
|
45 | 0 | public class SynergyUnEditCommand |
46 | |
extends AbstractUnEditCommand |
47 | |
implements SynergyCommand |
48 | |
{ |
49 | |
|
50 | |
protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet ) |
51 | |
throws ScmException |
52 | |
{ |
53 | 0 | if ( getLogger().isDebugEnabled() ) |
54 | |
{ |
55 | 0 | getLogger().debug( "executing unedit command..." ); |
56 | |
} |
57 | |
|
58 | 0 | SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository; |
59 | |
|
60 | 0 | if ( getLogger().isDebugEnabled() ) |
61 | |
{ |
62 | 0 | getLogger().debug( "basedir: " + fileSet.getBasedir() ); |
63 | |
} |
64 | |
|
65 | 0 | String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null ); |
66 | |
|
67 | |
try |
68 | |
{ |
69 | 0 | String projectSpec = |
70 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
71 | 0 | if ( projectSpec == null ) |
72 | |
{ |
73 | 0 | throw new ScmException( "You should checkout a working project first" ); |
74 | |
} |
75 | 0 | File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr ); |
76 | 0 | File destPath = new File( waPath, repo.getProjectName() ); |
77 | 0 | for ( Iterator<File> i = fileSet.getFileList().iterator(); i.hasNext(); ) |
78 | |
{ |
79 | 0 | File f = i.next(); |
80 | 0 | File source = new File( fileSet.getBasedir(), f.getPath() ); |
81 | 0 | File dest = new File( destPath, f.getPath() ); |
82 | 0 | SynergyUtil.delete( getLogger(), dest, ccmAddr, true ); |
83 | 0 | if ( !source.equals( dest ) ) |
84 | |
{ |
85 | 0 | if ( getLogger().isDebugEnabled() ) |
86 | |
{ |
87 | 0 | getLogger().debug( "Copy file [" + dest + "] to [" + source + "]." ); |
88 | |
} |
89 | |
try |
90 | |
{ |
91 | 0 | FileUtils.copyFile( dest, source ); |
92 | |
} |
93 | 0 | catch ( IOException e ) |
94 | |
{ |
95 | 0 | throw new ScmException( "Unable to restore file in output folder", e ); |
96 | 0 | } |
97 | |
} |
98 | 0 | } |
99 | |
} |
100 | |
finally |
101 | |
{ |
102 | 0 | SynergyUtil.stop( getLogger(), ccmAddr ); |
103 | 0 | } |
104 | 0 | List<ScmFile> files = new ArrayList<ScmFile>(); |
105 | 0 | for (File f : fileSet.getFileList()) |
106 | |
{ |
107 | 0 | files.add( new ScmFile(f.getPath(), ScmFileStatus.UNKNOWN) ); |
108 | |
} |
109 | 0 | return new UnEditScmResult( "", files ); |
110 | |
} |
111 | |
|
112 | |
} |