Example usage for org.apache.commons.lang3.exception ExceptionUtils printRootCauseStackTrace

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils printRootCauseStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils printRootCauseStackTrace.

Prototype

public static void printRootCauseStackTrace(final Throwable throwable) 

Source Link

Document

Prints a compact stack trace for the root cause of a throwable to System.err.

The compact stack trace starts with the root cause and prints stack frames up to the place where it was caught and wrapped.

Usage

From source file:io.stallion.plugins.javascript.JsTestSuite.java

public void run() {
    results = new TestResults(getName()).setFile(getFile());
    tearDownSuite(this);
    for (Map.Entry<String, Function> entry : tests) {
        Log.info("Run test {0}", entry.getKey());
        setUp(this);

        try {//w w w.j  a v  a 2 s  .  c  o  m
            entry.getValue().apply(this);
            results.addResult(entry.getKey(), true, false, null);
        } catch (AssertionError e) {
            ExceptionUtils.printRootCauseStackTrace(e);
            results.addResult(entry.getKey(), false, false, e);
        } catch (Exception e) {
            ExceptionUtils.printRootCauseStackTrace(e);
            results.addResult(entry.getKey(), false, true, e);
        }
        tearDown(this);
    }
}

From source file:io.stallion.boot.MainRunner.java

/**
 * Runs the main Stallion service in auto-reload mode, which means that if a configuration file,
 * or a server-side javascript file, or a plugin file is touched, the entire application context
 * will reload and all server-side javascript will be re-processed. Use this when developing
 * to avoid having to manually restart every time you change a file.
 *
 *
 * @param args//w w w. j a v  a2 s.  com
 * @param plugins
 * @throws Exception
 */
public static void runWithAutoReload(String[] args, StallionJavaPlugin[] plugins) throws Exception {
    isDebugRunner = true;

    Console console = System.console();
    while (true) {
        Log.info("(re)start in debug reloading mode.");
        try {
            reboot(args, plugins);
            if (doReload) {
                doReload = false;
                continue;
            }
            System.out.println("Interrupted. Type q to quit, any other key to reboot.");
            String input = console.readLine();
            if (input.startsWith("q")) {
                break;
            }
        } catch (Exception e) {
            ExceptionUtils.printRootCauseStackTrace(e);
            System.out.println("Other exception. Type q to quit, any other key to reboot.");
            String input = console.readLine();
            if (input.startsWith("q")) {
                break;
            }
        }
    }
    Log.info("Shutting down javascript and conf file watcher.");
    if (watcher != null) {
        watcher.setShouldRun(false);
    }
    watcherThread.interrupt();
    watcherThread.join();
    System.out.println("Exiting.");
    System.exit(0);
}

From source file:io.stallion.tools.ScriptExecBase.java

public void executeJavascript(String source, URL url, String scriptPath, String folder, List<String> args,
        String plugin) throws Exception {
    ScriptEngine scriptEngine = null;
    if (plugin.equals("js") || plugin.equals("stallion")) {
        JsPluginEngine pluginEngine = PluginRegistry.instance().getEngine("main.js");
        if (pluginEngine != null) {
            scriptEngine = pluginEngine.getScriptEngine();
        }/*  w ww.  ja va  2 s .c om*/
    } else if (!empty(plugin)) {
        JsPluginEngine pluginEngine = PluginRegistry.instance().getEngine(plugin);
        if (pluginEngine != null) {
            scriptEngine = pluginEngine.getScriptEngine();
        }
    }
    if (scriptEngine == null) {
        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        scriptEngine = scriptEngineManager.getEngineByName("nashorn");
        scriptEngine.eval(IOUtils.toString(getClass().getResource("/jslib/jvm-npm.js"), UTF8));
        scriptEngine.eval(IOUtils.toString(getClass().getResource("/jslib/stallion_shared.js"), UTF8));
        String nodePath = folder + "/node_modules";
        scriptEngine.eval("require.NODE_PATH = \"" + nodePath + "\"");
        scriptEngine.put("myContext",
                new SandboxedContext(plugin, Sandbox.allPermissions(), new JsPluginSettings()));
    }
    if (true || newCommandOptions().isDevMode()) {
        Scanner in = new Scanner(System.in);
        while (true) {
            source = IOUtils.toString(url, UTF8);
            try {
                scriptEngine.eval("load("
                        + JSON.stringify(map(val("script", source), val("name", url.toString()))) + ");");
                //scriptEngine.eval(IOUtils.)
            } catch (Exception e) {
                ExceptionUtils.printRootCauseStackTrace(e);
            } finally {

            }
            System.out.println("Hit enter to re-run the script. Type quit and hit enter to stop.");
            String line = in.nextLine().trim();
            if (empty(line)) {
                continue;
            } else {
                break;
            }
        }
    } else {
        scriptEngine.eval(source);
    }

}

