From 8fc25af053cb6b712f793c86cf7a32a160e8600c Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Mon, 14 Sep 2020 17:27:10 +0200 Subject: [PATCH 1/6] #1236 Set next development version --- cobigen/cobigen-tsplugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen/cobigen-tsplugin/pom.xml b/cobigen/cobigen-tsplugin/pom.xml index aaab698a16..cf38d06a80 100644 --- a/cobigen/cobigen-tsplugin/pom.xml +++ b/cobigen/cobigen-tsplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 tsplugin CobiGen - TypeScript Plug-in - 7.0.0 + 7.0.1-SNAPSHOT jar CobiGen - TypeScript Plug-in From 897453dc703448e908437c5f67b728bac6d06a24 Mon Sep 17 00:00:00 2001 From: Lilli Date: Tue, 13 Oct 2020 17:42:02 +0200 Subject: [PATCH 2/6] add read path from object input --- .../inputreader/TypeScriptInputReader.java | 11 ++++++++++- .../TypeScriptInputReaderTest.java | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java b/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java index fb837b0db8..be0b757230 100644 --- a/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java +++ b/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java @@ -8,6 +8,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -110,7 +111,15 @@ public boolean isValidInput(Object input) { } else if (input instanceof File) { path = ((File) input).toPath(); } else { - return false; + try { + // Input corresponds to the parsed file + Map mapModel = createModel(input); + mapModel = (Map) mapModel.get("model"); + path = Paths.get(mapModel.get("path").toString()); + } catch (Exception e) { + LOG.error("An exception occured while parsing the input", e); + return false; + } } if (serverIsNotDeployed) { diff --git a/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java b/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java index e3face2b37..90a163e0f1 100644 --- a/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java +++ b/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java @@ -122,6 +122,25 @@ public void testValidInput() { } + /** + * Test if the path of a file can be parsed from a given object + * + * @test fails + */ + @Test + public void testValidInputFromObject() { + + TypeScriptInputReader tsInputReader = new TypeScriptInputReader(); + File baseFile = new File(testFileRootPath + "baseFile.ts"); + String inputModel = (String) tsInputReader.read(baseFile.getAbsoluteFile().toPath(), Charset.defaultCharset()); + + boolean isValidInput = tsInputReader.isValidInput(inputModel); + + LOG.debug("Valid input ? " + isValidInput); + assertTrue(isValidInput); + + } + /** * Sends a fileEto containing only the path of the file that needs to be parsed. Checks whether the file * is most likely readable. From a186b3d7ed84a2fc73b722d7e3ab8edebb0693fa Mon Sep 17 00:00:00 2001 From: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> Date: Thu, 29 Oct 2020 10:58:23 +0100 Subject: [PATCH 3/6] re-added createModel input parser to isValidInput fixes: #1260 (#1274) replaced isValidInput file extension check on externalserver with isMostLikelyReadable (now detects ts, js and nest extensions inside the plugin) added new unit test for cli based isValidInput check --- .../inputreader/TypeScriptInputReader.java | 51 +++++-------------- .../TypeScriptInputReaderTest.java | 7 ++- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java b/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java index be0b757230..b15c6ff8a9 100644 --- a/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java +++ b/cobigen/cobigen-tsplugin/src/main/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReader.java @@ -10,6 +10,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -17,6 +18,7 @@ import java.util.Map; import java.util.stream.Stream; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,56 +104,26 @@ private Boolean startServerConnection() { @Override public boolean isValidInput(Object input) { - String fileContents = null; - - Path path = null; if (input instanceof Path) { - path = (Path) input; + return true; } else if (input instanceof File) { - path = ((File) input).toPath(); + return true; } else { try { // Input corresponds to the parsed file Map mapModel = createModel(input); mapModel = (Map) mapModel.get("model"); - path = Paths.get(mapModel.get("path").toString()); + if (Paths.get(mapModel.get("path").toString()) == null) { + return false; + } + return true; } catch (Exception e) { LOG.error("An exception occured while parsing the input", e); return false; } } - if (serverIsNotDeployed) { - LOG.error("We have not been able to send requests to the external server. " - + "Most probably there is an error on the executable file. " - + "Try to manually remove folder .cobigen/externalservers found at your user root folder"); - return false; - } - - // File content is not needed, as only the file extension is checked - fileContents = new String(""); - - String fileName = path.toString(); - InputFileTo inputFile = new InputFileTo(fileName, fileContents, charset); - - HttpURLConnection conn = request.getConnection("POST", "Content-Type", "application/json", "isValidInput"); - - if (request.sendRequest(inputFile, conn, charset)) { - - String response = new String(); - try (InputStreamReader isr = new InputStreamReader(conn.getInputStream()); - BufferedReader br = new BufferedReader(isr);) { - - LOG.info("Receiving response from Server...."); - response = br.readLine(); - - return Boolean.parseBoolean(response); - } catch (IOException e) { - connectionExc.handle(e); - } - } - return false; } @Override @@ -211,6 +183,7 @@ public List getInputObjects(Object input, Charset inputCharset, boolean try { if (isValidInput(input)) { + String inputModel = (String) read(new File(input.toString()).toPath(), inputCharset); Map mapModel = (Map) createModel(inputModel).get("model"); @@ -279,6 +252,7 @@ public Object read(Path path, Charset inputCharset, Object... additionalArgument s.parallel().forEachOrdered((String line) -> { inputModel.append(line); }); + return inputModel.toString(); } catch (Exception e) { @@ -292,7 +266,10 @@ public Object read(Path path, Charset inputCharset, Object... additionalArgument @Override public boolean isMostLikelyReadable(Path path) { - return path.toFile().isFile() && path.toString().endsWith("." + VALID_EXTENSION); + + List validExtensions = Arrays.asList("ts", "js", "nest"); + String fileExtension = FilenameUtils.getExtension(path.toString()).toLowerCase(); + return validExtensions.contains(fileExtension); } /** diff --git a/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java b/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java index 90a163e0f1..9aa69f1d1d 100644 --- a/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java +++ b/cobigen/cobigen-tsplugin/src/test/java/com/devonfw/cobigen/tsplugin/inputreader/TypeScriptInputReaderTest.java @@ -123,15 +123,18 @@ public void testValidInput() { } /** - * Test if the path of a file can be parsed from a given object + * Sends an Object containing only the path of the file that needs to be parsed. Checks whether it is a + * valid input. * * @test fails */ @Test - public void testValidInputFromObject() { + public void testValidInputObjectString() { + // arrange TypeScriptInputReader tsInputReader = new TypeScriptInputReader(); File baseFile = new File(testFileRootPath + "baseFile.ts"); + String inputModel = (String) tsInputReader.read(baseFile.getAbsoluteFile().toPath(), Charset.defaultCharset()); boolean isValidInput = tsInputReader.isValidInput(inputModel); From aad04ad171b29a2e21d26ca7993b7471ef39052c Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Fri, 4 Dec 2020 10:00:43 +0100 Subject: [PATCH 4/6] #1283 set release snapshot version --- cobigen/cobigen-tsplugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen/cobigen-tsplugin/pom.xml b/cobigen/cobigen-tsplugin/pom.xml index cf38d06a80..e226ffbda0 100644 --- a/cobigen/cobigen-tsplugin/pom.xml +++ b/cobigen/cobigen-tsplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 tsplugin CobiGen - TypeScript Plug-in - 7.0.1-SNAPSHOT + 7.1.0-SNAPSHOT jar CobiGen - TypeScript Plug-in From 12b2b8c32fcec81b6fa028387b1f6cde572e1823 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Fri, 4 Dec 2020 10:03:46 +0100 Subject: [PATCH 5/6] #1283 update wiki docs --- documentation/master-cobigen.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index 44db78fd70..66a74208e9 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -20,7 +20,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf * CobiGen v6.1.2 * CobiGen - Java Plug-in v2.2.3 * CobiGen - XML Plug-in v4.2.0 -* CobiGen - TypeScript Plug-in v7.0.0 +* CobiGen - TypeScript Plug-in v7.1.0 * CobiGen - Property Plug-in v2.1.0 * CobiGen - Text Merger v2.1.0 * CobiGen - JSON Plug-in v2.1.0 From 1162bd8b72c7c58d9d165f79ec0721a2e71f1040 Mon Sep 17 00:00:00 2001 From: MikeSchumacher Date: Fri, 4 Dec 2020 10:03:48 +0100 Subject: [PATCH 6/6] #1283 Set release version --- cobigen/cobigen-tsplugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen/cobigen-tsplugin/pom.xml b/cobigen/cobigen-tsplugin/pom.xml index e226ffbda0..39ee798c93 100644 --- a/cobigen/cobigen-tsplugin/pom.xml +++ b/cobigen/cobigen-tsplugin/pom.xml @@ -2,7 +2,7 @@ 4.0.0 tsplugin CobiGen - TypeScript Plug-in - 7.1.0-SNAPSHOT + 7.1.0 jar CobiGen - TypeScript Plug-in