View Javadoc
1   package org.apache.maven.scm.provider.tfs.command;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.scm.ScmException;
27  import org.apache.maven.scm.ScmFile;
28  import org.apache.maven.scm.ScmFileSet;
29  import org.apache.maven.scm.ScmFileStatus;
30  import org.apache.maven.scm.ScmResult;
31  import org.apache.maven.scm.ScmTagParameters;
32  import org.apache.maven.scm.command.tag.AbstractTagCommand;
33  import org.apache.maven.scm.command.tag.TagScmResult;
34  import org.apache.maven.scm.provider.ScmProviderRepository;
35  import org.apache.maven.scm.provider.tfs.TfsScmProviderRepository;
36  import org.apache.maven.scm.provider.tfs.command.consumer.ErrorStreamConsumer;
37  import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
38  
39  /**
40   * @author Olivier Lamy
41   *
42   */
43  public class TfsTagCommand
44      extends AbstractTagCommand
45  {
46  
47      protected ScmResult executeTagCommand( ScmProviderRepository r, ScmFileSet f, String tag, String message )
48          throws ScmException
49      {
50          return executeTagCommand( r, f, tag, new ScmTagParameters( message ) );
51      }
52  
53      protected ScmResult executeTagCommand( ScmProviderRepository r, ScmFileSet f, String tag,
54                                             ScmTagParameters scmTagParameters )
55          throws ScmException
56      {
57          TfsCommand command = createCommand( r, f, tag, scmTagParameters );
58  
59          StringStreamConsumer out = new StringStreamConsumer();
60          ErrorStreamConsumer err = new ErrorStreamConsumer();
61  
62          int status = command.execute( out, err );
63          if ( status != 0 || err.hasBeenFed() )
64          {
65              return new TagScmResult( command.getCommandString(), "Error code for TFS label command - " + status,
66                                       err.getOutput(), false );
67          }
68          List<ScmFile> files = new ArrayList<ScmFile>(f.getFileList().size());
69          for (File file : f.getFileList() )
70          {
71              files.add( new ScmFile( file.getPath(), ScmFileStatus.TAGGED ) );
72          }
73          return new TagScmResult( command.getCommandString(), files );
74  
75      }
76  
77      public TfsCommand createCommand( ScmProviderRepository r, ScmFileSet f, String tag,
78                                          ScmTagParameters scmTagParameters )
79      {
80          TfsScmProviderRepository tfsRepo = (TfsScmProviderRepository) r;
81          String url = tfsRepo.getServerPath();
82  
83          TfsCommand command = new TfsCommand( "label", r, f, getLogger() );
84          command.addArgument( tag );
85          command.addArgument( url );
86          command.addArgument( "-recursive" );
87          command.addArgument( "-child:replace" );
88          String message = scmTagParameters.getMessage();
89          if ( message != null && !message.equals( "" ) )
90          {
91              command.addArgument( "-comment:" + message );
92          }
93          return command;
94      }
95  
96  }