PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Extensions/org/objectweb/proactive/extensions/gcmdeployment/Helpers.java

https://bitbucket.org/lp/programming-multiactivities
Java | 94 lines | 37 code | 10 blank | 47 comment | 2 complexity | 1d9aeeb62b11439b9c85f81be7d6a2b6 MD5 | raw file
  1. /*
  2. * ################################################################
  3. *
  4. * ProActive Parallel Suite(TM): The Java(TM) library for
  5. * Parallel, Distributed, Multi-Core Computing for
  6. * Enterprise Grids & Clouds
  7. *
  8. * Copyright (C) 1997-2012 INRIA/University of
  9. * Nice-Sophia Antipolis/ActiveEon
  10. * Contact: proactive@ow2.org or contact@activeeon.com
  11. *
  12. * This library is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU Affero General Public License
  14. * as published by the Free Software Foundation; version 3 of
  15. * the License.
  16. *
  17. * This library is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this library; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  25. * USA
  26. *
  27. * If needed, contact us to obtain a release under GPL Version 2 or 3
  28. * or a different license than the AGPL.
  29. *
  30. * Initial developer(s): The ProActive Team
  31. * http://proactive.inria.fr/team_members.htm
  32. * Contributor(s):
  33. *
  34. * ################################################################
  35. * $$PROACTIVE_INITIAL_DEV$$
  36. */
  37. package org.objectweb.proactive.extensions.gcmdeployment;
  38. import java.io.File;
  39. import java.io.IOException;
  40. import java.net.MalformedURLException;
  41. import java.net.URL;
  42. import java.net.URLConnection;
  43. public class Helpers {
  44. /**
  45. * Checks that descriptor exist, is a file and is readable
  46. *
  47. * @param descriptor
  48. * The File to be checked
  49. * @throws IllegalArgumentException
  50. * If the File is does not exist, is not a file or is not readable
  51. */
  52. public static URLConnection openConnectionTo(URL descriptor) throws IllegalArgumentException {
  53. URLConnection conn;
  54. try {
  55. conn = descriptor.openConnection();
  56. } catch (IOException e) {
  57. throw new IllegalArgumentException("Connection to " + descriptor.toExternalForm() +
  58. " could not be established.", e);
  59. }
  60. return conn;
  61. }
  62. public static URL fileToURL(File file) {
  63. if (file == null)
  64. return null;
  65. URL answer = null;
  66. try {
  67. answer = file.toURI().toURL();
  68. } catch (MalformedURLException e) {
  69. e.printStackTrace();
  70. }
  71. return answer;
  72. }
  73. static public String escapeCommand(String command) {
  74. // At each step, the command must be protected with " or ' and the command
  75. // passed as parameter must be escaped. This can be quite difficult since
  76. // Runtime.getRuntime().exec() only take an array of String as parameter...
  77. String res = command.replaceAll("'", "'\\\\''");
  78. return "'" + res + "'";
  79. }
  80. static public String escapeWindowsCommand(String command) {
  81. String res = command.replaceAll("\"", "\\\"");
  82. return res;
  83. }
  84. }