Example usage for java.lang Error printStackTrace

List of usage examples for java.lang Error printStackTrace

Introduction

In this page you can find the example usage for java.lang Error printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:com.exquance.jenkins.plugins.HarbormasterTrigger.java

/**
 * Called when a POST is made./*from  w ww  . j  av  a2  s.  com*/
 */
public void onPost(String triggeredByUser) {
    final String pushBy = triggeredByUser;
    getDescriptor().queue.execute(new Runnable() {
        private boolean runPolling() {
            try {
                StreamTaskListener listener = new StreamTaskListener(getLogFile());
                try {
                    PrintStream logger = listener.getLogger();
                    long start = System.currentTimeMillis();
                    logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date()));
                    boolean result = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job).poll(listener)
                            .hasChanges();
                    logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start));
                    if (result)
                        logger.println("Changes found");
                    else
                        logger.println("No changes");
                    return result;
                } catch (Error e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } catch (RuntimeException e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } finally {
                    listener.close();
                }
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
            }
            return false;
        }

        public void run() {
            if (runPolling()) {
                String name = " #" + job.getNextBuildNumber();
                HarbormasterPushCause cause;
                try {
                    cause = new HarbormasterPushCause(getLogFile(), pushBy);
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, "Failed to parse the polling log", e);
                    cause = new HarbormasterPushCause(pushBy);
                }
                ParameterizedJobMixIn pJob = new ParameterizedJobMixIn() {
                    @Override
                    protected Job asJob() {
                        return job;
                    }
                };
                if (pJob.scheduleBuild(cause)) {
                    LOGGER.info("SCM changes detected in " + job.getName() + ". Triggering " + name);
                } else {
                    LOGGER.info("SCM changes detected in " + job.getName() + ". Job is already in the queue");
                }
            }
        }

    });
}

From source file:org.jenkinsci.plugins.gitbucket.GitBucketPushTrigger.java

public void onPost(final GitBucketPushRequest req) {
    getDescriptor().queue.execute(new Runnable() {
        private boolean polling() {
            try {
                StreamTaskListener listener = new StreamTaskListener(getLogFile());

                try {
                    PrintStream logger = listener.getLogger();

                    long start = System.currentTimeMillis();
                    logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date()));
                    boolean result = job.poll(listener).hasChanges();
                    logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start));

                    if (result) {
                        logger.println("Changes found");
                    } else {
                        logger.println("No changes");
                    }//from   ww w. j ava2 s.  com

                    return result;
                } catch (Error e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } catch (RuntimeException e) {
                    e.printStackTrace(listener.error("Failed to record SCM polling"));
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                    throw e;
                } finally {
                    listener.closeQuietly();
                }
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
            }

            return false;
        }

        public void run() {
            LOGGER.log(Level.INFO, "{0} triggered.", job.getName());
            if (polling()) {
                String name = " #" + job.getNextBuildNumber();
                GitBucketPushCause cause = createGitBucketPushCause(req);
                Action[] actions = createActions(req);
                if (job.scheduleBuild(job.getQuietPeriod(), cause, actions)) {
                    LOGGER.log(Level.INFO, "SCM changes detected in {0}. Triggering {1}",
                            new String[] { job.getName(), name });
                } else {
                    LOGGER.log(Level.INFO, "SCM changes detected in {0}. Job is already in the queue.",
                            job.getName());
                }
            }
        }

        private GitBucketPushCause createGitBucketPushCause(GitBucketPushRequest req) {
            GitBucketPushCause cause;
            String triggeredByUser = req.getPusher().getName();
            try {
                cause = new GitBucketPushCause(triggeredByUser, getLogFile());
            } catch (IOException ex) {
                cause = new GitBucketPushCause(triggeredByUser);
            }
            return cause;
        }

        private Action[] createActions(GitBucketPushRequest req) {
            List<Action> actions = new ArrayList<Action>();

            if (passThroughGitCommit) {
                Commit lastCommit = req.getLastCommit();
                actions.add(new RevisionParameterAction(lastCommit.getId(), false));
            }

            return actions.toArray(new Action[0]);
        }
    });
}

From source file:net.sourceforge.dvb.projectx.common.Common.java

/**
 * messages/*from  w w  w  .  j  a  va 2s  . c o m*/
 *
 * @param1 - the msg
 */
public static void setErrorMessage(Error err) {
    StringWriter sw = new StringWriter();
    err.printStackTrace(new PrintWriter(sw));

    setErrorMessage(sw.toString());
}