Skip to content

Commit 7b0260d

Browse files
authored
Merge pull request #156 from pwgit-create/develop
AppWish 2.0
2 parents 229844c + f302cc8 commit 7b0260d

31 files changed

+1639
-222
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>pn.dev</groupId>
5+
<artifactId>code-generator-gui-ollama</artifactId>
6+
<name>CodeGenerator-GUI</name>
7+
<version>1.8.1</version>
8+
<description>The GUI interface for the pn.dev.code-generator-ollama library is included in this package</description>
9+
<inceptionYear>2024</inceptionYear>
10+
<developers>
11+
<developer>
12+
<id>Peter</id>
13+
<name>Peter Westin</name>
14+
<email>snow_900@outlook.com</email>
15+
<roles>
16+
<role>Security Champion</role>
17+
<role>Backend Engineer</role>
18+
</roles>
19+
<timezone>Central European Time</timezone>
20+
</developer>
21+
</developers>
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<artifactId>maven-compiler-plugin</artifactId>
26+
<version>3.13.0</version>
27+
<configuration>
28+
<source>19</source>
29+
<target>19</target>
30+
</configuration>
31+
</plugin>
32+
<plugin>
33+
<groupId>org.openjfx</groupId>
34+
<artifactId>javafx-maven-plugin</artifactId>
35+
<version>0.0.8</version>
36+
<executions>
37+
<execution>
38+
<id>default-cli</id>
39+
<configuration>
40+
<mainClass>pn.app_wish.Main</mainClass>
41+
<launcher>app</launcher>
42+
<jlinkZipName>app</jlinkZipName>
43+
<jlinkImageName>app</jlinkImageName>
44+
<noManPages>true</noManPages>
45+
<stripDebug>true</stripDebug>
46+
<noHeaderFiles>true</noHeaderFiles>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
<plugin>
52+
<artifactId>maven-shade-plugin</artifactId>
53+
<version>3.6.0</version>
54+
<executions>
55+
<execution>
56+
<phase>package</phase>
57+
<goals>
58+
<goal>shade</goal>
59+
</goals>
60+
<configuration>
61+
<transformers>
62+
<transformer>
63+
<mainClass>pn.app_wish.Main</mainClass>
64+
</transformer>
65+
</transformers>
66+
</configuration>
67+
</execution>
68+
</executions>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
<dependencies>
73+
<dependency>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter-api</artifactId>
76+
<version>5.11.0-M2</version>
77+
<scope>test</scope>
78+
<exclusions>
79+
<exclusion>
80+
<artifactId>opentest4j</artifactId>
81+
<groupId>org.opentest4j</groupId>
82+
</exclusion>
83+
<exclusion>
84+
<artifactId>junit-platform-commons</artifactId>
85+
<groupId>org.junit.platform</groupId>
86+
</exclusion>
87+
<exclusion>
88+
<artifactId>apiguardian-api</artifactId>
89+
<groupId>org.apiguardian</groupId>
90+
</exclusion>
91+
</exclusions>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.junit.jupiter</groupId>
95+
<artifactId>junit-jupiter-engine</artifactId>
96+
<version>5.11.0-M2</version>
97+
<scope>test</scope>
98+
<exclusions>
99+
<exclusion>
100+
<artifactId>junit-platform-engine</artifactId>
101+
<groupId>org.junit.platform</groupId>
102+
</exclusion>
103+
<exclusion>
104+
<artifactId>apiguardian-api</artifactId>
105+
<groupId>org.apiguardian</groupId>
106+
</exclusion>
107+
</exclusions>
108+
</dependency>
109+
</dependencies>
110+
<distributionManagement>
111+
<repository>
112+
<id>github</id>
113+
<name>GitHub pwgit-create Apache Maven Packages</name>
114+
<url>https://maven.pkg.github.com/pwgit-create/APPWISH_OLLAMA</url>
115+
</repository>
116+
</distributionManagement>
117+
<properties>
118+
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
119+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
120+
<javafx.version>19.0.2.1</javafx.version>
121+
<junit.version>5.11.0-M2</junit.version>
122+
<sonar.organization>pn-dev</sonar.organization>
123+
</properties>
124+
</project>

AppWish/AppWish/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>pn.dev</groupId>
77
<artifactId>code-generator-gui-ollama</artifactId>
8-
<version>1.8.1</version>
8+
<version>2.0</version>
99
<name>CodeGenerator-GUI</name>
1010

1111

@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>pn.dev</groupId>
4747
<artifactId>code-generator-ollama</artifactId>
48-
<version>1.8.1</version>
48+
<version>2.0</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>org.openjfx</groupId>

AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import org.slf4j.LoggerFactory;
2424
import org.slf4j.simple.SimpleLogger;
2525

