diff --git a/Examples/Issue14.txt b/Examples/Issue14.txt new file mode 100644 index 0000000000000000000000000000000000000000..b917e5a49f5d8498dba1770e35c766cee01032ac --- /dev/null +++ b/Examples/Issue14.txt @@ -0,0 +1,18 @@ +[S:00] +{org:en} +For transitions to and from National Operation (STM) the ETCS shall request, an acknowledgement by the driver.. +{/org} +{unl} +pur(promise(icl>modal>be,obj>uw,aoj>thing).@entry,transition(icl>change_of_state>thing,equ>passage).@pl) +mod(transition(icl>change_of_state>thing,equ>passage).@pl,to(icl>how,com>content,obj>thing)) +mod(operation(icl>business_activity>thing).@maiuscul,national(icl>adj,ant>international).@maiuscul) +obj(to(icl>how,com>content,obj>thing),operation(icl>business_activity>thing).@maiuscul) +nam(operation(icl>business_activity>thing).@maiuscul,stm.@parenthesis) +frm(to(icl>how,com>content,obj>thing),) +aoj(promise(icl>modal>be,obj>uw,aoj>thing).@entry,etcs.@def) +agt(request(icl>communicate>do,agt>volitional_thing,obj>thing),etcs.@def) +obj(promise(icl>modal>be,obj>uw,aoj>thing).@entry,request(icl>communicate>do,agt>volitional_thing,obj>thing)) +cnt(promise(icl>modal>be,obj>uw,aoj>thing).@entry,acknowledgement(icl>message>thing,equ>acknowledgment).@indef) +met(acknowledgement(icl>message>thing,equ>acknowledgment).@indef,driver(icl>operator>thing,ant>nondriver).@def) +{/unl} +[/S] diff --git a/README.md b/README.md index 5327e921a472f217ff5362114c4fcdc7eb21add2..6093d3b371b21464b3f9efe5159c30308d6ffe71 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,11 @@ popd ``` + +# Generate jar file + +```shell +$ mvn package +$ cd unl-tools-main/target +# you should see unl-tools-main-0.9.jar that is the standalone jar file. +``` \ No newline at end of file diff --git a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java index 5edc94a874f6e7805b9a76814215e9c83f98264d..5cd1414286654c1f8bf402ab06dfd274efdbe4ac 100644 --- a/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java +++ b/unl-tools-application/src/main/java/fr/tetras_libre/unltools/Convert/ExportUnlDocumentsHandler.java @@ -18,7 +18,8 @@ public class ExportUnlDocumentsHandler implements CommandHandler<ExportUnlDocume public Result handle(ExportUnlDocuments command) { try { var graphExporter = factory.createGraphExporter(command.getWriter(), command.getExporterName()); - graphExporter.write(command.getGraphImporter().Import()); + var importedGraph = command.getGraphImporter().Import(); + graphExporter.write(importedGraph); } catch (IOException | GraphExportException e) { return Result.Failure(String.format("Cannot export unl documents to format '%s' (reason: '%s')", command.getExporterName(), e.getMessage()), e); diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java index f293807504a8bc545bdd7fa27ee2f18c7c2d8518..8ebdab4df725a939726d46a3638d534f31ba1b17 100644 --- a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/UnlGraphImporterFromUnlParser.java @@ -8,11 +8,13 @@ import java.io.InputStreamReader; import java.util.List; public class UnlGraphImporterFromUnlParser implements GraphImporter { - private List<UnlDocument> documents; private BufferedReader bufferedReader; + WrapperUnlParser wrapper; + public UnlGraphImporterFromUnlParser(BufferedReader bufferedReader) { this.bufferedReader = bufferedReader; + this.wrapper = null; } public static UnlGraphImporterFromUnlParser FromInputReader(InputStreamReader inputStreamReader) { @@ -21,13 +23,14 @@ public class UnlGraphImporterFromUnlParser implements GraphImporter { @Override public List<UnlDocument> Import() { - if (documents == null) { - try { - documents = new UnlParser(this.bufferedReader).createUnlDocumentList(); - } catch (ParseException e) { - e.printStackTrace(); - } + if (this.wrapper == null) { + this.wrapper = new WrapperUnlParser(this.bufferedReader); + this.wrapper.parseUnlSource(); + if(this.wrapper.hasError()){ + var message = String.format("Current error: '%s'", String.join(",", wrapper.getErrors())); + throw new RuntimeException(message); + } } - return documents; + return wrapper.getUnlDocumentList(); } } diff --git a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java similarity index 98% rename from unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java rename to unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java index 50d10a33dc695ae288e881eb34b4e6bf7446b919..74843632ea7a217d0159c6fe925da39fc6f27c25 100644 --- a/unl-tools-infrastructure/src/test/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/parser/WrapperUnlParser.java @@ -26,7 +26,7 @@ public class WrapperUnlParser { } public void parseUnlSource(){ - parseContentAndRetrieveErrors(); + parseContentIfNecessary(); } /** diff --git a/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java index 9f5c58d362eabda45334cc5641405f7a42b3a15b..459613f7c7c6cc141e16756eb0a5ba427a890c9b 100644 --- a/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java +++ b/unl-tools-main/src/test/java/unl2rdf/Unl2RdfTest.java @@ -21,27 +21,10 @@ class Unl2RdfTest { } @Tag("integration") - @Test - public void r1ShouldBeConvertedToRdfFile() { - Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "r1", "--output-type", "rdf"})); - } - - @Tag("integration") - @Test - public void r2ShouldBeConvertedToRdfFile() { - Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "r2", "--output-type", "rdf"})); - } - - @Tag("integration") - @Test - public void catShouldBeConvertedToRdfFile() { - Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "cat", "--output-type", "rdf"})); - } - - @Tag("integration") - @Test - public void exemplesShouldBeConvertedToRdfFile() { - Assertions.assertDoesNotThrow(() -> Unl2Rdf.main(new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "exemples_unl", "--output-type", "rdf"})); + @ParameterizedTest(name = "RuntimeException({index}) ==> Unl2Rdf.main({arguments})") + @ArgumentsSource(TestMainShouldNotThrowRuntimeExceptionParameterArgumentProvider.class) + public void TestMainShouldNotThrowRuntimeException(String[] args) { + Assertions.assertThrows(RuntimeException.class, () -> Unl2Rdf.main(args)); } static class TestMainShouldNotThrowOnPartialParameterArgumentProvider implements ArgumentsProvider { @@ -49,9 +32,33 @@ class Unl2RdfTest { @Override public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { return Stream.of( + Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "dotOnly", "--output-type", "dot"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/cat.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "dotOnly", "--output-type", "dot"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/exemples_unl.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}), Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotOnly", "--output-type", "dot"}), Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), - Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}) + Arguments.of((Object) new String[]{"--input-file", "../Examples/issue12.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "dotOnly", "--output-type", "dot"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r1.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "dotOnly", "--output-type", "dot"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/r2.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}) + ); + } + } + + static class TestMainShouldNotThrowRuntimeExceptionParameterArgumentProvider implements ArgumentsProvider { + + @Override + public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { + return Stream.of( + Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "dotOnly", "--output-type", "dot"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "rdfOnly", "--output-type", "rdf"}), + Arguments.of((Object) new String[]{"--input-file", "../Examples/issue14.txt", "--output-file", "dotWithRdf", "--output-type", "dot,rdf"}) ); } }