GithubHelp home page GithubHelp logo

smarkwal / jarhc Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 51.23 MB

JarHC - JAR Health Check

License: Apache License 2.0

Java 98.76% CSS 0.12% Batchfile 0.01% Shell 1.11% HTML 0.02%
java classpath jar static-analysis binary-compatibility

jarhc's Introduction

JarHC - JAR Health Check

JarHC is a static analysis tool to help you find your way through "JAR hell" or "classpath hell".

Its main purpose is to analyze a set of JAR files (*.jar) and check whether they are compatible on a binary level, and whether they contain any "unpleasant surprises" for you.

It is available as Gradle plugin, or as standalone Java application run from the command line:

java -jar jarhc-with-deps.jar [options] <artifact> [<artifact>]*

More information can be found in the wiki.

JarHC Logo


License Release Downloads

Build Tests Coverage Quality

Issues

jarhc's People

Contributors

dependabot[bot] avatar smarkwal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jarhc's Issues

New analyzer: "Missing Dependencies" or "Missing Classes"

List missing classes, grouped by package.
Mark annotation classes (low issue).
Show number of usages.
List JAR files using the missing class.
Two states: "class missing" vs. "package missing".

Auto-suggest missing dependencies based on missing classes or packages.
Prerequisite: Some service to find a dependency (Maven artifact) given a class name or package name.

Reports: Implement consistent sorting of JAR files

Implement consistent sorting of JAR files in report sections (some are case-sensitive, some case-insensitive).

Update

Idea: Add a command line option to control the order: --sort-jars classpath, --sort-jars name, etc.

Build: Integrate SonarQube scan in build workflow

Open questions:

  • Does every build trigger a SonarQube scan?
  • Or does a scan have to be triggered manually?
  • Or is a scan triggered once every week or month? (only if there have been changes)

Update 1

Currently, a SonarQube scan can be started by passing additional Gradle options when starting the Build workflow manually:

Additional Gradle options: sonarqube

To be reviewed:
The SonarQube task seems to download plugins from the SonarQube server. It seems as if they are stored in a 'user cache'. A line from the task output:

User cache: /home/runner/.sonar/cache

If this observation is true, we should check whether this directory can be cached between workflow runs.

Update 2

The path to the above user cache directory can be set with the environment variable SONAR_USER_HOME. Example run:

export SONAR_USER_HOME=/tmp
 ./gradlew sonarqube --info
...
User cache: /tmp/cache

Build: Run tests on different Java versions

Get the build artifacts.

Prepare a matrix build on different Java versions and operating systems:

  • Java 8, 11, 17
  • Linux, Windows, MacOS

Run all JUnit tests using build artifacts:

  • jarhc-<version>.jar
  • jarhc-<version>-tests.jar
  • jarhc-<version>-test-libs.zip

Build: Add integration test results to SonarQube scan results

SonarQube only shows unit tests (271), but the Gradle build also runs ~ 90 integration tests. The results from these integration tests do not seem to be uploaded to SonarCloud.

Links:

  • Tests reported to SonarQube: https://sonarcloud.io/component_measures?id=smarkwal_jarhc&metric=tests&view=list
  • SonarQube configuration in Gradle build script:

    jarhc/build.gradle.kts

    Lines 148 to 158 in b998ce5

    // connection to SonarCloud
    property("sonar.host.url", "https://sonarcloud.io")
    property("sonar.organization", "smarkwal")
    property("sonar.projectKey", "smarkwal_jarhc")
    // Git branch
    property("sonar.branch.name", getGitBranchName())
    // include test coverage results
    property("sonar.java.coveragePlugin", "jacoco")
    property("sonar.coverage.jacoco.xmlReportPaths", "${jacocoTestReportXml},${jacocoIntegrationTestReportXml}")

Idea: Create plugins

Create various plugins: Maven, Gradle, Ant, IntelliJ, Eclipse, TeamCity, SonarQube, ...

Build: Create workflow to run Dependency-Check analysis

Gradle command:
./gradlew dependencyCheckAnalyze

Requirements:

  • Triggers:
    • on change of Gradle build files.
    • on schedule every month.
  • Cache Dependency-Check database directory.
  • Publish reports.
    • dependency-check-report.html
    • dependency-check-report.sarif