26+
import pn.app_wish.model.AppCmd;
27+
import pn.app_wish.model.CodeBaseCmd;
2628
import pn.app_wish.constant.CodeEvent;
2729
import pn.app_wish.constant.GUIConstants;
2830
import pn.app_wish.constant.StaticAppWishConstants;
29-
import pn.app_wish.util.AppWishUtil;
3031
import pn.cg.app_system.AppSystem;
3132
import pn.cg.app_system.code_generation.model.CompilationJob;
3233
import pn.cg.datastorage.DataStorage;
@@ -38,12 +39,13 @@
3839
import java.nio.file.Files;
3940
import java.nio.file.Paths;
4041

42+
import java.util.LinkedList;
4143
import java.util.List;
4244

4345

4446
import static java.util.Objects.requireNonNull;
45-
import static pn.app_wish.constant.GUIConstants.APP_HISTORY_STAGE_TILE;
46-
import static pn.app_wish.constant.GUIConstants.DEFAULT_FXML_FILE;
47+
import static pn.app_wish.constant.GUIConstants.*;
48+
import static pn.app_wish.constant.StaticAppWishConstants.*;
4749

4850

4951
public class AppWish extends Application {
@@ -67,6 +69,8 @@ public class AppWish extends Application {
6769
public Button btn_StopGeneratedApp;
6870
@FXML
6971
public ImageView logo;
72+
@FXML
73+
public Button btn_super_app_creation;
7074

7175
private String javaExecutablePath;
7276
private Process executingJavaAppProcess;
@@ -100,11 +104,13 @@ public void start(Stage primaryStage) throws IOException {
100104
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
101105
Parent root = FXMLLoader.load(requireNonNull(getClass().getClassLoader().getResource(DEFAULT_FXML_FILE)));
102106
mainStage = primaryStage;
107+
mainStage.setResizable(false);
103108
primaryStage.setTitle(GUIConstants.DEFAULT_STAGE_TITLE);
104109
Scene scene = new Scene(root);
105110
primaryStage.setScene(scene);
106111
primaryStage.show();
107112
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");
113+
108114
}
109115

110116
/**
@@ -149,7 +155,7 @@ private void onAppWish(CodeEvent codeEvent) {
149155

150156
waitForCompilationResult();
151157

152-
handleCompilationResult();
158+
handleCompilationResult(false);
153159

154160
});
155161

@@ -161,21 +167,44 @@ private void onRunJavaApp(ActionEvent ae) {
161167
btn_StopGeneratedApp.setVisible(true);
162168

163169
if (javaExecutablePath != null) {
164-
System.out.println("Executing java app on path -> " + javaExecutablePath);
170+
171+
if (!output_label.isVisible()) {
172+
log.info("Executing java app on path -> {}", javaExecutablePath);
173+
}
165174
try {
166-
ProcessBuilder pb;
167-
pb = new ProcessBuilder(StaticAppWishConstants.BASH_PATH, StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + javaExecutablePath);
175+
ProcessBuilder pb = GetProcessBuilderForRunningGeneratedJavaApplications();
168176
executingJavaAppProcess = pb.inheritIO().start();
169177
} catch (IOException e) {
170178
throw new RuntimeException(e);
171179
}
172180
}
173181
}
174182

183+
private final ProcessBuilder GetProcessBuilderForRunningGeneratedJavaApplications() {
184+
ProcessBuilder pb = null;
185+
186+
final String classPath = javaExecutablePath.replace(MAIN_DOT_JAVA, NOTHING_STRING);
187+
188+
if (output_label.isVisible()) {
189+
// Super App Creation
190+
191+
// Security
192+
if (classPath.concat(MAIN_DOT_JAVA).equals(javaExecutablePath)) {
193+
log.info("Executing java app on path -> {}", javaExecutablePath.replace(MAIN_DOT_JAVA, NOTHING_STRING) + MAIN_TEXT);
194+
pb = new ProcessBuilder(new CodeBaseCmd(classPath).GetCMDForRunningCodeBaseApplication());
195+
}
196+
} else {
197+
// New App
198+
// Continue an App
199+
pb = new ProcessBuilder(new AppCmd(javaExecutablePath).GetCMDForRunningCodeBaseApplication());
200+
}
201+
return pb;
202+
}
203+
175204
@FXML
176205
private void onViewAppHistory(ActionEvent ae) throws IOException {
177206

178-
if(!isCodeGenerationOnGoing) {
207+
if (!isCodeGenerationOnGoing) {
179208
AnchorPane pane = FXMLLoader.load(
180209
requireNonNull(getClass().getClassLoader().getResource(GUIConstants.APP_HISTORY_FXML_FILE)));
181210
Scene scene = new Scene(pane);
@@ -220,21 +249,22 @@ private void startGuiThread(CodeEvent codeEvent) {
220249
/**
221250
* The method for the event CREATE_APPLICATION
222251
*/
223-
private void codeEventCreateApplication(){
224-
if(!btn_StopGeneratedApp.isVisible()){
225-
setButtonGroupVisibilityForCodeGenerationButtons(false);
226-
output_label.setText("Generating code...");
227-
}
252+
private void codeEventCreateApplication() {
253+
if (!btn_StopGeneratedApp.isVisible()) {
254+
setButtonGroupVisibilityForCodeGenerationButtons(false);
255+
output_label.setText(GUIConstants.GENERATING_CODE_DEFAULT_TEXT);
256+
}
228257
}
258+
229259
/**
230260
* The method for the event CONTINUE_ON_EXISTING_APPLICATION
231261
*/
232-
private void codeEventContinueAnApplication(){
233-
if(!btn_StopGeneratedApp.isVisible()) {
262+
private void codeEventContinueAnApplication() {
263+
if (!btn_StopGeneratedApp.isVisible()) {
234264
setButtonGroupVisibilityForCodeGenerationButtons(false);
235-
output_label.setText("Generating code...\nContinue with existing application");
236-
}
265+
output_label.setText(GUIConstants.CONTINUING_CODE_TEXT);
237266
}
267+
}
238268

239269
/**
240270
* Create application button event
@@ -260,7 +290,6 @@ private void continueOnExistingApplication(ActionEvent ae) {
260290
}
261291
}
262292

263-
264293
/**
265294
* Starts the AI Code-Generation if the text input field is not null
266295
*/
@@ -290,20 +319,27 @@ private void waitForCompilationResult() {
290319
}
291320
}
292321

322+
293323
/**
294324
* If a compilation result exist , check if the singleton in code-generator-ollama contains a path for an executable Java file
295325
* If the above is true , activate the "run application" button and remove the "generating code..." text
296326
*/
297-
private void handleCompilationResult() {
327+
private void handleCompilationResult(boolean isSuperGeneration) {
298328
if (DataStorage.getInstance().getCompilationJob().isResult()) {
299329
javaExecutablePath = DataStorage.getInstance().getJavaExecutionPath();
300330
// Draw success or error texts, and show run app button
301331
Platform.runLater(() -> {
302-
if (DataStorage.getInstance().getJavaExecutionPath() != null) {
303-
output_label.setVisible(false);
332+
if (DataStorage.getInstance().getJavaExecutionPath() != null || isSuperGeneration) {
333+
if (!isSuperGeneration) {
334+
output_label.setVisible(false);
335+
btn_run_application.setVisible(true);
336+
}
304337
btn_run_application.setVisible(true);
305338
setButtonGroupVisibilityForCodeGenerationButtons(true);
306339
isCodeGenerationOnGoing = false;
340+
if (isSuperGeneration) {
341+
output_label.setText(SUCCESS_ON_SUPER_APP_CREATION_TEXT);
342+
}
307343
} else {
308344
output_label.setText("Something went wrong :(");
309345
}
@@ -318,6 +354,7 @@ private void handleCompilationResult() {
318354
private void setButtonGroupVisibilityForCodeGenerationButtons(boolean isVisible) {
319355
btn_create_application.setVisible(isVisible);
320356
btn_continue_on_application.setVisible(isVisible);
357+
btn_super_app_creation.setVisible(isVisible);
321358
}
322359

323360
/**
@@ -354,4 +391,42 @@ private List<String> readTextByLinesFromFile(File file) {
354391
return null;
355392
}
356393
}
394+
395+
@FXML
396+
public void OnSuperAppCreationButton(ActionEvent ae) {
397+
398+
isCodeGenerationOnGoing = true;
399+
DataStorage.getInstance().setCompilationJob(new CompilationJob(GUIConstants.DEFAULT_STAGE_TITLE));
400+
ThreadPoolMaster.getInstance().getExecutor().execute(() -> {
401+
StartGuiThreadForSuperAppCreation();
402+
403+
AppSystem.StartSuperAppGeneration(tf_input.getText(), true, false, new LinkedList<>(), false, null);
404+
405+
waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented();
406+
handleCompilationResult(true);
407+
});
408+
}
409+
410+
/**
411+
* Starts a thread that handles GUI Updates
412+
*/
413+
private void StartGuiThreadForSuperAppCreation() {
414+
415+
Platform.runLater(() -> {
416+
setButtonGroupVisibilityForCodeGenerationButtons(false);
417+
setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons();
418+
output_label.setText(GENERATING_CODE_BASE_TEXT);
419+
output_label.setVisible(true);
420+
});
421+
}
422+
423+
/**
424+
* Wait until the singleton in code-generator-ollama has created the entire super app
425+
*/
426+
private void waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented() {
427+
428+
while (!DataStorage.getInstance().isSuperAppCreated()) {
429+
}
430+
}
431+
357432
}

AppWish/AppWish/src/main/java/pn/app_wish/constant/GUIConstants.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@ public class GUIConstants {
77
public static final String APP_HISTORY_FXML_FILE="app_history.fxml";
88
public static final String APP_HISTORY_STAGE_TILE="My apps";
99

10+
public static final String GENERATING_CODE_DEFAULT_TEXT="Generating code...";
11+
public static final String CONTINUING_CODE_TEXT="Continuing with existing application...";
12+
public static final String GENERATING_CODE_BASE_TEXT="Generating codebase...";
13+
public static final String SUCCESS_ON_SUPER_APP_CREATION_TEXT="Success :)";
14+
15+
1016

1117
}

0 commit comments

Comments
 (0)