PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/maven-scm-providers/maven-scm-provider-jazz/src/main/java/org/apache/maven/scm/provider/jazz/command/update/JazzUpdateCommand.java

https://github.com/intelchen/maven-scm
Java | 125 lines | 62 code | 16 blank | 47 comment | 7 complexity | ac0cd58209ca94a1d4f8a8ad6d04c428 MD5 | raw file
  1. package org.apache.maven.scm.provider.jazz.command.update;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.maven.scm.ScmException;
  21. import org.apache.maven.scm.ScmFile;
  22. import org.apache.maven.scm.ScmFileSet;
  23. import org.apache.maven.scm.ScmVersion;
  24. import org.apache.maven.scm.command.changelog.ChangeLogCommand;
  25. import org.apache.maven.scm.command.update.AbstractUpdateCommand;
  26. import org.apache.maven.scm.command.update.UpdateScmResult;
  27. import org.apache.maven.scm.provider.ScmProviderRepository;
  28. import org.apache.maven.scm.provider.jazz.command.JazzConstants;
  29. import org.apache.maven.scm.provider.jazz.command.JazzScmCommand;
  30. import org.apache.maven.scm.provider.jazz.command.changelog.JazzChangeLogCommand;
  31. import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer;
  32. //
  33. // The Maven SCM Plugin "update" goal is equivalent to the RTC "accept" command.
  34. //
  35. // NOTE: What is not clear from the docs, is that the accept command will also
  36. // update the sandbox with the changes that have been accepted into the repository.
  37. // However, I have checked with Rational Support, and this is indeed the expected
  38. // behaviour. This may come from the fact that you can accept changes into a
  39. // repository workspace, without having a sandbox loaded; though this makes no
  40. // sense to us from a maven usage context (as we only work in a sandbox).
  41. //
  42. // See the following links for additional information on the RTC "create snapshot" command:
  43. // RTC 2.0.0.2:
  44. // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
  45. // RTC 3.0:
  46. // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
  47. // RTC 3.0.1:
  48. // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_accept.html
  49. //
  50. /**
  51. * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
  52. */
  53. public class JazzUpdateCommand
  54. extends AbstractUpdateCommand
  55. {
  56. /**
  57. * {@inheritDoc}
  58. */
  59. protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version )
  60. throws ScmException
  61. {
  62. if ( getLogger().isDebugEnabled() )
  63. {
  64. getLogger().debug( "Executing update command..." );
  65. }
  66. JazzUpdateConsumer updateConsumer = new JazzUpdateConsumer( repo, getLogger() );
  67. ErrorConsumer err = new ErrorConsumer( getLogger() );
  68. JazzScmCommand updateCmd = createAcceptCommand( repo, fileSet );
  69. int status = updateCmd.execute( updateConsumer, err );
  70. if ( status != 0 || err.hasBeenFed() )
  71. {
  72. return new UpdateScmResult( updateCmd.getCommandString(),
  73. "Error code for Jazz SCM update command - " + status, err.getOutput(), false );
  74. }
  75. if ( getLogger().isDebugEnabled() )
  76. {
  77. if ( !updateConsumer.getUpdatedFiles().isEmpty() )
  78. {
  79. getLogger().debug( "Iterating over \"Update\" results" );
  80. for ( ScmFile file : updateConsumer.getUpdatedFiles() )
  81. {
  82. getLogger().debug( file.getPath() + " : " + file.getStatus() );
  83. }
  84. }
  85. else
  86. {
  87. getLogger().debug( "There are no updated files" );
  88. }
  89. }
  90. // Now, just (re)load the workspace into the sand box.
  91. // We can use the checkout directory for this.
  92. return new UpdateScmResult( updateCmd.getCommandString(), updateConsumer.getUpdatedFiles() );
  93. }
  94. public JazzScmCommand createAcceptCommand( ScmProviderRepository repo, ScmFileSet fileSet )
  95. {
  96. JazzScmCommand command = new JazzScmCommand( JazzConstants.CMD_ACCEPT, repo, fileSet, getLogger() );
  97. command.addArgument( JazzConstants.ARG_FLOW_COMPONENTS );
  98. return command;
  99. }
  100. /**
  101. * {@inheritDoc}
  102. */
  103. protected ChangeLogCommand getChangeLogCommand()
  104. {
  105. JazzChangeLogCommand command = new JazzChangeLogCommand();
  106. command.setLogger( getLogger() );
  107. return command;
  108. }
  109. }