1 package org.apache.maven.scm.provider.starteam.command.checkin;
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.checkin.AbstractCheckInCommand;
26 import org.apache.maven.scm.command.checkin.CheckInScmResult;
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.io.File;
36 import java.util.ArrayList;
37 import java.util.List;
38
39
40
41
42
43
44 public class StarteamCheckInCommand
45 extends AbstractCheckInCommand
46 implements StarteamCommand
47 {
48
49
50
51
52
53 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
54 ScmVersion version )
55 throws ScmException
56 {
57
58
59 String issueType = System.getProperty( "maven.scm.issue.type" );
60 String issueValue = System.getProperty( "maven.scm.issue.value" );
61 String deprecatedIssue = System.getProperty( "maven.scm.issue" );
62
63 if ( deprecatedIssue != null && deprecatedIssue.trim().length() > 0 )
64 {
65 issueType = "cr";
66 issueValue = deprecatedIssue;
67 }
68
69 if ( getLogger().isInfoEnabled() )
70 {
71 getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() );
72 }
73
74 StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo;
75
76 StarteamCheckInConsumer consumer = new StarteamCheckInConsumer( getLogger(), fileSet.getBasedir() );
77
78 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
79
80 List<File> checkInFiles = fileSet.getFileList();
81
82 if ( checkInFiles.isEmpty() )
83 {
84 Commandline cl = createCommandLine( repository, fileSet, message, version, issueType, issueValue );
85
86 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
87
88 if ( exitCode != 0 )
89 {
90 return new CheckInScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false );
91 }
92 }
93 else
94 {
95
96 for ( int i = 0; i < checkInFiles.size(); ++i )
97 {
98 ScmFileSet checkInFile = new ScmFileSet( fileSet.getBasedir(), (File) checkInFiles.get( i ) );
99
100 Commandline cl = createCommandLine( repository, checkInFile, message, version, issueType, issueValue );
101
102 int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() );
103
104 if ( exitCode != 0 )
105 {
106 return new CheckInScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(),
107 false );
108 }
109 }
110 }
111
112 return new CheckInScmResult( null, consumer.getCheckedInFiles() );
113
114 }
115
116
117 public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet fileSet, String message,
118 ScmVersion version, String issueType, String issueValue )
119 {
120 List<String> args = new ArrayList<String>();
121
122 if ( message != null && message.length() != 0 )
123 {
124 args.add( "-r" );
125 args.add( message );
126 }
127
128 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
129 {
130 args.add( "-vl" );
131 args.add( version.getName() );
132 }
133
134 if ( issueType != null && issueType.trim().length() > 0 )
135 {
136 args.add( "-" + issueType.trim() );
137 if ( issueValue != null && issueValue.trim().length() > 0 )
138 {
139 args.add( issueValue.trim() );
140 }
141 }
142
143 boolean checkinDirectory = fileSet.getFileList().size() == 0;
144 if ( !checkinDirectory )
145 {
146 if ( fileSet.getFileList().size() != 0 )
147 {
148 File subFile = (File) fileSet.getFileList().get( 0 );
149 checkinDirectory = subFile.isDirectory();
150 }
151 }
152
153 if ( checkinDirectory )
154 {
155 args.add( "-f" );
156 args.add( "NCI" );
157 }
158
159 StarteamCommandLineUtils.addEOLOption( args );
160
161 return StarteamCommandLineUtils.createStarteamCommandLine( "ci", args, fileSet, repo );
162
163 }
164
165 }