1 | |
package org.apache.maven.scm.provider.tfs.command; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.scm.ScmException; |
23 | |
import org.apache.maven.scm.ScmFileSet; |
24 | |
import org.apache.maven.scm.ScmVersion; |
25 | |
import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand; |
26 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
27 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
28 | |
import org.apache.maven.scm.provider.tfs.TfsScmProviderRepository; |
29 | |
import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer; |
30 | |
import org.apache.maven.scm.provider.tfs.command.consumer.FileListConsumer; |
31 | |
|
32 | |
|
33 | 1 | public class TfsCheckOutCommand |
34 | |
extends AbstractCheckOutCommand |
35 | |
{ |
36 | |
|
37 | |
protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository r, ScmFileSet f, ScmVersion v, |
38 | |
boolean recursive ) |
39 | |
throws ScmException |
40 | |
{ |
41 | 0 | TfsScmProviderRepository tfsRepo = (TfsScmProviderRepository) r; |
42 | 0 | String url = tfsRepo.getServerPath(); |
43 | 0 | String tfsUrl = tfsRepo.getTfsUrl(); |
44 | 0 | String workspace = tfsRepo.getWorkspace(); |
45 | |
|
46 | |
|
47 | 0 | boolean workspaceProvided = workspace != null && !workspace.trim().equals( "" ); |
48 | 0 | if ( workspaceProvided ) |
49 | |
{ |
50 | 0 | createWorkspace( r, f, workspace, tfsUrl ); |
51 | |
} |
52 | |
|
53 | |
TfsCommand command; |
54 | |
int status; |
55 | |
|
56 | 0 | if ( workspaceProvided ) |
57 | |
{ |
58 | 0 | status = executeUnmapCommand( r, f ); |
59 | |
} |
60 | |
|
61 | 0 | ErrorStreamConsumer out = new ErrorStreamConsumer(); |
62 | 0 | ErrorStreamConsumer err = new ErrorStreamConsumer(); |
63 | 0 | if ( workspaceProvided ) |
64 | |
{ |
65 | 0 | command = new TfsCommand( "workfold", r, null, getLogger() ); |
66 | 0 | command.addArgument( "-workspace:" + workspace ); |
67 | 0 | command.addArgument( "-map" ); |
68 | 0 | command.addArgument( url ); |
69 | 0 | command.addArgument( f.getBasedir().getAbsolutePath() ); |
70 | 0 | status = command.execute( out, err ); |
71 | 0 | if ( status != 0 || err.hasBeenFed() ) |
72 | |
{ |
73 | 0 | return new CheckOutScmResult( command.getCommandString(), |
74 | |
"Error code for TFS checkout (workfold map) command - " + status, |
75 | |
err.getOutput(), false ); |
76 | |
} |
77 | |
} |
78 | 0 | FileListConsumer fileConsumer = new FileListConsumer(); |
79 | 0 | err = new ErrorStreamConsumer(); |
80 | 0 | command = createGetCommand( r, f, v, recursive ); |
81 | 0 | status = command.execute( fileConsumer, err ); |
82 | 0 | if ( status != 0 || err.hasBeenFed() ) |
83 | |
{ |
84 | 0 | return new CheckOutScmResult( command.getCommandString(), "Error code for TFS checkout (get) command - " |
85 | |
+ status, err.getOutput(), false ); |
86 | |
} |
87 | |
|
88 | 0 | return new CheckOutScmResult( command.getCommandString(), fileConsumer.getFiles() ); |
89 | |
} |
90 | |
|
91 | |
public TfsCommand createGetCommand( ScmProviderRepository r, ScmFileSet f, ScmVersion v, boolean recursive ) |
92 | |
{ |
93 | 1 | TfsCommand command = new TfsCommand( "get", r, f, getLogger() ); |
94 | 1 | if ( recursive ) |
95 | |
{ |
96 | 1 | command.addArgument( "-recursive" ); |
97 | |
} |
98 | |
|
99 | 1 | command.addArgument( "-force" ); |
100 | |
|
101 | 1 | if ( v != null && !v.equals( "" ) ) |
102 | |
{ |
103 | 1 | String vType = ""; |
104 | 1 | if ( v.getType().equals( "Tag" ) ) |
105 | |
{ |
106 | 0 | vType = "L"; |
107 | |
} |
108 | 1 | if ( v.getType().equals( "Revision" ) ) |
109 | |
{ |
110 | 1 | vType = "C"; |
111 | |
} |
112 | 1 | command.addArgument( "-version:" + vType + v.getName() ); |
113 | |
} |
114 | |
|
115 | 1 | command.addArgument( f.getBasedir().getAbsolutePath() ); |
116 | |
|
117 | 1 | return command; |
118 | |
} |
119 | |
|
120 | |
public int executeUnmapCommand( ScmProviderRepository r, ScmFileSet f ) |
121 | |
throws ScmException |
122 | |
{ |
123 | 0 | TfsScmProviderRepository tfsRepo = (TfsScmProviderRepository) r; |
124 | 0 | String url = tfsRepo.getServerPath(); |
125 | 0 | String workspace = tfsRepo.getWorkspace(); |
126 | 0 | ErrorStreamConsumer out = new ErrorStreamConsumer(); |
127 | 0 | ErrorStreamConsumer err = new ErrorStreamConsumer(); |
128 | |
|
129 | 0 | TfsCommand command = new TfsCommand( "workfold", r, null, getLogger() ); |
130 | 0 | command.addArgument( "-workspace:" + workspace ); |
131 | 0 | command.addArgument( "-unmap" ); |
132 | 0 | command.addArgument( url ); |
133 | |
|
134 | 0 | return command.execute( out, err ); |
135 | |
} |
136 | |
|
137 | |
private void createWorkspace( ScmProviderRepository r, ScmFileSet f, String workspace, String url ) |
138 | |
throws ScmException |
139 | |
{ |
140 | 0 | ErrorStreamConsumer out = new ErrorStreamConsumer(); |
141 | 0 | ErrorStreamConsumer err = new ErrorStreamConsumer(); |
142 | |
|
143 | 0 | TfsCommand command = new TfsCommand( "workspace", r, null, getLogger() ); |
144 | 0 | command.addArgument( "-new" ); |
145 | 0 | command.addArgument( "-comment:Creating workspace for maven command" ); |
146 | 0 | command.addArgument( "-server:" + url ); |
147 | 0 | command.addArgument( workspace ); |
148 | |
|
149 | 0 | command.execute( out, err ); |
150 | 0 | } |
151 | |
|
152 | |
} |