From f7d0031d09937080046d3c7b802f506336ce3382 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 1 May 2024 20:31:45 +0300 Subject: [PATCH] automatically spins up the server to serve rendered graph --- output.json | 174 --------------- src/main/java/org/lumijiez/Main.java | 45 ++-- winx-serve/README.md | 70 ------ winx-serve/src/Data.js | 314 ++++++++++++--------------- 4 files changed, 167 insertions(+), 436 deletions(-) delete mode 100644 output.json delete mode 100644 winx-serve/README.md diff --git a/output.json b/output.json deleted file mode 100644 index 5df711c..0000000 --- a/output.json +++ /dev/null @@ -1,174 +0,0 @@ -[ { - "name" : "Database", - "interfaces" : [ { - "name" : "Database", - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "public", - "implemented_interface" : "none", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "\"CustomDataType\"", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ] - }, { - "name" : "DatabaseAccessImpl", - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "public", - "implemented_interface" : "none", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "\"CustomDataType\"", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ] - } ], - "specifications" : [ { - "name" : "DatabaseAccess", - "implemented_interface" : "Database", - "requirements" : [ { - "name" : "DatabaseAccessMember", - "annotations" : [ { - "importance" : "optional", - "name" : "UserHasAdminAccess" - }, { - "importance" : "critical", - "name" : "UserIsNotBanned" - } ] - } ], - "results" : [ { - "name" : "DatabaseAdminPanel", - "importance" : "optional" - }, { - "name" : "DatabaseVisualizerPanel", - "importance" : "critical" - }, { - "name" : "Clock", - "importance" : "none" - } ], - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "public", - "implemented_interface" : "DatabaseAccessImpl", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUserdList", - "access_modifier" : "public", - "implemented_interface" : "Database", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUserdfList", - "access_modifier" : "public", - "implemented_interface" : "Database", - "importance" : "optional", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUsesfrList", - "access_modifier" : "public", - "implemented_interface" : "Database", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ], - "implementedInterface" : "Database" - } ] -} ] \ No newline at end of file diff --git a/src/main/java/org/lumijiez/Main.java b/src/main/java/org/lumijiez/Main.java index 095b86f..ac5fe70 100644 --- a/src/main/java/org/lumijiez/Main.java +++ b/src/main/java/org/lumijiez/Main.java @@ -9,7 +9,6 @@ import org.lumijiez.parser.WinxParser; import com.fasterxml.jackson.databind.ObjectMapper; -import java.awt.Desktop; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -21,55 +20,57 @@ import java.util.Objects; public class Main { public static void main(String[] args) { try { - // Load the input from a resource file Path inputPath = Path.of(Objects.requireNonNull(Main.class.getResource("/TestProgram.txt")).toURI()); String input = Files.readString(inputPath); - // Initialize ANTLR components CharStream inputStream = CharStreams.fromString(input); WinxLexer lexer = new WinxLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); WinxParser parser = new WinxParser(tokenStream); - // Parsing the input ParseTree tree = parser.winx(); - // Creating and using the collector to process the parse tree WinxCollector collector = new WinxCollector(); collector.visit(tree); - // Retrieve the collected data and save it to JSON List packages = collector.getPackages(); - String json = saveAsJson(packages); + saveAsJson(packages); System.out.println("Data successfully saved to 'output.json'."); + System.out.println("Spinning up React environment..."); - Path templatePath = Path.of(Objects.requireNonNull(Main.class.getResource("/graph.html")).toURI()); - String htmlTemplate = Files.readString(templatePath); - - // Replace placeholder with JSON - String finalHtmlContent = htmlTemplate.replace("const jsonData = null;", "const jsonData = " + json + ";"); - - // Save the modified HTML to a temporary file and open in a browser - Path tempFile = Files.createTempFile("output", ".html"); - Files.writeString(tempFile, finalHtmlContent); - Desktop.getDesktop().browse(tempFile.toUri()); - - System.out.println("HTML with JSON data successfully opened in a browser."); + startReactServer(); } catch (IOException | URISyntaxException e) { System.err.println("Error processing the input file: " + e.getMessage()); } } - private static String saveAsJson(List packages) throws IOException { + private static void saveAsJson(List packages) throws IOException { ObjectMapper mapper = new ObjectMapper(); try { String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(packages); - Files.writeString(Paths.get("output.json"), jsonString); - return jsonString; + String jsContent = "export const jsonData = " + jsonString + ";"; + Files.writeString(Paths.get("winx-serve/src/Data.js"), jsContent); + System.out.println("Data successfully saved to '" + "frontend/src/data.js" + "'."); } catch (JsonProcessingException e) { throw new IOException("Failed to serialize data to JSON", e); } } + + private static void startReactServer() throws IOException { + ProcessBuilder processBuilder = new ProcessBuilder(); + String os = System.getProperty("os.name").toLowerCase(); + if (os.contains("win")) { + processBuilder.command("cmd.exe", "/c", "cd winx-serve && npm start"); + } else { + processBuilder.command("bash", "-c", "cd winx-serve && npm start"); + } + processBuilder.inheritIO(); +// Process process = + processBuilder.start(); + + // int exitCode = process.waitFor(); + // System.out.println("React server started with exit code " + exitCode); + } } diff --git a/winx-serve/README.md b/winx-serve/README.md deleted file mode 100644 index 58beeac..0000000 --- a/winx-serve/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/winx-serve/src/Data.js b/winx-serve/src/Data.js index 600f97b..2bb452f 100644 --- a/winx-serve/src/Data.js +++ b/winx-serve/src/Data.js @@ -1,174 +1,148 @@ export const jsonData = [ { + "name" : "Database", + "interfaces" : [ { "name" : "Database", - "interfaces" : [ { - "name" : "Database", - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "public", - "implemented_interface" : "none", - "importance" : "optional", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "\"CustomDataType\"", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ] - }, { - "name" : "DatabaseAccessImpl", - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "protected", - "implemented_interface" : "none", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "\"CustomDataType\"", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ] - } ], - "specifications" : [ { - "name" : "DatabaseAccess", - "implemented_interface" : "Database", - "requirements" : [ { - "name" : "DatabaseAccessMember", - "annotations" : [ { - "importance" : "optional", - "name" : "UserHasAdminAccess" - }, { - "importance" : "critical", - "name" : "UserIsNotBanned" - } ] - } ], - "results" : [ { - "name" : "DatabaseAdminPanel", - "importance" : "optional" - }, { - "name" : "DatabaseVisualizerPanel", - "importance" : "critical" - }, { - "name" : "Clock", - "importance" : "none" - } ], - "functions" : [ { - "name" : "GetUserList", - "access_modifier" : "public", - "implemented_interface" : "DatabaseAccessImpl", - "importance" : "critical", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUserdList", - "access_modifier" : "private", - "implemented_interface" : "Database", - "importance" : "optional", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUserdfList", - "access_modifier" : "public", - "implemented_interface" : "Database", - "importance" : "optional", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - }, { - "name" : "GetUsesfrList", - "access_modifier" : "private", - "implemented_interface" : "Database", - "importance" : "optional", - "inputTypes" : [ { - "type" : "FLOAT", - "identifier" : "x" - }, { - "type" : "STRING", - "identifier" : "ag" - } ], - "returnTypes" : [ { - "type" : "INT", - "identifier" : "x" - } ], - "specificationEntries" : [ { - "key" : "ExecTime", - "value" : "\"10s\"" - }, { - "key" : "MaxReturnVals", - "value" : "\"10s\"" - } ] - } ], - "implementedInterface" : "Database" + "functions" : [ { + "name" : "GetUserList", + "access_modifier" : "public", + "implemented_interface" : "none", + "importance" : "critical", + "inputTypes" : [ { + "type" : "FLOAT", + "identifier" : "x" + }, { + "type" : "STRING", + "identifier" : "ag" + } ], + "returnTypes" : [ { + "type" : "\"CustomDataType\"", + "identifier" : "x" + } ], + "specificationEntries" : [ { + "key" : "ExecTime", + "value" : "\"10s\"" + }, { + "key" : "MaxReturnVals", + "value" : "\"10s\"" + } ] } ] + } ], + "specifications" : [ { + "name" : "DatabaseAccess", + "implemented_interface" : "Database", + "requirements" : [ { + "name" : "DatabaseAccessMember", + "annotations" : [ { + "importance" : "optional", + "name" : "UserHasAdminAccess" + }, { + "importance" : "critical", + "name" : "UserIsNotBanned" + } ] + } ], + "results" : [ { + "name" : "DatabaseAdminPanel", + "importance" : "optional" + }, { + "name" : "DatabaseVisualizerPanel", + "importance" : "critical" + }, { + "name" : "Clock", + "importance" : "none" + } ], + "functions" : [ { + "name" : "GetUserList", + "access_modifier" : "public", + "implemented_interface" : "DatabaseAccessImpl", + "importance" : "critical", + "inputTypes" : [ { + "type" : "FLOAT", + "identifier" : "x" + }, { + "type" : "STRING", + "identifier" : "ag" + } ], + "returnTypes" : [ { + "type" : "INT", + "identifier" : "x" + } ], + "specificationEntries" : [ { + "key" : "ExecTime", + "value" : "\"10s\"" + }, { + "key" : "MaxReturnVals", + "value" : "\"10s\"" + } ] + }, { + "name" : "GetUserdList", + "access_modifier" : "private", + "implemented_interface" : "Database", + "importance" : "critical", + "inputTypes" : [ { + "type" : "FLOAT", + "identifier" : "x" + }, { + "type" : "STRING", + "identifier" : "ag" + } ], + "returnTypes" : [ { + "type" : "INT", + "identifier" : "x" + } ], + "specificationEntries" : [ { + "key" : "ExecTime", + "value" : "\"10s\"" + }, { + "key" : "MaxReturnVals", + "value" : "\"10s\"" + } ] + }, { + "name" : "GetUserdfList", + "access_modifier" : "public", + "implemented_interface" : "Database", + "importance" : "critical", + "inputTypes" : [ { + "type" : "FLOAT", + "identifier" : "x" + }, { + "type" : "STRING", + "identifier" : "ag" + } ], + "returnTypes" : [ { + "type" : "INT", + "identifier" : "x" + } ], + "specificationEntries" : [ { + "key" : "ExecTime", + "value" : "\"10s\"" + }, { + "key" : "MaxReturnVals", + "value" : "\"10s\"" + } ] + }, { + "name" : "GetUsesfrList", + "access_modifier" : "public", + "implemented_interface" : "Database", + "importance" : "optional", + "inputTypes" : [ { + "type" : "FLOAT", + "identifier" : "x" + }, { + "type" : "STRING", + "identifier" : "ag" + } ], + "returnTypes" : [ { + "type" : "INT", + "identifier" : "x" + } ], + "specificationEntries" : [ { + "key" : "ExecTime", + "value" : "\"10s\"" + }, { + "key" : "MaxReturnVals", + "value" : "\"10s\"" + } ] + } ], + "implementedInterface" : "Database" + } ] } ]; \ No newline at end of file