Пример #1
0
 private void executeSingleScenario(final File scenarioFile, final Project p) {
   getLog()
       .info(
           "Executing scenario "
               + scenarioFile.getName()
               + " with sut "
               + p.getProperty("sutFile"));
   try {
     p.fireBuildStarted();
     p.init();
     ProjectHelper helper = ProjectHelper.getProjectHelper();
     p.addReference("ant.projectHelper", helper);
     helper.parse(p, scenarioFile);
     p.executeTarget(p.getDefaultTarget());
   } catch (Exception e) {
     getLog().error("Failed to execute scenario " + scenarioFile.getName());
     getLog().error(e);
   } finally {
     p.fireBuildFinished(null);
   }
   getLog()
       .info(
           "Execution of scenario "
               + scenarioFile.getName()
               + " with sut "
               + p.getProperty("sutFile")
               + " has ended");
   getLog().info("------------------------------------------------------------------------");
 }
  public boolean perform(Build build, Launcher launcher, BuildListener listener) {
    // this is where you 'build' the project
    // since this is a dummy, we just say 'hello world' and call that a build

    // this also shows how you can consult the global configuration of the builder
    if (DESCRIPTOR.useFrench()) listener.getLogger().println("Bonjour, " + name + "!");
    else listener.getLogger().println("Hello, " + name + "!");

    listener.getLogger().println("START");

    Project project = new HelloAntProject();
    project.init();

    BuildLogger logger = new DefaultLogger();
    logger.setMessageOutputLevel(Project.MSG_INFO);
    logger.setOutputPrintStream(new java.io.PrintStream(System.out));
    logger.setErrorPrintStream(new java.io.PrintStream(System.err));
    logger.setEmacsMode(false);
    //		project.addBuildListener((org.apache.tools.ant.BuildListener) listener);
    project.addBuildListener(logger);

    java.util.Vector list = new java.util.Vector();

    /*
     * ターゲットを指定 list.add("compile"); のようにすれば任意のターゲットを指定できます。
     */
    list.add(project.getDefaultTarget());
    // project.executeTargets(new java.util.Vector(list));

    listener.getLogger().println("DONE");
    return true;
  }
Пример #3
0
  /**
   * Runs the given Target.
   *
   * @param _target The name of the target to run. If null, the project's default \ target will be
   *     used.
   * @throws Exception Exceptions are self-explanatory (read their Message)
   */
  public void runTarget(String _target, boolean newThread) throws Exception {
    // Test if the project exists
    if (project == null)
      throw new Exception(
          "No target can be launched because the project has not been initialized. Please call the 'init' method first !");
    // If no target is specified, run the default one.
    if (_target == null) _target = project.getDefaultTarget();
    // Run the target
    final String targetToRun = _target;
    project.addBuildListener(
        new BuildListener() {

          public void buildFinished(BuildEvent arg0) {}

          public void buildStarted(BuildEvent arg0) {}

          public void messageLogged(BuildEvent arg0) {}

          public void targetFinished(BuildEvent arg0) {}

          public void targetStarted(BuildEvent arg0) {}

          public void taskFinished(BuildEvent arg0) {}

          public void taskStarted(BuildEvent arg0) {}
        });
    if (newThread == true)
      try {
        Thread t =
            new Thread(
                new Runnable() {
                  public void run() {
                    project.executeTarget(targetToRun);
                  }
                });
        t.start();
      } catch (BuildException e) {
        throw new Exception(e.getMessage());
      }
    else project.executeTarget(targetToRun);
  }
Пример #4
0
  /** Runs the given targets for the test project specified */
  public Map run(
      File buildFile, List targets, Properties projectProperties, Properties pluginState) {
    Project project = new Project();
    project.setCoreLoader(getClass().getClassLoader());
    antListener = new AntRunner.AntListener();

    project.addBuildListener(
        createLogger(projectProperties.getProperty("quokka.debugger.logLevel")));
    project.addBuildListener(antListener);

    //        project.setInputHandler(new DefaultInputHandler());
    project.setInputHandler(
        new InputHandler() {
          public void handleInput(InputRequest request) throws BuildException {
            System.out.println(request.getPrompt());

            try {
              String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
              request.setInput(line);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
    project.setKeepGoingMode(false);

    //        PrintStream err = System.err;
    //        PrintStream out = System.out;
    //        InputStream in = System.in;
    project.setDefaultInputStream(System.in);

    //        System.setIn(new DemuxInputStream(project));
    //        System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
    //        System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
    for (Iterator i = projectProperties.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      project.setUserProperty((String) entry.getKey(), (String) entry.getValue());
    }

    Exception exception = null;

    try {
      project.fireBuildStarted();

      project.init();
      project.setUserProperty("ant.version", "1.7.0");
      project.setUserProperty("ant.file", buildFile.getAbsolutePath());

      // Remove hard dependency on core.main to allow integration tests to be
      // done within the core.main package. This is ok as AntRunner is loaded via the integration
      // test class loader.
      org.apache.tools.ant.ProjectHelper helper =
          (org.apache.tools.ant.ProjectHelper)
              getClass()
                  .getClassLoader()
                  .loadClass("ws.quokka.core.main.ant.ProjectHelper")
                  .newInstance();
      project.addReference("ant.projectHelper", helper);
      helper.parse(project, buildFile);

      // Add any plugin state
      PluginState state = (PluginState) project.getReference("quokka.pluginState");

      for (Iterator i = pluginState.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        state.put((String) entry.getKey(), entry.getValue());
      }

      Vector targetsVector = new Vector();
      targetsVector.addAll(targets);

      // make sure that we have a target to execute
      if (targets.size() == 0) {
        if (project.getDefaultTarget() != null) {
          targetsVector.add(project.getDefaultTarget());
        }
      }

      project.executeTargets(targetsVector);

      Map results = antListener.toMap();
      results.put("antProperties", new HashMap(project.getProperties()));

      return results;
    } catch (Exception e) {
      exception = e;

      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new BuildException(e);
      }
    } finally {
      //            System.setOut(out);
      //            System.setErr(err);
      //            System.setIn(in);
      project.fireBuildFinished(exception);
    }
  }