Skip to content

Commit

Permalink
Header support for 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
javaduke committed Jul 9, 2024
1 parent 8c4f10b commit 5e7f6d7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Russell Duhon <[email protected]>

_Powerful, portable data transformation_

Latest version: 2.5
Latest version: 3.0

== Introduction

Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/datasonnet/header/Header.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.datasonnet.header;

/*-
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ public class Header {
public static final String DATASONNET_PRESERVE_ORDER = "preserveOrder";
public static final String DATAFORMAT_PREFIX = "dataformat";
public static final String DATAFORMAT_ALL = "*";
public static final String LATEST_RELEASE_VERSION = "2.5"; //update this as required
public static final String LATEST_RELEASE_VERSION = "3.0"; //update this as required
private final String versionMajor;
private final String versionMinor;
private final boolean preserveOrder;
Expand Down Expand Up @@ -159,6 +159,15 @@ public static Header parseHeader(String script) throws HeaderParseException {
"The latest release version is: " + LATEST_RELEASE_VERSION);
return parseHeader20(headerWithoutVersion, version);
}
case "3":
if ("0".equals(splitVersion[1])) {
return parseHeader30(headerWithoutVersion);
} else {
//not sure if a print out is a good enough warning or if we want to add loggers
System.err.println("WARNING: You are using a version that is still in development. " +
"The latest release version is: " + LATEST_RELEASE_VERSION);
return parseHeader20(headerWithoutVersion, version);
}
default:
throw new HeaderParseException("Major version must be one of [1,2] but is " + splitVersion[0]);
}
Expand Down Expand Up @@ -332,6 +341,10 @@ private static Header parseHeader20(String headerSection, String version) throws
private static Header parseHeader20(String headerSection) throws HeaderParseException{
return parseHeader20(headerSection, "2.0");
}
@NotNull
private static Header parseHeader30(String headerSection) throws HeaderParseException{
return parseHeader20(headerSection, "3.0");
}

public String getVersion() {
return versionMajor + "." + versionMinor;
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/datasonnet/HeaderTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.datasonnet;

/*-
* Copyright 2019-2020 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@ public class HeaderTest {
Header header;

String headerStr = "/** DataSonnet\n" +
"version=2.0\n" +
"version=3.0\n" +
"preserveOrder=false\n" +
" \n" +
"// comment\n" +
Expand All @@ -63,7 +63,7 @@ void setUp() throws Exception{

@Test
void testHeaderVersion() throws HeaderParseException {
assertEquals(header.getVersion(), "2.0");
assertEquals(header.getVersion(), "3.0");
assertEquals(Header.parseHeader(
"/** DataSonnet\n" +
"version=2.1\n" +
Expand All @@ -83,7 +83,7 @@ void testHeaderVersion() throws HeaderParseException {
assertThrows(HeaderParseException.class, () -> {
Header.parseHeader(
"/** DataSonnet\n" +
"version=3.2\n" +
"version=4.2\n" +
"*/\n"
);});
}
Expand Down Expand Up @@ -129,7 +129,7 @@ void testHeaderOutput() {
void testUnknownHeaderFails() {
assertThrows(HeaderParseException.class, () -> {
Header.parseHeader("/** DataSonnet\n" +
"version=2.0\n" +
"version=3.0\n" +
"nonsense\n" +
"*/");
});
Expand All @@ -139,14 +139,14 @@ void testUnknownHeaderFails() {
void testUnterminatedHeaderFailsNicely() {
assertThrows(HeaderParseException.class, () -> {
Header.parseHeader("/** DataSonnet\n" +
"version=2.0\n");
"version=3.0\n");
});
}

@Test
public void testDefaultOutput() throws HeaderParseException {
Header header1 = Header.parseHeader("/** DataSonnet\n" +
"version=2.0\n" +
"version=3.0\n" +
"output application/x-java-object;q=0.9\n" +
"output application/json;q=1.0\n" +
"*/");
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/defaultHeader.ds
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** DataSonnet
version=2.5
version=3.0
default="OK"
*/

Expand Down

0 comments on commit 5e7f6d7

Please sign in to comment.