Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/maven/org.fusesource.jansi-jansi-…
Browse files Browse the repository at this point in the history
…2.4.1
  • Loading branch information
filip26 authored Jul 27, 2024
2 parents 7769c44 + 9dd586b commit 958c974
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/executables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
uses: graalvm/setup-graalvm@v1
with:
version: 'latest'
java-version: '17'
java-version: '21'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Build Native Image'
run: mvn package -P native-image
run: mvn package -P native
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ A simple command line utility allowing to process JSON-LD, RDF, and CBOR-LD, doc
## Features

* [JSON-LD 1.1](https://www.w3.org/TR/json-ld/)
* [CBOR-LD 1.0](https://digitalbazaar.github.io/cbor-ld-spec/)
* [CBOR-LD 1.0](https://json-ld.github.io/cbor-ld-spec/)

## Installation

[Downloads](https://github.com/filip26/ld-cli/releases/tag/v0.8.0)
[Downloads](https://github.com/filip26/ld-cli/releases/)

```bash
> unzip ld-cli-....zip
Expand Down Expand Up @@ -71,18 +71,18 @@ All PR's welcome!

### Building

1. [Install GraalVM and Native Image](https://www.graalvm.org/java/quickstart/)
- download and unpack ```graalvm-ce-java17-[platform]-[version].tar.gz```
1. [Install GraalVM and Native Image](https://www.graalvm.org/latest/docs/)
- download and unpack ```graalvm-jdk-....tar.gz```
- set ```JAVA_HOME``` and ```PATH``` env variables
- ```gu install native-image```
3. ```mvn clean package -P native-image```
3. ```mvn clean package -Pnative```
4. ```./target/ld-cli```


## Resources

* [Titanium JSON-LD 1.1 Processor](https://github.com/filip26/titanium-json-ld)
* [Iridium CBOR-LD Processor](https://github.com/filip26/iridium-cbor-ld)
* [LEXREX](https://lexrex.web.app/) - Semantic vocabularies visual builder and manager

## Sponsors

Expand Down
95 changes: 78 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.apicatalog</groupId>
<artifactId>ld-cli</artifactId>
<version>0.8.0</version>
<version>0.9.0</version>
<packaging>jar</packaging>

<name>A Command Line Processor for Linked Data Processing</name>

<url>https://github.com/filip26/ld-cli</url>

<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -25,16 +27,18 @@
<mainClass>com.apicatalog.cli.App</mainClass>
<command.name>ld-cli</command.name>

<titanium.version>1.3.2</titanium.version>
<iridium.version>0.1.1</iridium.version>
<titanium.version>1.4.1</titanium.version>
<iridium.version>0.2.2</iridium.version>
<jakarta.json-p.version>2.0.1</jakarta.json-p.version>

<graal.version>23.0.1</graal.version>
<picocli.version>4.7.4</picocli.version>
<graal.version>24.0.2</graal.version>
<picocli.version>4.7.6</picocli.version>
<picocli-jansi-graalvm.version>1.2.0</picocli-jansi-graalvm.version>

<jansi.version>2.4.1</jansi.version>
<!-- <jansi.version>1.18</jansi.version>-->

<junit.jupiter.version>5.10.0</junit.jupiter.version>
<junit.jupiter.version>5.10.3</junit.jupiter.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -92,18 +96,17 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<version>2.16.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
Expand All @@ -117,12 +120,13 @@
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.2</version>
<executions>
<execution>
<goals>
Expand All @@ -131,18 +135,26 @@
<id>default-jar</id>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.apicatalog.App</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.3.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<excludedGroups>native-image</excludedGroups>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<version>3.3.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
Expand All @@ -162,6 +174,48 @@
</build>

<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.10.2</version>
<extensions>true</extensions>
<configuration>
<!-- <imageName>${command.name}</imageName>-->
<!-- <mainClass>${mainClass}</mainClass>-->
<buildArgs>&#45;&#45;no-server &#45;&#45;no-fallback
&#45;&#45;report-unsupported-elements-at-runtime
&#45;H:+UnlockExperimentalVMOptions
&#45;H:+ReportExceptionStackTraces
&#45;H:+AddAllCharsets
&#45;H:ReflectionConfigurationFiles=${project.basedir}/graal.json
&#45;H:IncludeResourceBundles=org.glassfish.json.messages
&#45;H:IncludeResources=.*/.*jsonld$</buildArgs>
</configuration>

<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>test-native</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native-image</id>
<activation>
Expand All @@ -177,7 +231,14 @@
<configuration>
<imageName>${command.name}</imageName>
<mainClass>${mainClass}</mainClass>
<buildArgs>&#45;&#45;no-server &#45;&#45;no-fallback &#45;&#45;report-unsupported-elements-at-runtime &#45;&#45;allow-incomplete-classpath &#45;H:ReflectionConfigurationFiles=${project.basedir}/graal.json &#45;H:+ReportExceptionStackTraces &#45;H:+AddAllCharsets &#45;H:IncludeResourceBundles=org.glassfish.json.messages &#45;H:IncludeResources=.*/.*jsonld$</buildArgs>
<buildArgs>&#45;&#45;no-server &#45;&#45;no-fallback
&#45;&#45;report-unsupported-elements-at-runtime
&#45;&#45;allow-incomplete-classpath
&#45;H:ReflectionConfigurationFiles=${project.basedir}/graal.json
&#45;H:+ReportExceptionStackTraces
&#45;H:+AddAllCharsets
&#45;H:IncludeResourceBundles=org.glassfish.json.messages
&#45;H:IncludeResources=.*/.*jsonld$</buildArgs>
</configuration>
<executions>
<execution>
Expand All @@ -191,7 +252,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/apicatalog/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.2 https://github.com/filip26/iridium-cbor-ld",
}
)
public final class App {
Expand All @@ -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) {
Expand Down
58 changes: 26 additions & 32 deletions src/main/java/com/apicatalog/cli/command/CompressCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Integer> {

@Option(names = { "-h", "--help" }, hidden = true, usageHelp = true)
Expand All @@ -39,22 +32,23 @@ public final class CompressCmd implements Callable<Integer> {
@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 {
Expand All @@ -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();
}
}
Loading

0 comments on commit 958c974

Please sign in to comment.