Skip to content

Commit

Permalink
yaml: Eclipse integration work
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 18, 2021
1 parent 8d3cad3 commit fc79b90
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
/*/build/
/*/out/
/*/bin/
/*/.factorypath
buildSrc/build/
buildSrc/out/
buildSrc/*/bin/
/build/
buildSrc/build/
/format/*/bin/
/format/*/build/
/format/*/out/
/format/*/.factorypath
/extra/*/build/
/extra/*/out/
/extra/*/bin/
/extra/*/.factorypath

# gitpatcher local data
/vendor/snakeyaml/
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ dependencies {
api "net.ltgt.gradle:gradle-nullaway-plugin:1.2.0"
api "me.champeau.gradle:japicmp-gradle-plugin:0.3.0"
api "de.thetaphi:forbiddenapis:3.2"
api "com.diffplug.gradle:goomph:3.34.0"
implementation "com.google.guava:guava:31.0.1-jre"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ plugins {
id "me.champeau.gradle.japicmp"
id "de.thetaphi.forbiddenapis"
id 'pmd'
id 'com.diffplug.eclipse.apt'
}

configurations.configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,61 @@ import org.yaml.snakeyaml.parser.ParserImpl
import org.yaml.snakeyaml.reader.StreamReader
import org.yaml.snakeyaml.scanner.ScannerImpl

import java.nio.charset.StandardCharsets
trait YamlTest {

interface YamlTest {

default CommentedConfigurationNode parseString(final String input) {
CommentedConfigurationNode parseString(final String input) {
// Print events
def scanner = new ScannerImpl(new StreamReader(input))
scanner.emitComments = true
scanner.parseComments = true
scanner.acceptTabs = true
def parser = new ParserImpl(scanner)
do {

while (true) {
println parser.getEvent()
} while (parser.peekEvent())
if (!parser.peekEvent()) break
}

final YamlParserComposer loader = new YamlParserComposer(new StreamReader(input), Yaml11Tags.REPOSITORY, true)
final CommentedConfigurationNode result = CommentedConfigurationNode.root()
loader.singleDocumentStream(result)
return result
}

default CommentedConfigurationNode parseResource(final URL url) {
CommentedConfigurationNode parseResource(final URL url) {
// Print events
url.openStream().withReader('UTF-8') {reader ->
def scanner = new ScannerImpl(new StreamReader(reader))
scanner.emitComments = true
scanner.parseComments = true
scanner.acceptTabs = true
def parser = new ParserImpl(scanner)
do {
while (true) {
println parser.getEvent()
} while (parser.peekEvent())
if (!parser.peekEvent()) break
}
}

assertNotNull(url, "Expected resource is missing")
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
url.openStream().withReader('UTF-8') { reader ->
final YamlParserComposer loader = new YamlParserComposer(new StreamReader(reader), Yaml11Tags.REPOSITORY, true)
final CommentedConfigurationNode result = CommentedConfigurationNode.root()
loader.singleDocumentStream(result)
return result
}
}

default String dump(final CommentedConfigurationNode input) {
String dump(final CommentedConfigurationNode input) {
return dump(input, null)
}

default String dump(final CommentedConfigurationNode input, final NodeStyle preferredStyle) {
String dump(final CommentedConfigurationNode input, final NodeStyle preferredStyle) {
return YamlConfigurationLoader.builder()
.nodeStyle(preferredStyle)
.indent(2)
.commentsEnabled(true)
.buildAndSaveString(input)
}

default String normalize(final String input) {
String normalize(final String input) {
return input.stripIndent(true)
}

Expand Down
4 changes: 2 additions & 2 deletions vendor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ project(":snakeyaml") {
val applyPatches = rootProject.tasks.named("applyPatches")
tasks.withType(JavaCompile::class) {
options.release.set(7)
dependsOn(applyPatches)
// dependsOn(applyPatches)
}
tasks.withType(ProcessResources::class) {
dependsOn(applyPatches)
// dependsOn(applyPatches)
}

tasks.named("test", Test::class) {
Expand Down

0 comments on commit fc79b90

Please sign in to comment.