Skip to content

Commit 67255e1

Browse files
committed
Add initial project structure with dependency mapping tool
- Created .gitignore to exclude build and dependency files. - Added jest.config.js for Jest testing configuration. - Implemented package-dependencies.ts for extracting and analyzing Java package dependencies from JSONL files. - Initialized package.json and package-lock.json for project dependencies. - Created README.md with usage instructions and project overview. - Added sample-dependencies.jsonl for testing purposes. - Set up CI/CD pipeline in .github/workflows/main.yml for automated testing and deployment. - Included tests for package dependency extraction in tests/package-dependencies.test.ts. - Generated initial Markdown output for package dependencies in test-output.md. - Configured TypeScript settings in tsconfig.json.
0 parents  commit 67255e1

File tree

11 files changed

+5460
-0
lines changed

11 files changed

+5460
-0
lines changed

.github/workflows/main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build-and-test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [16.x, 18.x]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: "npm"
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run tests
31+
run: npm test
32+
33+
- name: Run test with coverage
34+
run: npm run test:coverage
35+
36+
- name: Build project
37+
run: npm run build
38+
39+
- name: Run sample analysis
40+
run: node dist/package-dependencies.js samples/sample-dependencies.jsonl -o sample-analysis.md
41+
if: success()
42+
43+
- name: Upload test coverage
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: coverage-report
47+
path: coverage/
48+
if: success()
49+
50+
- name: Upload sample analysis
51+
uses: actions/upload-artifact@v3
52+
with:
53+
name: sample-analysis
54+
path: sample-analysis.md
55+
if: success()

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
samples/
2+
3+
# Dependency directories
4+
node_modules/
5+
dist/
6+
7+
# TypeScript build output
8+
*.tsbuildinfo
9+
build/
10+
lib/
11+
12+
# IDE and editor files
13+
.vscode/
14+
.idea/
15+
*.swp
16+
*.swo
17+
.DS_Store
18+
19+
# Test coverage output
20+
coverage/
21+
22+
# Environment variables
23+
.env
24+
.env.local
25+
.env.*.local
26+
27+
# Debug logs
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Optional eslint cache
36+
.eslintcache
37+
38+
# Optional REPL history
39+
.node_repl_history

