diff --git a/AppWish/AppWish/dependency-reduced-pom.xml b/AppWish/AppWish/dependency-reduced-pom.xml new file mode 100644 index 0000000..deae5e0 --- /dev/null +++ b/AppWish/AppWish/dependency-reduced-pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + pn.dev + code-generator-gui-ollama + CodeGenerator-GUI + 1.8.1 + The GUI interface for the pn.dev.code-generator-ollama library is included in this package + 2024 + + + Peter + Peter Westin + snow_900@outlook.com + + Security Champion + Backend Engineer + + Central European Time + + + + + + maven-compiler-plugin + 3.13.0 + + 19 + 19 + + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + + default-cli + + pn.app_wish.Main + app + app + app + true + true + true + + + + + + maven-shade-plugin + 3.6.0 + + + package + + shade + + + + + pn.app_wish.Main + + + + + + + + + + + org.junit.jupiter + junit-jupiter-api + 5.11.0-M2 + test + + + opentest4j + org.opentest4j + + + junit-platform-commons + org.junit.platform + + + apiguardian-api + org.apiguardian + + + + + org.junit.jupiter + junit-jupiter-engine + 5.11.0-M2 + test + + + junit-platform-engine + org.junit.platform + + + apiguardian-api + org.apiguardian + + + + + + + github + GitHub pwgit-create Apache Maven Packages + https://maven.pkg.github.com/pwgit-create/APPWISH_OLLAMA + + + + https://sonarcloud.io + UTF-8 + 19.0.2.1 + 5.11.0-M2 + pn-dev + + diff --git a/AppWish/AppWish/pom.xml b/AppWish/AppWish/pom.xml index abf7d34..6d8d0c8 100644 --- a/AppWish/AppWish/pom.xml +++ b/AppWish/AppWish/pom.xml @@ -5,7 +5,7 @@ 4.0.0 pn.dev code-generator-gui-ollama - 1.8.1 + 2.0 CodeGenerator-GUI @@ -45,7 +45,7 @@ pn.dev code-generator-ollama - 1.8.1 + 2.0 org.openjfx diff --git a/AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java b/AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java index 746dfe4..4cf00ab 100644 --- a/AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java +++ b/AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java @@ -23,10 +23,11 @@ import org.slf4j.LoggerFactory; import org.slf4j.simple.SimpleLogger; +import pn.app_wish.model.AppCmd; +import pn.app_wish.model.CodeBaseCmd; import pn.app_wish.constant.CodeEvent; import pn.app_wish.constant.GUIConstants; import pn.app_wish.constant.StaticAppWishConstants; -import pn.app_wish.util.AppWishUtil; import pn.cg.app_system.AppSystem; import pn.cg.app_system.code_generation.model.CompilationJob; import pn.cg.datastorage.DataStorage; @@ -38,12 +39,13 @@ import java.nio.file.Files; import java.nio.file.Paths; +import java.util.LinkedList; import java.util.List; import static java.util.Objects.requireNonNull; -import static pn.app_wish.constant.GUIConstants.APP_HISTORY_STAGE_TILE; -import static pn.app_wish.constant.GUIConstants.DEFAULT_FXML_FILE; +import static pn.app_wish.constant.GUIConstants.*; +import static pn.app_wish.constant.StaticAppWishConstants.*; public class AppWish extends Application { @@ -67,6 +69,8 @@ public class AppWish extends Application { public Button btn_StopGeneratedApp; @FXML public ImageView logo; + @FXML + public Button btn_super_app_creation; private String javaExecutablePath; private Process executingJavaAppProcess; @@ -100,11 +104,13 @@ public void start(Stage primaryStage) throws IOException { System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG"); Parent root = FXMLLoader.load(requireNonNull(getClass().getClassLoader().getResource(DEFAULT_FXML_FILE))); mainStage = primaryStage; + mainStage.setResizable(false); primaryStage.setTitle(GUIConstants.DEFAULT_STAGE_TITLE); Scene scene = new Scene(root); primaryStage.setScene(scene); primaryStage.show(); System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + } /** @@ -149,7 +155,7 @@ private void onAppWish(CodeEvent codeEvent) { waitForCompilationResult(); - handleCompilationResult(); + handleCompilationResult(false); }); @@ -161,10 +167,12 @@ private void onRunJavaApp(ActionEvent ae) { btn_StopGeneratedApp.setVisible(true); if (javaExecutablePath != null) { - System.out.println("Executing java app on path -> " + javaExecutablePath); + + if (!output_label.isVisible()) { + log.info("Executing java app on path -> {}", javaExecutablePath); + } try { - ProcessBuilder pb; - pb = new ProcessBuilder(StaticAppWishConstants.BASH_PATH, StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + javaExecutablePath); + ProcessBuilder pb = GetProcessBuilderForRunningGeneratedJavaApplications(); executingJavaAppProcess = pb.inheritIO().start(); } catch (IOException e) { throw new RuntimeException(e); @@ -172,10 +180,31 @@ private void onRunJavaApp(ActionEvent ae) { } } + private final ProcessBuilder GetProcessBuilderForRunningGeneratedJavaApplications() { + ProcessBuilder pb = null; + + final String classPath = javaExecutablePath.replace(MAIN_DOT_JAVA, NOTHING_STRING); + + if (output_label.isVisible()) { + // Super App Creation + + // Security + if (classPath.concat(MAIN_DOT_JAVA).equals(javaExecutablePath)) { + log.info("Executing java app on path -> {}", javaExecutablePath.replace(MAIN_DOT_JAVA, NOTHING_STRING) + MAIN_TEXT); + pb = new ProcessBuilder(new CodeBaseCmd(classPath).GetCMDForRunningCodeBaseApplication()); + } + } else { + // New App + // Continue an App + pb = new ProcessBuilder(new AppCmd(javaExecutablePath).GetCMDForRunningCodeBaseApplication()); + } + return pb; + } + @FXML private void onViewAppHistory(ActionEvent ae) throws IOException { - if(!isCodeGenerationOnGoing) { + if (!isCodeGenerationOnGoing) { AnchorPane pane = FXMLLoader.load( requireNonNull(getClass().getClassLoader().getResource(GUIConstants.APP_HISTORY_FXML_FILE))); Scene scene = new Scene(pane); @@ -220,21 +249,22 @@ private void startGuiThread(CodeEvent codeEvent) { /** * The method for the event CREATE_APPLICATION */ - private void codeEventCreateApplication(){ - if(!btn_StopGeneratedApp.isVisible()){ - setButtonGroupVisibilityForCodeGenerationButtons(false); - output_label.setText("Generating code..."); - } + private void codeEventCreateApplication() { + if (!btn_StopGeneratedApp.isVisible()) { + setButtonGroupVisibilityForCodeGenerationButtons(false); + output_label.setText(GUIConstants.GENERATING_CODE_DEFAULT_TEXT); + } } + /** * The method for the event CONTINUE_ON_EXISTING_APPLICATION */ - private void codeEventContinueAnApplication(){ - if(!btn_StopGeneratedApp.isVisible()) { + private void codeEventContinueAnApplication() { + if (!btn_StopGeneratedApp.isVisible()) { setButtonGroupVisibilityForCodeGenerationButtons(false); - output_label.setText("Generating code...\nContinue with existing application"); - } + output_label.setText(GUIConstants.CONTINUING_CODE_TEXT); } + } /** * Create application button event @@ -260,7 +290,6 @@ private void continueOnExistingApplication(ActionEvent ae) { } } - /** * Starts the AI Code-Generation if the text input field is not null */ @@ -290,20 +319,27 @@ private void waitForCompilationResult() { } } + /** * If a compilation result exist , check if the singleton in code-generator-ollama contains a path for an executable Java file * If the above is true , activate the "run application" button and remove the "generating code..." text */ - private void handleCompilationResult() { + private void handleCompilationResult(boolean isSuperGeneration) { if (DataStorage.getInstance().getCompilationJob().isResult()) { javaExecutablePath = DataStorage.getInstance().getJavaExecutionPath(); // Draw success or error texts, and show run app button Platform.runLater(() -> { - if (DataStorage.getInstance().getJavaExecutionPath() != null) { - output_label.setVisible(false); + if (DataStorage.getInstance().getJavaExecutionPath() != null || isSuperGeneration) { + if (!isSuperGeneration) { + output_label.setVisible(false); + btn_run_application.setVisible(true); + } btn_run_application.setVisible(true); setButtonGroupVisibilityForCodeGenerationButtons(true); isCodeGenerationOnGoing = false; + if (isSuperGeneration) { + output_label.setText(SUCCESS_ON_SUPER_APP_CREATION_TEXT); + } } else { output_label.setText("Something went wrong :("); } @@ -318,6 +354,7 @@ private void handleCompilationResult() { private void setButtonGroupVisibilityForCodeGenerationButtons(boolean isVisible) { btn_create_application.setVisible(isVisible); btn_continue_on_application.setVisible(isVisible); + btn_super_app_creation.setVisible(isVisible); } /** @@ -354,4 +391,42 @@ private List readTextByLinesFromFile(File file) { return null; } } + + @FXML + public void OnSuperAppCreationButton(ActionEvent ae) { + + isCodeGenerationOnGoing = true; + DataStorage.getInstance().setCompilationJob(new CompilationJob(GUIConstants.DEFAULT_STAGE_TITLE)); + ThreadPoolMaster.getInstance().getExecutor().execute(() -> { + StartGuiThreadForSuperAppCreation(); + + AppSystem.StartSuperAppGeneration(tf_input.getText(), true, false, new LinkedList<>(), false, null); + + waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented(); + handleCompilationResult(true); + }); + } + + /** + * Starts a thread that handles GUI Updates + */ + private void StartGuiThreadForSuperAppCreation() { + + Platform.runLater(() -> { + setButtonGroupVisibilityForCodeGenerationButtons(false); + setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons(); + output_label.setText(GENERATING_CODE_BASE_TEXT); + output_label.setVisible(true); + }); + } + + /** + * Wait until the singleton in code-generator-ollama has created the entire super app + */ + private void waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented() { + + while (!DataStorage.getInstance().isSuperAppCreated()) { + } + } + } \ No newline at end of file diff --git a/AppWish/AppWish/src/main/java/pn/app_wish/constant/GUIConstants.java b/AppWish/AppWish/src/main/java/pn/app_wish/constant/GUIConstants.java index d6db59c..a8d34c3 100644 --- a/AppWish/AppWish/src/main/java/pn/app_wish/constant/GUIConstants.java +++ b/AppWish/AppWish/src/main/java/pn/app_wish/constant/GUIConstants.java @@ -7,5 +7,11 @@ public class GUIConstants { public static final String APP_HISTORY_FXML_FILE="app_history.fxml"; public static final String APP_HISTORY_STAGE_TILE="My apps"; + public static final String GENERATING_CODE_DEFAULT_TEXT="Generating code..."; + public static final String CONTINUING_CODE_TEXT="Continuing with existing application..."; + public static final String GENERATING_CODE_BASE_TEXT="Generating codebase..."; + public static final String SUCCESS_ON_SUPER_APP_CREATION_TEXT="Success :)"; + + } diff --git a/AppWish/AppWish/src/main/java/pn/app_wish/constant/StaticAppWishConstants.java b/AppWish/AppWish/src/main/java/pn/app_wish/constant/StaticAppWishConstants.java index d81eeee..32f7d06 100644 --- a/AppWish/AppWish/src/main/java/pn/app_wish/constant/StaticAppWishConstants.java +++ b/AppWish/AppWish/src/main/java/pn/app_wish/constant/StaticAppWishConstants.java @@ -3,7 +3,12 @@ public record StaticAppWishConstants() { public static final String BASH_PATH = "/bin/bash"; public static final String C_ARGUMENT = "-c"; - public final static String JAVA_TEXT = "java "; + public static final String JAVA_TEXT = "java "; + + + public static final String MAIN_TEXT="Main"; + public static final String MAIN_DOT_JAVA="Main.java"; + public static final String NOTHING_STRING=""; public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION = "*.java"; public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION_DESCRIPTION = "A extension filter with purpose to only show .java files"; diff --git a/AppWish/AppWish/src/main/java/pn/app_wish/model/AppCmd.java b/AppWish/AppWish/src/main/java/pn/app_wish/model/AppCmd.java new file mode 100644 index 0000000..f8d95af --- /dev/null +++ b/AppWish/AppWish/src/main/java/pn/app_wish/model/AppCmd.java @@ -0,0 +1,10 @@ +package pn.app_wish.model; +import pn.app_wish.constant.StaticAppWishConstants; + +public record AppCmd(String javaExecutablePath) { + + public final String[] GetCMDForRunningCodeBaseApplication() { + + return new String[]{StaticAppWishConstants.BASH_PATH,StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + javaExecutablePath}; + } +} diff --git a/AppWish/AppWish/src/main/java/pn/app_wish/model/CodeBaseCmd.java b/AppWish/AppWish/src/main/java/pn/app_wish/model/CodeBaseCmd.java new file mode 100644 index 0000000..a6d3e11 --- /dev/null +++ b/AppWish/AppWish/src/main/java/pn/app_wish/model/CodeBaseCmd.java @@ -0,0 +1,12 @@ +package pn.app_wish.model; + +public record CodeBaseCmd(String classPath) { + + public final String[] GetCMDForRunningCodeBaseApplication() { + final String JAVA_PATH = "/usr/bin/java"; + final String C_ARGUMENT_SUPER_APP="-cp"; + final String CLASS_NAME="Main"; + + return new String[]{JAVA_PATH,C_ARGUMENT_SUPER_APP,classPath,CLASS_NAME}; + } +} diff --git a/AppWish/AppWish/src/main/resources/ollama_model.props b/AppWish/AppWish/src/main/resources/ollama_model.props index ab1a2a4..786a39c 100644 --- a/AppWish/AppWish/src/main/resources/ollama_model.props +++ b/AppWish/AppWish/src/main/resources/ollama_model.props @@ -1 +1 @@ -MODEL_NAME=llama3:latest +MODEL_NAME=codestral:22b \ No newline at end of file diff --git a/AppWish/AppWish/src/main/resources/start.fxml b/AppWish/AppWish/src/main/resources/start.fxml index 67a25dc..a979c82 100644 --- a/AppWish/AppWish/src/main/resources/start.fxml +++ b/AppWish/AppWish/src/main/resources/start.fxml @@ -1,81 +1,63 @@ - - - - - - - - - - - + + + + + + - - - - - - - -