Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-preview.20190925' into master/1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eiiches committed Sep 24, 2019
2 parents 18677ec + e12eb98 commit 26094bd
Show file tree
Hide file tree
Showing 289 changed files with 18,621 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/deploy-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# this name appears in the badge
name: 'test'
on:
push:
branches:
- develop/1.x
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Download jq-1.5 and jq-1.6
run: |
mkdir -p $HOME/bin
wget -O $HOME/bin/jq-1.5 https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
wget -O $HOME/bin/jq-1.6 https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x $HOME/bin/jq-1.5 $HOME/bin/jq-1.6
- name: Configure Maven
env:
M2_SETTINGS_XML: ${{ secrets.M2_SETTINGS_XML }}
run: |
mkdir -p $HOME/.m2
echo "$M2_SETTINGS_XML" > $HOME/.m2/settings.xml
- name: Build & Deploy
run: 'PATH="$HOME/bin:$PATH" mvn clean deploy'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.classpath
.project
.settings
target/
dependency-reduced-pom.xml
.idea/
*.iml
.vscode/
65 changes: 65 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
jackson-jq
----------

Copyright (C) 2015 Eiichi Sato

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


jackson-jq/src/test/resources
-----------------------------

These files are generated from files in stedolan/jq repository:

jackson-jq/src/main/resources/net/thisptr/jackson/jq/jq.json
jackson-jq/src/test/resources/jq-test-all-ng.json
jackson-jq/src/test/resources/jq-test-all-ok.json
jackson-jq/src/test/resources/jq-test-official-ng.json
jackson-jq/src/test/resources/jq-test-official-ok.json
jackson-jq/src/test/resources/compiler-test-ok.txt
jackson-jq/src/test/resources/compiler-test-ng.txt

Therefore, is a derivative work of jq and the following license terms apply:


jq is copyright (C) 2012 Stephen Dolan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


jq's documentation (everything found under the docs/ subdirectory in
the source tree) is licensed under the Creative Commons CC BY 3.0
license, which can be found at:

https://creativecommons.org/licenses/by/3.0/

The documentation website includes a copy of Twitter's Boostrap and
relies on Bonsai, Liquid templates and various other projects, look
them up for detailed licensing conditions.
305 changes: 305 additions & 0 deletions README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions bin/jackson-jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

scriptpath=`readlink -f $0`
scriptdir=`dirname $scriptpath`

jarpath=`find $scriptdir/../jackson-jq-cli -name "jackson-jq-cli-*.jar" | grep -v sources | grep -v javadoc`
if [ -z $jarpath ]; then
echo "ERROR: jackson-jar-cli-\${version}.jar does not exist; please run 'mvn package' first." 1>&2
exit 1
fi

java -jar $jarpath "$@"
59 changes: 59 additions & 0 deletions jackson-jq-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<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>

<artifactId>jackson-jq-cli</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>jar</packaging>

<parent>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<version>1.0.0-preview.20190925</version>
</parent>

<dependencies>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-extra</artifactId>
<version>1.0.0-preview.20190925</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>com.google.auto.service:auto-service-annotations</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.thisptr.jackson.jq.cli.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>net/thisptr/jackson/jq/jq.json</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
136 changes: 136 additions & 0 deletions jackson-jq-cli/src/main/java/net/thisptr/jackson/jq/cli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package net.thisptr.jackson.jq.cli;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import net.thisptr.jackson.jq.BuiltinFunctionLoader;
import net.thisptr.jackson.jq.JsonQuery;
import net.thisptr.jackson.jq.Scope;
import net.thisptr.jackson.jq.Version;
import net.thisptr.jackson.jq.Versions;
import net.thisptr.jackson.jq.exception.JsonQueryException;
import net.thisptr.jackson.jq.internal.functions.EnvFunction;

public class Main {
private static final ObjectMapper MAPPER = new ObjectMapper();

private static final Option OPT_COMPACT = Option.builder("c")
.longOpt("compact")
.desc("compact instead of pretty-printed output")
.build();

private static final Option OPT_RAW = Option.builder("r")
.longOpt("raw")
.desc("output raw strings, not JSON texts")
.build();

private static final Option OPT_NULL_INPUT = Option.builder("n")
.longOpt("null-input")
.desc("use `null` as the single input value")
.build();

private static final Option OPT_VERSION = Option.builder()
.longOpt("jq")
.desc("specify jq version")
.numberOfArgs(1)
.build();

private static final Option OPT_HELP = Option.builder("h")
.longOpt("help")
.desc("print this message")
.build();

public static void main(String[] args) throws IOException, ParseException {
final Options options = new Options();
options.addOption(OPT_COMPACT);
options.addOption(OPT_RAW);
options.addOption(OPT_NULL_INPUT);
options.addOption(OPT_VERSION);
options.addOption(OPT_HELP);

final CommandLine command;
final List<String> rest;
try {
final CommandLineParser parser = new DefaultParser();
command = parser.parse(options, args);
rest = command.getArgList();
} catch (ParseException e) {
System.err.println("invalid arguments: " + Arrays.toString(args));
System.exit(1);
throw e;
}

Version version = Versions.JQ_1_6;
if (command.hasOption(OPT_VERSION.getLongOpt())) {
version = Version.valueOf(command.getOptionValue(OPT_VERSION.getLongOpt()));
if (!Versions.versions().contains(version)) {
System.err.println("unsupported --jq version: " + version);
System.exit(1);
}
}

if (rest.isEmpty() || command.hasOption(OPT_HELP.getOpt())) {
final HelpFormatter help = new HelpFormatter();
help.printHelp("jackson-jq [OPTIONS...] QUERY", options, false);
System.exit(0);
}

final JsonQuery jq = JsonQuery.compile(rest.get(0), version);

if (!command.hasOption(OPT_COMPACT.getOpt())) {
MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
}

InputStream is = System.in;
if (command.hasOption(OPT_NULL_INPUT.getOpt())) {
is = new ByteArrayInputStream("null".getBytes());
}

final Scope scope = Scope.newEmptyScope();
BuiltinFunctionLoader.getInstance().loadFunctions(version, scope);
scope.addFunction("env", 0, new EnvFunction());

try (final BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
final JsonParser parser = MAPPER.getFactory().createParser(reader);
while (!parser.isClosed()) {
final JsonNode tree = parser.readValueAsTree();
if (tree == null)
continue;
try {
jq.apply(scope, tree, (out) -> {
if (out.isTextual() && command.hasOption(OPT_RAW.getOpt())) {
System.out.println(out.asText());
} else {
try {
System.out.println(MAPPER.writeValueAsString(out));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
} catch (JsonQueryException e) {
System.err.println("jq: error: " + e.getMessage());
System.exit(1);
}
}
}
}
}
35 changes: 35 additions & 0 deletions jackson-jq-extra/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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>

<artifactId>jackson-jq-extra</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>bundle</packaging>

<parent>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq-parent</artifactId>
<version>1.0.0-preview.20190925</version>
</parent>

<dependencies>
<dependency>
<groupId>net.thisptr</groupId>
<artifactId>jackson-jq</artifactId>
<version>1.0.0-preview.20190925</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Include-Resource>META-INF/services/net.thisptr.jackson.jq.Function=${project.build.outputDirectory}/META-INF/services/net.thisptr.jackson.jq.Function</Include-Resource>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 26094bd

Please sign in to comment.