From source file:org.kie.workbench.common.services.datamodel.backend.server.ModuleDataModelConcurrencyTest.java

@Test
public void testConcurrentResourceUpdates() throws URISyntaxException {
    final URL pomUrl = this.getClass().getResource("/DataModelBackendTest1/pom.xml");
    final org.uberfire.java.nio.file.Path nioPomPath = ioService.get(pomUrl.toURI());
    final Path pomPath = paths.convert(nioPomPath);

    final URL resourceUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/resources/empty.rdrl");
    final org.uberfire.java.nio.file.Path nioResourcePath = ioService.get(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);

    //Force full build before attempting incremental changes
    final KieModule module = moduleService.resolveModule(resourcePath);
    final BuildResults buildResults = buildService.build(module);
    assertNotNull(buildResults);//  w  w  w  . j  ava 2s  . c  o  m
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());

    //Perform incremental build
    final int THREADS = 200;
    final Result result = new Result();
    ExecutorService es = Executors.newCachedThreadPool();
    for (int i = 0; i < THREADS; i++) {
        final int operation = (i % 3);

        switch (operation) {
        case 0:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request to update POM received");
                        invalidateCaches(module, pomPath);
                        buildChangeListener.updateResource(pomPath);
                        logger.debug("[Thread: " + Thread.currentThread().getName() + "] POM update completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });
            break;
        case 1:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request to update Resource received");
                        invalidateCaches(module, resourcePath);
                        buildChangeListener.addResource(resourcePath);
                        logger.debug(
                                "[Thread: " + Thread.currentThread().getName() + "] Resource update completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });
            break;
        case 2:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request for DataModel received");
                        dataModelService.getDataModel(resourcePath);
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] DataModel request completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });
        }
    }

    es.shutdown();
    try {
        es.awaitTermination(5, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
    }
    if (result.isFailed()) {
        fail(result.getMessage());
    }
}

From source file:org.kie.workbench.common.services.datamodel.backend.server.ProjectDataModelConcurrencyTest.java

@Test
public void testConcurrentResourceUpdates() throws URISyntaxException {
    final URL pomUrl = this.getClass().getResource("/DataModelBackendTest1/pom.xml");
    final org.uberfire.java.nio.file.Path nioPomPath = ioService.get(pomUrl.toURI());
    final Path pomPath = paths.convert(nioPomPath);

    final URL resourceUrl = this.getClass().getResource("/DataModelBackendTest1/src/main/resources/empty.rdrl");
    final org.uberfire.java.nio.file.Path nioResourcePath = ioService.get(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);

    //Force full build before attempting incremental changes
    final KieProject project = projectService.resolveProject(resourcePath);
    final BuildResults buildResults = buildService.build(project);
    assertNotNull(buildResults);/* www  . j  a  v  a2  s . com*/
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());

    //Perform incremental build
    final int THREADS = 200;
    final Result result = new Result();
    ExecutorService es = Executors.newCachedThreadPool();
    for (int i = 0; i < THREADS; i++) {
        final int operation = (i % 3);

        switch (operation) {
        case 0:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request to update POM received");
                        invalidateCaches(project, pomPath);
                        buildChangeListener.updateResource(pomPath);
                        logger.debug("[Thread: " + Thread.currentThread().getName() + "] POM update completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });
            break;
        case 1:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request to update Resource received");
                        invalidateCaches(project, resourcePath);
                        buildChangeListener.addResource(resourcePath);
                        logger.debug(
                                "[Thread: " + Thread.currentThread().getName() + "] Resource update completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });
            break;
        case 2:
            es.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] Request for DataModel received");
                        dataModelService.getDataModel(resourcePath);
                        logger.debug("[Thread: " + Thread.currentThread().getName()
                                + "] DataModel request completed");
                    } catch (Throwable e) {
                        result.setFailed(true);
                        result.setMessage(e.getMessage());
                        ExceptionUtils.printRootCauseStackTrace(e);
                    }
                }
            });

        }
    }

    es.shutdown();
    try {
        es.awaitTermination(5, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
    }
    if (result.isFailed()) {
        fail(result.getMessage());
    }

}

