added Wcfg file parser and CLI

This commit is contained in:
2023-10-30 22:30:00 +08:00
parent b7d00d9d9c
commit 9cb37790c2
45 changed files with 1445 additions and 219 deletions

2
Jenkinsfile vendored
View File

@@ -9,7 +9,7 @@ pipeline {
sh "./gradlew clean assemble build" sh "./gradlew clean assemble build"
junit testResults: "build/test-results/test/*.xml" junit testResults: "build/test-results/test/*.xml"
javadoc javadocDir: "build/docs/javadoc", keepAll: true javadoc javadocDir: "build/docs/javadoc", keepAll: true
archiveArtifacts artifacts: 'build/libs/*.jar,benchmark/build/libs/*.jar,wson-cli/build/distributions/wson-cli-envelope-*.jar', archiveArtifacts artifacts: 'build/libs/*.jar,benchmark/build/libs/*.jar,wson-cli/build/distributions/wson-cli-envelope-*.jar,wson-cli/build/distributions/wson-cli',
allowEmptyArchive: true, allowEmptyArchive: true,
fingerprint: true, fingerprint: true,
onlyIfSuccessful: true onlyIfSuccessful: true

View File

@@ -4,6 +4,7 @@ plugins {
dependencies { dependencies {
implementation rootProject implementation rootProject
runtimeOnly catalog.antlr.runtime
testImplementation catalog.jwo testImplementation catalog.jwo
testImplementation project(':test-utils') testImplementation project(':test-utils')
@@ -11,7 +12,6 @@ dependencies {
testImplementation catalog.xz testImplementation catalog.xz
antlr catalog.antlr antlr catalog.antlr
antlr catalog.antlr.runtime
} }
generateGrammarSource { generateGrammarSource {

View File

@@ -1,5 +1,6 @@
plugins { plugins {
alias(catalog.plugins.envelope) alias(catalog.plugins.envelope)
id 'me.champeau.jmh' version '0.7.1'
} }
envelopeJar { envelopeJar {
@@ -21,4 +22,15 @@ dependencies {
implementation catalog.jackson.databind implementation catalog.jackson.databind
runtimeOnly project(':test-utils') runtimeOnly project(':test-utils')
jmhAnnotationProcessor catalog.lombok
}
jmh {
threads = 1
iterations = 2
fork = 1
warmupIterations = 1
warmupForks = 0
resultFormat = 'JSON'
} }

View File

@@ -0,0 +1,135 @@
package net.woggioni.wson.benchmark;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.woggioni.wson.antlr.JSONLexer;
import net.woggioni.wson.antlr.JSONListenerImpl;
import net.woggioni.wson.serialization.binary.JBONParser;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.tukaani.xz.XZInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;
public class WsonParserBenchmark {
@State(Scope.Benchmark)
public static class ExecutionPlan {
@SneakyThrows
public InputStream hugeTestData() {
return new XZInputStream(Main.class.getResourceAsStream("/citylots.json.xz"));
}
@SneakyThrows
public InputStream hugeBinaryTestData() {
return new XZInputStream(new BufferedInputStream(WsonParserBenchmark.class.getResourceAsStream("/citylots.jbon.xz")));
}
public InputStream smallTestData() {
return new BufferedInputStream(WsonParserBenchmark.class.getResourceAsStream("/wordpress.json"));
}
public InputStream smallBinaryTestData() {
return new BufferedInputStream(WsonParserBenchmark.class.getResourceAsStream("/wordpress.jbon"));
}
}
private static Value.Configuration buildConfiguration() {
return Value.Configuration.builder()
.objectValueImplementation(ObjectValue.Implementation.ArrayList)
.build();
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void antlr(ExecutionPlan plan) {
try (InputStream is = plan.smallTestData()) {
CharStream inputStream = CharStreams.fromReader(new InputStreamReader(is));
JSONLexer lexer = new JSONLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
net.woggioni.wson.antlr.JSONParser parser = new net.woggioni.wson.antlr.JSONParser(commonTokenStream);
JSONListenerImpl listener = new JSONListenerImpl();
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.json());
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void worthJson(ExecutionPlan plan) {
try (InputStream is = plan.smallTestData()) {
new JSONParser(buildConfiguration()).parse(is);
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void worthJbon(ExecutionPlan plan) {
try (InputStream is = plan.smallBinaryTestData()) {
new JBONParser(buildConfiguration()).parse(is);
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.SECONDS)
public void worthJbonHuge(ExecutionPlan plan) {
try (InputStream is = plan.hugeBinaryTestData()) {
new JBONParser(buildConfiguration()).parse(is);
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.SECONDS)
public void worthHuge(ExecutionPlan plan) {
try (InputStream is = plan.hugeTestData()) {
new JSONParser(buildConfiguration()).parse(is);
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void jackson(ExecutionPlan plan) {
try (InputStream is = plan.smallTestData()) {
ObjectMapper om = new ObjectMapper();
om.readTree(new InputStreamReader(is));
}
}
@SneakyThrows
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.SECONDS)
public void jacksonHuge(ExecutionPlan plan) {
try (InputStream is = plan.hugeTestData()) {
ObjectMapper om = new ObjectMapper();
om.readTree(new InputStreamReader(is));
}
}
}

View File

@@ -14,6 +14,10 @@ allprojects {
java { java {
modularity.inferModulePath = true modularity.inferModulePath = true
toolchain {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.GRAAL_VM
}
} }
lombok { lombok {

View File

View File

@@ -1,4 +1,4 @@
wson.version = 2023.10.01 wson.version = 2023.11.01
lys.version = 2023.10.01 lys.version = 2023.10.31

View File

@@ -7,6 +7,9 @@ pluginManagement {
includeGroup 'net.woggioni.gradle.lombok' includeGroup 'net.woggioni.gradle.lombok'
includeGroup 'net.woggioni.gradle.envelope' includeGroup 'net.woggioni.gradle.envelope'
includeGroup 'net.woggioni.gradle.multi-release-jar' includeGroup 'net.woggioni.gradle.multi-release-jar'
includeGroup 'net.woggioni.gradle.graalvm.native-image'
includeGroup 'net.woggioni.gradle.graalvm.jlink'
includeGroup 'net.woggioni.gradle.sambal'
} }
} }
gradlePluginPortal() gradlePluginPortal()
@@ -38,7 +41,6 @@ def includeDirs = [
'wson-cli', 'wson-cli',
'wson-w3c-json', 'wson-w3c-json',
'wcfg', 'wcfg',
'wcfg-cli'
] ]
includeDirs.each { includeDirs.each {

View File

@@ -0,0 +1,229 @@
<EFBFBD>v _linksh
about<EFBFBD>_href?https://www.sitepoint.com/wp-json/wp/v2/types/post author<6F>`embeddablehref@https://www.sitepoint.com/wp-json/wp/v2/users/72596collection<6F>_href:https://www.sitepoint.com/wp-json/wp/v2/posts curies<65>ahref$https://api.w.org/{rel}namewptemplatedreplies<65>`embeddablehrefIhttps://www.sitepoint.com/wp-json/wp/v2/comments?post=168697self<6C>_hrefAhttps://www.sitepoint.com/wp-json/wp/v2/posts/168697version-history<72>_hrefKhttps://www.sitepoint.com/wp-json/wp/v2/posts/168697/revisionswp:attachment<6E>_hrefHhttps://www.sitepoint.com/wp-json/wp/v2/media?parent=168697 wp:featuredmedia<69>`embeddablehrefAhttps://www.sitepoint.com/wp-json/wp/v2/media/168703wp:term<72>aembeddablehrefKhttps://www.sitepoint.com/wp-json/wp/v2/categories?post=168697taxonomycategoryaembeddablehrefEhttps://www.sitepoint.com/wp-json/wp/v2/tags?post=168697taxonomypost_tag author<01><>categories<65><01>[<01>[comment_statusopencontent`protectedrendered]<5D><><p class="wp-special"><em>This article was created in partnership with <a href="https://bawmedia.com/" rel="nofollow">BAWMedia</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p>A well-designed website can serve as a powerful marketing tool. These days, creating one for a small business is not distressing or expensive at all. However, it was just a few short years ago.</p>
<p>Today, you can take advantage of the features provided by the best WordPress themes. There are special themes for small business-oriented websites. It&#39;s not difficult to find a website-building theme that matches a specific business. This can be a startup, a service provider, or some other venture.</p>
<p>You undoubtedly want nothing but the best business theme, right? Check out those described below. Each possesses functional designs loaded with amazing features. They will help you create a thoroughly engaging website to promote a business.</p>
<h2>1. <a href="http://themes.muffingroup.com/be/splash/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Be Theme</a></h2>
<p><a href="http://themes.muffingroup.com/be/splash/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215231.png" alt="" width="1000" height="481" class="aligncenter size-full wp-image-168702" /></a></p>
<p>We&#8217;ll start with Be Theme, a responsive, multipurpose WordPress theme that takes every small business need into account with its more than 370 pre-built websites. There&#39;s a multiplicity of small business WordPress themes in this pre-built website collection ? each one embedded with the functionality you need to establish an effective online presence, and fully customizable to meet your business and marketing needs.</p>
<p>The range of business niches covered is impressive, With more pre-built websites being added every month it&#39;s destined to become even more so. Web designers like Be Theme because it allows them to create a website for most small business types in as little as four hours.</p>
<p>Clients appreciate the rapid turnaround they receive and the ease in which changes or additions they have in mind can be accommodated.</p>
<p>Be Theme, one of the best WordPress themes for small business websites is a ThemeForest top 5 best seller whose core features include easy to work with page-building tools, a multiplicity of design features and options, and great support.</p>
<h2>2. <a href="http://bit.ly/2wxuUpA" rel="nofollow">Astra</a></h2>
<p><a href="http://bit.ly/2wxuUpA" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215352.jpg" alt="" width="1000" height="491" class="aligncenter size-full wp-image-168703" /></a></p>
<p>Astra is fast, fully customizable, and one of the best WordPress themes for business websites as well as for blogs and personal portfolios. Built with SEO in mind, Astra is responsive and WooCommerce ready ? mandatory features in today&#39;s online business environment. Its capabilities are easily extendible with premium addons and Astra can be used with most of the popular page builders. This free WP-based theme is definitely worth considering.</p>
<h2 id="">3. <a href="http://bit.ly/2oiQkTS" rel="nofollow">The100</a></h2>
<p><a href="http://bit.ly/2oiQkTS" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215473.jpg" alt="" width="1000" height="491" class="aligncenter size-full wp-image-168704" /></a></p>
<p>A theme selected for WordPress for small businesses can be free or it can be a premium theme requiring an expenditure on your behalf. There are several excellent free themes on the market, and one of them is The100. While it is advertised as having premium-like features, bear in mind that free themes like this one generally can&#39;t compete with premium themes. Nevertheless, The100 is an easy-to-use WP theme that features a multiplicity of layouts and plenty of customization options.</p>
<h2 id="">4. <a href="https://undsgn.com/uncode/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Uncode ? Creative Multiuse WordPress Theme</a></h2>
<p><a href="https://undsgn.com/uncode/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215604.jpg" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168705" /></a></p>
<p>Uncode has proven to be one of the best WordPress themes for business websites. It&#39;s a multipurpose theme featuring 30+ homepage concepts designed to get designers and their clients off to a fast start on any small business website. Features include an enhanced version of the popular Visual Composer page builder, and an Adaptive Images System that enables mobile users to see what you want and expect them to see.</p>
<h2 id="">5. <a href="http://houzez.co/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Houzez ? Highly Customizable Real Estate WordPress Theme</a></h2>
<p><a href="http://houzez.co/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215715.jpg" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168706" /></a></p>
<p>Some WordPress themes are created with a specific purpose in mind. Houzez is a specialty theme offering the features and functionality realtors and real estate agencies look for to promote their businesses and their marketability. Houzez&#39; features include advanced property search filters, IDX systems, property management functionality, and solid customer support.</p>
<h2 id="">6. <a href="http://preview.themeforest.net/item/thegem-creative-multipurpose-highperformance-wordpress-theme/full_screen_preview/16061685?sort_priority_group=meta-smallbusiness-startups&amp;utm_source=baw&amp;utm_medium=listing&amp;utm_campaign=smallbusiness" rel="nofollow">TheGem ? Creative Multi-Purpose High-Performance WordPress Theme</a></h2>
<p><a href="http://preview.themeforest.net/item/thegem-creative-multipurpose-highperformance-wordpress-theme/full_screen_preview/16061685?sort_priority_group=meta-smallbusiness-startups&amp;utm_source=baw&amp;utm_medium=listing&amp;utm_campaign=smallbusiness" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215846.jpg" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168707" /></a></p>
<p>TheGem is without doubt one of the best WordPress business themes on the market. Its users like working with the trendy design concepts the authors have presented based on their analysis of current UX trends. Visual Composer is TheGems&#39; page builder, and a judiciously selected set of plugins gives the web designer the flexibility to satisfy any small business&#39;s needs. The package includes a ready-to-go online fashion store.</p>
<h2 id="">7. <a href="https://cesis.co/ts/rs.php?theme=cesis&amp;utm_source=bawmedia&amp;utm_medium=article&amp;utm_campaign=bawmedia_cesis_sep2018&amp;utm_content=post" rel="nofollow">Cesis ? Responsive Multi-Purpose WordPress Theme</a></h2>
<p><a href="https://cesis.co/ts/rs.php?theme=cesis&amp;utm_source=bawmedia&amp;utm_medium=article&amp;utm_campaign=bawmedia_cesis_sep2018&amp;utm_content=post" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215977.png" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168708" /></a></p>
<p>When you&#39;re searching among the best WordPress themes for small business websites, Cesis is definitely worth a closer look. Its easy-to-use interface combined with a host of design elements and options allows you to build virtually anything you want. This is an important attribute when working with small businesses and startups, each having their unique business model and branding style.</p>
<h2 id="">8. <a href="http://wpdemos.themezaa.com/pofo/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Pofo &#8211; Creative Portfolio and Blog WordPress Theme</a></h2>
<p><a href="http://wpdemos.themezaa.com/pofo/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361216138.jpg" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168709" /></a></p>
<p>Web designers in need of small business WordPress themes include those whose clients represent creative teams and agencies as well as individual artists. Pofo is an ideal choice with its portfolio, eCommerce and blog features, bundled plugins, and more than 150 pre-built design elements. This premium theme&#39;s package also includes a nice assortment of home pages and more than 200 demo pages. Pofo is fully responsive, visually stunning, highly flexible, SEO and loading speed optimized.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Did you like this selection of the best WordPress themes for small business websites? It provides you with a wide range of options and merits close and careful study.</p>
<p>You really can&#39;t make a bad choice. With a little extra effort, you should be able to walk away with a perfect WordPress theme. It can be ideal for creating a certain small business website you have in mind. Likewise, it can help you create a range of websites for small businesses.</p>
date 2018-09-06T09:30:53date_gmt 2018-09-06T16:30:53excerpt`protectedrendered]<5D>N<p class="wp-special"><em>This article was created in partnership with <a href="https://bawmedia.com/" rel="nofollow">BAWMedia</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p>A well-designed website can serve as a powerful marketing tool. These days, creating one for a small business is not distressing or expensive at all. However, it was just a few short years ago.</p>
<p>Today, you can take advantage of the features provided by the best WordPress themes. There are special themes for small business-oriented websites. It&#39;s not difficult to find a website-building theme that matches a specific business. This can be a startup, a service provider, or some other venture.</p>
<p>You undoubtedly want nothing but the best business theme, right? Check out those described below. Each possesses functional designs loaded with amazing features. They will help you create a thoroughly engaging website to promote a business.</p>
<h2>1. <a href="http://themes.muffingroup.com/be/splash/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Be Theme</a></h2>
<p><a href="http://themes.muffingroup.com/be/splash/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215231.png" alt="" width="1000" height="481" class="aligncenter size-full wp-image-168702" /></a></p>
<p>We&#8217;ll start with Be Theme, a responsive, multipurpose WordPress theme that takes every small business need into account with its more than 370 pre-built websites. There&#39;s a multiplicity of small business WordPress themes in this pre-built website collection ? each one embedded with the functionality you need to establish an effective online presence, and fully customizable to meet your business and marketing needs.</p>
<p>The range of business niches covered is impressive, With more pre-built websites being added every month it&#39;s destined to become even more so. Web designers like Be Theme because it allows them to create a website for most small business types in as little as four hours.</p>
<p>Clients appreciate the rapid turnaround they receive and the ease in which changes or additions they have in mind can be accommodated.</p>
<p>Be Theme, one of the best WordPress themes for small business websites is a ThemeForest top 5 best seller whose core features include easy to work with page-building tools, a multiplicity of design features and options, and great support.</p>
<h2>2. <a href="http://bit.ly/2wxuUpA" rel="nofollow">Astra</a></h2>
<p><a href="http://bit.ly/2wxuUpA" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215352.jpg" alt="" width="1000" height="491" class="aligncenter size-full wp-image-168703" /></a></p>
<p>Astra is fast, fully customizable, and one of the best WordPress themes for business websites as well as for blogs and personal portfolios. Built with SEO in mind, Astra is responsive and WooCommerce ready ? mandatory features in today&#39;s online business environment. Its capabilities are easily extendible with premium addons and Astra can be used with most of the popular page builders. This free WP-based theme is definitely worth considering.</p>
<h2 id="">3. <a href="http://bit.ly/2oiQkTS" rel="nofollow">The100</a></h2>
<p><a href="http://bit.ly/2oiQkTS" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215473.jpg" alt="" width="1000" height="491" class="aligncenter size-full wp-image-168704" /></a></p>
<p>A theme selected for WordPress for small businesses can be free or it can be a premium theme requiring an expenditure on your behalf. There are several excellent free themes on the market, and one of them is The100. While it is advertised as having premium-like features, bear in mind that free themes like this one generally can&#39;t compete with premium themes. Nevertheless, The100 is an easy-to-use WP theme that features a multiplicity of layouts and plenty of customization options.</p>
<h2 id="">4. <a href="https://undsgn.com/uncode/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow">Uncode ? Creative Multiuse WordPress Theme</a></h2>
<p><a href="https://undsgn.com/uncode/?utm_source=sitepoint.com&amp;utm_medium=content&amp;utm_campaign=wpstartups18" rel="nofollow"><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/15361215604.jpg" alt="" width="1000" height="415" class="aligncenter size-full wp-image-168705" /></a></p>
<p>Uncode has proven to be one of the best WordPress themes for business websites. It&#39;s a multipurpose theme featuring 30+ homepage concepts designed to get designers and their clients off to a fast start on any small business website. Features include an enhanced version of the popular Visual Composer page builder, and an Adaptive Images System that enables mobile users to see what you want and expect them to see.</p>
featured_media<01><> formatstandardguid_rendered0https://www.sitepoint.com/?p=168697id<01><>link]<5D>https://www.sitepoint.com/the-8-best-wordpress-themes-for-small-business-websites/meta<74>modified 2018-09-04T21:31:02modified_gmt 2018-09-05T04:31:02ping_statusclosedslugDthe-8-best-wordpress-themes-for-small-business-websites statuspublish stickytags<67><01><><01><><01>btemplate
title_renderedDThe 8 Best WordPress Themes for Small Business Websitestypepostv _linksh
about<EFBFBD>_href?https://www.sitepoint.com/wp-json/wp/v2/types/post author<6F>`embeddablehref@https://www.sitepoint.com/wp-json/wp/v2/users/72676collection<6F>_href:https://www.sitepoint.com/wp-json/wp/v2/posts curies<65>ahref$https://api.w.org/{rel}namewptemplatedreplies<65>`embeddablehrefIhttps://www.sitepoint.com/wp-json/wp/v2/comments?post=168397self<6C>_hrefAhttps://www.sitepoint.com/wp-json/wp/v2/posts/168397version-history<72>_hrefKhttps://www.sitepoint.com/wp-json/wp/v2/posts/168397/revisionswp:attachment<6E>_hrefHhttps://www.sitepoint.com/wp-json/wp/v2/media?parent=168397 wp:featuredmedia<69>`embeddablehrefAhttps://www.sitepoint.com/wp-json/wp/v2/media/168458wp:term<72>aembeddablehrefKhttps://www.sitepoint.com/wp-json/wp/v2/categories?post=168397taxonomycategoryaembeddablehrefEhttps://www.sitepoint.com/wp-json/wp/v2/tags?post=168397taxonomypost_tag author<01><>categories<65><01>comment_statusopencontent`protectedrendered]<5D><><p class="wp-special"><em>This article was originally published on <a href="https://synd.co/2NCzyKk?" rel="canonical">MongoDB</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p>You can build your online, operational workloads atop MongoDB and still respond to events in real time by kicking off <a href="https://aws.amazon.com/kinesis/">Amazon Kinesis</a> stream processing actions, using MongoDB Stitch Triggers.</p>
<p>Let?s look at an example scenario in which a stream of data is being generated as a result of actions users take on a website. We?ll durably store the data and simultaneously feed a Kinesis process to do streaming analytics on something like cart abandonment, product recommendations, or even credit card fraud detection.</p>
<p>We?ll do this by setting up a Stitch Trigger. When relevant data updates are made in MongoDB, the trigger will use a Stitch Function to call out to AWS Kinesis, as you can see in this architecture diagram:</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536043981image5-d4wtr8tn5c.png" alt="" width="1525" height="844" class="aligncenter size-full wp-image-168426" /></p>
<h4 id="whatyoullneedtofollowalong">What you?ll need to follow along</h4>
<ol>
<li><strong>An Atlas instance</strong> <br />
If you don?t already have an application running on Atlas, you can follow our <a href="https://docs.atlas.mongodb.com/getting-started/">getting started with Atlas guide here</a>. In this example, we?ll be using a database called <em><strong>streamdata</strong></em>, with a collection called <em><strong>clickdata</strong></em> where we?re writing data from our web-based e-commerce application.</li>
<li><strong>An AWS account and a Kinesis stream</strong> <br />
In this example, we?ll use a Kinesis stream to send data downstream to additional applications such as Kinesis Analytics. This is the stream we want to feed our updates into.</li>
<li><strong>A Stitch application</strong> <br />
If you don?t already have a Stitch application, <a href="https://cloud.mongodb.com/user#/atlas/login">log into Atlas</a>, and click <strong>Stitch Apps</strong> from the navigation on the left, then click <strong>Create New Application</strong>.</li>
</ol>
<h3 id="createacollection">Create a Collection</h3>
<p>The first step is to create a database and collection from the Stitch application console. Click <strong>Rules</strong> from the left navigation menu and click the <strong>Add Collection</strong> button. Type <strong>streamdata</strong> for the database and <strong>clickdata</strong> for the collection name. Select the template labeled Users can <strong>only read and write their own data</strong> and provide a field name where we?ll specify the user id.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044010image2-51q4gsi7u2.png" alt="Figure 2. Create a collection" width="1999" height="923" class="aligncenter size-full wp-image-168427" /></p>
<h3 id="configuringstitchtotalktoaws">Configuring Stitch to Talk to AWS</h3>
<p>Stitch lets you configure <em>Services</em> to interact with external <a href="https://docs.mongodb.com/stitch/reference/partner-services/amazon-service/">services such as AWS Kinesis</a>. Choose <strong>Services</strong> from the navigation on the left, and click the <strong>Add a Service</strong> button, select the AWS service and set <strong>AWS <a href="https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/">Access Key ID, and Secret Access Key</a></strong>.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044038image8-2a9rr3qc4k.png" alt="Figure 3. Service Configuration in Stitch" width="1999" height="1041" class="aligncenter size-full wp-image-168428" /></p>
<p><em>Services</em> use <em>Rules</em> to specify what aspect of a service Stitch can use, and how. Add a rule which will enable that service to communicate with Kinesis by clicking the button labeled NEW RULE. Name the rule ?kinesis? as we?ll be using this specific rule to enable communication with AWS Kinesis. In the section marked Action, select the API labeled Kinesis and select All Actions.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044067image1-h45v2y48z7.gif" alt="Figure 4. Add a rule to enable integration with Kinesis" width="1424" height="746" class="aligncenter size-full wp-image-168429" /></p>
<h3 id="writeafunctionthatstreamsdocumentsintokinesis">Write a Function that Streams Documents into Kinesis</h3>
<p>Now that we have a working AWS service, we can use it to put records into a Kinesis stream. The way we do that in Stitch is with Functions. Let?s set up a <em>putKinesisRecord</em> function.</p>
<p>Select Functions from the left-hand menu, and click Create New Function. Provide a name for the function and paste the following in the body of the function.</p>
<p><img src="https://webassets.mongodb.com/_com_assets/cms/image6-7wtiny60ji.gif" alt="Figure 5. Example Function - putKinesisRecord" /></p>
<pre><code class="javascript language-javascript">exports = function(event){
const awsService = context.services.get('aws');
try{
awsService.kinesis().PutRecord({
Data: JSON.stringify(event.fullDocument),
StreamName: "stitchStream",
PartitionKey: "1"
}).then(function(response) {
return response;
});
}
catch(error){
console.log(JSON.parse(error));
}
};
</code></pre>
<h3 id="testoutthefunction">Test Out the Function</h3>
<p>Let?s make sure everything is working by calling that function manually. From the <strong>Function Editor</strong>, Click <strong>Console</strong> to view the interactive javascript console for Stitch.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044162image9-utm60qwobl.png" alt="" width="1999" height="947" class="aligncenter size-full wp-image-168430" /></p>
<p>Functions called from Triggers require an event. To test execution of our function, we?ll need to pass a dummy event to the function. Creating variables from the console in Stitch is simple. Simply set the value of the variable to a JSON document. For our simple example, use the following:</p>
<pre><code class="javascript language-javascript">event = {
"operationType": "replace",
"fullDocument": {
"color": "black",
"inventory": {
"$numberInt": "1"
},
"overview": "test document",
"price": {
"$numberDecimal": "123"
},
"type": "backpack"
},
"ns": {
"db": "streamdata",
"coll": "clickdata"
}
}
exports(event);
</code></pre>
<p>Paste the above into the console and click the button labeled <strong>Run Function As</strong>. Select a user and the function will execute.</p>
<p>Ta-da!</p>
<h3 id="puttingittogetherwithstitchtriggers">Putting It Together with Stitch Triggers</h3>
<p>We?ve got our MongoDB collection living in Atlas, receiving events from our web app. We?ve got our Kinesis stream ready for data. We?ve got a Stitch Function that can put data into a Kinesis stream.</p>
<p><a href="https://docs.mongodb.com/stitch/mongodb/triggers/">Configuring Stitch Triggers</a> is so simple it?s almost anticlimactic. Click <strong>Triggers</strong> from the left navigation, name your trigger, provide the database and collection context, and select the database events Stitch will react to with execution of a function.</p>
<p>For the database and collection, use the names from step one. Now we?ll set the operations we want to watch with our trigger. (Some triggers might care about all of them ? inserts, updates, deletes, and replacements ? while others can be more efficient because they logically can only matter for some of those.) In our case, we?re going to watch for insert, update and replace operations.</p>
<p>Now we specify our <em>putKinesisRecord</em> function as the linked function, and we?re done.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044235image4-mkz3w061j6.gif" alt="Figure 6. Trigger Configuration in Stitch" width="1430" height="928" class="aligncenter size-full wp-image-168431" /></p>
<p>As part of trigger execution, Stitch will forward details associated with the trigger event, including the full document involved in the event (i.e. the newly inserted, updated, or deleted document from the collection.) This is where we can evaluate some condition or attribute of the incoming document and decide whether or not to put the record onto a stream.</p>
<h3 id="testthetrigger">Test the Trigger!</h3>
<p>Amazon provides a dashboard which will enable you to view details associated with the data coming into your stream.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044263image3-fbdbnbh0zx.png" alt="Figure 7. Kinesis Stream Monitoring" width="1878" height="1021" class="aligncenter size-full wp-image-168432" /></p>
<p>As you execute the function from within Stitch, you?ll begin to see the data entering the Kinesis stream.</p>
<h3 id="buildingmorefunctionality">Building More Functionality</h3>
<p>So far our trigger is pretty basic ? it watches a collection and when any updates or inserts happen, it feeds the entire document to our Kinesis stream. From here we can build out some more intelligent functionality. To wrap up this post, let?s look at what we can do with the data once it?s been durably stored in MongoDB and placed into a stream.</p>
<p>Once the record is in the Kinesis Stream you can configure additional services downstream to act on the data. A common use case incorporates Amazon Kinesis Data Analytics to perform analytics on the streaming data. <a href="https://aws.amazon.com/kinesis/data-analytics/">Amazon Kinesis Data Analytics</a> offers pre-configured templates to accomplish things like anomaly detection, simple alerts, aggregations, and more.</p>
<p>For example, our stream of data will contain orders resulting from purchases. These orders may originate from point-of-sale systems, as well as from our web-based e-commerce application. Kinesis Analytics can be leveraged to create applications that process the incoming stream of data. For our example, we could build a <a href="https://docs.aws.amazon.com/kinesisanalytics/latest/dev/app-anomaly-detection.html">machine learning algorithm</a> to detect anomalies in the data or create a product performance leaderboard from a <a href="https://docs.aws.amazon.com/kinesisanalytics/latest/dev/sliding-window-concepts.html">sliding</a>, or <a href="https://docs.aws.amazon.com/kinesisanalytics/latest/dev/tumbling-window-concepts.html">tumbling</a> window of data from our stream.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044289image7-5c0nd1hscb.png" alt="Figure 8. Amazon Data Analytics - Anomaly Detection Example" width="1203" height="676" class="aligncenter size-full wp-image-168433" /></p>
<h3 id="wrappingup">Wrapping Up</h3>
<p>Now you can connect MongoDB to Kinesis. From here, you?re able to leverage any one of the many services offered from Amazon Web Services to build on your application. In our next article in the series, we?ll focus on getting the data back from Kinesis into MongoDB. In the meantime, let us know what you?re building with Atlas, Stitch, and Kinesis!</p>
<h4 id="resources">Resources</h4>
<p><strong>MongoDB Atlas</strong></p>
<ul>
<li><a href="https://www.mongodb.com/presentations/tutorial-series-getting-started-with-mongodb-atlas">Getting Started</a> &#8211; Tutorial Playlist</li>
<li><a href="https://www.mongodb.com/cloud/atlas/lp/general">Signup for Free</a></li>
<li><a href="https://www.mongodb.com/cloud/atlas/faq">FAQ</a></li>
</ul>
<p><strong>MongoDB Stitch</strong></p>
<ul>
<li><a href="https://docs.mongodb.com/stitch/getting-started/">Getting Started Documentation</a></li>
<li><a href="https://docs.mongodb.com/stitch/tutorials/">MongoDB Stitch Tutorials</a></li>
<li><a href="https://www.mongodb.com/collateral/mongodb-stitch-serverless-platform">MongoDB Stitch White Paper</a></li>
<li><a href="https://www.mongodb.com/webinar/mongodb-stitch">Webinar ? 8th August 2018</a></li>
</ul>
<p><strong>Amazon Kinesis</strong></p>
<ul>
<li><a href="https://docs.aws.amazon.com/streams/latest/dev/getting-started.html">Getting Started</a></li>
<li><a href="https://aws.amazon.com/kinesis/data-streams/">Kinesis Data Streams</a></li>
<li><a href="https://aws.amazon.com/kinesis/data-analytics/">Kinesis Data Analytics</a></li>
</ul>
date 2018-09-06T09:30:31date_gmt 2018-09-06T16:30:31excerpt`protectedrendered]<5D>Y<p class="wp-special"><em>This article was originally published on <a href="https://synd.co/2NCzyKk?" rel="canonical">MongoDB</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p>You can build your online, operational workloads atop MongoDB and still respond to events in real time by kicking off <a href="https://aws.amazon.com/kinesis/">Amazon Kinesis</a> stream processing actions, using MongoDB Stitch Triggers.</p>
<p>Let?s look at an example scenario in which a stream of data is being generated as a result of actions users take on a website. We?ll durably store the data and simultaneously feed a Kinesis process to do streaming analytics on something like cart abandonment, product recommendations, or even credit card fraud detection.</p>
<p>We?ll do this by setting up a Stitch Trigger. When relevant data updates are made in MongoDB, the trigger will use a Stitch Function to call out to AWS Kinesis, as you can see in this architecture diagram:</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536043981image5-d4wtr8tn5c.png" alt="" width="1525" height="844" class="aligncenter size-full wp-image-168426" /></p>
<h4 id="whatyoullneedtofollowalong">What you?ll need to follow along</h4>
<ol>
<li><strong>An Atlas instance</strong> <br />
If you don?t already have an application running on Atlas, you can follow our <a href="https://docs.atlas.mongodb.com/getting-started/">getting started with Atlas guide here</a>. In this example, we?ll be using a database called <em><strong>streamdata</strong></em>, with a collection called <em><strong>clickdata</strong></em> where we?re writing data from our web-based e-commerce application.</li>
<li><strong>An AWS account and a Kinesis stream</strong> <br />
In this example, we?ll use a Kinesis stream to send data downstream to additional applications such as Kinesis Analytics. This is the stream we want to feed our updates into.</li>
<li><strong>A Stitch application</strong> <br />
If you don?t already have a Stitch application, <a href="https://cloud.mongodb.com/user#/atlas/login">log into Atlas</a>, and click <strong>Stitch Apps</strong> from the navigation on the left, then click <strong>Create New Application</strong>.</li>
</ol>
<h3 id="createacollection">Create a Collection</h3>
<p>The first step is to create a database and collection from the Stitch application console. Click <strong>Rules</strong> from the left navigation menu and click the <strong>Add Collection</strong> button. Type <strong>streamdata</strong> for the database and <strong>clickdata</strong> for the collection name. Select the template labeled Users can <strong>only read and write their own data</strong> and provide a field name where we?ll specify the user id.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044010image2-51q4gsi7u2.png" alt="Figure 2. Create a collection" width="1999" height="923" class="aligncenter size-full wp-image-168427" /></p>
<h3 id="configuringstitchtotalktoaws">Configuring Stitch to Talk to AWS</h3>
<p>Stitch lets you configure <em>Services</em> to interact with external <a href="https://docs.mongodb.com/stitch/reference/partner-services/amazon-service/">services such as AWS Kinesis</a>. Choose <strong>Services</strong> from the navigation on the left, and click the <strong>Add a Service</strong> button, select the AWS service and set <strong>AWS <a href="https://aws.amazon.com/blogs/security/wheres-my-secret-access-key/">Access Key ID, and Secret Access Key</a></strong>.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044038image8-2a9rr3qc4k.png" alt="Figure 3. Service Configuration in Stitch" width="1999" height="1041" class="aligncenter size-full wp-image-168428" /></p>
<p><em>Services</em> use <em>Rules</em> to specify what aspect of a service Stitch can use, and how. Add a rule which will enable that service to communicate with Kinesis by clicking the button labeled NEW RULE. Name the rule ?kinesis? as we?ll be using this specific rule to enable communication with AWS Kinesis. In the section marked Action, select the API labeled Kinesis and select All Actions.</p>
<p><img src="https://www.sitepoint.com/wp-content/uploads/2018/09/1536044067image1-h45v2y48z7.gif" alt="Figure 4. Add a rule to enable integration with Kinesis" width="1424" height="746" class="aligncenter size-full wp-image-168429" /></p>
<h3 id="writeafunctionthatstreamsdocumentsintokinesis">Write a Function that Streams Documents into Kinesis</h3>
<p>Now that we have a working AWS service, we can use it to put records into a Kinesis stream. The way we do that in Stitch is with Functions. Let?s set up a <em>putKinesisRecord</em> function.</p>
<p>Select Functions from the left-hand menu, and click Create New Function. Provide a name for the function and paste the following in the body of the function.</p>
<p><img src="https://webassets.mongodb.com/_com_assets/cms/image6-7wtiny60ji.gif" alt="Figure 5. Example Function - putKinesisRecord" /></p>
<pre><code class="javascript language-javascript">exports = function(event){
const awsService = context.services.get('aws');
try{
awsService.kinesis().PutRecord({
Data: JSON.stringify(event.fullDocument),
StreamName: "stitchStream",
PartitionKey: "1"
}).then(function(response) {
return response;
});
}
catch(error){
console.log(JSON.parse(error));
}
};
</code></pre>
<h3 id="testoutthefunction">Test Out the Function</h3>
<p>Let?s make sure everything is working by calling that function manually. From the <strong>Function Editor</strong>, Click <strong>Console</strong> to view the interactive javascript console for Stitch.</p>
featured_media<01><> formatstandardguid_rendered0https://www.sitepoint.com/?p=168397id<01><>link]<5D>https://www.sitepoint.com/integrating-mongodb-and-amazon-kinesis-for-intelligent-durable-streams/meta<74>modified 2018-09-04T00:20:42modified_gmt 2018-09-04T07:20:42ping_statusclosedslugSintegrating-mongodb-and-amazon-kinesis-for-intelligent-durable-streams statuspublish stickytags<67><01><><01><01>btemplate
title_renderedTIntegrating MongoDB and Amazon Kinesis for Intelligent, Durable Streamstypepostv _linksh
about<EFBFBD>_href?https://www.sitepoint.com/wp-json/wp/v2/types/post author<6F>`embeddablehref@https://www.sitepoint.com/wp-json/wp/v2/users/72596collection<6F>_href:https://www.sitepoint.com/wp-json/wp/v2/posts curies<65>ahref$https://api.w.org/{rel}namewptemplatedreplies<65>`embeddablehrefIhttps://www.sitepoint.com/wp-json/wp/v2/comments?post=167869self<6C>_hrefAhttps://www.sitepoint.com/wp-json/wp/v2/posts/167869version-history<72>_hrefKhttps://www.sitepoint.com/wp-json/wp/v2/posts/167869/revisionswp:attachment<6E>_hrefHhttps://www.sitepoint.com/wp-json/wp/v2/media?parent=167869 wp:featuredmedia<69>`embeddablehrefAhttps://www.sitepoint.com/wp-json/wp/v2/media/167879wp:term<72>aembeddablehrefKhttps://www.sitepoint.com/wp-json/wp/v2/categories?post=167869taxonomycategoryaembeddablehrefEhttps://www.sitepoint.com/wp-json/wp/v2/tags?post=167869taxonomypost_tag author<01><>categories<65><01><01>comment_statusopencontent`protectedrendered]<5D><p><iframe width="900" height="506" src="https://www.youtube.com/embed/c9YzHtgsiKE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p class="wp-special"><em>This article was originally published on <a href="https://resource.alibabacloud.com/webinar/live.htm?spm=a2c5p.11425181.0.0.4d913c86X8D869&#038;webinarId=26" rel="canonical">Alibaba Cloud</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p class="wp-special"><strong>Think you got a better tip for making the best use of Alibaba Cloud services? Tell us about it and go in for your chance to win a Macbook Pro (plus other cool stuff). <a href="https://www.sitepoint.com/alibaba-competition">Find out more here</a>.</strong></p>
<p>Gain an introduction to ApsaraDB for RDS, a cloud-based relational database product provided by Alibaba Cloud. In this webinar you will watch over the shoulder of a Solution Architect and Trainer, as he covers the basic concepts and features of ApsaraDB for RDS including:</p>
<ul>
<li>HA feature (Master/Slave Architecture, Backup/Recovery, Temporary Instance)</li>
<li>Scalability features (Read-only Instance)</li>
<li>Security and Monitoring features</li>
</ul>
<p>This webinar is ideally suited for database engineers and beginners to the Alibaba Cloud product suite.</p>
date 2018-09-05T09:30:47date_gmt 2018-09-05T16:30:47excerpt`protectedrendered]<5D><p><iframe width="560" height="315" src="https://www.youtube.com/embed/c9YzHtgsiKE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe></p>
<p class="wp-special"><em>This article was originally published on <a href="https://resource.alibabacloud.com/webinar/live.htm?spm=a2c5p.11425181.0.0.4d913c86X8D869&#038;webinarId=26" rel="canonical">Alibaba Cloud</a>. Thank you for supporting the partners who make SitePoint possible.</em></p>
<p>Gain an introduction to ApsaraDB for RDS, a cloud-based relational database product provided by Alibaba Cloud. In this webinar you will watch over the shoulder of a Solution Architect and Trainer, as he covers the basic concepts and features of ApsaraDB for RDS including:</p>
<ul>
<li>HA feature (Master/Slave Architecture, Backup/Recovery, Temporary Instance)</li>
<li>Scalability features (Read-only Instance)</li>
<li>Security and Monitoring features</li>
</ul>
<p>This webinar is ideally suited for database engineers and beginners to the Alibaba Cloud product suite.</p>
featured_media<01><> formatstandardguid_rendered0https://www.sitepoint.com/?p=167869id<01><>link]<5D>https://www.sitepoint.com/how-to-set-up-a-secure-relational-database-on-alibaba-cloud/meta<74>modified 2018-09-06T01:21:52modified_gmt 2018-09-06T08:21:52ping_statusclosedslugHhow-to-set-up-a-secure-relational-database-on-alibaba-cloud statuspublish stickytags<67><01><><01><>template
title_renderedHHow to Set up a Secure Relational Database on Alibaba Cloudtypepost

View File

@@ -1,12 +0,0 @@
plugins {
alias(catalog.plugins.envelope)
}
dependencies {
implementation catalog.picocli
implementation project(':wcfg')
}
envelopeJar {
mainClass = 'net.woggioni.wson.wcfg.cli.Main'
}

View File

@@ -1,3 +0,0 @@
module net.woggioni.wson.wcfg.cli {
requires net.woggioni.wson.wcfg;
}

View File

@@ -1,7 +0,0 @@
package net.woggioni.wson.wcfg.cli;
public class Main {
public void main(String[] args) {
System.out.println();
}
}

View File

@@ -2,12 +2,18 @@ plugins {
id 'antlr' id 'antlr'
} }
configurations {
api {
exclude group: 'org.antlr', module: 'antlr4'
}
}
dependencies { dependencies {
implementation catalog.jwo implementation catalog.jwo
implementation rootProject implementation rootProject
implementation catalog.antlr.runtime
antlr catalog.antlr antlr catalog.antlr
antlr catalog.antlr.runtime
} }
generateGrammarSource { generateGrammarSource {

View File

@@ -1,15 +1,19 @@
grammar WCFG; grammar WCFG;
wcfg wcfg
: assignment* : assignment* export?
; ;
export
: 'export' value ';'
;
assignment assignment
: IDENTIFIER ':=' (expression | value) ';' : IDENTIFIER ':=' value ';'
; ;
expression expression
: value ('<<' value)+ : (obj | IDENTIFIER) ('<<' (obj | IDENTIFIER))+
; ;
obj obj
@@ -18,7 +22,7 @@ obj
; ;
pair pair
: STRING ':' (expression | value) : STRING ':' value
; ;
array array
@@ -34,6 +38,7 @@ value
| IDENTIFIER | IDENTIFIER
| obj | obj
| array | array
| expression
; ;
BOOLEAN BOOLEAN

View File

@@ -1,6 +1,6 @@
module net.woggioni.wson.wcfg { module net.woggioni.wson.wcfg {
requires static lombok; requires static lombok;
requires static org.antlr.antlr4.runtime; requires org.antlr.antlr4.runtime;
requires net.woggioni.jwo; requires net.woggioni.jwo;
requires net.woggioni.wson; requires net.woggioni.wson;

View File

@@ -1,6 +1,7 @@
package net.woggioni.wson.wcfg; package net.woggioni.wson.wcfg;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.woggioni.jwo.LazyValue;
import net.woggioni.wson.traversal.ValueIdentity; import net.woggioni.wson.traversal.ValueIdentity;
import net.woggioni.wson.value.ObjectValue; import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value; import net.woggioni.wson.xface.Value;
@@ -11,53 +12,55 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import static net.woggioni.jwo.JWO.dynamicCast;
@RequiredArgsConstructor @RequiredArgsConstructor
public class CompositeObjectValue implements ObjectValue { public class CompositeObjectValue implements ObjectValue {
private final List<ObjectValue> elements; private final List<? extends Value> elements;
private ObjectValue wrapped; private LazyValue<ObjectValue> wrapped;
public CompositeObjectValue(List<ObjectValue> elements, Value.Configuration cfg) { public CompositeObjectValue(List<? extends Value> elements, Value.Configuration cfg) {
this.elements = elements; this.elements = elements;
wrapped = ObjectValue.newInstance(cfg); this.wrapped = LazyValue.of(() -> {
List<ValueIdentity> identities = new ArrayList<>(); ObjectValue result = ObjectValue.newInstance(cfg);
for (ObjectValue element : elements) { List<ValueIdentity> identities = new ArrayList<>();
CompositeObjectValue compositeObjectValue; for (Value element : elements) {
if ((compositeObjectValue = dynamicCast(element, CompositeObjectValue.class)) != null) { if (element instanceof CompositeObjectValue compositeObjectValue) {
boolean differenceFound = false; boolean differenceFound = false;
for (int i = 0; i < compositeObjectValue.elements.size(); i++) { for (int i = 0; i < compositeObjectValue.elements.size(); i++) {
ObjectValue objectValue = compositeObjectValue.elements.get(i); ObjectValue objectValue = (ObjectValue) compositeObjectValue.elements.get(i);
if (!differenceFound && (i >= identities.size() || !Objects.equals( if (!differenceFound && (i >= identities.size() || !Objects.equals(
identities.get(i), identities.get(i),
new ValueIdentity(compositeObjectValue.elements.get(i))))) { new ValueIdentity(compositeObjectValue.elements.get(i))))) {
differenceFound = true; differenceFound = true;
} }
if (differenceFound) { if (differenceFound) {
merge(wrapped, objectValue); merge(result, objectValue);
identities.add(new ValueIdentity(objectValue)); identities.add(new ValueIdentity(objectValue));
}
} }
} else {
merge(result, (ObjectValue) element);
identities.add(new ValueIdentity(element));
} }
} else {
merge(wrapped, element);
identities.add(new ValueIdentity(element));
} }
} return result;
}, LazyValue.ThreadSafetyMode.NONE);
} }
private static void merge(ObjectValue v1, ObjectValue v2) { private static void merge(ObjectValue v1, ObjectValue v2) {
for (Map.Entry<String, Value> entry : v2) { for (Map.Entry<String, Value> entry : v2) {
Value putResult = v1.getOrPut(entry.getKey(), entry.getValue()); String key = entry.getKey();
if (putResult != entry.getValue()) { Value value2put = entry.getValue();
if (putResult.type() == Value.Type.OBJECT && entry.getValue().type() == Value.Type.OBJECT) { Value putResult = v1.getOrPut(key, value2put);
if (putResult != value2put) {
if (putResult.type() == Value.Type.OBJECT && value2put.type() == Value.Type.OBJECT) {
ObjectValue ov = ObjectValue.newInstance(); ObjectValue ov = ObjectValue.newInstance();
merge(ov, (ObjectValue) putResult); merge(ov, (ObjectValue) putResult);
merge(ov, (ObjectValue) entry.getValue()); merge(ov, (ObjectValue) value2put);
v1.put(entry.getKey(), ov); v1.put(key, ov);
} else { } else {
v1.put(entry.getKey(), entry.getValue()); v1.put(key, value2put);
} }
} }
} }
@@ -65,27 +68,27 @@ public class CompositeObjectValue implements ObjectValue {
@Override @Override
public Iterator<Map.Entry<String, Value>> iterator() { public Iterator<Map.Entry<String, Value>> iterator() {
return wrapped.iterator(); return wrapped.get().iterator();
} }
@Override @Override
public Value get(String key) { public Value get(String key) {
return wrapped.get(key); return wrapped.get().get(key);
} }
@Override @Override
public Value getOrDefault(String key, Value defaultValue) { public Value getOrDefault(String key, Value defaultValue) {
return wrapped.getOrDefault(key, defaultValue); return wrapped.get().getOrDefault(key, defaultValue);
} }
@Override @Override
public boolean has(String key) { public boolean has(String key) {
return wrapped.has(key); return wrapped.get().has(key);
} }
@Override @Override
public int size() { public int size() {
return wrapped.size(); return wrapped.get().size();
} }
@Override @Override

View File

@@ -0,0 +1,18 @@
package net.woggioni.wson.wcfg;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
class ErrorHandler extends BaseErrorListener {
@Override
public void syntaxError(Recognizer<?, ?> recognizer,
Object offendingSymbol,
int line, int charPositionInLine,
String msg,
RecognitionException e) {
throw new SyntaxError(msg, line, charPositionInLine);
}
}

View File

@@ -1,6 +1,9 @@
package net.woggioni.wson.wcfg; package net.woggioni.wson.wcfg;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.woggioni.jwo.JWO;
import net.woggioni.wson.value.ArrayValue; import net.woggioni.wson.value.ArrayValue;
import net.woggioni.wson.value.BooleanValue; import net.woggioni.wson.value.BooleanValue;
import net.woggioni.wson.value.FloatValue; import net.woggioni.wson.value.FloatValue;
@@ -10,27 +13,45 @@ import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.value.StringValue; import net.woggioni.wson.value.StringValue;
import net.woggioni.wson.xface.Value; import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import static net.woggioni.jwo.JWO.dynamicCast; import static net.woggioni.jwo.JWO.newThrowable;
import static net.woggioni.jwo.JWO.tail;
class ListenerImpl implements WCFGListener { class ListenerImpl implements WCFGListener {
private final Value.Configuration cfg; private final Value.Configuration cfg;
@Getter @Getter
private final Value result; private Value result;
private final List<ValueHolder> holders = new ArrayList<>(); private final Map<String, ValueHolder> unresolvedReferences = new TreeMap<>();
private interface StackLevel { private interface StackLevel {
Value getValue(); Value getValue();
} }
@RequiredArgsConstructor
private static class ExportStackLevel implements StackLevel {
@Setter
private Value value;
@Override
public Value getValue() {
return value;
}
}
private static class ArrayStackLevel implements StackLevel { private static class ArrayStackLevel implements StackLevel {
private final ArrayValue value = new ArrayValue(); private final ArrayValue value = new ArrayValue();
@@ -57,7 +78,7 @@ class ListenerImpl implements WCFGListener {
private static class ExpressionStackLevel implements StackLevel { private static class ExpressionStackLevel implements StackLevel {
private final Value.Configuration cfg; private final Value.Configuration cfg;
private ObjectValue value = null; private ObjectValue value = null;
public List<ObjectValue> elements = new ArrayList<>(); public List<Value> elements = new ArrayList<>();
public ExpressionStackLevel(Value.Configuration cfg) { public ExpressionStackLevel(Value.Configuration cfg) {
this.cfg = cfg; this.cfg = cfg;
@@ -65,8 +86,19 @@ class ListenerImpl implements WCFGListener {
@Override @Override
public Value getValue() { public Value getValue() {
if(value == null) { if (value == null) {
value = new CompositeObjectValue(elements, cfg); List<ObjectValue> objects = elements.stream()
.map(it -> {
if (it instanceof ObjectValue ov)
return ov;
else if (it instanceof ValueHolder vh) {
return (ObjectValue) vh.getDelegate();
} else {
throw newThrowable(RuntimeException.class, "");
}
})
.collect(Collectors.toList());
value = new CompositeObjectValue(objects, cfg);
} }
return value; return value;
} }
@@ -75,26 +107,37 @@ class ListenerImpl implements WCFGListener {
private final List<StackLevel> stack = new ArrayList<>(); private final List<StackLevel> stack = new ArrayList<>();
private void add2Last(Value value) { private void add2Last(Value value) {
StackLevel last = stack.get(stack.size() - 1); StackLevel last = tail(stack);
if (last instanceof ArrayStackLevel asl) { if (last instanceof ArrayStackLevel asl) {
asl.value.add(value); asl.value.add(value);
if(value instanceof ValueHolder holder) { if (value instanceof ValueHolder holder) {
Value arrayValue = asl.getValue(); Value arrayValue = asl.getValue();
int index = arrayValue.size() - 1; int index = arrayValue.size() - 1;
holder.addDeleter(() -> arrayValue.set(index, holder.getDelegate())); holder.addDeleter(() -> arrayValue.set(index, holder.getDelegate()));
} }
} else if (last instanceof ObjectStackLevel osl) { } else if (last instanceof ObjectStackLevel osl) {
String key = osl.currentKey; String key = osl.currentKey;
osl.currentKey = null; Value objectValue = osl.getValue();
osl.value.put(key, value); objectValue.put(key, value);
if(value instanceof ValueHolder holder) { if (value instanceof ValueHolder holder) {
Value objectValue = osl.getValue(); holder.addDeleter(() -> {
holder.addDeleter(() -> objectValue.put(key, holder.getDelegate())); objectValue.put(key, holder.getDelegate());
});
} }
} else if(last instanceof ExpressionStackLevel esl) { } else if (last instanceof ExpressionStackLevel esl) {
esl.elements.add((ObjectValue) value); List<Value> values = esl.elements;
int index = values.size();
values.add(value);
if (value instanceof ValueHolder holder) {
holder.addDeleter(() -> {
values.set(index, holder.getDelegate());
});
}
} else if (last instanceof ExportStackLevel esl) {
esl.setValue(value);
} }
} }
private static String unquote(String quoted) { private static String unquote(String quoted) {
return quoted.substring(1, quoted.length() - 1); return quoted.substring(1, quoted.length() - 1);
} }
@@ -121,6 +164,17 @@ class ListenerImpl implements WCFGListener {
@Override @Override
public void exitWcfg(WCFGParser.WcfgContext ctx) { public void exitWcfg(WCFGParser.WcfgContext ctx) {
stack.clear(); stack.clear();
for (ValueHolder holder : unresolvedReferences.values()) {
if (holder.getDelegate() == null) {
TerminalNode node = holder.getNode();
throw new ParseError(
"Undeclared identifier '" + node.getText() + "'",
node.getSymbol().getLine(),
node.getSymbol().getCharPositionInLine() + 1
);
}
holder.replace();
}
} }
@Override @Override
@@ -128,15 +182,15 @@ class ListenerImpl implements WCFGListener {
ObjectStackLevel osl = (ObjectStackLevel) stack.get(0); ObjectStackLevel osl = (ObjectStackLevel) stack.get(0);
String key = ctx.IDENTIFIER().getText(); String key = ctx.IDENTIFIER().getText();
osl.currentKey = key; osl.currentKey = key;
ValueHolder holder = new ValueHolder(); ValueHolder holder = unresolvedReferences.computeIfAbsent(key, it -> new ValueHolder(ctx.IDENTIFIER()));
holders.add(holder); // holder.addDeleter(() -> holder.setDelegate(result.get(key)));
holder.addDeleter(() -> result.put(key, holder.getDelegate()));
result.put(key, holder);
} }
@Override @Override
public void exitAssignment(WCFGParser.AssignmentContext ctx) { public void exitAssignment(WCFGParser.AssignmentContext ctx) {
ObjectStackLevel osl = (ObjectStackLevel) stack.get(0); ObjectStackLevel osl = (ObjectStackLevel) stack.get(0);
String key = osl.currentKey;
unresolvedReferences.get(key).setDelegate(osl.getValue().get(key));
osl.currentKey = null; osl.currentKey = null;
} }
@@ -144,6 +198,16 @@ class ListenerImpl implements WCFGListener {
public void enterExpression(WCFGParser.ExpressionContext ctx) { public void enterExpression(WCFGParser.ExpressionContext ctx) {
ExpressionStackLevel esl = new ExpressionStackLevel(cfg); ExpressionStackLevel esl = new ExpressionStackLevel(cfg);
stack.add(esl); stack.add(esl);
for(TerminalNode node : ctx.IDENTIFIER()) {
String key = node.getSymbol().getText();
ValueHolder holder = unresolvedReferences
.computeIfAbsent(key, k -> new ValueHolder(node));
int index = esl.elements.size();
esl.elements.add(holder);
holder.addDeleter(() -> {
esl.elements.set(index, holder.getDelegate());
});
}
} }
@Override @Override
@@ -200,16 +264,25 @@ class ListenerImpl implements WCFGListener {
} else { } else {
add2Last(new FloatValue(Double.parseDouble(text))); add2Last(new FloatValue(Double.parseDouble(text)));
} }
} else if(ctx.IDENTIFIER() != null) { } else if (ctx.IDENTIFIER() != null) {
String name = ctx.IDENTIFIER().getText(); String name = ctx.IDENTIFIER().getText();
Value referredValue = result.getOrDefault(name, null); ValueHolder referredValue = unresolvedReferences.computeIfAbsent(name,
if(referredValue == null) { it -> new ValueHolder(ctx.IDENTIFIER())
throw new ParseError( );
"Undeclared identifier '" + name + "'", // referredValue.addError(() -> new ParseError(
ctx.start.getLine(), // "Undeclared identifier '" + name + "'",
ctx.start.getCharPositionInLine() + 1 // ctx.start.getLine(),
); // ctx.start.getCharPositionInLine() + 1
} // )
// );
// Value referredValue = result.getOrDefault(name, null);
// if(referredValue == null) {
// throw new ParseError(
// "Undeclared identifier '" + name + "'",
// ctx.start.getLine(),
// ctx.start.getCharPositionInLine() + 1
// );
// }
add2Last(referredValue); add2Last(referredValue);
} }
} }
@@ -238,9 +311,19 @@ class ListenerImpl implements WCFGListener {
} }
public void replaceHolders() { @Override
for(ValueHolder holder : holders) { public void enterExport(WCFGParser.ExportContext ctx) {
holder.replace(); ExportStackLevel esl = new ExportStackLevel();
stack.add(esl);
}
@Override
public void exitExport(WCFGParser.ExportContext ctx) {
result = pop().getValue();
if (result instanceof ValueHolder holder) {
holder.addDeleter(() -> {
result = holder.getDelegate();
});
} }
} }
} }

View File

@@ -0,0 +1,15 @@
package net.woggioni.wson.wcfg;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class SyntaxError extends RuntimeException {
public SyntaxError(String message, int line, int column) {
super(message + String.format(" at %d:%d", line, column));
}
@Override
public String getMessage() {
return super.getMessage();
}
}

View File

@@ -1,23 +1,32 @@
package net.woggioni.wson.wcfg; package net.woggioni.wson.wcfg;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.SneakyThrows;
import net.woggioni.wson.xface.Value; import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
@RequiredArgsConstructor
class ValueHolder implements Value { class ValueHolder implements Value {
private List<Runnable> deleters = new ArrayList<>();
@Getter
private final TerminalNode node;
private List<Runnable> deleters = new ArrayList<>();
public void addDeleter(Runnable runnable) { public void addDeleter(Runnable runnable) {
deleters.add(runnable); deleters.add(runnable);
} }
@Setter @Setter
@Getter @Getter
private Value delegate = Value.Null; private Value delegate = null;
@Override @Override
public Type type() { public Type type() {
return delegate.type(); return delegate.type();

View File

@@ -18,12 +18,14 @@ public class WConfig {
private final Value value; private final Value value;
@SneakyThrows @SneakyThrows
public WConfig(Reader reader, Value.Configuration cfg) { private WConfig(Reader reader, Value.Configuration cfg) {
this.cfg = cfg; this.cfg = cfg;
CodePointCharStream inputStream = CharStreams.fromReader(reader); CodePointCharStream inputStream = CharStreams.fromReader(reader);
WCFGLexer lexer = new WCFGLexer(inputStream); WCFGLexer lexer = new WCFGLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
WCFGParser parser = new WCFGParser(commonTokenStream); WCFGParser parser = new WCFGParser(commonTokenStream);
parser.removeErrorListeners();
parser.addErrorListener(new ErrorHandler());
ListenerImpl listener = new ListenerImpl(cfg); ListenerImpl listener = new ListenerImpl(cfg);
ParseTreeWalker walker = new ParseTreeWalker(); ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.wcfg()); walker.walk(listener, parser.wcfg());
@@ -44,4 +46,8 @@ public class WConfig {
public Value whole() { public Value whole() {
return value; return value;
} }
public static WConfig parse(Reader reader, Value.Configuration cfg) {
return new WConfig(reader, cfg);
}
} }

View File

@@ -2,6 +2,7 @@ package net.woggioni.wson.wcfg;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.woggioni.wson.serialization.json.JSONDumper; import net.woggioni.wson.serialization.json.JSONDumper;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.xface.Value; import net.woggioni.wson.xface.Value;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream; import org.antlr.v4.runtime.CodePointCharStream;
@@ -23,24 +24,21 @@ public class ParseTest {
@SneakyThrows @SneakyThrows
@ParameterizedTest @ParameterizedTest
@ValueSource(strings = { @ValueSource(strings = {
// "build.wcfg", "build.wcfg",
// "test.wcfg", "test.wcfg",
// "recursive.wcfg", "recursive.wcfg",
"recursive2.wcfg", "recursive2.wcfg",
"recursive3.wcfg",
}) })
public void test(String resource) { public void test(String resource) {
Value.Configuration cfg = Value.Configuration.builder()
.objectValueImplementation(ObjectValue.Implementation.HashMap)
.serializeReferences(true)
.build();
try(Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resource))) { try(Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(resource))) {
CodePointCharStream inputStream = CharStreams.fromReader(reader); WConfig wcfg = WConfig.parse(reader, cfg);
WCFGLexer lexer = new WCFGLexer(inputStream); new JSONDumper(cfg).dump(wcfg.whole(), System.out);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer); System.out.println();
WCFGParser parser = new WCFGParser(commonTokenStream);
Value.Configuration cfg = Value.Configuration.builder().serializeReferences(true).build();
ListenerImpl listener = new ListenerImpl(cfg);
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, parser.wcfg());
listener.replaceHolders();
Value result = listener.getResult();
new JSONDumper(cfg).dump(result, System.out);
} }
} }
@@ -49,8 +47,8 @@ public class ParseTest {
public void test2() { public void test2() {
Value.Configuration cfg = Value.Configuration.builder().serializeReferences(true).build(); Value.Configuration cfg = Value.Configuration.builder().serializeReferences(true).build();
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream("/build.wcfg"))) { try (Reader reader = new InputStreamReader(getClass().getResourceAsStream("/build.wcfg"))) {
WConfig wConfig = new WConfig(reader, cfg); WConfig wcfg = WConfig.parse(reader, cfg);
Value result = wConfig.get("release", "dev"); Value result = wcfg.get("release", "dev");
try (OutputStream os = new BufferedOutputStream(new FileOutputStream("/tmp/build.json"))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream("/tmp/build.json"))) {
new JSONDumper(cfg).dump(result, os); new JSONDumper(cfg).dump(result, os);
} }

View File

@@ -0,0 +1,5 @@
value := [1, 2, value2, null, false];
value2 := [3, 4, value, null, true, value3];
value3 := {"key" : "Some string" };

View File

@@ -21,3 +21,5 @@ foobar := {
"enabled" : true "enabled" : true
} }
}; };
export default << foobar;

View File

@@ -1,21 +1,68 @@
plugins { plugins {
id 'maven-publish' id 'maven-publish'
alias catalog.plugins.envelope alias catalog.plugins.envelope
alias catalog.plugins.kotlin.jvm alias catalog.plugins.graalvm.native.image
alias catalog.plugins.sambal
} }
import net.woggioni.gradle.graalvm.NativeImageTask
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
dependencies { dependencies {
implementation catalog.kotlin.stdlib.jdk8 implementation catalog.jwo
implementation catalog.jcommander implementation catalog.picocli
implementation catalog.slf4j.simple implementation catalog.slf4j.simple
implementation rootProject implementation rootProject
implementation project(':wcfg')
} }
envelopeJar { application {
mainClass = 'net.woggioni.wson.cli.MainKt' mainClass = 'net.woggioni.wson.cli.WsonCli'
mainModule = 'net.woggioni.wson.cli' mainModule = 'net.woggioni.wson.cli'
} }
compileJava {
options.compilerArgs = [
"--patch-module",
"net.woggioni.wson.cli=${sourceSets.main.output.asPath}"
]
options.javaModuleMainClass = 'net.woggioni.wson.cli.MainKt'
options.javaModuleVersion = project.version
}
configureNativeImage {
// args = [
// 'wson',
// '-f',
// '../test-utils/src/main/resources/wordpress.json',
// '-t',
// 'jbon',
// '-o',
// '/dev/null'
// ]
args = [
'wcfg',
'-f',
'../wcfg/src/test/resources/build.wcfg',
'-t',
'jbon',
'-o',
'/dev/null'
]
mergeConfiguration = true
}
Provider<NativeImageTask> nativeImageTaskProvider = tasks.named("nativeImage") {
useMusl = true
buildStaticImage = true
}
artifacts {
archives nativeImageTaskProvider.map(NativeImageTask.&getOutputFile)
}
publishing { publishing {
repositories { repositories {
maven { maven {
@@ -25,7 +72,11 @@ publishing {
publications { publications {
myDistribution(MavenPublication) { myDistribution(MavenPublication) {
artifact envelopeJar artifact envelopeJar
def host = DefaultNativePlatform.host()
artifact(
source: nativeImageTaskProvider,
classifier: host.operatingSystem.name + '-' + host.architecture.name
)
} }
} }
} }

View File

@@ -0,0 +1,6 @@
[
{
"name":"java.lang.Boolean",
"methods":[{"name":"getBoolean","parameterTypes":["java.lang.String"] }]
}
]

View File

@@ -0,0 +1 @@
Args=-H:Optimize=3 --initialize-at-run-time=net.woggioni.wson.cli.WsonCli

View File

@@ -0,0 +1,8 @@
[
{
"type":"agent-extracted",
"classes":[
]
}
]

View File

@@ -0,0 +1,2 @@
[
]

View File

@@ -0,0 +1,248 @@
[
{
"name":"com.sun.crypto.provider.AESCipher$General",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.ARCFOURCipher",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.ChaCha20Cipher$ChaCha20Poly1305",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.DESCipher",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.DESedeCipher",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.sun.crypto.provider.GaloisCounterMode$AESGCM",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"groovy.lang.Closure"
},
{
"name":"java.lang.Object",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"java.nio.file.Path"
},
{
"name":"java.nio.file.Paths",
"methods":[{"name":"get","parameterTypes":["java.lang.String","java.lang.String[]"] }]
},
{
"name":"java.security.AlgorithmParametersSpi"
},
{
"name":"java.security.KeyStoreSpi"
},
{
"name":"java.security.SecureRandomParameters"
},
{
"name":"java.sql.Connection"
},
{
"name":"java.sql.Driver"
},
{
"name":"java.sql.DriverManager",
"methods":[{"name":"getConnection","parameterTypes":["java.lang.String"] }, {"name":"getDriver","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.sql.Time",
"methods":[{"name":"<init>","parameterTypes":["long"] }]
},
{
"name":"java.sql.Timestamp",
"methods":[{"name":"valueOf","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.time.Duration",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.Instant",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.LocalDate",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.LocalDateTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.LocalTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.MonthDay",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.OffsetDateTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.OffsetTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.Period",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.Year",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.YearMonth",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"java.time.ZoneId",
"methods":[{"name":"of","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.time.ZoneOffset",
"methods":[{"name":"of","parameterTypes":["java.lang.String"] }]
},
{
"name":"java.time.ZonedDateTime",
"methods":[{"name":"parse","parameterTypes":["java.lang.CharSequence"] }]
},
{
"name":"javax.security.auth.x500.X500Principal",
"fields":[{"name":"thisX500Name"}],
"methods":[{"name":"<init>","parameterTypes":["sun.security.x509.X500Name"] }]
},
{
"name":"net.woggioni.wson.cli.OutputTypeConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"net.woggioni.wson.cli.SerializationTypeConverter",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"net.woggioni.wson.cli.VersionProvider",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"net.woggioni.wson.cli.WcfgCommand",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"net.woggioni.wson.cli.WsonCli",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"net.woggioni.wson.cli.WsonCommand",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.pkcs12.PKCS12KeyStore$DualFormatPKCS12",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.JavaKeyStore$JKS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.NativePRNG",
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"<init>","parameterTypes":["java.security.SecureRandomParameters"] }]
},
{
"name":"sun.security.provider.SHA",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.provider.X509Factory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.rsa.RSAKeyFactory$Legacy",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.KeyManagerFactoryImpl$SunX509",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.SSLContextImpl$DefaultSSLContext",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.ssl.TrustManagerFactoryImpl$PKIXFactory",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"sun.security.x509.AuthorityInfoAccessExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.AuthorityKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.BasicConstraintsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CRLDistributionPointsExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.CertificatePoliciesExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.ExtendedKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.IssuerAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.KeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.NetscapeCertTypeExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.PrivateKeyUsageExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectAlternativeNameExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
},
{
"name":"sun.security.x509.SubjectKeyIdentifierExtension",
"methods":[{"name":"<init>","parameterTypes":["java.lang.Boolean","java.lang.Object"] }]
}
]

View File

@@ -0,0 +1,17 @@
{
"resources":{
"includes":[{
"pattern":"\\QMETA-INF/MANIFEST.MF\\E"
}, {
"pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E"
}, {
"pattern":"\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E"
}, {
"pattern":"\\QMETA-INF/services/java.time.zone.ZoneRulesProvider\\E"
}, {
"pattern":"\\QMETA-INF/services/org.slf4j.spi.SLF4JServiceProvider\\E"
}, {
"pattern":"\\Qsimplelogger.properties\\E"
}]},
"bundles":[]
}

View File

@@ -0,0 +1,8 @@
{
"types":[
],
"lambdaCapturingTypes":[
],
"proxies":[
]
}

View File

@@ -1,8 +0,0 @@
module net.woggioni.wson.cli {
requires kotlin.stdlib;
requires kotlin.stdlib.jdk8;
requires net.woggioni.wson;
requires com.beust.jcommander;
opens net.woggioni.wson.cli to com.beust.jcommander;
}

View File

@@ -1,4 +0,0 @@
package net.woggioni.wson.cli;
public class Foo {
}

View File

@@ -0,0 +1,12 @@
module net.woggioni.wson.cli {
requires static lombok;
requires net.woggioni.jwo;
requires net.woggioni.wson;
requires net.woggioni.wson.wcfg;
requires org.slf4j;
requires org.slf4j.simple;
requires info.picocli;
exports net.woggioni.wson.cli;
opens net.woggioni.wson.cli to info.picocli;
}

View File

@@ -0,0 +1,51 @@
package net.woggioni.wson.cli;
import lombok.SneakyThrows;
import picocli.CommandLine;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
abstract class AbstractVersionProvider implements CommandLine.IVersionProvider {
private String version;
private String vcsHash;
@SneakyThrows
protected AbstractVersionProvider(String specificationTitle) {
String version = null;
String vcsHash = null;
Enumeration<URL> it = getClass().getClassLoader().getResources(JarFile.MANIFEST_NAME);
while (it.hasMoreElements()) {
URL manifestURL = it.nextElement();
Manifest mf = new Manifest();
try (InputStream inputStream = manifestURL.openStream()) {
mf.read(inputStream);
}
Attributes mainAttributes = mf.getMainAttributes();
if (Objects.equals(specificationTitle, mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE))) {
version = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
vcsHash = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
}
}
if (version == null || vcsHash == null) {
throw new RuntimeException("Version information not found in manifest");
}
this.version = version;
this.vcsHash = vcsHash;
}
@Override
public String[] getVersion() {
if (version.endsWith("-SNAPSHOT")) {
return new String[]{version, vcsHash};
} else {
return new String[]{version};
}
}
}

View File

@@ -0,0 +1,34 @@
package net.woggioni.wson.cli;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static net.woggioni.jwo.JWO.newThrowable;
@RequiredArgsConstructor
enum SerializationFormat {
JSON("json"), JBON("jbon");
private final String name;
public static SerializationFormat parse(String value) {
return Arrays.stream(SerializationFormat.values())
.filter(sf -> Objects.equals(sf.name, value))
.findFirst()
.orElseThrow(() -> {
var availableValues = Stream.of(
JSON,
JBON
).map(SerializationFormat::name).collect(Collectors.joining(", "));
throw newThrowable(IllegalArgumentException.class,
"Unknown serialization format '%s', possible values are %s",
value, availableValues
);
});
}
}

View File

@@ -0,0 +1,10 @@
package net.woggioni.wson.cli;
import picocli.CommandLine;
class SerializationTypeConverter implements CommandLine.ITypeConverter<SerializationFormat> {
@Override
public SerializationFormat convert(String value) {
return SerializationFormat.parse(value);
}
}

View File

@@ -0,0 +1,7 @@
package net.woggioni.wson.cli;
class VersionProvider extends AbstractVersionProvider {
protected VersionProvider() {
super("wson-cli");
}
}

View File

@@ -0,0 +1,92 @@
package net.woggioni.wson.cli;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import net.woggioni.jwo.Fun;
import net.woggioni.wson.serialization.binary.JBONDumper;
import net.woggioni.wson.serialization.json.JSONDumper;
import net.woggioni.wson.value.ObjectValue;
import net.woggioni.wson.wcfg.WConfig;
import net.woggioni.wson.xface.Value;
import picocli.CommandLine;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
@CommandLine.Command(
name = "wcfg",
versionProvider = VersionProvider.class)
public class WcfgCommand implements Runnable {
@CommandLine.Option(
names = {"-f", "--file"},
description = {"Name of the input file to parse"}
)
private Path fileName;
@CommandLine.Option(names = {"-o", "--output"},
description = {"Name of the JSON file to generate"})
private Path output;
@CommandLine.Option(
names = {"-t", "--type"},
description = {"Output type"},
converter = {SerializationTypeConverter.class})
private SerializationFormat outputType = SerializationFormat.JSON;
@CommandLine.Option(names = {"-d", "--resolve-refernces"}, description = "Resolve references")
private boolean resolveReferences = false;
@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true)
private boolean help = false;
@SneakyThrows
public void run() {
Value.Configuration cfg = Value.Configuration.builder()
.objectValueImplementation(ObjectValue.Implementation.LinkedHashMap)
.serializeReferences(!resolveReferences)
.build();
InputStream inputStream;
if (fileName != null) {
inputStream = new BufferedInputStream(Files.newInputStream(fileName));
} else {
inputStream = System.in;
}
Value result;
try(Reader reader = new InputStreamReader(inputStream)) {
WConfig wcfg = WConfig.parse(reader, cfg);
result = wcfg.whole();
}
OutputStream outputStream = Optional.ofNullable(output)
.map((Fun<Path, OutputStream>) Files::newOutputStream)
.<OutputStream>map(BufferedOutputStream::new)
.orElse(System.out);
switch (outputType) {
case JSON:
try (Writer writer = new OutputStreamWriter(outputStream)) {
new JSONDumper(cfg).dump(result, writer);
}
break;
case JBON:
try {
new JBONDumper(cfg).dump(result, outputStream);
} finally {
outputStream.close();
}
}
}
}

View File

@@ -0,0 +1,33 @@
package net.woggioni.wson.cli;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine;
@Slf4j
@CommandLine.Command(
name = "wcfg",
versionProvider = VersionProvider.class,
subcommands = {WsonCommand.class, WcfgCommand.class})
public class WsonCli implements Runnable {
public static void main(String[] args) {
final var commandLine = new CommandLine(new WsonCli());
commandLine.setExecutionExceptionHandler((ex, cl, parseResult) -> {
log.error(ex.getMessage(), ex);
return CommandLine.ExitCode.SOFTWARE;
});
System.exit(commandLine.execute(args));
}
@Getter
@CommandLine.Option(names = {"-V", "--version"}, versionHelp = true)
private boolean versionHelp;
@CommandLine.Spec
private CommandLine.Model.CommandSpec spec;
@Override
public void run() {
spec.commandLine().usage(System.out);
}
}

View File

@@ -0,0 +1,104 @@
package net.woggioni.wson.cli;
import lombok.SneakyThrows;
import net.woggioni.jwo.Fun;
import net.woggioni.wson.serialization.binary.JBONDumper;
import net.woggioni.wson.serialization.binary.JBONParser;
import net.woggioni.wson.serialization.json.JSONDumper;
import net.woggioni.wson.serialization.json.JSONParser;
import net.woggioni.wson.xface.Value;
import picocli.CommandLine;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import static net.woggioni.jwo.JWO.newThrowable;
@CommandLine.Command(
name = "wson",
versionProvider = VersionProvider.class)
public class WsonCommand implements Runnable {
@CommandLine.Option(
names = {"-f", "--file"},
description = {"Name of the input file to parse"}
)
private Path fileName;
@CommandLine.Option(
names = {"--input-type"},
description = {"Input type"},
converter = {SerializationTypeConverter.class})
private SerializationFormat inputType = SerializationFormat.JSON;
@CommandLine.Option(names = {"-o", "--output"},
description = {"Name of the JSON file to generate"})
private Path output;
@CommandLine.Option(
names = {"-t", "--type"},
description = {"Output type"},
converter = {SerializationTypeConverter.class})
private SerializationFormat outputType = SerializationFormat.JSON;
@CommandLine.Option(names = {"-h", "--help"}, usageHelp = true)
private boolean help = false;
@SneakyThrows
public void run() {
Value.Configuration cfg = Value.Configuration.builder().serializeReferences(true).build();
InputStream inputStream;
if (fileName != null) {
inputStream = new BufferedInputStream(Files.newInputStream(fileName));
} else {
inputStream = System.in;
}
Value result;
switch (inputType) {
case JSON:
try (Reader reader = new InputStreamReader(inputStream)) {
result = new JSONParser(cfg).parse(reader);
}
break;
case JBON:
try {
result = new JBONParser(cfg).parse(inputStream);
} finally {
inputStream.close();
}
break;
default:
throw newThrowable(RuntimeException.class, "This sohuld never happen");
}
OutputStream outputStream = Optional.ofNullable(output)
.map((Fun<Path, OutputStream>) Files::newOutputStream)
.<OutputStream>map(BufferedOutputStream::new)
.orElse(System.out);
switch (outputType) {
case JSON:
try (Writer writer = new OutputStreamWriter(outputStream)) {
new JSONDumper(cfg).dump(result, writer);
}
break;
case JBON:
try {
new JBONDumper(cfg).dump(result, outputStream);
} finally {
outputStream.close();
}
}
}
}

View File

@@ -1,9 +0,0 @@
module net.woggioni.wson.cli {
requires kotlin.stdlib;
requires kotlin.stdlib.jdk8;
requires net.woggioni.wson;
requires com.beust.jcommander;
exports net.woggioni.wson.cli;
opens net.woggioni.wson.cli to com.beust.jcommander;
}

View File

@@ -0,0 +1,45 @@
package net.woggioni.wson.cli
import java.net.URL
import java.util.Enumeration
import java.util.jar.Attributes
import java.util.jar.JarFile
import java.util.jar.Manifest
import lombok.SneakyThrows
import picocli.CommandLine
abstract class AbstractVersionProvider @SneakyThrows protected constructor(specificationTitle: String?) :
CommandLine.IVersionProvider {
private val version: String
private val vcsHash: String
init {
var version: String? = null
var vcsHash: String? = null
val it: Enumeration<URL> = javaClass.classLoader.getResources(JarFile.MANIFEST_NAME)
while (it.hasMoreElements()) {
val manifestURL: URL = it.nextElement()
val mf = Manifest()
manifestURL.openStream().use(mf::read)
val mainAttributes: Attributes = mf.mainAttributes
if (specificationTitle == mainAttributes.getValue(Attributes.Name.SPECIFICATION_TITLE)) {
version = mainAttributes.getValue(Attributes.Name.SPECIFICATION_VERSION)
vcsHash = mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION)
}
}
if (version == null || vcsHash == null) {
throw RuntimeException("Version information not found in manifest")
}
this.version = version
this.vcsHash = vcsHash
}
override fun getVersion(): Array<String?> {
return if (version.endsWith("-SNAPSHOT")) {
arrayOf(version, vcsHash)
} else {
arrayOf(version)
}
}
}

View File

@@ -7,16 +7,13 @@ import java.io.OutputStreamWriter
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import kotlin.system.exitProcess import kotlin.system.exitProcess
import com.beust.jcommander.IStringConverter
import com.beust.jcommander.JCommander
import com.beust.jcommander.Parameter
import com.beust.jcommander.ParameterException
import com.beust.jcommander.converters.PathConverter
import net.woggioni.wson.serialization.binary.JBONDumper import net.woggioni.wson.serialization.binary.JBONDumper
import net.woggioni.wson.serialization.binary.JBONParser import net.woggioni.wson.serialization.binary.JBONParser
import net.woggioni.wson.serialization.json.JSONDumper import net.woggioni.wson.serialization.json.JSONDumper
import net.woggioni.wson.serialization.json.JSONParser import net.woggioni.wson.serialization.json.JSONParser
import net.woggioni.wson.xface.Value import net.woggioni.wson.xface.Value
import org.slf4j.LoggerFactory
import picocli.CommandLine
sealed class SerializationFormat(val name: String) { sealed class SerializationFormat(val name: String) {
@@ -41,88 +38,99 @@ sealed class SerializationFormat(val name: String) {
} }
} }
private class OutputTypeConverter : IStringConverter<SerializationFormat> { class OutputTypeConverter : CommandLine.ITypeConverter<SerializationFormat> {
override fun convert(value: String): SerializationFormat = SerializationFormat.parse(value) override fun convert(value: String): SerializationFormat = SerializationFormat.parse(value)
} }
private class CliArg {
@Parameter(names = ["-f", "--file"], description = "Name of the input file to parse", converter = PathConverter::class) class VersionProvider internal constructor() : AbstractVersionProvider("wson-cli")
@CommandLine.Command(
name = "wson-cli",
versionProvider = VersionProvider::class)
private class WsonCli : Runnable {
@CommandLine.Option(
names = ["-f", "--file"],
description = ["Name of the input file to parse"],
)
var fileName: Path? = null var fileName: Path? = null
@Parameter(names = ["--input-type"], description = "Input type", converter = OutputTypeConverter::class) @CommandLine.Option(
names = ["--input-type"],
description = ["Input type"],
converter = [OutputTypeConverter::class])
var inputType: SerializationFormat = SerializationFormat.JSON var inputType: SerializationFormat = SerializationFormat.JSON
@Parameter(names = ["-o", "--output"], description = "Name of the JSON file to generate", converter = PathConverter::class) @CommandLine.Option(names = ["-o", "--output"],
description = ["Name of the JSON file to generate"])
var output: Path? = null var output: Path? = null
@Parameter(names = ["-t", "--type"], description = "Output type", converter = OutputTypeConverter::class) @CommandLine.Option(
names = ["-t", "--type"],
description = ["Output type"],
converter = [OutputTypeConverter::class])
var outputType: SerializationFormat = SerializationFormat.JSON var outputType: SerializationFormat = SerializationFormat.JSON
@Parameter(names = ["-h", "--help"], help = true) @CommandLine.Option(names = ["-h", "--help"], usageHelp = true)
var help: Boolean = false var help: Boolean = false
override fun run() {
val cfg = Value.Configuration.builder().serializeReferences(true).build()
val inputStream = if (fileName != null) {
BufferedInputStream(Files.newInputStream(fileName))
} else {
System.`in`
}
val result = when(inputType) {
SerializationFormat.JSON -> {
val reader = InputStreamReader(inputStream)
try {
JSONParser(cfg).parse(reader)
} finally {
reader.close()
}
}
SerializationFormat.JBON -> {
try {
JBONParser(cfg).parse(inputStream)
} finally {
inputStream.close()
}
}
}
val outputStream = output?.let {
BufferedOutputStream(Files.newOutputStream(it))
} ?: System.out
when(outputType) {
SerializationFormat.JSON -> {
val writer = OutputStreamWriter(outputStream)
try {
JSONDumper(cfg).dump(result, writer)
} finally {
writer.close()
}
}
SerializationFormat.JBON -> {
try {
JBONDumper(cfg).dump(result, outputStream)
} finally {
outputStream.close()
}
}
}
}
} }
fun main(vararg args: String) { fun main(vararg args: String) {
val cliArg = CliArg() val log = LoggerFactory.getLogger("wson-cli")
val cliArgumentParser = JCommander.newBuilder() val commandLine = CommandLine(WsonCli())
.addObject(cliArg) commandLine.setExecutionExceptionHandler { ex, cl, parseResult ->
.build() log.error(ex.message, ex)
try { CommandLine.ExitCode.SOFTWARE
cliArgumentParser.parse(*args)
} catch (pe: ParameterException) {
cliArgumentParser.usage()
exitProcess(-1)
}
if (cliArg.help) {
cliArgumentParser.usage()
exitProcess(0)
}
val cfg = Value.Configuration.builder().serializeReferences(true).build()
val inputStream = if (cliArg.fileName != null) {
BufferedInputStream(Files.newInputStream(cliArg.fileName))
} else {
System.`in`
}
val result = when(cliArg.inputType) {
SerializationFormat.JSON -> {
val reader = InputStreamReader(inputStream)
try {
JSONParser(cfg).parse(reader)
} finally {
reader.close()
}
}
SerializationFormat.JBON -> {
try {
JBONParser(cfg).parse(inputStream)
} finally {
inputStream.close()
}
}
}
val outputStream = if (cliArg.output != null) {
BufferedOutputStream(Files.newOutputStream(cliArg.output))
} else {
System.out
}
when(cliArg.outputType) {
SerializationFormat.JSON -> {
val writer = OutputStreamWriter(outputStream)
try {
JSONDumper(cfg).dump(result, writer)
} finally {
writer.close()
}
}
SerializationFormat.JBON -> {
try {
JBONDumper(cfg).dump(result, outputStream)
} finally {
outputStream.close()
}
}
} }
exitProcess(commandLine.execute(*args))
} }