README.md

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Java Dependency Mapper
2+
3+
A tool for analyzing Java dependencies from extracted EAR files.
4+
5+
## Overview
6+
7+
This tool parses JSONL files containing dependency information extracted from Java EAR/JAR/WAR files. It helps visualize and analyze dependencies between classes and artifacts.
8+
9+
The input JSONL files are typically generated from Jarviz-lib static analysis of Java applications. Jarviz-lib analyzes the bytecode of Java applications and extracts method-level dependencies between classes.
10+
11+
## Features
12+
13+
- Parse JSONL files with Java dependency information
14+
- Build a dependency graph of classes and artifacts
15+
- Find cycles in the dependency graph
16+
- Generate statistics about dependencies
17+
- View the most depended-upon classes
18+
- Extract and analyze package dependencies
19+
20+
## Installation
21+
22+
1. Make sure you have Node.js installed (v14+ recommended)
23+
2. Clone this repository
24+
3. Install dependencies:
25+
26+
```bash
27+
npm install
28+
```
29+
30+
## Usage
31+
32+
### Dependency Mapper
33+
34+
Run the tool with a path to your JSONL file:
35+
36+
```bash
37+
npm start -- path/to/your/dependencies.jsonl
38+
```
39+
40+
### Package Dependencies Extractor
41+
42+
The package dependencies extractor tool generates a Markdown report of all base packages that a project depends on:
43+
44+
```bash
45+
npx ts-node package-dependencies.ts <jsonl-file-path> [--output <output-file-path>]
46+
```
47+
48+
Where:
49+
- `<jsonl-file-path>` is the path to the JSONL file containing dependency data (required)
50+
- `--output` or `-o` followed by path where the Markdown output will be written (optional, defaults to `package-dependencies.md`)
51+
52+
Example usage:
53+
```bash
54+
# Basic usage with default output file
55+
npx ts-node package-dependencies.ts sample-dependencies.jsonl
56+
57+
# Specify custom output file
58+
npx ts-node package-dependencies.ts sample-dependencies.jsonl --output reports/packages.md
59+
60+
# Using shorthand parameter
61+
npx ts-node package-dependencies.ts sample-dependencies.jsonl -o custom-output.md
62+
```
63+
64+
## Development
65+
66+
### Running Tests
67+
68+
The project includes unit tests for the package dependencies extractor. To run the tests:
69+
70+
```bash
71+
npm test
72+
```
73+
74+
This will execute all Jest tests in the `tests` directory.
75+
76+
To run tests with coverage reports:
77+
78+
```bash
79+
npm run test:coverage
80+
```
81+
82+
This will generate a detailed coverage report showing which parts of the code are covered by tests.
83+
84+
### Input Data
85+
86+
This tool is designed to work with JSONL output from Jarviz-lib analysis. Jarviz-lib is a static analysis tool that extracts method-level dependencies from Java bytecode. To generate the input data:
87+
88+
1. Extract your EAR/WAR/JAR files
89+
2. Run Jarviz-lib analysis on the extracted files
90+
3. Use the resulting JSONL file as input to this tool
91+
92+
### Expected JSONL Format
93+
94+
Each line in the JSONL file should be a JSON object with the following structure:
95+
96+
```json
97+
{
98+
"appSetName": "AppName",
99+
"applicationName": "AppName",
100+
"artifactFileName": "example.jar",
101+
"artifactId": "exampleModule",
102+
"artifactGroup": "com.example",
103+
"artifactVersion": "1.0.0",
104+
"sourceClass": "com.example.SourceClass",
105+
"sourceMethod": "methodName",
106+
"targetClass": "com.example.TargetClass",
107+
"targetMethod": "targetMethod"
108+
}
109+
```
110+
111+
## Dependency Mapper Output
112+
113+
The dependency mapper will output:
114+
- General statistics about dependencies
115+
- Artifact dependency relationships
116+
- Cycles in the dependency graph (if any)
117+
- Top 10 most depended upon classes
118+
119+
### Example Output
120+
121+
```
122+
Parsing dependencies from sample-dependencies.jsonl...
123+
124+
Dependency Statistics:
125+
Total components: 4
126+
Total artifacts: 1
127+
Total dependencies: 3
128+
129+
Top 10 most depended upon classes:
130+
1. com.example.sample.component.servicelocator.ServiceLocatorException: 1 dependents
131+
2. java.lang.Object: 1 dependents
132+
3. java.lang.Boolean: 1 dependents
133+
4. com.example.sample.component.servicelocator.ejb.ServiceLocator: 0 dependents
134+
135+
Artifact Dependencies:
136+
No inter-artifact dependencies found.
137+
138+
Cycles in Dependencies:
139+
No cycles found.
140+
```
141+
142+
## Package Dependencies Extractor Output
143+
144+
The package dependencies extractor generates a Markdown file with the following sections:
145+
146+
1. **Base Packages**: A list of all base packages used by the project, grouped by:
147+
- External Dependencies (e.g., `java.lang`, `javax.servlet`)
148+
- Internal Packages (e.g., `com.example`)
149+
150+
2. **Dependency Relationships**: Shows which base packages depend on other base packages
151+
152+
3. **Package Details**: Detailed information about each base package, including:
153+
- Type (Internal or External)
154+
- Number of sub-packages
155+
- Number of classes
156+
- Dependencies on other base packages
157+
- List of all sub-packages
158+
159+
### How It Works
160+
161+
1. The tool reads the JSONL file line by line
162+
2. For each record, it extracts the source and target class names and their packages
163+
3. It categorizes packages as internal or external based on their artifact group
164+
4. Base packages are determined by:
165+
- For standard packages (java, javax, org, com, net), the first two segments are used (e.g., `java.lang`)
166+
- For other packages, the first three segments are used (or fewer if there aren't three)
167+
5. Dependencies between packages are tracked and rolled up to the base package level
168+
169+
### Example
170+
171+
For a sample input like:
172+
173+
```json
174+
{"sourceClass":"com.example.sample.component.servicelocator.ejb.ServiceLocator","targetClass":"java.lang.Object"}
175+
```
176+
177+
The tool will extract:
178+
- Base packages: `com.example` and `java.lang`
179+
- Dependencies: `com.example` depends on `java.lang`
180+
181+
## Using as a Library
182+
183+
You can also use the various analyzer classes in your own code:
184+
185+
```typescript
186+
import { DependencyAnalyzer } from './dependency-mapper';
187+
188+
async function analyze() {
189+
const analyzer = new DependencyAnalyzer();
190+
await analyzer.parseJsonlFile('path/to/dependencies.jsonl');
191+
192+
// Get artifact dependency summary
193+
const artifactDeps = analyzer.getArtifactDependencySummary();
194+
195+
// Find cycles
196+
const cycles = analyzer.findCycles();
197+
198+
// Get more data as needed
199+
}
200+
201+
analyze().catch(console.error);
202+
```

jest.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
moduleFileExtensions: ["ts", "js", "json"],
5+
transform: {
6+
"^.+\\.ts$": [
7+
"ts-jest",
8+
{
9+
tsconfig: "tsconfig.json",
10+
},
11+
],
12+
},
13+
testMatch: ["**/tests/**/*.test.ts"],
14+
collectCoverage: true,
15+
coverageDirectory: "coverage",
16+
collectCoverageFrom: [
17+
"**/*.ts",
18+
"!**/*.d.ts",
19+
"!**/node_modules/**",
20+
"!jest.config.js",
21+
],
22+
};

0 commit comments

Comments
 (0)