/FlexUnit4AntTasks/src/org/flexunit/ant/launcher/FlexUnitLauncher.java

https://github.com/jhabegger/flexunit · Java · 94 lines · 71 code · 15 blank · 8 comment · 6 complexity · 5cfcdc3b2f6ce4a5762dd092e7e4c60d MD5 · raw file

  1. package org.flexunit.ant.launcher;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import org.apache.tools.ant.Project;
  5. import org.flexunit.ant.LoggingUtil;
  6. import org.flexunit.ant.launcher.commands.player.PlayerCommand;
  7. /**
  8. * This class is used to launch the FlexUnit tests.
  9. */
  10. public class FlexUnitLauncher
  11. {
  12. private static final String WINDOWS_OS = "Windows";
  13. private static final String MAC_OS_X = "Mac OS X";
  14. private boolean localTrusted;
  15. private boolean headless;
  16. private boolean snapshot;
  17. private String player;
  18. private String xcommand;
  19. private File snapshotFile;
  20. private Project project;
  21. private OperatingSystem os;
  22. public FlexUnitLauncher(Project project, boolean localTrusted, boolean headless, String player, String xcommand, boolean snapshot, File snapshotFile)
  23. {
  24. this.project = project;
  25. this.localTrusted = localTrusted;
  26. this.headless = headless;
  27. this.snapshot = snapshot;
  28. this.player = player;
  29. this.xcommand = xcommand;
  30. this.snapshotFile = snapshotFile;
  31. this.os = identifyOperatingSystem();
  32. }
  33. private OperatingSystem identifyOperatingSystem()
  34. {
  35. OperatingSystem os = null;
  36. String env = System.getProperty("os.name");
  37. if (env.startsWith(WINDOWS_OS))
  38. {
  39. LoggingUtil.log("OS: [Windows]");
  40. os = OperatingSystem.WINDOWS;
  41. }
  42. else if (env.startsWith(MAC_OS_X))
  43. {
  44. LoggingUtil.log("OS: [Mac OSX]");
  45. os = OperatingSystem.MACOSX;
  46. }
  47. else
  48. {
  49. LoggingUtil.log("OS: [Unix]");
  50. os = OperatingSystem.UNIX;
  51. }
  52. return os;
  53. }
  54. public void runTests(File swf) throws IOException
  55. {
  56. if(headless)
  57. {
  58. //creat headless process and run
  59. CommandFactory.createHeadlessStart(xcommand);
  60. }
  61. //setup command to run
  62. PlayerCommand command = CommandFactory.createPlayer(os, player, localTrusted);
  63. command.setProject(project);
  64. command.setSwf(swf);
  65. //run player command
  66. LoggingUtil.log("Launching player:\n" + command.describe());
  67. command.execute();
  68. if(snapshot)
  69. {
  70. //create snapshot command and run
  71. CommandFactory.createSnapshot(headless, xcommand);
  72. }
  73. if(headless)
  74. {
  75. //create stop headless process and run
  76. CommandFactory.createHeadlessStop(xcommand);
  77. }
  78. }
  79. }