예제 #1
0
 /** Run the script. */
 private boolean run() {
   try {
     if (processSockets) {
       processSockets();
     } else if (processFiles) {
       processFiles();
     } else {
       processOnce();
     }
     return true;
   } catch (CompilationFailedException e) {
     System.err.println(e);
     return false;
   } catch (Throwable e) {
     if (e instanceof InvokerInvocationException) {
       InvokerInvocationException iie = (InvokerInvocationException) e;
       e = iie.getCause();
     }
     System.err.println("Caught: " + e);
     if (!debug) {
       StackTraceUtils.deepSanitize(e);
     }
     e.printStackTrace();
     return false;
   }
 }
예제 #2
0
 private static void logTraceIfNecessary() {
   if (isTraceLoggingEnabled()) {
     StackTraceElement[] stack = StackTraceUtils.sanitize(new Exception()).getStackTrace();
     for (StackTraceElement frame : stack) {
       if (!frame.getClassName().startsWith(DeprecationLogger.class.getName())) {
         LOGGER.warn("    {}", frame.toString());
       }
     }
   }
 }
예제 #3
0
 protected Map<Object, Object> loadMetadata() {
   final Properties meta = new Properties();
   Resource r = new ClassPathResource(PROJECT_META_FILE, getClassLoader());
   try {
     meta.load(r.getInputStream());
   } catch (IOException e) {
     StackTraceUtils.deepSanitize(e);
     log.warn("No application metadata file found at " + r);
   }
   if (System.getProperty(Environment.KEY) != null) {
     meta.setProperty(Environment.KEY, System.getProperty(Environment.KEY));
   }
   return Collections.unmodifiableMap(meta);
 }
예제 #4
0
  /**
   * This code was copied from BuildExceptionReporter.reportBuildFailure in gradle's source, then
   * modified slightly to compensate for the fact that we're not driven by options or logging things
   * to a logger object.
   */
  public static String getGradleExceptionMessage(
      Throwable failure, StartParameter.ShowStacktrace stackTraceLevel) {
    if (failure == null) {
      return "";
    }

    Formatter formatter = new Formatter();

    formatter.format("%nBuild failed.%n");

    if (stackTraceLevel == StartParameter.ShowStacktrace.INTERNAL_EXCEPTIONS) {
      formatter.format("Use the stack trace options to get more details.");
    }

    if (failure != null) {
      formatter.format("%n");

      if (failure instanceof LocationAwareException) {
        LocationAwareException scriptException = (LocationAwareException) failure;
        formatter.format("%s%n%n", scriptException.getLocation());
        formatter.format("%s", scriptException.getOriginalMessage());

        for (Throwable cause : scriptException.getReportableCauses()) {
          formatter.format("%nCause: %s", getMessage(cause));
        }
      } else {
        formatter.format("%s", getMessage(failure));
      }

      if (stackTraceLevel != StartParameter.ShowStacktrace.INTERNAL_EXCEPTIONS) {
        formatter.format("%n%nException is:\n");
        if (stackTraceLevel == StartParameter.ShowStacktrace.ALWAYS_FULL) {
          return formatter.toString() + getStackTraceAsText(failure);
        }

        return formatter.toString() + getStackTraceAsText(StackTraceUtils.deepSanitize(failure));
      }
    }

    return formatter.toString();
  }
  public void loadEventsScript(File eventScript) {
    if (eventScript == null) {
      return;
    }

    GrailsConsole console = GrailsConsole.getInstance();
    try {
      Class<?> scriptClass = classLoader.parseClass(eventScript);
      if (scriptClass == null) {
        console.error("Could not load event script (script may be empty): " + eventScript);
        return;
      }

      Script script = (Script) scriptClass.newInstance();
      script.setBinding(
          new Binding(binding.getVariables()) {
            @SuppressWarnings("rawtypes")
            @Override
            public void setVariable(String var, Object o) {
              final Matcher matcher = EVENT_NAME_PATTERN.matcher(var);
              if (matcher.matches() && (o instanceof Closure)) {
                String eventName = matcher.group(1);
                List<Closure> hooks = globalEventHooks.get(eventName);
                if (hooks == null) {
                  hooks = new ArrayList<Closure>();
                  globalEventHooks.put(eventName, hooks);
                }
                hooks.add((Closure<?>) o);
              }
              super.setVariable(var, o);
            }
          });
      script.run();
    } catch (Throwable e) {
      StackTraceUtils.deepSanitize(e);
      console.error(
          "Error loading event script from file [" + eventScript + "] " + e.getMessage(), e);
    }
  }