예제 #1
0
 public static JUnitReportsFactory createFromBuildBinding(Binding buildBinding) {
   // This is not great, the phase and type names probably shouldn't be sourced from the binding.
   return new JUnitReportsFactory(
       (String) buildBinding.getProperty("currentTestPhaseName"),
       (String) buildBinding.getProperty("currentTestTypeName"),
       (File) buildBinding.getProperty("testReportsDir"),
       (List<String>) buildBinding.getProperty("reportFormats"));
 }
예제 #2
0
  /**
   * Attempts to call a Closure in the scripts binding with the given arguments.
   *
   * @param ignoreMissing If set to true, null will be returned if the Closure does not exist.
   *     Otherwise an UpsupportedOperationException will be thrown.
   * @param returnException If set to true, any Exception thrown by the invoked Closure will be
   *     returned as the result. Otherwise the exception will be logged and null will be returned.
   * @param name The name of the Closure to call.
   * @param args The arguments to pass to the Closure being called.
   * @return The result of the Closure, if successful.
   */
  @Nullable
  public Object invokeClosure(
      boolean ignoreMissing, boolean returnException, @Nonnull String name, Object... args) {
    Object property = null;
    try {
      property = binding.getProperty(name);
    } catch (MissingPropertyException e) {
    }

    try {
      if (property instanceof Closure) return ((Closure<?>) property).call(args);
    } catch (Exception e) {
      if (returnException) return e;

      log.error("Exception in closure " + name + " of " + scriptName + ":", e);
      return null;
    }

    if (!ignoreMissing)
      throw new UnsupportedOperationException("Groovy script is missing the Closure: " + name);

    return null;
  }