|
1 | 1 | # Polystat CLI |
2 | | -This repository provides an alternative implementation to [Polystat](https://github.com/polystat/polystat). |
| 2 | +This repository provides an alternative implementation to [Polystat](https://github.com/polystat/polystat). This tool's objective is to extend the functionality of the original implementation. These extensions include: |
| 3 | +* A precise [specification](#full) for the command-line interface. |
| 4 | +* A configuration file that is not tied to the command-line interface. |
| 5 | +* A setup-free and customizable integration with the existing source-to-EO translators (specifically [j2eo](https://github.com/polystat/j2eo) and [py2eo](https://github.com/polystat/py2eo)). The following features are implemented for the `j2eo` translator: |
| 6 | + * Automatic downloading of the specified version from Maven Central |
| 7 | + * If you have `j2eo` installed locally, you can provide a path to it via a configuration option. |
| 8 | +* The [SARIF](https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html) output of the analyzers can be produced in the following two forms: |
| 9 | + * A **directory** with the `.sarif.json` files, where each SARIF file corresponds to the file in the input directory. |
| 10 | + * An **single file** where the outputs of the analyzers for all the analyzed files are aggregated in a single SARIF JSON object. |
| 11 | + |
| 12 | +...and many minor quality-of-life improvements. |
3 | 13 |
|
4 | 14 | # Installation |
5 | | -The CLI is distributed as a fat jar, so that you can run without any prerequisites other than the JRE. To run it, just execute: |
| 15 | +The CLI is distributed as a fat jar (can be downloaded from [Github Releases](https://github.com/polystat/polystat-cli/releases)), so you can run without any prerequisites other than the [JRE](https://ru.wikipedia.org/wiki/Java_Runtime_Environment). If you have it installed, you can run `polystat-cli` by just executing: |
6 | 16 | ``` |
7 | | -java -jar polystat.jar <args> |
| 17 | +$ java -jar polystat.jar <args> |
8 | 18 | ``` |
9 | | -It may be helpful to define an alias (the following works in Unix/MacOs): |
| 19 | +It may be helpful to define an alias (the following works in most Linux and macos): |
10 | 20 | ``` |
11 | | -alias polystat="java -jar /path/to/polystat.jar" |
| 21 | +$ alias polystat="java -jar /path/to/polystat.jar" |
12 | 22 | ``` |
13 | 23 | And then simply run it like: |
14 | 24 | ``` |
15 | | -polystat <args> |
| 25 | +$ polystat <args> |
16 | 26 | ``` |
17 | 27 | More about the arguments you can pass can be found [here](#basic) and [here](#full). |
18 | 28 |
|
19 | 29 |
|
20 | 30 | # <a name="basic"></a> Basic usage |
21 | 31 |
|
22 | | -> `polystat` |
| 32 | +* If no arguments are provided to `polystat`, it will read the configuration from the [HOCON](https://github.com/lightbend/config/blob/main/HOCON.md) config file in the current working directory. The default name for this file is `.polystat.conf` in the current working directory. |
23 | 33 |
|
24 | | -If no arguments are provided to `polystat`, it will read the configuration from the [HOCON](https://github.com/lightbend/config/blob/main/HOCON.md) config file in the current working directory. The default name for this file is `.polystat.conf` in the current working directory. If you want to read the configuration from the file located elsewhere, the following command can be used: |
| 34 | +``` |
| 35 | +$ polystat |
| 36 | +``` |
| 37 | + |
| 38 | +* If you want to read the configuration from the file located elsewhere, the following command can be used: |
25 | 39 |
|
26 | 40 | ``` |
27 | | -polystat --config path/to/hocon/config.conf |
| 41 | +$ polystat --config path/to/hocon/config.conf |
28 | 42 | ``` |
29 | 43 |
|
30 | | -> `polystat list -c` |
31 | 44 |
|
32 | | -Prints all the available config keys. |
33 | | -> `polystat list` |
| 45 | +* Print all the available configuration keys that can be used in the config file. |
34 | 46 |
|
35 | | -Prints the rule IDs for all the available analyzers. By default, all of them are enabled, however you can exclude some / include only the ones you want using the following commands: |
| 47 | +``` |
| 48 | +$ polystat list -c |
| 49 | +``` |
36 | 50 |
|
37 | | -> `polystat eo --in tmp --exclude mutualrec --sarif` |
| 51 | +* Print the rule IDs for all the available analyzers. |
38 | 52 |
|
39 | | -All the rules BUT the `mutualrec` will be executed. |
| 53 | +``` |
| 54 | +$ polystat list |
| 55 | +``` |
40 | 56 |
|
| 57 | +* Don't execute some rules during the analysis. This option is repeatable, so you can add any number of `--exclude rule` arguments to exclude all the specified rules. In the example below all the rules **but** `mutualrec` and `long` will be executed. |
| 58 | +``` |
| 59 | +$ polystat eo --in tmp --exclude mutualrec --exclude long --sarif |
| 60 | +``` |
41 | 61 |
|
42 | | -> `polystat eo --in tmp --include mutualrec --include liskov --sarif` |
| 62 | +* Execute _only_ the given rules during the analysis. This option is also repeatable. |
| 63 | +In the example below **only** `mutualrec` and `liskov` rules will be executed. |
43 | 64 |
|
44 | | -Only `mutualrec` and `liskov` rules will be executed. |
| 65 | +``` |
| 66 | +$ polystat eo --in tmp --include mutualrec --include liskov --sarif |
| 67 | +``` |
45 | 68 |
|
| 69 | +* Get the plain text console output from analyzing Java files located in the directory `src/main/java`. |
46 | 70 |
|
47 | | -> `polystat java --in src/main/java --console` |
| 71 | +``` |
| 72 | +$ polystat java --in src/main/java --console |
| 73 | +``` |
48 | 74 |
|
49 | | -Get the plain text console output from analyzing Java files. The Java files are in the directory `src/main/java`. |
| 75 | +* Write the SARIF JSON files to `polystat_out/sarif` from analysing the `tmp` directory with `.eo` files. |
50 | 76 |
|
51 | | -> `polystat eo --in tmp --sarif --to dir=polystat_out` |
52 | 77 |
|
53 | | -Write the [SARIF](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html) JSON files to `polystat_out/sarif` from analysing the `tmp` directory with `.eo` files. |
| 78 | +``` |
| 79 | +$ polystat eo --in tmp --sarif --to dir=polystat_out |
| 80 | +``` |
| 81 | + |
54 | 82 |
|
55 | 83 |
|
56 | 84 | # <a name="full"></a> Full Usage Specification |
@@ -85,7 +113,7 @@ polystat list [--config | -c] |
85 | 113 | * The temporary files produced by analyzers are to be stored in `--tmp` directory. If `--tmp` is not specified, temporary files will be stored in the OS-created tempdir. Each target language may have a different structure of the files in the temporary directory. It is assumed that the `path` supplied by `--tmp` points to an empty directory. If not, the contents of the `path` will be purged. If the `--tmp` option is specified but the directory it points to does not exist, it will be created. |
86 | 114 |
|
87 | 115 | ## Configuration options |
88 | | -* `--include` and `--exclude` respectively define which rules should be included/excluded from the analysis run. These options are mutually exclusive, so specifying both should not be valid. If neither option is specified, all the available analyzers will be run. The list of available rule specifiers can be found via `polystat list` command. |
| 116 | +* <a name="inex"></a>`--include` and `--exclude` respectively define which rules should be included/excluded from the analysis run. These options are mutually exclusive, so specifying both should not be valid. If neither option is specified, all the available analyzers will be run. The list of available rule specifiers can be found via `polystat list` command. |
89 | 117 | * `--j2eo` option allows users to specify the path to the j2eo executable jar. If it's not specified, it looks for one in the current working diretory. |
90 | 118 | If it's not present in the current working directory, download one from Maven Central (for now, the version is hardcoded to be 0.4.0). |
91 | 119 | * `--j2eo-version` option allows users to specify which version of `j2eo` should be downloaded. |
@@ -115,24 +143,28 @@ If it's not present in the current working directory, download one from Maven Ce |
115 | 143 | # Development |
116 | 144 | ## Setup |
117 | 145 | This is an sbt Scala project. In order to build the project you need the following: |
118 | | - * JDK 8+ |
119 | | - * sbt 1.6.2 |
| 146 | + * [JDK](https://ru.wikipedia.org/wiki/Java_Development_Kit) 8+ |
| 147 | + * [sbt](https://www.scala-sbt.org/) 1.6.2 |
120 | 148 |
|
121 | 149 | Both can be easily fetched via [coursier](https://get-coursier.io/docs/overview). |
122 | 150 |
|
123 | 151 | ## Running the CLI |
124 | | -> `sbt run` |
| 152 | +``` |
| 153 | +$ sbt run |
| 154 | +``` |
125 | 155 |
|
126 | 156 | It's best to run this command in the interactive mode, because you can specify the cmdline args there. |
127 | 157 | However, for better turnaround time, it's better to tailor the `.polystat.conf` in the repository root for your needs and just run `run`. |
128 | 158 | If you want to change the command-line arguments, edit the `.polystat.conf` in the repository root. |
129 | 159 |
|
130 | 160 | ## Generating the fat JAR |
131 | | -> `sbt assembly` |
| 161 | +``` |
| 162 | +$ sbt assembly |
| 163 | +``` |
132 | 164 |
|
133 | | -The jar can be then found at `target/scala-3.1.2/polystat.jar`. |
| 165 | +The generated jar can be then found at `target/scala-3.1.2/polystat.jar`. |
134 | 166 |
|
135 | 167 | ## Running the tests |
136 | | -> `sbt test` |
137 | | -
|
138 | | - |
| 168 | +``` |
| 169 | +$ sbt test |
| 170 | +``` |
0 commit comments