diff --git a/cobigen/cobigen-tsplugin/pom.xml b/cobigen/cobigen-tsplugin/pom.xml index aaab698a16..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.0.0 + 7.1.0 jar CobiGen - TypeScript Plug-in 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..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 @@ -8,7 +8,9 @@ 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.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -16,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; @@ -101,48 +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 { - 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); + try { + // Input corresponds to the parsed file + Map mapModel = createModel(input); + mapModel = (Map) mapModel.get("model"); + 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; } } - return false; + } @Override @@ -202,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"); @@ -270,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) { @@ -283,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 e3face2b37..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 @@ -122,6 +122,28 @@ public void testValidInput() { } + /** + * 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 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); + + 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. diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index ace127cc6c..24d3828b2d 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 v7.0.0 * CobiGen - Java Plug-in v7.0.0 * CobiGen - XML Plug-in v7.0.0 -* CobiGen - TypeScript Plug-in v7.0.0 +* CobiGen - TypeScript Plug-in v7.1.0 * CobiGen - Property Plug-in v7.0.0 * CobiGen - Text Merger v7.0.0 * CobiGen - JSON Plug-in v7.0.0