Gradle 3.2.1, flat map for XContentBuilder
This commit is contained in:
parent
ae7934381c
commit
73afbd806f
15 changed files with 81 additions and 19 deletions
|
@ -4,17 +4,15 @@ plugins {
|
|||
id "org.xbib.gradle.plugin.jbake" version "1.2.1"
|
||||
}
|
||||
|
||||
|
||||
ext {
|
||||
versions = [
|
||||
'jackson' : '2.8.4'
|
||||
]
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'build-dashboard'
|
||||
|
||||
group = 'org.xbib'
|
||||
version = '1.0.6'
|
||||
allprojects {
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
|
@ -42,7 +40,7 @@ allprojects {
|
|||
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:all" << "-profile" << "compact2"
|
||||
options.compilerArgs << "-Xlint:all" << "-profile" << "compact1"
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
|
@ -766,6 +766,15 @@ public final class XContentBuilder implements ToXContent, Flushable, Closeable {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public XContentBuilder flatMap(Map<String, String> map) throws IOException {
|
||||
if (map == null) {
|
||||
return nullValue();
|
||||
}
|
||||
writeFlatMap(map);
|
||||
return this;
|
||||
}
|
||||
|
||||
public XContentBuilder value(Iterable<?> value) throws IOException {
|
||||
if (value == null) {
|
||||
return nullValue();
|
||||
|
@ -825,6 +834,20 @@ public final class XContentBuilder implements ToXContent, Flushable, Closeable {
|
|||
generator.writeEndObject();
|
||||
}
|
||||
|
||||
private void writeFlatMap(Map<String, String> map) throws IOException {
|
||||
generator.writeStartObject();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
field(entry.getKey());
|
||||
Object value = entry.getValue();
|
||||
if (value == null) {
|
||||
generator.writeNull();
|
||||
} else {
|
||||
writeValue(value);
|
||||
}
|
||||
}
|
||||
generator.writeEndObject();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void writeValue(Object value) throws IOException {
|
||||
if (value == null) {
|
||||
|
|
|
@ -96,7 +96,7 @@ public class BytesStreamOutput extends OutputStream {
|
|||
if (length == 0) {
|
||||
return;
|
||||
}
|
||||
if ((long)count + length > Integer.MAX_VALUE) {
|
||||
if ((long) count + length > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("overflow, stream output larger than " + Integer.MAX_VALUE);
|
||||
}
|
||||
int newcount = count + length;
|
||||
|
|
|
@ -13,4 +13,4 @@ public interface PlaceholderResolver {
|
|||
* @return the replacement value or <code>null</code> if no replacement is to be made.
|
||||
*/
|
||||
String resolvePlaceholder(String placeholderName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,4 +117,4 @@ public class PropertyPlaceholder {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,13 @@ package org.xbib.content.settings;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.xbib.content.XContentBuilder;
|
||||
import org.xbib.content.XContentHelper;
|
||||
import org.xbib.content.json.JsonSettingsLoader;
|
||||
import org.xbib.content.json.JsonXContent;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
@ -102,4 +106,21 @@ public class SettingsTest extends Assert {
|
|||
.build();
|
||||
assertEquals("{a.b=c}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatLoader() throws IOException {
|
||||
String s = "{\"a\":{\"b\":\"c\"}}";
|
||||
JsonSettingsLoader loader = new JsonSettingsLoader();
|
||||
Map<String, String> flatMap = loader.load(s);
|
||||
assertEquals("{a.b=c}", flatMap.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatLoaderToJsonString() throws IOException {
|
||||
String s = "{\"a\":{\"b\":\"c\"}}";
|
||||
JsonSettingsLoader loader = new JsonSettingsLoader();
|
||||
String result = JsonXContent.contentBuilder().flatMap(loader.load(s)).string();
|
||||
assertEquals("{\"a.b\":\"c\"}", result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
dependencies {
|
||||
compile project(':content-xml')
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:all" << "-profile" << "compact2"
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
*
|
||||
* @param <R> parameter type
|
||||
*/
|
||||
public interface RdfContentParser<R extends RdfContentParams> {
|
||||
|
||||
|
|
4
content-resource/build.gradle
Normal file
4
content-resource/build.gradle
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:all" << "-profile" << "compact2"
|
||||
}
|
|
@ -3,3 +3,8 @@ dependencies {
|
|||
compile project(':content-resource')
|
||||
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${versions.jackson}"
|
||||
}
|
||||
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:all" << "-profile" << "compact2"
|
||||
}
|
3
gradle.properties
Normal file
3
gradle.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
group = org.xbib
|
||||
name = content
|
||||
version = 1.0.7
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
|||
#Mon Oct 03 00:03:03 CEST 2016
|
||||
#Sat Dec 03 23:47:13 CET 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
|
||||
|
|
19
gradlew
vendored
19
gradlew
vendored
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
|
@ -154,16 +154,19 @@ if $cygwin ; then
|
|||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save ( ) {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
exec "$JAVACMD" "$@"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
rootProject.name = 'content'
|
||||
rootProject.name = name
|
||||
include 'content-core'
|
||||
include 'content-resource'
|
||||
include 'content-language'
|
||||
|
|
Loading…
Reference in a new issue