Skip to content

Commit

Permalink
merge snakeyaml into source
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Mar 1, 2010
1 parent 4c9cf29 commit 18a1a5f
Show file tree
Hide file tree
Showing 88 changed files with 8,990 additions and 16 deletions.
9 changes: 0 additions & 9 deletions .idea/libraries/snakeyaml.xml

This file was deleted.

1 change: 0 additions & 1 deletion .idea/modules/elasticsearch.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ Written by Cliff Click and released as Public Domain.

Logging abstraction provided by SLF4J (http://www.slf4j.org).
Copyright (c) 2004-2008 QOS.ch

Yaml support uses SnakeYaml Copyright of Andrey Somov under the
Apache 2 License.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ allprojects {
repositories {
mavenCentral()
mavenRepo urls: 'http://repository.jboss.com/maven2/'
mavenRepo urls: 'http://snakeyamlrepo.appspot.com/repository' // for snakeyaml
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
##############################################################################

# Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
# GRADLE_OPTS="$GRADLE_OPTS -Xmx512"
GRADLE_OPTS="$GRADLE_OPTS -Xmx512m"
# JAVA_OPTS="$JAVA_OPTS -Xmx512"

warn ( ) {
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if "%OS%"=="Windows_NT" setlocal

@rem Uncomment those lines to set JVM options. GRADLE_OPTS and JAVA_OPTS can be used together.
@rem set GRADLE_OPTS=%GRADLE_OPTS% -Xmx512
set GRADLE_OPTS=%GRADLE_OPTS% -Xmx512m
@rem set JAVA_OPTS=%JAVA_OPTS% -Xmx512

set DIRNAME=%~dp0
Expand Down
2 changes: 0 additions & 2 deletions modules/elasticsearch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ dependencies {
compile 'joda-time:joda-time:1.6'
compile 'com.google.collections:google-collections:1.0'

compile 'org.yaml:snakeyaml:1.5'

compile 'org.codehaus.jackson:jackson-core-asl:1.4.2'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.4.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.elasticsearch.util.settings.loader;

import org.yaml.snakeyaml.Yaml;
import org.elasticsearch.util.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.util.yaml.snakeyaml;

import org.elasticsearch.util.yaml.snakeyaml.composer.Composer;
import org.elasticsearch.util.yaml.snakeyaml.constructor.BaseConstructor;
import org.elasticsearch.util.yaml.snakeyaml.constructor.Constructor;
import org.elasticsearch.util.yaml.snakeyaml.error.YAMLException;
import org.elasticsearch.util.yaml.snakeyaml.events.Event;
import org.elasticsearch.util.yaml.snakeyaml.nodes.Node;
import org.elasticsearch.util.yaml.snakeyaml.parser.Parser;
import org.elasticsearch.util.yaml.snakeyaml.parser.ParserImpl;
import org.elasticsearch.util.yaml.snakeyaml.reader.StreamReader;
import org.elasticsearch.util.yaml.snakeyaml.resolver.Resolver;

import java.io.Reader;
import java.util.Iterator;

/**
* @see <a href="http://pyyaml.org/wiki/PyYAML">PyYAML</a> for more information
*/
public class Loader {
protected final BaseConstructor constructor;
protected Resolver resolver;
private boolean attached = false;

public Loader(BaseConstructor constructor) {
super();
this.constructor = constructor;
}

public Loader() {
this(new Constructor());
}

public Object load(Reader io) {
Composer composer = new Composer(new ParserImpl(new StreamReader(io)), resolver);
constructor.setComposer(composer);
return constructor.getSingleData();
}

public Iterable<Object> loadAll(Reader yaml) {
Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
this.constructor.setComposer(composer);
Iterator<Object> result = new Iterator<Object>() {
public boolean hasNext() {
return constructor.checkData();
}

public Object next() {
return constructor.getData();
}

public void remove() {
throw new UnsupportedOperationException();
}
};
return new YamlIterable(result);
}

/**
* Parse the first YAML document in a stream and produce the corresponding
* representation tree.
*
* @param yaml YAML document
* @return parsed root Node for the specified YAML document
*/
public Node compose(Reader yaml) {
Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
this.constructor.setComposer(composer);
return composer.getSingleNode();
}

/**
* Parse all YAML documents in a stream and produce corresponding
* representation trees.
*
* @param yaml stream of YAML documents
* @return parsed root Nodes for all the specified YAML documents
*/
public Iterable<Node> composeAll(Reader yaml) {
final Composer composer = new Composer(new ParserImpl(new StreamReader(yaml)), resolver);
this.constructor.setComposer(composer);
Iterator<Node> result = new Iterator<Node>() {
public boolean hasNext() {
return composer.checkNode();
}

public Node next() {
return composer.getNode();
}

public void remove() {
throw new UnsupportedOperationException();
}
};
return new NodeIterable(result);
}

private class NodeIterable implements Iterable<Node> {
private Iterator<Node> iterator;

public NodeIterable(Iterator<Node> iterator) {
this.iterator = iterator;
}

public Iterator<Node> iterator() {
return iterator;
}

}

private class YamlIterable implements Iterable<Object> {
private Iterator<Object> iterator;

public YamlIterable(Iterator<Object> iterator) {
this.iterator = iterator;
}

public Iterator<Object> iterator() {
return iterator;
}

}

public void setResolver(Resolver resolver) {
this.resolver = resolver;
}

/**
* Because Loader is stateful it cannot be shared
*/
void setAttached() {
if (!attached) {
attached = true;
} else {
throw new YAMLException("Loader cannot be shared.");
}
}

/**
* Parse a YAML stream and produce parsing events.
*
* @param yaml YAML document(s)
* @return parsed events
*/
public Iterable<Event> parse(Reader yaml) {
final Parser parser = new ParserImpl(new StreamReader(yaml));
Iterator<Event> result = new Iterator<Event>() {
public boolean hasNext() {
return parser.peekEvent() != null;
}

public Event next() {
return parser.getEvent();
}

public void remove() {
throw new UnsupportedOperationException();
}
};
return new EventIterable(result);
}

private class EventIterable implements Iterable<Event> {
private Iterator<Event> iterator;

public EventIterable(Iterator<Event> iterator) {
this.iterator = iterator;
}

public Iterator<Event> iterator() {
return iterator;
}
}
}
Loading

0 comments on commit 18a1a5f

Please sign in to comment.