PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/jenkins/plugins/shiningpanda/command/WindowsCommand.java

https://github.com/jenkinsci/shiningpanda-plugin
Java | 127 lines | 61 code | 9 blank | 57 comment | 0 complexity | cc6a19f8e10881b5db170ad0ff00bfba MD5 | raw file
  1. /*
  2. * ShiningPanda plug-in for Jenkins
  3. * Copyright (C) 2011-2015 ShiningPanda S.A.S.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of its license which incorporates the terms and
  7. * conditions of version 3 of the GNU Affero General Public License,
  8. * supplemented by the additional permissions under the GNU Affero GPL
  9. * version 3 section 7: if you modify this program, or any covered work,
  10. * by linking or combining it with other code, such other code is not
  11. * for that reason alone subject to any of the requirements of the GNU
  12. * Affero GPL version 3.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * license for more details.
  18. *
  19. * You should have received a copy of the license along with this program.
  20. * If not, see <https://raw.github.com/jenkinsci/shiningpanda-plugin/master/LICENSE.txt>.
  21. */
  22. package jenkins.plugins.shiningpanda.command;
  23. import java.util.regex.Pattern;
  24. import hudson.FilePath;
  25. import hudson.util.ArgumentListBuilder;
  26. public class WindowsCommand extends ShellCommand {
  27. /**
  28. * Store the variable pattern.
  29. */
  30. private final static Pattern VARIABLE = Pattern.compile("\\$\\{?(\\w+)\\}?");
  31. /**
  32. * Constructor using fields.
  33. *
  34. * @param command
  35. * The content of the execution script
  36. * @param ignoreExitCode
  37. * Is exit code ignored?
  38. * @param convert
  39. * Convert shell to batch
  40. */
  41. protected WindowsCommand(String command, boolean ignoreExitCode, boolean convert) {
  42. super(command, ignoreExitCode, convert);
  43. }
  44. /*
  45. * (non-Javadoc)
  46. *
  47. * @see jenkins.plugins.shiningpanda.command.Command#getExtension()
  48. */
  49. @Override
  50. protected String getExtension() {
  51. return ".bat";
  52. }
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see
  57. * jenkins.plugins.shiningpanda.command.ShellCommand#getOriginalContent()
  58. */
  59. @Override
  60. protected String getSourceContent() {
  61. return getCommand() + "\r\nexit %ERRORLEVEL%";
  62. }
  63. /*
  64. * (non-Javadoc)
  65. *
  66. * @see
  67. * jenkins.plugins.shiningpanda.command.ShellCommand#getSourceSeparator()
  68. */
  69. @Override
  70. protected String getSourceSeparator() {
  71. return "/";
  72. }
  73. /*
  74. * (non-Javadoc)
  75. *
  76. * @see
  77. * jenkins.plugins.shiningpanda.command.ShellCommand#getTargetSeparator()
  78. */
  79. @Override
  80. protected String getTargetSeparator() {
  81. return "\\";
  82. }
  83. /*
  84. * (non-Javadoc)
  85. *
  86. * @see
  87. * jenkins.plugins.shiningpanda.command.ShellCommand#getSourceVariable()
  88. */
  89. @Override
  90. protected Pattern getSourceVariable() {
  91. return VARIABLE;
  92. }
  93. /*
  94. * (non-Javadoc)
  95. *
  96. * @see
  97. * jenkins.plugins.shiningpanda.command.ShellCommand#getTargetVariable()
  98. */
  99. @Override
  100. protected String getTargetVariable() {
  101. return "%$1%";
  102. }
  103. /*
  104. * (non-Javadoc)
  105. *
  106. * @see
  107. * jenkins.plugins.shiningpanda.command.Command#getArguments(hudson.FilePath
  108. * )
  109. */
  110. @Override
  111. protected ArgumentListBuilder getArguments(FilePath script) {
  112. return new ArgumentListBuilder("cmd.exe", "/c", "call", script.getRemote());
  113. }
  114. }