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

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

https://github.com/jenkinsci/shiningpanda-plugin
Java | 95 lines | 26 code | 8 blank | 61 comment | 0 complexity | 684955678dc5dddfde2b85a107cabb7b 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 hudson.FilePath;
  24. import hudson.util.ArgumentListBuilder;
  25. import jenkins.plugins.shiningpanda.utils.StringUtil;
  26. public class PythonCommand extends Command {
  27. /**
  28. * Is this on UNIX?
  29. */
  30. private boolean isUnix;
  31. /**
  32. * Store PYTHON executable
  33. */
  34. private String executable;
  35. /**
  36. * Constructor using fields.
  37. *
  38. * @param isUnix
  39. * Is this on UNIX?
  40. * @param executable
  41. * The PYTHON executable
  42. * @param command
  43. * The content of the execution script
  44. * @param ignoreExitCode
  45. * Is exit code ignored?
  46. */
  47. protected PythonCommand(boolean isUnix, String executable, String command, boolean ignoreExitCode) {
  48. // Call super
  49. super(command, ignoreExitCode);
  50. // Store UNIX flag
  51. this.isUnix = isUnix;
  52. // Store executable
  53. this.executable = executable;
  54. }
  55. /*
  56. * (non-Javadoc)
  57. *
  58. * @see jenkins.plugins.shiningpanda.command.Command#getExtension()
  59. */
  60. @Override
  61. protected String getExtension() {
  62. return ".py";
  63. }
  64. /*
  65. * (non-Javadoc)
  66. *
  67. * @see jenkins.plugins.shiningpanda.command.Command#getContents()
  68. */
  69. @Override
  70. protected String getContents() {
  71. return StringUtil.fixCrLf(getCommand());
  72. }
  73. /*
  74. * (non-Javadoc)
  75. *
  76. * @see
  77. * jenkins.plugins.shiningpanda.command.Command#getArguments(hudson.FilePath
  78. * )
  79. */
  80. @Override
  81. protected ArgumentListBuilder getArguments(FilePath script) {
  82. // Get the arguments
  83. ArgumentListBuilder args = new ArgumentListBuilder(executable, script.getRemote());
  84. // Check if on UNIX to return the right command
  85. return isUnix ? args : args.toWindowsCommand();
  86. }
  87. }