Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/fred"/>
<classpathentry kind="lib" path="/fred/lib/freenet-ext.jar"/>
<classpathentry kind="lib" path="lib/SnakeYAML-1.3.jar"/>
<classpathentry kind="lib" path="/usr/share/java/junit.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>
19 changes: 10 additions & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@
<delete dir="${tmp}"/>
</target>

<property name="SnakeYAML.mirror" value="http://snakeyamlrepo.appspot.com/repository/org/yaml/snakeyaml/1.5/snakeyaml-1.5.jar" />
<property name="SnakeYAML.md5" value="1788db5d529a981b090632b8e49b8cd2" />
<property name="SnakeYAML.sha" value="a3654035d0b68db775034afa5425a62250de8184" />
<property name="SnakeYAML.mirror" value="http://repo2.maven.org/maven2/org/yaml/snakeyaml/1.10/snakeyaml-1.10.jar" />
<property name="SnakeYAML.name" value="snakeyaml-1.10.jar" />
<property name="SnakeYAML.md5" value="5f1bbedd96c3a745fda676e3d653efd5" />
<property name="SnakeYAML.sha" value="032634ca71ed45db1a7f6b0f9e24c648466b40f1" />
<available property="SnakeYAML.exist" classname="org.yaml.snakeyaml.Yaml" classpathref="lib.path"/>
<target name="SnakeYAML-get" unless="SnakeYAML.exist">
<get verbose="true" src="${SnakeYAML.mirror}" dest="${tmp}/snakeyaml-1.5.jar" />
<checksum file="${tmp}/snakeyaml-1.5.jar" algorithm="MD5" property="${SnakeYAML.md5}" verifyProperty="SnakeYAMLMD5ok" />
<checksum file="${tmp}/snakeyaml-1.5.jar" algorithm="SHA" property="${SnakeYAML.sha}" verifyProperty="SnakeYAMLSHAok" />
<fail message="SnakeYAML.zip checksum mismatch">
<get verbose="true" src="${SnakeYAML.mirror}" dest="${tmp}/${SnakeYAML.name}" />
<checksum file="${tmp}/${SnakeYAML.name}" algorithm="MD5" property="${SnakeYAML.md5}" verifyProperty="SnakeYAMLMD5ok" />
<checksum file="${tmp}/${SnakeYAML.name}" algorithm="SHA" property="${SnakeYAML.sha}" verifyProperty="SnakeYAMLSHAok" />
<fail message="SnakeYAML.jar checksum mismatch">
<condition>
<or>
<equals arg1="${SnakeYAMLMD5ok}" arg2="false" />
<equals arg1="${SnakeYAMLSHAok}" arg2="false" />
</or>
</condition>
</fail>
<move file="${tmp}/snakeyaml-1.5.jar" todir="lib/" />
<move file="${tmp}/${SnakeYAML.name}" todir="lib/" />
</target>

<!--<property name="KeyExplorer.mirror" value="http://cloud.github.com/downloads/freenet/plugin-Library-staging/KeyExplorer-dacfafecbc82aecdeffa56bef4a047a7f6c7f08d.jar" />
Expand Down Expand Up @@ -234,7 +235,7 @@
</fileset>
<link href="http://java.sun.com/j2se/1.5.0/docs/api"/>
<link href="http://freenet.github.com/fred-staging/api"/>
<link href="http://snakeyamlrepo.appspot.com/releases/1.5/site/apidocs"/>
<link href="http://repo2.maven.org/maven2/org/yaml/snakeyaml/1.10/snakeyaml-1.10-javadoc.jar"/>
</javadoc>
</target>

Expand Down
21 changes: 11 additions & 10 deletions src/plugins/Library/io/YamlReaderWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.AbstractConstruct;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class YamlReaderWriter

final public static String MIME_TYPE = "text/yaml";
final public static String FILE_EXTENSION = ".yml";

final static int MAX_PARALLEL = 1; // Limited by memory mainly. If memory is no object it could be limited by threads.
// Each Yaml instance uses a *significant* amount of memory...
static final Semaphore parallelLimiter = new Semaphore(MAX_PARALLEL);
Expand Down Expand Up @@ -89,7 +90,7 @@ public YamlReaderWriter() {
}

