Skip to content

Commit 8a8a643

Browse files
authored
feat: add cli entrypoint and fat jar to use standalone (#149)
Generate a fat jar with `cli` suffix Add a default entrypoint that accepts some arguments in order to execute the analysis standalone --------- Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent 451c08b commit 8a8a643

10 files changed

Lines changed: 1193 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# Maven
2323
target
2424
.flattened-pom.xml
25+
dependency-reduced-pom.xml
2526

2627
# Gradle
2728
.gradle

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,73 @@ By Default, The API algorithm will use native commands of PIP installer as data
503503
It's also possible, to use lightweight Python PIP utility [pipdeptree](https://pypi.org/project/pipdeptree/) as data source instead, in order to activate this,
504504
Need to set environment variable/system property - `EXHORT_PIP_USE_DEP_TREE` to true.
505505

506+
### CLI Support
507+
508+
The Exhort Java API includes a command-line interface for standalone usage.
509+
510+
#### Building the CLI
511+
512+
To build the CLI JAR with all dependencies included:
513+
514+
```shell
515+
mvn clean package
516+
```
517+
518+
This creates two JAR files in the `target/` directory:
519+
- `exhort-java-api.jar` - Library JAR (for programmatic use)
520+
- `exhort-java-api-cli.jar` - CLI JAR (includes all dependencies)
521+
522+
#### Usage
523+
524+
```shell
525+
java -jar target/exhort-java-api-cli.jar <COMMAND> <FILE_PATH> [OPTIONS]
526+
```
527+
528+
#### Commands
529+
530+
**Stack Analysis**
531+
```shell
532+
java -jar exhort-java-api-cli.jar stack <file_path> [--summary|--html]
533+
```
534+
Perform stack analysis on the specified manifest file.
535+
536+
Options:
537+
- `--summary` - Output summary in JSON format
538+
- `--html` - Output full report in HTML format
539+
- (default) - Output full report in JSON format
540+
541+
**Component Analysis**
542+
```shell
543+
java -jar exhort-java-api-cli.jar component <file_path> [--summary]
544+
```
545+
Perform component analysis on the specified manifest file.
546+
547+
Options:
548+
- `--summary` - Output summary in JSON format
549+
- (default) - Output full report in JSON format
550+
551+
#### Examples
552+
553+
```shell
554+
# Stack analysis with JSON output (default)
555+
java -jar exhort-java-api-cli.jar stack /path/to/pom.xml
556+
557+
# Stack analysis with summary
558+
java -jar exhort-java-api-cli.jar stack /path/to/package.json --summary
559+
560+
# Stack analysis with HTML output
561+
java -jar exhort-java-api-cli.jar stack /path/to/build.gradle --html
562+
563+
# Component analysis with JSON output (default)
564+
java -jar exhort-java-api-cli.jar component /path/to/requirements.txt
565+
566+
# Component analysis with summary
567+
java -jar exhort-java-api-cli.jar component /path/to/go.mod --summary
568+
569+
# Show help
570+
java -jar exhort-java-api-cli.jar --help
571+
```
572+
506573
### Image Support
507574

508575
Generate vulnerability analysis report for container images.

pom.xml

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<maven-site-plugin.version>4.0.0-M6</maven-site-plugin.version>
4545
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
4646
<maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
47+
<maven-shade-plugin.version>3.4.1</maven-shade-plugin.version>
4748
<build-helper-maven-plugin.version>3.4.0</build-helper-maven-plugin.version>
4849
<extra-enforcer-rules.version>1.6.2</extra-enforcer-rules.version>
4950
<flatten-maven-plugin.version>1.4.1</flatten-maven-plugin.version>
@@ -454,6 +455,11 @@ limitations under the License.]]>
454455
<artifactId>spotless-maven-plugin</artifactId>
455456
<version>${spotless-maven-plugin.version}</version>
456457
</plugin>
458+
<plugin>
459+
<groupId>org.apache.maven.plugins</groupId>
460+
<artifactId>maven-shade-plugin</artifactId>
461+
<version>${maven-shade-plugin.version}</version>
462+
</plugin>
457463
</plugins>
458464
</pluginManagement>
459465

@@ -651,6 +657,87 @@ limitations under the License.]]>
651657
</execution>
652658
</executions>
653659
</plugin>
660+
<plugin>
661+
<artifactId>maven-jar-plugin</artifactId>
662+
<configuration>
663+
<archive>
664+
<manifest>
665+
<mainClass>com.redhat.exhort.cli.App</mainClass>
666+
</manifest>
667+
</archive>
668+
</configuration>
669+
</plugin>
670+
<plugin>
671+
<groupId>org.apache.maven.plugins</groupId>
672+
<artifactId>maven-shade-plugin</artifactId>
673+
<executions>
674+
<execution>
675+
<phase>package</phase>
676+
<goals>
677+
<goal>shade</goal>
678+
</goals>
679+
<configuration>
680+
<shadedArtifactAttached>true</shadedArtifactAttached>
681+
<shadedClassifierName>cli</shadedClassifierName>
682+
683+
<!-- Filters to exclude problematic files -->
684+
<filters>
685+
<filter>
686+
<artifact>*:*</artifact>
687+
<excludes>
688+
<!-- Exclude module-info.class files to avoid strong encapsulation warnings -->
689+
<exclude>module-info.class</exclude>
690+
<exclude>META-INF/versions/*/module-info.class</exclude>
691+
<!-- Exclude signature files -->
692+
<exclude>META-INF/*.SF</exclude>
693+
<exclude>META-INF/*.DSA</exclude>
694+
<exclude>META-INF/*.RSA</exclude>
695+
<!-- Exclude duplicate MANIFEST.MF files (will be recreated) -->
696+
<exclude>META-INF/MANIFEST.MF</exclude>
697+
</excludes>
698+
</filter>
699+
</filters>
700+
701+
<!-- Transformers to handle overlapping resources -->
702+
<transformers>
703+
<!-- Main class transformer -->
704+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
705+
<mainClass>com.redhat.exhort.cli.App</mainClass>
706+
</transformer>
707+
708+
<!-- Service files transformer for Jackson and other services -->
709+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
710+
711+
<!-- Append NOTICE files -->
712+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
713+
<resource>META-INF/NOTICE</resource>
714+
</transformer>
715+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
716+
<resource>META-INF/NOTICE.txt</resource>
717+
</transformer>
718+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
719+
<resource>META-INF/NOTICE.md</resource>
720+
</transformer>
721+
722+
<!-- Append LICENSE files -->
723+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
724+
<resource>META-INF/LICENSE</resource>
725+
</transformer>
726+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
727+
<resource>META-INF/LICENSE.txt</resource>
728+
</transformer>
729+
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
730+
<resource>META-INF/LICENSE.md</resource>
731+
</transformer>
732+
733+
</transformers>
734+
735+
<!-- Create non-verbose output -->
736+
<createDependencyReducedPom>false</createDependencyReducedPom>
737+
</configuration>
738+
</execution>
739+
</executions>
740+
</plugin>
654741
<plugin>
655742
<groupId>com.diffplug.spotless</groupId>
656743
<artifactId>spotless-maven-plugin</artifactId>
@@ -813,9 +900,6 @@ limitations under the License.]]>
813900
<plugin>
814901
<groupId>de.sormuras.junit</groupId>
815902
<artifactId>junit-platform-maven-plugin</artifactId>
816-
<version>${junit-platform-maven-plugin.version}</version>
817-
<configuration>
818-
</configuration>
819903
</plugin>
820904
</plugins>
821905
</build>

0 commit comments

Comments
 (0)