1 package org.apache.maven.scm.provider.starteam.command.checkout;
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.starteam.command.StarteamCommand;
29 import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
30 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
31 import org.codehaus.plexus.util.StringUtils;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38
39
40
41
42
43
44 public class StarteamCheckOutCommand
45 extends AbstractCheckOutCommand
46 implements StarteamCommand
47 {
48
49
50
51
52
53 protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
54 ScmVersion version, boolean recursive )
55 throws ScmException
56 {
57 if ( fileSet.getFileList().size() != 0 )
58 {
59 throw new ScmException( "This provider doesn't support checking out subsets of a directory" );
60 }
61
62 if ( getLogger().isInfoEnabled() )
63 {
64 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
65 }
66
67 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
68
69 StarteamCheckOutConsumer consumer = new StarteamCheckOutConsumer( getLogger(), fileSet.getBasedir() );
70
71 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
72
73 Commandline cl = createCommandLine( repository, fileSet, version );
74
75 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
76
77 if ( exitCode != 0 )
78 {
79 return new CheckOutScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
80 }
81
82 return new CheckOutScmResult( cl.toString(), consumer.getCheckedOutFiles() );
83 }
84
85
86
87
88
89 public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet baseDir,
90 ScmVersion version )
91 {
92 List<String> args = new ArrayList<String>();
93
94 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
95 {
96 args.add( "-vl" );
97 args.add( version.getName() );
98 }
99
100 StarteamCommandLineUtils.addEOLOption( args );
101
102 return StarteamCommandLineUtils.createStarteamCommandLine( "co", args, baseDir, repo );
103 }
104 }