1 | |
package org.apache.maven.scm.provider.synergy.command.checkout; |
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.ScmVersion; |
33 | |
import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand; |
34 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
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 SynergyCheckOutCommand |
46 | |
extends AbstractCheckOutCommand |
47 | |
implements SynergyCommand |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet, |
52 | |
ScmVersion version, boolean recursive ) |
53 | |
throws ScmException |
54 | |
{ |
55 | 0 | if ( fileSet.getFileList().size() != 0 ) |
56 | |
{ |
57 | 0 | throw new ScmException( "This provider doesn't support checking out subsets of a project" ); |
58 | |
} |
59 | |
|
60 | 0 | if ( getLogger().isDebugEnabled() ) |
61 | |
{ |
62 | 0 | getLogger().debug( "executing checkout command..." ); |
63 | |
} |
64 | |
|
65 | 0 | SynergyScmProviderRepository repo = (SynergyScmProviderRepository) repository; |
66 | |
|
67 | 0 | if ( getLogger().isDebugEnabled() ) |
68 | |
{ |
69 | 0 | getLogger().debug( fileSet.toString() ); |
70 | |
} |
71 | |
|
72 | 0 | String ccmAddr = SynergyUtil.start( getLogger(), repo.getUser(), repo.getPassword(), null ); |
73 | |
|
74 | |
File waPath; |
75 | |
try |
76 | |
{ |
77 | 0 | String projectSpec = |
78 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
79 | 0 | if ( projectSpec != null ) |
80 | |
{ |
81 | 0 | if ( getLogger().isInfoEnabled() ) |
82 | |
{ |
83 | 0 | getLogger().info( "A working project already exists [" + projectSpec + "]." ); |
84 | |
} |
85 | 0 | SynergyUtil.synchronize( getLogger(), projectSpec, ccmAddr ); |
86 | |
} |
87 | |
else |
88 | |
{ |
89 | 0 | SynergyUtil.checkoutProject( getLogger(), null, repo.getProjectSpec(), version, |
90 | |
repo.getProjectPurpose(), repo.getProjectRelease(), ccmAddr ); |
91 | 0 | projectSpec = |
92 | |
SynergyUtil.getWorkingProject( getLogger(), repo.getProjectSpec(), repo.getUser(), ccmAddr ); |
93 | 0 | if ( getLogger().isInfoEnabled() ) |
94 | |
{ |
95 | 0 | getLogger().info( "A new working project [" + projectSpec + "] was created." ); |
96 | |
} |
97 | |
} |
98 | 0 | SynergyUtil.reconfigure( getLogger(), projectSpec, ccmAddr ); |
99 | 0 | waPath = SynergyUtil.getWorkArea( getLogger(), projectSpec, ccmAddr ); |
100 | |
|
101 | |
} |
102 | |
finally |
103 | |
{ |
104 | 0 | SynergyUtil.stop( getLogger(), ccmAddr ); |
105 | 0 | } |
106 | |
|
107 | 0 | File source = new File( waPath, repo.getProjectName() ); |
108 | |
|
109 | 0 | if ( getLogger().isInfoEnabled() ) |
110 | |
{ |
111 | 0 | getLogger().info( |
112 | |
"We will now copy files from Synergy Work Area [" + source |
113 | |
+ "] to expected folder [" + fileSet.getBasedir() + "]" ); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
try |
118 | |
{ |
119 | 0 | FileUtils.copyDirectoryStructure( source, fileSet.getBasedir() ); |
120 | |
} |
121 | 0 | catch ( IOException e1 ) |
122 | |
{ |
123 | 0 | throw new ScmException( "Unable to copy directory structure", e1 ); |
124 | 0 | } |
125 | |
|
126 | 0 | if ( getLogger().isDebugEnabled() ) |
127 | |
{ |
128 | 0 | getLogger().debug( "We will list content of checkout directory." ); |
129 | |
} |
130 | |
|
131 | |
|
132 | 0 | List<ScmFile> files = new ArrayList<ScmFile>(); |
133 | |
try |
134 | |
{ |
135 | |
@SuppressWarnings( "unchecked" ) |
136 | 0 | List<File> realFiles = FileUtils.getFiles( fileSet.getBasedir(), null, "_ccmwaid.inf" ); |
137 | 0 | for (File f : realFiles) |
138 | |
{ |
139 | 0 | files.add( new ScmFile( f.getPath(), ScmFileStatus.CHECKED_OUT ) ); |
140 | |
} |
141 | |
} |
142 | 0 | catch ( IOException e ) |
143 | |
{ |
144 | 0 | throw new ScmException( "Unable to list files in checkout directory", e ); |
145 | 0 | } |
146 | |
|
147 | 0 | if ( getLogger().isDebugEnabled() ) |
148 | |
{ |
149 | 0 | getLogger().debug( "checkout command end successfully ..." ); |
150 | |
} |
151 | |
|
152 | 0 | return new CheckOutScmResult( files, new ScmResult( "multiple commandline", "OK", "OK", true ) ); |
153 | |
} |
154 | |
|
155 | |
} |