buildframework/helium/sf/java/scm/src/com/nokia/maven/scm/provider/hg/command/tag/HgTagCommand.java
changeset 628 7c4a911dc066
parent 588 c7c26511138f
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    37 import org.apache.maven.scm.provider.hg.HgUtils;
    37 import org.apache.maven.scm.provider.hg.HgUtils;
    38 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
    38 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
    39 import org.apache.maven.scm.provider.hg.command.HgConsumer;
    39 import org.apache.maven.scm.provider.hg.command.HgConsumer;
    40 import org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer;
    40 import org.apache.maven.scm.provider.hg.command.inventory.HgListConsumer;
    41 import org.apache.maven.scm.provider.hg.command.tag.HgTagConsumer;
    41 import org.apache.maven.scm.provider.hg.command.tag.HgTagConsumer;
    42 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
       
    43 import org.codehaus.plexus.util.StringUtils;
    42 import org.codehaus.plexus.util.StringUtils;
       
    43 
       
    44 import com.nokia.maven.scm.provider.hg.repository.HgScmProviderRepository;
    44 
    45 
    45 /**
    46 /**
    46  * Tag
    47  * Tag
    47  * 
    48  * 
    48  * @author <a href="mailto:ryan@darksleep.com">ryan daum</a>
    49  * @author <a href="mailto:ryan@darksleep.com">ryan daum</a>
    49  * @version $Id: HgTagCommand.java 686566 2008-08-16 21:52:46Z olamy $
    50  * @version $Id: HgTagCommand.java 686566 2008-08-16 21:52:46Z olamy $
    50  */
    51  */
    51 public class HgTagCommand extends AbstractTagCommand implements Command {
    52 public class HgTagCommand extends AbstractTagCommand implements Command {
    52     /** {@inheritDoc} */
    53     /** {@inheritDoc} */
    53     @SuppressWarnings("unchecked")
    54     @SuppressWarnings("unchecked")
    54     protected ScmResult executeTagCommand(
    55     protected ScmResult executeTagCommand(ScmProviderRepository scmProviderRepository,
    55             ScmProviderRepository scmProviderRepository, ScmFileSet fileSet,
    56         ScmFileSet fileSet, String tag, String level) throws ScmException {
    56             String tag, String level) throws ScmException {
       
    57         if (tag == null || StringUtils.isEmpty(tag.trim())) {
    57         if (tag == null || StringUtils.isEmpty(tag.trim())) {
    58             throw new ScmException("tag must be specified");
    58             throw new ScmException("tag must be specified");
    59         }
    59         }
    60 
    60 
    61         if (fileSet.getFileList().size() != 0) {
    61         if (fileSet.getFileList().size() != 0) {
    62             throw new ScmException(
    62             throw new ScmException("This provider doesn't support tagging subsets of a directory");
    63                     "This provider doesn't support tagging subsets of a directory");
       
    64         }
    63         }
    65 
    64 
    66         File workingDir = fileSet.getBasedir();
    65         File workingDir = fileSet.getBasedir();
    67 
    66 
    68         // build the command
    67         // build the command
    69         String[] tagCmd;
    68         String[] tagCmd;
    70         if (level.equals(new String("local"))) {
    69         if (level.equals(new String("local"))) {
    71             tagCmd = new String[] { HgCommandConstants.TAG_CMD, "--local",
    70             tagCmd = new String[] { HgCommandConstants.TAG_CMD, "--local",
    72                     HgCommandConstants.MESSAGE_OPTION,
    71                 HgCommandConstants.MESSAGE_OPTION, "[maven-scm] copy for tag " + tag, tag };
    73                     "[maven-scm] copy for tag " + tag, tag };
    72         }
    74         } else {
    73         else {
    75             tagCmd = new String[] { HgCommandConstants.TAG_CMD,
    74             tagCmd = new String[] { HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION,
    76                     HgCommandConstants.MESSAGE_OPTION,
    75                 "[maven-scm] copy for tag " + tag, tag };
    77                     "[maven-scm] copy for tag " + tag, tag };
       
    78         }
    76         }
    79         // keep the command about in string form for reporting
    77         // keep the command about in string form for reporting
    80         StringBuffer cmd = joinCmd(tagCmd);
    78         StringBuffer cmd = joinCmd(tagCmd);
    81 
    79 
    82         HgTagConsumer consumer = new HgTagConsumer(getLogger());
    80         HgTagConsumer consumer = new HgTagConsumer(getLogger());
    83         ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir,
    81         ScmResult result = HgUtils.execute(consumer, getLogger(), workingDir, tagCmd);
    84                 tagCmd);
       
    85         HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
    82         HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
    86         if (result.isSuccess()) {
    83         if (result.isSuccess()) {
    87             // now push
    84             // now push
    88             // Push to parent branch if any
    85             // Push to parent branch if any
    89             if (!repository.getURI().equals(
    86             if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
    90                     fileSet.getBasedir().getAbsolutePath())) {
    87                 String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, repository.getURI() };
    91                 String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD,
    88                 result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
    92                         repository.getURI() };
       
    93                 result = HgUtils.execute(new HgConsumer(getLogger()),
       
    94                         getLogger(), fileSet.getBasedir(), pushCmd);
       
    95             }
    89             }
    96         } else {
    90         }
    97             throw new ScmException("Error while executing command "
    91         else {
    98                     + cmd.toString());
    92             throw new ScmException("Error while executing command " + cmd.toString());
    99         }
    93         }
   100 
    94 
   101         // do an inventory to return the files tagged (all of them)
    95         // do an inventory to return the files tagged (all of them)
   102         String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
    96         String[] listCmd = new String[] { HgCommandConstants.INVENTORY_CMD };
   103         HgListConsumer listconsumer = new HgListConsumer(getLogger());
    97         HgListConsumer listconsumer = new HgListConsumer(getLogger());
   104         result = HgUtils.execute(listconsumer, getLogger(), fileSet
    98         result = HgUtils.execute(listconsumer, getLogger(), fileSet.getBasedir(), listCmd);
   105                 .getBasedir(), listCmd);
       
   106         if (result.isSuccess()) {
    99         if (result.isSuccess()) {
   107             List<ScmFile> files = listconsumer.getFiles();
   100             List<ScmFile> files = listconsumer.getFiles();
   108             ArrayList<ScmFile> fileList = new ArrayList<ScmFile>();
   101             ArrayList<ScmFile> fileList = new ArrayList<ScmFile>();
   109             for (ScmFile scmFile : files) {
   102             for (ScmFile scmFile : files) {
   110                 
   103 
   111                 if (!scmFile.getPath().endsWith(".hgtags")) {
   104                 if (!scmFile.getPath().endsWith(".hgtags")) {
   112                     fileList
   105                     fileList.add(new ScmFile(scmFile.getPath(), ScmFileStatus.TAGGED));
   113                             .add(new ScmFile(scmFile.getPath(), ScmFileStatus.TAGGED));
       
   114                 }
   106                 }
   115             }
   107             }
   116 
   108 
   117             return new TagScmResult(fileList, result);
   109             return new TagScmResult(fileList, result);
   118         } else {
   110         }
   119             throw new ScmException("Error while executing command "
   111         else {
   120                     + cmd.toString());
   112             throw new ScmException("Error while executing command " + cmd.toString());
   121         }
   113         }
   122     }
   114     }
   123 
   115 
   124     private StringBuffer joinCmd(String[] cmds) {
   116     private StringBuffer joinCmd(String[] cmds) {
   125         StringBuffer result = new StringBuffer();
   117         StringBuffer result = new StringBuffer();