Add json report version and documentation (#749)

* Add version number to the json report
* Add documentation and borrow Pants' export versioning guideline: afa6a286f1/src/python/pants/backend/project_info/tasks/export.py (L49-L59)
This commit is contained in:
Yi Cheng 2018-02-01 10:44:05 -08:00 committed by GitHub
parent 212b5fe298
commit f6ceba5b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 181 additions and 2 deletions

View File

@ -386,6 +386,15 @@ Welcome to the Ammonite Repl 0.7.0
@
```
Fetch with module level attributes, as opposed to e.g. `--classifier` is applied globally.
```
$ ./coursier fetch org.apache.avro:avro:1.7.4,classifier=tests --artifact-type test-jar,jar
```
Fetch and generate a machine readable json report. [Json Report Documentation](/doc/cli.md)
```
$ ./coursier fetch org.apache.avro:avro:1.7.4 --json-output-file report.json
```

View File

@ -16,12 +16,25 @@ final case class JsonPrintRequirement(fileByArtifact: Map[String, File], depToAr
final case class DepNode(coord: String, files: Vector[(String, String)], dependencies: Set[String])
final case class ReportNode(conflict_resolution: Map[String, String], dependencies: Vector[DepNode])
final case class ReportNode(conflict_resolution: Map[String, String], dependencies: Vector[DepNode], version: String)
/**
* FORMAT_VERSION_NUMBER: Version number for identifying the export file format output. This
* version number should change when there is a change to the output format.
*
* Major Version 1.x.x : Increment this field when there is a major format change
* Minor Version x.1.x : Increment this field when there is a minor change that breaks backward
* compatibility for an existing field or a field is removed.
* Patch version x.x.1 : Increment this field when a minor format change that just adds information
* that an application can safely ignore.
*
* Note format changes in cli/README.md and update the Changelog section.
*/
object ReportNode {
import argonaut.ArgonautShapeless._
implicit val encodeJson = EncodeJson.of[ReportNode]
implicit val decodeJson = DecodeJson.of[ReportNode]
val version = "0.0.1"
}
@ -54,7 +67,7 @@ object JsonReport {
DepNode(reconciledVersionStr(r), getFiles(r).toVector, acc.toSet)
})
val report = ReportNode(conflictResolutionForRoots, rootDeps.toVector)
val report = ReportNode(conflictResolutionForRoots, rootDeps.toVector, ReportNode.version)
printer.pretty(report.asJson)
}

148
doc/cli.md Normal file
View File

@ -0,0 +1,148 @@
# CLI Documentation
## Json Report
When invoking coursier cli with
```
fetch -t <modules...> --json-output-file <report.json>
```
The report will contain the info about resolved modules and their relationships.
## Format and Version Change Log
### 0.0.1
Add 'version' field to the report.
```
{
"version": "0.0.1",
"conflict_resolution": {
...
},
"dependencies": [
...
]
}
```
### Initial version (before we add the version to the report)
```
{
"conflict_resolution": {
"org:name:version" (requested): "org:name:version" (reconciled)
},
"dependencies": [
{
"coord": "orgA:nameA:versionA",
"files": [
[
<classifier>,
<path>
]
],
"dependencies": [ // coodinates for its transitive dependencies
<orgX:nameX:versionX>,
<orgY:nameY:versionY>,
]
},
{
"coord": "orgB:nameB:versionB",
"files": [
[
<classifier>,
<path>
]
],
"dependencies": [ // coodinates for its transitive dependencies
<orgX:nameX:versionX>,
<orgZ:nameZ:versionZ>,
]
},
]
}
```
For example:
```
fetch -t org.apache.avro:trevni-avro:1.8.2 org.slf4j:slf4j-api:1.7.6 --json-output-file x.out
Result:
├─ org.apache.avro:trevni-avro:1.8.2
│ ├─ org.apache.avro:trevni-core:1.8.2
│ │ ├─ org.apache.commons:commons-compress:1.8.1
│ │ ├─ org.slf4j:slf4j-api:1.7.7
│ │ └─ org.xerial.snappy:snappy-java:1.1.1.3
│ └─ org.slf4j:slf4j-api:1.7.7
└─ org.slf4j:slf4j-api:1.7.6 -> 1.7.7
```
would produce the following json file:
```
$ jq < x.out
{
"conflict_resolution": {
"org.slf4j:slf4j-api:1.7.6": "org.slf4j:slf4j-api:1.7.7"
},
"dependencies": [
{
"coord": "org.apache.avro:trevni-core:1.8.2",
"files": [
[
"",
"<coursier_cache>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/apache/avro/trevni-core/1.8.2/trevni-core-1.8.2.jar"
]
],
"dependencies": [
"org.slf4j:slf4j-api:1.7.7",
"org.xerial.snappy:snappy-java:1.1.1.3",
"org.apache.commons:commons-compress:1.8.1"
]
},
{
"coord": "org.apache.avro:trevni-avro:1.8.2",
"files": [
[
"",
"<coursier_cache>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/apache/avro/trevni-avro/1.8.2/trevni-avro-1.8.2.jar"
]
],
"dependencies": [
"org.apache.avro:trevni-core:1.8.2",
"org.slf4j:slf4j-api:1.7.7",
"org.xerial.snappy:snappy-java:1.1.1.3",
"org.apache.commons:commons-compress:1.8.1"
]
},
{
"coord": "org.slf4j:slf4j-api:1.7.7",
"files": [
[
"",
"<coursier_cache>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar"
]
],
"dependencies": []
},
{
"coord": "org.apache.commons:commons-compress:1.8.1",
"files": [
[
"",
"<coursier_cache>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar"
]
],
"dependencies": []
},
{
"coord": "org.xerial.snappy:snappy-java:1.1.1.3",
"files": [
[
"",
"<coursier_cache>/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/xerial/snappy/snappy-java/1.1.1.3/snappy-java-1.1.1.3.jar"
]
],
"dependencies": []
}
]
}
```

View File

@ -414,6 +414,15 @@ Welcome to the Ammonite Repl 0.7.0
@
```
Fetch with module level attributes, as opposed to e.g. `--classifier` is applied globally.
```
$ ./coursier fetch org.apache.avro:avro:1.7.4,classifier=tests --artifact-type test-jar,jar
```
Fetch and generate a machine readable json report. [Json Report Documentation](/doc/cli.md)
```
$ ./coursier fetch org.apache.avro:avro:1.7.4 --json-output-file report.json
```
```tut:invisible
// TODO options: repositories, sources/javadoc, attributes