npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

java-stack-parser

v1.0.0

Published

Parse Java stack traces and transform them into comprehensive JS objects

Downloads

43

Readme

java-stack-parser

Parse Java stack traces and transform them into comprehensive JS objects

Install

You can install this package either with npm, yarn or bower.

npm / yarn

For npm:

~$ npm install java-stack-parser

For yarn:

~$ yarn add java-stack-parser

Then, you can require('java-stack-parser') or include the library in your web page directly via a <script> tag

<script src="/node_modules/java-stack-parser/lib/java-stack-parser.min.js"></script>

bower

~$ bower install java-stack-parser

Then, you can include the library in your web page directly via a <script> tag

<script src="/bower_components/java-stack-parser/lib/java-stack-parser.min.js"></script>

Documentation

The library defines 3 objects:

  • Stack: represents the full stacktrace. It is compose of a list of StackGroups.
  • StackGroup represents a group of consecutive StackLines with the same StackPackage.
  • StackLine represents a line of the full stacktrace, e.g. at java.net.SocketInputStream.read(SocketInputStream.java:185).
  • StackPackage represents the package of the current StackLine. Taking the StackLine above, the resulting StackPackage will be java.net.

Stack Object

This object is used to parse and transform a string representing a Java stack trace. Here is an example of how to use it. Alternatively, you can check out the working demo

let stacktrace = '...';
let stack = new Stack();

stack.parse(stacktrace);

// Display stack trace information into the console
stack.groups.forEach((group)=> {
    console.log('Package: ' + group.stackPackage.name + ' contains ' + group.lines.length + ' lines');
    group.lines.forEach((line)=> {
        console.log(line.javaClass + '.' java.method + ' (Source: ' + line.source + ' at line: ' line.line + ')');
    });
});

The Stack object gives you the ability of defining your own "vendor" packages, resulting of a better grouping. For example, if your application uses 2 libraries with a groupId of com.acme and my.library, you can pass this as an optional parameter to the constructor:

let stacktrace = '...';
let stack = new Stack({
    'My libraries': ['com.acme', 'my.library'],
    "Java/Sun/Oracle": ["java", "javax", "sun", "sunw", "com.sun", "com.oracle"],
    "Apache": ["org.apache"],
});

stack.parse(stacktrace);

// Display stack trace information into the console
stack.groups.forEach((group)=> {
    console.log('Package: ' + group.stackPackage.name + ' contains ' + group.lines.length + ' lines');
    group.lines.forEach((line)=> {
        console.log(line.javaClass + '.' java.method + ' (Source: ' + line.source + ' at line: ' line.line + ')');
    });
});

Now, if the stack trace contains consecutive lin with the package com.acme or my.library, they will be group under the same StackGroup.

Development

To build the library in development mode (non-uglified, with a watch on the source) simply do:

~$ npm run dev

For the production version:

~$ npm run build

You can run tests and check the coverage with the following 2 commands:

# Run tests
~$ npm test
# Check covergae
~$ npm run coverage

License

This library is released under Apache 2.0 license