1 package org.apache.maven.scm.provider.starteam.command.tag;
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.ScmResult;
25 import org.apache.maven.scm.ScmTagParameters;
26 import org.apache.maven.scm.command.tag.AbstractTagCommand;
27 import org.apache.maven.scm.command.tag.TagScmResult;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.starteam.command.StarteamCommand;
30 import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
31 import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36
37
38
39
40
41
42 public class StarteamTagCommand
43 extends AbstractTagCommand
44 implements StarteamCommand
45 {
46
47
48
49
50 protected ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag, String message )
51 throws ScmException
52 {
53 return executeTagCommand( repo, fileSet, tag, new ScmTagParameters( message ) );
54 }
55
56
57 protected ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag,
58 ScmTagParameters scmTagParameters )
59 throws ScmException
60 {
61 if ( fileSet.getFileList().isEmpty() )
62 {
63 throw new ScmException( "This provider doesn't support tagging subsets of a directory" );
64 }
65
66 if ( tag == null || tag.trim().length() == 0 )
67 {
68 throw new ScmException( "tag must be specified" );
69 }
70
71 if ( getLogger().isInfoEnabled() )
72 {
73 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
74 }
75
76 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
77
78 StarteamTagConsumer consumer = new StarteamTagConsumer( getLogger() );
79
80 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
81
82 Commandline cl = createCommandLine( repository, fileSet.getBasedir(), tag );
83
84 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
85
86 if ( exitCode != 0 )
87 {
88 return new TagScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
89 }
90
91 return new TagScmResult( cl.toString(), consumer.getTaggedFiles() );
92 }
93
94
95
96
97
98 public static Commandline createCommandLine( StarteamScmProviderRepository repo, File workingDirectory, String tag )
99 throws ScmException
100 {
101 Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "label", repo );
102
103 cl.createArg().setValue( "-p" );
104
105 cl.createArg().setValue( repo.getFullUrl() );
106
107 cl.createArg().setValue( "-nl" );
108
109 cl.createArg().setValue( tag );
110
111 cl.createArg().setValue( "-b" );
112
113 return cl;
114 }
115 }