Build: Run JarHC on JarHC as post-build validation

After building JarHC, run it "on itself" to check if the build artifacts are valid.

  • Run --help and --version.
  • Run with JAR on classpath and all third-party dependencies as provided.
  • Run with fat/uber JAR on classpath.
  • more ideas?

Validation:

  • Check exit code.
  • Compare new report with previous report. Accept a certain number of differences, e.g. percentage of changed lines.
  • Extract relevant information about JarHC JAR like class file versions (must be Java 8).
  • more ideas?

Binary Compatibility: Check annotation references

Check annotation references (does the annotation exist, are all mandatory parameters present, is the target class accessible, etc.)

Update

Add a field target to AnnotationRef, holding an instance of java.lang.annotation.ElementType to remember the type of element the annotation is attached to. Check whether this is a valid target.

Update 2

Keep information about name/value pairs of annotations.
Example: @SomeAnnotation(a = 1, b = true, c = "Hello", d = List.class, e = {1.0, 2.0, 3.5})
This requires a much more complex model in AnnotationRef.

Once this is supported, @Target annotations with an ElementType[] and ElementType enum values can be parsed. This is required to later check if an annotation is valid to be attached to a target element.

Example: The annotation SomeAnnotation must only be attached to fields or methods, but it is attached to a class:

@Target({ElementType.METHOD,ElementType.FIELD})
@interface SomeAnnotation {}

@SomeAnnotation
public class SomeClass {
   ...

Report Format: Make implementations self-describing

Make implementations self-describing: getType() returns "text" or "html", getExtensions() returns "txt" or "html", etc.

Goal: The factory can decide automatically which implementation to use based on command line arguments.

Modules: Report services declared with keywords `uses` and `provides`

A provides…with module directive specifies that a module provides a service implementation — making the module a service provider. The provides part of the directive specifies an interface or abstract class listed in a module’s uses directive and the with part of the directive specifies the name of the service provider class that implements the interface or extends the abstract class.

A uses module directive specifies a service used by this module — making the module a service consumer. A service is an object of a class that implements the interface or extends the abstract class specified in the uses directive.

New analyzer: Security Vulnerabilities

Include a new section "Security Vulnerabilities" with information about known security vulnerabilities found in JAR files.

Prerequisite:
A service to get vulnerabilities given Maven artifact coordinates.

Build: Automate release process

Implement a workflow to create a new release.

Draft process:

  • Update version number by removing -SNAPSHOT.
  • Update version numbers in source code (tests) and documentation.
  • Create a tag.
  • Create a release, including release notes.
  • Increment version number to next patch version and append -SNAPSHOT.

Project: Split into multi-module project

Code redesign: Main (static entry point) -> Application (command line application) -> Engine ( "core", reused in plugins etc.)

Split into multi-module project:

  • jarhc-core
  • jarhc-cli
  • jarhc-jmh
  • jarhc-gui
  • jarhc-maven-plugin
  • jarhc-gradle-plugin
  • jarhc-intellij-plugin
  • jarhc-sonar-plugin
  • jarhc-ant-task
  • ...

Binary Compatibility Analyzer: Correctly handle calls to MethodHandle.invoke(...)

Example output with JarHC version 1.4-SNAPSHOT:

jetty-util-9.4.20.v20190813.jar | org.eclipse.jetty.util.ModuleLocation
                                | • Method not found: java.lang.Object java.lang.invoke.MethodHandle.invoke(java.lang.Class)
                                | > java.lang.invoke.MethodHandle (method not found)
                                | > java.lang.Object (method not found)
                                | • Method not found: java.lang.Object java.lang.invoke.MethodHandle.invoke(java.lang.Object)
                                | > java.lang.invoke.MethodHandle (method not found)
                                | > java.lang.Object (method not found)

The class MethodHandle does indeed not contain a method "invoke" with a single parameter of type Class or Object. Instead, there is such a method with parameter type Object[] (vararg).

It seems as if the bytecode produced for calling the "invoke" method does not have to match the actual signature of this method. The same is probably true for the methods "invokeExact" and "invokeWithArguments".

For information about MethodHandle, see Javadoc:
https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodHandle.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.