1 | |
package org.apache.maven.scm.provider.synergy.command.add; |
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.List; |
26 | |
|
27 | |
import org.apache.maven.scm.ScmException; |
28 | |
import org.apache.maven.scm.ScmFile; |
29 | |
import org.apache.maven.scm.ScmFileSet; |
30 | |
import org.apache.maven.scm.ScmFileStatus; |
31 | |
import org.apache.maven.scm.ScmResult; |
32 | |
import org.apache.maven.scm.command.add.AbstractAddCommand; |
33 | |
import org.apache.maven.scm.command.add.AddScmResult; |
34 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
35 | |
import org.apache.maven.scm.provider.synergy.command.SynergyCommand; |
36 | |
import org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository; |
37 | |
import org.apache.maven.scm.provider.synergy.util.SynergyUtil; |
38 | |
import org.codehaus.plexus.util.FileUtils; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class SynergyAddCommand |
45 | |
extends AbstractAddCommand |
46 | |
implements SynergyCommand |
47 | |
{ |
48 | |
|
49 | |
protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message, |
50 | |
boolean binary ) |
51 | |
throws ScmException |
52 | |
{ |
53 | 0 | if ( getLogger().isDebugEnabled() ) |
54 | |
{ |
55 | 0 | getLogger().debug( "executing add 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 | if ( message == null || message.equals( "" ) ) |
66 | |
{ |
67 | 0 | message = "Maven SCM Synergy provider: adding file(s) to project " + repo.getProjectSpec(); |
68 | |
} |
69 | |
|
70 | 0 | String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null ); |
71 | |
|
72 | |
try |
73 | |
{ |
74 | 0 | int taskNum = SynergyUtil.createTask( getLogger(), message, repo.getProjectRelease(), true, ccmAddr ); |
75 | 0 | String projectSpec = |
76 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
77 | 0 | if ( projectSpec == null ) |
78 | |
{ |
79 | 0 | throw new ScmException( "You should checkout a working project first" ); |
80 | |
} |
81 | 0 | File waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr ); |
82 | 0 | File destPath = new File( waPath, repo.getProjectName() ); |
83 | 0 | for ( File source : fileSet.getFileList() ) |
84 | |
{ |
85 | 0 | File dest = new File( destPath, SynergyUtil.removePrefix( fileSet.getBasedir(), source ) ); |
86 | 0 | if ( !source.equals( dest ) ) |
87 | |
{ |
88 | 0 | if ( getLogger().isDebugEnabled() ) |
89 | |
{ |
90 | 0 | getLogger().debug( "Copy file [" + source + "] to Synergy Work Area [" + dest + "]." ); |
91 | |
} |
92 | |
try |
93 | |
{ |
94 | 0 | FileUtils.copyFile( source, dest ); |
95 | |
} |
96 | 0 | catch ( IOException e ) |
97 | |
{ |
98 | 0 | throw new ScmException( "Unable to copy file in Work Area", e ); |
99 | 0 | } |
100 | |
} |
101 | 0 | SynergyUtil.create( getLogger(), dest, message, ccmAddr ); |
102 | 0 | } |
103 | 0 | SynergyUtil.checkinTask( getLogger(), taskNum, message, ccmAddr ); |
104 | |
|
105 | |
} |
106 | |
finally |
107 | |
{ |
108 | 0 | SynergyUtil.stop( getLogger(), ccmAddr ); |
109 | 0 | } |
110 | 0 | List<ScmFile> scmFiles = new ArrayList<ScmFile>(fileSet.getFileList().size()); |
111 | 0 | for (File f : fileSet.getFileList()) |
112 | |
{ |
113 | 0 | scmFiles.add( new ScmFile( f.getPath(), ScmFileStatus.ADDED ) ); |
114 | |
} |
115 | 0 | return new AddScmResult( "", scmFiles ); |
116 | |
} |
117 | |
|
118 | |
|
119 | |
} |