Skip to content

Commit

Permalink
Merge pull request #155 from pwgit-create/superApp
Browse files Browse the repository at this point in the history
Super app
  • Loading branch information
pwgit-create authored Jul 1, 2024
2 parents 2cc8015 + 6954982 commit f302cc8
Show file tree
Hide file tree
Showing 31 changed files with 1,639 additions and 222 deletions.
124 changes: 124 additions & 0 deletions AppWish/AppWish/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pn.dev</groupId>
<artifactId>code-generator-gui-ollama</artifactId>
<name>CodeGenerator-GUI</name>
<version>1.8.1</version>
<description>The GUI interface for the pn.dev.code-generator-ollama library is included in this package</description>
<inceptionYear>2024</inceptionYear>
<developers>
<developer>
<id>Peter</id>
<name>Peter Westin</name>
<email>[email protected]</email>
<roles>
<role>Security Champion</role>
<role>Backend Engineer</role>
</roles>
<timezone>Central European Time</timezone>
</developer>
</developers>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<mainClass>pn.app_wish.Main</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>pn.app_wish.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>opentest4j</artifactId>
<groupId>org.opentest4j</groupId>
</exclusion>
<exclusion>
<artifactId>junit-platform-commons</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit-platform-engine</artifactId>
<groupId>org.junit.platform</groupId>
</exclusion>
<exclusion>
<artifactId>apiguardian-api</artifactId>
<groupId>org.apiguardian</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub pwgit-create Apache Maven Packages</name>
<url>https://maven.pkg.github.com/pwgit-create/APPWISH_OLLAMA</url>
</repository>
</distributionManagement>
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javafx.version>19.0.2.1</javafx.version>
<junit.version>5.11.0-M2</junit.version>
<sonar.organization>pn-dev</sonar.organization>
</properties>
</project>
4 changes: 2 additions & 2 deletions AppWish/AppWish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pn.dev</groupId>
<artifactId>code-generator-gui-ollama</artifactId>
<version>1.8.1</version>
<version>2.0</version>
<name>CodeGenerator-GUI</name>


Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>pn.dev</groupId>
<artifactId>code-generator-ollama</artifactId>
<version>1.8.1</version>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
Expand Down
117 changes: 96 additions & 21 deletions AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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");

}

/**
Expand Down Expand Up @@ -149,7 +155,7 @@ private void onAppWish(CodeEvent codeEvent) {

waitForCompilationResult();

handleCompilationResult();
handleCompilationResult(false);

});

Expand All @@ -161,21 +167,44 @@ 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);
}
}
}

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);
Expand Down Expand Up @@ -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
Expand All @@ -260,7 +290,6 @@ private void continueOnExistingApplication(ActionEvent ae) {
}
}


/**
* Starts the AI Code-Generation if the text input field is not null
*/
Expand Down Expand Up @@ -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 :(");
}
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -354,4 +391,42 @@ private List<String> 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()) {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)";



}
Loading

0 comments on commit f302cc8

Please sign in to comment.