/** We do NOT keep this thread-local, because the Composer is only cleared after
* the next call to load(), so it can persist with a lot of useless data if we
* the next call to load(), so it can persist with a lot of useless data if we
* then use a different thread. So lets just construct them as needed. */
private Yaml makeYAML() {
DumperOptions opt = new DumperOptions();
Expand Down Expand Up @@ -122,14 +123,14 @@ public static class ExtendedRepresenter extends Representer {
public ExtendedRepresenter() {
this.representers.put(FreenetURI.class, new Represent() {
/*@Override**/ public Node representData(Object data) {
return representScalar("!FreenetURI", ((FreenetURI) data).toString());
return representScalar(new Tag("!FreenetURI"), ((FreenetURI) data).toString());
}
});
this.representers.put(Packer.BinInfo.class, new Represent() {
/*@Override**/ public Node representData(Object data) {
Packer.BinInfo inf = (Packer.BinInfo)data;
Map<Object, Object> map = Collections.<Object, Object>singletonMap(inf.getID(), inf.getWeight());
return representMapping("!BinInfo", map, true);
return representMapping(new Tag("!BinInfo"), map, true);
}
});
this.representers.put(TermTermEntry.class, new RepresentTermEntry(tebp_term));
Expand All @@ -148,7 +149,7 @@ public RepresentTermEntry(ObjectBlueprint<T> bp) {
}

/*@Override**/ public Node representData(Object data) {
return representMapping(tag, blueprint.objectAsMap((T)data), true);
return representMapping(new Tag(tag), blueprint.objectAsMap((T)data), true);
}

}
Expand All @@ -161,7 +162,7 @@ public RepresentTermEntry(ObjectBlueprint<T> bp) {
*/
public static class ExtendedConstructor extends Constructor {
public ExtendedConstructor() {
this.yamlConstructors.put("!FreenetURI", new AbstractConstruct() {
this.yamlConstructors.put(new Tag("!FreenetURI"), new AbstractConstruct() {
/*@Override**/ public Object construct(Node node) {
String uri = (String) constructScalar((ScalarNode)node);
try {
Expand All @@ -171,7 +172,7 @@ public ExtendedConstructor() {
}
}
});
this.yamlConstructors.put("!BinInfo", new AbstractConstruct() {
this.yamlConstructors.put(new Tag("!BinInfo"), new AbstractConstruct() {
/*@Override**/ public Object construct(Node node) {
Map<?, ?> map = (Map) constructMapping((MappingNode)node);
if (map.size() != 1) {
Expand All @@ -183,9 +184,9 @@ public ExtendedConstructor() {
throw new AssertionError();
}
});
this.yamlConstructors.put("!TermTermEntry", new ConstructTermEntry(tebp_term));
this.yamlConstructors.put("!TermIndexEntry", new ConstructTermEntry(tebp_index));
this.yamlConstructors.put("!TermPageEntry", new ConstructTermEntry(tebp_page));
this.yamlConstructors.put(new Tag("!TermTermEntry"), new ConstructTermEntry(tebp_term));
this.yamlConstructors.put(new Tag("!TermIndexEntry"), new ConstructTermEntry(tebp_index));
this.yamlConstructors.put(new Tag("!TermPageEntry"), new ConstructTermEntry(tebp_page));
}

public class ConstructTermEntry<T extends TermEntry> extends AbstractConstruct {
Expand Down
5 changes: 3 additions & 2 deletions test/plugins/Library/io/serial/YamlMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.Construct;
Expand Down Expand Up @@ -100,15 +101,15 @@ public ExtendedRepresenter() {

private class RepresentCustom implements Represent {
public Node representData(Object data) {
return representScalar("!Custom", ((Custom) data).toString());
return representScalar(new Tag("!Custom"), ((Custom) data).toString());
}
}
}


public static class ExtendedConstructor extends Constructor {
public ExtendedConstructor() {
this.yamlConstructors.put("!Custom", new ConstructCustom());
this.yamlConstructors.put(new Tag("!Custom"), new ConstructCustom());
}

private class ConstructCustom implements Construct {
Expand Down