1 | |
package org.apache.maven.scm.provider.synergy.command.edit; |
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.LinkedList; |
27 | |
import java.util.List; |
28 | |
|
29 | |
import org.apache.maven.scm.ScmException; |
30 | |
import org.apache.maven.scm.ScmFile; |
31 | |
import org.apache.maven.scm.ScmFileSet; |
32 | |
import org.apache.maven.scm.ScmFileStatus; |
33 | |
import org.apache.maven.scm.ScmResult; |
34 | |
import org.apache.maven.scm.command.edit.AbstractEditCommand; |
35 | |
import org.apache.maven.scm.command.edit.EditScmResult; |
36 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
37 | |
import org.apache.maven.scm.provider.synergy.command.SynergyCommand; |
38 | |
import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository; |
39 | |
import org.apache.maven.scm.provider.synergy.util.SynergyTaskManager; |
40 | |
import org.apache.maven.scm.provider.synergy.util.SynergyUtil; |
41 | |
import org.codehaus.plexus.util.FileUtils; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class SynergyEditCommand |
48 | |
extends AbstractEditCommand |
49 | |
implements SynergyCommand |
50 | |
{ |
51 | |
|
52 | |
protected ScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet ) |
53 | |
throws ScmException |
54 | |
{ |
55 | 0 | if ( getLogger().isDebugEnabled() ) |
56 | |
{ |
57 | 0 | getLogger().debug( "executing edit command..." ); |
58 | |
} |
59 | |
|
60 | 0 | SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository; |
61 | |
|
62 | 0 | if ( getLogger().isDebugEnabled() ) |
63 | |
{ |
64 | 0 | getLogger().debug( fileSet.toString() ); |
65 | |
} |
66 | |
|
67 | 0 | String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null ); |
68 | |
|
69 | |
try |
70 | |
{ |
71 | 0 | String projectSpec = |
72 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
73 | 0 | File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr ); |
74 | 0 | File sourcePath = new File( waPath, repo.getProjectName() ); |
75 | 0 | if ( projectSpec == null ) |
76 | |
{ |
77 | 0 | throw new ScmException( "You should checkout project first" ); |
78 | |
} |
79 | 0 | int taskNum = SynergyUtil.createTask( getLogger(), "Maven SCM Synergy provider: edit command for project " |
80 | |
+ repo.getProjectSpec(), repo.getProjectRelease(), true, ccmAddr ); |
81 | 0 | if ( getLogger().isInfoEnabled() ) |
82 | |
{ |
83 | 0 | getLogger().info( "Task " + taskNum + " was created to perform checkout." ); |
84 | |
} |
85 | 0 | for ( Iterator<File> i = fileSet.getFileList().iterator(); i.hasNext(); ) |
86 | |
{ |
87 | 0 | File f = (File) i.next(); |
88 | 0 | File dest = f; |
89 | 0 | File source = new File( sourcePath, SynergyUtil.removePrefix( fileSet.getBasedir(), f ) ); |
90 | 0 | List<File> list = new LinkedList<File>(); |
91 | 0 | list.add( source ); |
92 | 0 | SynergyUtil.checkoutFiles( getLogger(), list, ccmAddr ); |
93 | 0 | if ( !source.equals( dest ) ) |
94 | |
{ |
95 | 0 | if ( getLogger().isDebugEnabled() ) |
96 | |
{ |
97 | 0 | getLogger().debug( "Copy file [" + source + "] to expected folder [" + dest + "]." ); |
98 | |
} |
99 | |
try |
100 | |
{ |
101 | 0 | FileUtils.copyFile( source, dest ); |
102 | |
} |
103 | 0 | catch ( IOException e ) |
104 | |
{ |
105 | 0 | throw new ScmException( "Unable to copy file from Work Area", e ); |
106 | 0 | } |
107 | |
} |
108 | 0 | } |
109 | |
} |
110 | |
finally |
111 | |
{ |
112 | 0 | SynergyUtil.stop( getLogger(), ccmAddr ); |
113 | 0 | } |
114 | 0 | List<ScmFile> scmFiles = new ArrayList<ScmFile>(fileSet.getFileList().size()); |
115 | 0 | for (File f : fileSet.getFileList()) |
116 | |
{ |
117 | 0 | scmFiles.add( new ScmFile( f.getPath(), ScmFileStatus.EDITED ) ); |
118 | |
} |
119 | 0 | return new EditScmResult( "", scmFiles ); |
120 | |
} |
121 | |
|
122 | |
} |