From source file:ubic.gemma.core.apps.DifferentialExpressionAnalysisCli.java

private void processExperiment(ExpressionExperiment ee) {
    Collection<DifferentialExpressionAnalysis> results;
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();

    try {// w w  w.j a  v  a 2s  .c o m

        ee = this.eeService.thawLite(ee);

        if (delete) {
            AbstractCLI.log.info("Deleting any analyses for experiment=" + ee);
            differentialExpressionAnalyzerService.deleteAnalyses(ee);
            successObjects.add("Deleted analysis for: " + ee.toString());
            return;
        }

        Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign()
                .getExperimentalFactors();
        if (experimentalFactors.size() == 0) {
            if (this.expressionExperiments.size() == 1) {
                /*
                 * Only need to be noisy if this is the only ee. Batch processing should be less so.
                 */
                throw new RuntimeException(
                        "Experiment does not have an experimental design populated: " + ee.getShortName());
            }
            AbstractCLI.log
                    .warn("Experiment does not have an experimental design populated: " + ee.getShortName());
            return;
        }

        Collection<ExperimentalFactor> factors = this.guessFactors(ee);

        if (factors.size() > 0) {
            /*
             * Manual selection of factors
             */
            ExperimentalFactor subsetFactor = this.getSubsetFactor(ee);

            AbstractCLI.log.info("Using " + factors.size() + " factors provided as arguments");

            if (subsetFactor != null) {
                if (factors.contains(subsetFactor)) {
                    throw new IllegalArgumentException(
                            "Subset factor cannot also be included as factor to analyze");
                }
                AbstractCLI.log.info("Subsetting by " + subsetFactor);

            }

            config.setAnalysisType(this.type);
            config.setFactorsToInclude(factors);
            config.setSubsetFactor(subsetFactor);
            config.setModerateStatistics(this.ebayes);
            config.setPersist(this.persist);
            boolean rnaSeq = super.eeService.isRNASeq(ee);
            config.setUseWeights(rnaSeq);
            /*
             * Interactions included by default. It's actually only complicated if there is a subset factor.
             */
            if (type == null && factors.size() == 2) {
                config.getInteractionsToInclude().add(factors);
            }

            results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);

        } else {
            /*
             * Automatically
             */

            if (tryToCopyOld) {
                this.tryToRedoBasedOnOldAnalysis(ee);
            }

            Collection<ExperimentalFactor> factorsToUse = new HashSet<>();

            if (this.ignoreBatch) {
                for (ExperimentalFactor ef : experimentalFactors) {
                    if (!ExperimentalDesignUtils.isBatch(ef)) {
                        factorsToUse.add(ef);
                    }
                }
            } else {
                factorsToUse.addAll(experimentalFactors);
            }

            if (factorsToUse.isEmpty()) {
                throw new RuntimeException("No factors available for " + ee.getShortName());
            }

            if (factorsToUse.size() > 3) {

                if (!tryToCopyOld) {
                    throw new RuntimeException("Experiment has too many factors to run automatically: "
                            + ee.getShortName()
                            + "; try using the -redo flag to base it on an old analysis, or select factors manually");
                }
                results = this.tryToRedoBasedOnOldAnalysis(ee);

            } else {

                config.setFactorsToInclude(factorsToUse);
                config.setPersist(this.persist);
                config.setModerateStatistics(this.ebayes);

                if (factorsToUse.size() == 2) {
                    // include interactions by default
                    config.addInteractionToInclude(factorsToUse);
                }

                boolean rnaSeq = super.eeService.isRNASeq(ee);
                config.setUseWeights(rnaSeq);

                results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee,
                        config);
            }

        }

        if (results == null) {
            throw new Exception(
                    "Failed to process differential expression for experiment " + ee.getShortName());
        }

        if (!this.persist) {
            AbstractCLI.log.info("Writing results to disk");
            for (DifferentialExpressionAnalysis r : results) {
                expressionDataFileService.writeDiffExArchiveFile(ee, r, config);
            }
        }

        successObjects.add(ee.toString());

    } catch (Exception e) {
        AbstractCLI.log.error("Error while processing " + ee + ": " + e.getMessage());
        ExceptionUtils.printRootCauseStackTrace(e);
        errorObjects.add(ee + ": " + e.getMessage());
    }

}