diff --git a/.github/workflows/executables.yml b/.github/workflows/executables.yml index ec158cb..95c3e2e 100644 --- a/.github/workflows/executables.yml +++ b/.github/workflows/executables.yml @@ -32,7 +32,7 @@ jobs: uses: graalvm/setup-graalvm@v1 with: version: 'latest' - java-version: '17' + java-version: '21' components: 'native-image' github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ad773b2..01d7da2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Build with Maven env: GITHUB_ACTOR: ${{ github.actor }} diff --git a/pom.xml b/pom.xml index c5226ab..58271b0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.apicatalog ld-cli - 0.8.0 + 0.9.0-SNAPSHOT jar A Command Line Processor for Linked Data Processing @@ -12,8 +12,8 @@ https://github.com/filip26/ld-cli - 17 - 17 + 21 + 21 true UTF-8 @@ -26,7 +26,7 @@ ld-cli 1.4.1 - 0.1.3 + 0.2.0 2.0.1 24.0.2 diff --git a/src/main/java/com/apicatalog/cli/App.java b/src/main/java/com/apicatalog/cli/App.java index 1e4d28f..e0a10e0 100644 --- a/src/main/java/com/apicatalog/cli/App.java +++ b/src/main/java/com/apicatalog/cli/App.java @@ -35,9 +35,9 @@ optionListHeading = "%nOptions:%n", commandListHeading = "%nCommands:%n", version = { - "ld-cli 0.8.0 https://github.com/filip26/ld-cli", - "titanium-json-ld 1.3.1 https://github.com/filip26/titanium-json-ld", - "iridium-cbor-ld 0.1.1 https://github.com/filip26/iridium-cbor-ld", + "ld-cli 0.9.0 https://github.com/filip26/ld-cli", + "titanium-json-ld 1.4.1 https://github.com/filip26/titanium-json-ld", + "iridium-cbor-ld 0.2.0 https://github.com/filip26/iridium-cbor-ld", } ) public final class App { @@ -49,7 +49,7 @@ public final class App { boolean version; static { - ((HttpLoader) HttpLoader.defaultInstance()).setFallbackContentType(MediaType.JSON); + ((HttpLoader) HttpLoader.defaultInstance()).fallbackContentType(MediaType.JSON); } public static void main(String[] args) { diff --git a/src/main/java/com/apicatalog/cli/command/CompressCmd.java b/src/main/java/com/apicatalog/cli/command/CompressCmd.java index f94e72a..b4a7f32 100644 --- a/src/main/java/com/apicatalog/cli/command/CompressCmd.java +++ b/src/main/java/com/apicatalog/cli/command/CompressCmd.java @@ -5,8 +5,9 @@ import java.util.concurrent.Callable; import com.apicatalog.cborld.CborLd; +import com.apicatalog.cborld.barcode.BarcodesConfig; import com.apicatalog.cborld.config.DefaultConfig; -import com.apicatalog.cborld.db.DbConfig; +import com.apicatalog.cborld.config.V05Config; import com.apicatalog.cborld.encoder.EncoderConfig; import com.apicatalog.jsonld.document.Document; import com.apicatalog.jsonld.document.JsonDocument; @@ -22,15 +23,7 @@ import picocli.CommandLine.Parameters; import picocli.CommandLine.Spec; -@Command( - name = "compress", - mixinStandardHelpOptions = false, - description = "Compress JSON-LD document into CBOR-LD", - sortOptions = true, - descriptionHeading = "%n", - parameterListHeading = "%nParameters:%n", - optionListHeading = "%nOptions:%n" - ) +@Command(name = "compress", mixinStandardHelpOptions = false, description = "Compress JSON-LD document into CBOR-LD", sortOptions = true, descriptionHeading = "%n", parameterListHeading = "%nParameters:%n", optionListHeading = "%nOptions:%n") public final class CompressCmd implements Callable { @Option(names = { "-h", "--help" }, hidden = true, usageHelp = true) @@ -39,22 +32,23 @@ public final class CompressCmd implements Callable { @Option(names = { "-i", "--input" }, description = "input document IRI") URI input = null; - @Parameters(index = "0", arity = "1", description = "output document filename" ) + @Parameters(index = "0", arity = "1", description = "output document filename") String output = null; @Option(names = { "-b", "--base" }, description = "input document base IRI") URI base = null; - + @Option(names = { "-a", "--keep-arrays" }, description = "keep arrays with just one element") boolean keepArrays = false; - - @Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|digitalbazaar") + + @Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|barcodes|v05") String mode = "default"; @Spec CommandSpec spec; - private CompressCmd() {} + private CompressCmd() { + } @Override public Integer call() throws Exception { @@ -64,35 +58,35 @@ public Integer call() throws Exception { if (input != null) { final DocumentLoader loader = SchemeRouter.defaultInstance(); document = loader.loadDocument(input, new DocumentLoaderOptions()); - + } else { - document = JsonDocument.of(System.in); + document = JsonDocument.of(System.in); } - final JsonStructure json = document.getJsonContent().orElseThrow(() -> new IllegalArgumentException("Invalid input document. JSON document expected but got [" + document.getContentType() + "].")); - + final JsonStructure json = document.getJsonContent() + .orElseThrow(() -> new IllegalArgumentException("Invalid input document. JSON document expected but got [" + document.getContentType() + "].")); + if (JsonUtils.isNotObject(json)) { throw new IllegalArgumentException("The input docunent root is not JSON object but [" + json.getValueType() + "]."); } - EncoderConfig config = DefaultConfig.INSTANCE; - - if ("digitalbazaar".equalsIgnoreCase(mode)) { - config = DbConfig.INSTANCE; - } + final EncoderConfig config = switch (mode) { + case "barcodes" -> BarcodesConfig.INSTANCE; + case "v05" -> V05Config.INSTANCE; + default -> DefaultConfig.INSTANCE; + }; - final byte[] encoded = CborLd.encoder(json.asJsonObject()) - .config(config) - .base(base) - .compactArray(!keepArrays) - .encode(); - + final byte[] encoded = CborLd.createEncoder(config) + .base(base) + .compactArray(!keepArrays) + .build() + .encode(json.asJsonObject()); try (FileOutputStream os = new FileOutputStream(output)) { os.write(encoded); os.flush(); } - - return spec.exitCodeOnSuccess(); + + return spec.exitCodeOnSuccess(); } } \ No newline at end of file diff --git a/src/main/java/com/apicatalog/cli/command/DecompressCmd.java b/src/main/java/com/apicatalog/cli/command/DecompressCmd.java index 4b49fc0..9b87d84 100644 --- a/src/main/java/com/apicatalog/cli/command/DecompressCmd.java +++ b/src/main/java/com/apicatalog/cli/command/DecompressCmd.java @@ -6,8 +6,9 @@ import java.util.concurrent.Callable; import com.apicatalog.cborld.CborLd; +import com.apicatalog.cborld.barcode.BarcodesConfig; import com.apicatalog.cborld.config.DefaultConfig; -import com.apicatalog.cborld.db.DbConfig; +import com.apicatalog.cborld.config.V05Config; import com.apicatalog.cborld.decoder.DecoderConfig; import com.apicatalog.cli.JsonOutput; @@ -19,15 +20,7 @@ import picocli.CommandLine.Parameters; import picocli.CommandLine.Spec; -@Command( - name = "decompress", - mixinStandardHelpOptions = false, - description = "Decompress CBOR-LD document into JSON-LD", - sortOptions = true, - descriptionHeading = "%n", - parameterListHeading = "%nParameters:%n", - optionListHeading = "%nOptions:%n" - ) +@Command(name = "decompress", mixinStandardHelpOptions = false, description = "Decompress CBOR-LD document into JSON-LD", sortOptions = true, descriptionHeading = "%n", parameterListHeading = "%nParameters:%n", optionListHeading = "%nOptions:%n") public final class DecompressCmd implements Callable { @Option(names = { "-h", "--help" }, hidden = true, usageHelp = true) @@ -41,36 +34,37 @@ public final class DecompressCmd implements Callable { @Option(names = { "-b", "--base" }, description = "input document base IRI") URI base = null; - + @Option(names = { "-a", "--keep-arrays" }, description = "keep arrays with just one element") boolean keepArrays = false; - - @Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|digitalbazaar") + + @Option(names = { "-m", "--mode" }, description = "processing mode", paramLabel = "default|barcodes|v05") String mode = "default"; @Spec CommandSpec spec; - private DecompressCmd() {} + private DecompressCmd() { + } @Override public Integer call() throws Exception { - byte[] encoded = Files.readAllBytes(input.toPath()); - - DecoderConfig config = DefaultConfig.INSTANCE; - - if ("digitalbazaar".equalsIgnoreCase(mode)) { - config = DbConfig.INSTANCE; - } - - final JsonValue output = CborLd.decoder(encoded) - .config(config) - .base(base) - .compactArray(!keepArrays) - .decode(); - - JsonOutput.print((JsonStructure)output, pretty); + final byte[] encoded = Files.readAllBytes(input.toPath()); + + final DecoderConfig config = switch (mode) { + case "barcodes" -> BarcodesConfig.INSTANCE; + case "v05" -> V05Config.INSTANCE; + default -> DefaultConfig.INSTANCE; + }; + + final JsonValue output = CborLd.createDecoder(config) + .base(base) + .compactArray(!keepArrays) + .build() + .decode(encoded); + + JsonOutput.print((JsonStructure) output, pretty); return spec.exitCodeOnSuccess(); }