Skip to content

Commit bba23ff

Browse files
authored
Merge pull request #168 from pwgit-create/develop
V 2.0.2
2 parents 10a68f2 + 8f09543 commit bba23ff

File tree

10 files changed

+192
-48
lines changed

10 files changed

+192
-48
lines changed

AppWish/AppWish/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>pn.dev</groupId>
55
<artifactId>code-generator-gui-ollama</artifactId>
66
<name>CodeGenerator-GUI</name>
7-
<version>1.8.1</version>
7+
<version>2.0.2</version>
88
<description>The GUI interface for the pn.dev.code-generator-ollama library is included in this package</description>
99
<inceptionYear>2024</inceptionYear>
1010
<developers>

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>2.0.1</version>
8+
<version>2.0.2</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>2.0.1</version>
48+
<version>2.0.2</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>org.openjfx</groupId>

cg/CodeGenerator/CodeGenerator/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>pn.dev</groupId>
55
<artifactId>code-generator-ollama</artifactId>
6-
<version>1.8.1</version>
6+
<version>2.0.2</version>
77
<description>The Java Application-Generator (pn.dev.code-generator-ollama) creates applications by giving a string of your desired features for a Java application, like this: AppSystem.StartCodeGenerator(String appWish)</description>
88
<inceptionYear>2024</inceptionYear>
99
<developers>

cg/CodeGenerator/CodeGenerator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>pn.dev</groupId>
88
<artifactId>code-generator-ollama</artifactId>
9-
<version>2.0.1</version>
9+
<version>2.0.2</version>
1010

1111

1212
<description>The Java Application-Generator (pn.dev.code-generator-ollama) creates applications by giving a string of your desired features for a Java application, like this: AppSystem.StartCodeGenerator(String appWish)</description>

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/app_system/AppSystem.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pn.cg.datastorage.DataStorage;
88
import pn.cg.ollama_ai_remote.OllamaRemoteSystem;
99
import pn.cg.util.CodeGeneratorUtil;
10+
import pn.cg.util.StringUtil;
1011

1112

1213
import java.io.File;
@@ -54,6 +55,13 @@ private static void StartCodeGenerator(String appWish, boolean isFirstRun, boole
5455
if (isCreateAppGeneration) {
5556
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, "", null);
5657
} else {
58+
DataStorage.getInstance().setContinueAnAppDirectoryName(CodeGeneratorUtil.getIncrementedContinueOnAppDirectoryName(StringUtil.extractClassNameFromTextWithJavaClasses(javaFileContentInLines)));
59+
try {
60+
Files.createDirectory(new File(COMPILE_CLASS_STORAGE + File.separator + DataStorage.getInstance().getContinueAnAppDirectoryName()).toPath());
61+
} catch (IOException e) {
62+
throw new RuntimeException(e);
63+
}
64+
5765
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, pathOfJavaFileIfModifyRequest, javaFileContentInLines);
5866
}
5967
}

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/datastorage/DataStorage.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ public class DataStorage {
3434
/**
3535
* Data holder for the current Super App Directory name
3636
*/
37-
private String SuperAppDirectoryName;
37+
private String superAppDirectoryName;
3838

39+
/**
40+
* Data holder for the current Continue an App Directory
41+
*/
42+
private String continueAnAppDirectoryName;
3943
/**
4044
* The class that is selected for implementation tries in a super app creation process
4145
*/
@@ -52,15 +56,15 @@ public class DataStorage {
5256
* The path for the project root directory
5357
*/
5458
private final Path PROJECT_ROOT_WORKING_DIR;
55-
private DataStorage() {
59+
private DataStorage() {
5660

5761
this.compilationJob = getCompilationJob();
5862
this.isSuperAppCreated = false;
5963
this.PROJECT_ROOT_WORKING_DIR = Path.of(System.getProperty("user.dir"));
6064
}
6165

6266

63-
synchronized public static DataStorage getInstance() {
67+
synchronized public static DataStorage getInstance() {
6468
if (instance == null) {
6569

6670
instance = new DataStorage();
@@ -69,70 +73,78 @@ synchronized public static DataStorage getInstance() {
6973
}
7074

7175

72-
public CompilationJob getCompilationJob() {
76+
public final CompilationJob getCompilationJob() {
7377
return compilationJob;
7478
}
7579

76-
public void setCompilationJob(CompilationJob compilationJob) {
80+
public final void setCompilationJob(CompilationJob compilationJob) {
7781
this.compilationJob = compilationJob;
7882
}
7983

80-
public String getJavaExecutionPath() {
84+
public final String getJavaExecutionPath() {
8185
return javaExecutionPath;
8286
}
8387

84-
public void setJavaExecutionPath(String javaExecutionPath) {
88+
public final void setJavaExecutionPath(String javaExecutionPath) {
8589
this.javaExecutionPath = javaExecutionPath;
8690
}
8791

88-
public SuperApp getCurrentSuperClass() {
92+
public final SuperApp getCurrentSuperClass() {
8993
return currentSuperClass;
9094
}
9195

92-
public void setCurrentSuperClass(SuperApp currentSuperClass) {
96+
public final void setCurrentSuperClass(SuperApp currentSuperClass) {
9397
this.currentSuperClass = currentSuperClass;
9498
}
9599

96-
public boolean isSuperAppCreated() {
100+
public final boolean isSuperAppCreated() {
97101
return isSuperAppCreated;
98102
}
99103

100-
public void setSuperAppCreated(boolean superAppCreated) {
104+
public final void setSuperAppCreated(boolean superAppCreated) {
101105
isSuperAppCreated = superAppCreated;
102106
}
103107

104-
public String getSuperAppDirectoryName() {
105-
return SuperAppDirectoryName;
108+
public final String getSuperAppDirectoryName() {
109+
return superAppDirectoryName;
106110
}
107111

108-
public void setSuperAppDirectoryName(String superAppDirectoryName) {
109-
SuperAppDirectoryName = superAppDirectoryName;
112+
public final void setSuperAppDirectoryName(String superAppDirectoryName) {
113+
this.superAppDirectoryName = superAppDirectoryName;
110114
}
111115

112-
public List<SuperApp> getListOfCurrentSuperAppClasses() {
116+
public final List<SuperApp> getListOfCurrentSuperAppClasses() {
113117
return listOfCurrentSuperAppClasses;
114118
}
115119

116-
public void setListOfCurrentSuperAppClasses(List<SuperApp> listOfCurrentSuperAppClasses) {
120+
public final void setListOfCurrentSuperAppClasses(List<SuperApp> listOfCurrentSuperAppClasses) {
117121
this.listOfCurrentSuperAppClasses = listOfCurrentSuperAppClasses;
118122
}
119123

120-
public List<Path> getListOfPathsToTmpFiles() {
124+
public final List<Path> getListOfPathsToTmpFiles() {
121125
return listOfPathsToTmpFiles;
122126
}
123127

124-
public void setListOfPathsToTmpFiles(List<Path> listOfPathsToTmpFiles) {
128+
public final void setListOfPathsToTmpFiles(List<Path> listOfPathsToTmpFiles) {
125129
this.listOfPathsToTmpFiles = listOfPathsToTmpFiles;
126130
}
127131

128-
public void addPathToTmpFileList(Path path){
132+
public final void addPathToTmpFileList(Path path){
129133

130134
this.listOfPathsToTmpFiles.add(path);
131135
}
132136

133-
public Path getPROJECT_ROOT_WORKING_DIR() {
137+
public final Path getPROJECT_ROOT_WORKING_DIR() {
134138
return PROJECT_ROOT_WORKING_DIR;
135139
}
140+
141+
public final String getContinueAnAppDirectoryName() {
142+
return continueAnAppDirectoryName;
143+
}
144+
145+
public final void setContinueAnAppDirectoryName(String continueAnAppDirectoryName) {
146+
this.continueAnAppDirectoryName = continueAnAppDirectoryName;
147+
}
136148
}
137149

138150

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/ollama_ai_remote/OllamaRemoteSystem.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import pn.cg.app_wish.QuestionBuilder;
99
import pn.cg.datastorage.DataStorage;
1010
import pn.cg.datastorage.constant.CommonStringConstants;
11-
import pn.cg.datastorage.constant.PathConstants;
1211
import pn.cg.datastorage.constant.QuestionConstants;
13-
import pn.cg.datastorage.constant.ScriptConstants;
1412
import pn.cg.ollama_ai_remote.request.*;
1513
import pn.cg.util.CodeGeneratorUtil;
1614
import pn.cg.util.FileUtil;
@@ -112,8 +110,8 @@ public synchronized boolean CreateApp(String appWish, boolean firstRun, String i
112110

113111

114112
log.info("Java source code after modification = {}", javaSourceCode);
115-
// Create file instance with class name and file extension
116-
File file = new File(TaskUtil.addFilePathToClassName(className + JAVA_FILE_EXTENSION));
113+
114+
File file = getFileForJavaFileOutput(isCreateNewApp, className);
117115

118116
// Save the path to shared storage (if user wants to execute the java app after the build
119117
DataStorage.getInstance().setJavaExecutionPath(file.getAbsolutePath());
@@ -134,6 +132,35 @@ public synchronized boolean CreateApp(String appWish, boolean firstRun, String i
134132
return DataStorage.getInstance().getCompilationJob().isResult();
135133
}
136134

135+
/**
136+
* Gets a File that is initialized with the correct path
137+
*
138+
* @param isCreateNewApp A new app will be stationed in the default resource folder while a continue an app will
139+
* be stationed in its designated folder
140+
* @param className The name of the Class
141+
* @return File
142+
*/
143+
private static File getFileForJavaFileOutput(boolean isCreateNewApp, String className) {
144+
145+
// Placeholder for the output .java file
146+
File file = null;
147+
148+
if (isCreateNewApp) {
149+
// Create file instance with class name and file extension
150+
file = new File(TaskUtil.addFilePathToClassName(className + JAVA_FILE_EXTENSION));
151+
152+
}
153+
154+
// Continue on existing application
155+
else {
156+
157+
// Create file instance with class name and file extension
158+
file = new File(TaskUtil.AddFilePathToContinueOnApplication(className + JAVA_FILE_EXTENSION, DataStorage.getInstance().getContinueAnAppDirectoryName()));
159+
160+
}
161+
return file;
162+
}
163+
137164
/**
138165
* Get a list of classes needed for the creation of the super app and sets the output list as reference in the shared singleton
139166
*
@@ -193,9 +220,10 @@ public synchronized boolean CreateSuperApp(SuperApp classInSuperAppDesign, boole
193220
// Create file instance with class name and file extension
194221
File file = new File(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName()));
195222

196-
if(className.equals("Main")){
197-
// Save the path to shared storage (if user wants to execute the java app after the build
198-
DataStorage.getInstance().setJavaExecutionPath(file.getAbsolutePath());}
223+
if (className.equals("Main")) {
224+
// Save the path to shared storage (if user wants to execute the java app after the build
225+
DataStorage.getInstance().setJavaExecutionPath(file.getAbsolutePath());
226+
}
199227

200228
// Write the Java code provided from OLLAMA to file
201229
try {
@@ -224,17 +252,17 @@ public synchronized boolean CreateSuperApp(SuperApp classInSuperAppDesign, boole
224252
try {
225253
CodeGeneratorUtil.SetMethodAndConstructorListForImplementedClass(className, Path.of(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.CLASS_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())));
226254
} catch (MalformedURLException | ClassNotFoundException e) {
227-
log.error("Could not set Methods or/ and constructors");
228-
classInSuperAppDesign.setConstructors(new LinkedList<String>());
229-
classInSuperAppDesign.setMethods(new LinkedList<String>());
255+
log.error("Could not set Methods or/ and constructors");
256+
classInSuperAppDesign.setConstructors(new LinkedList<String>());
257+
classInSuperAppDesign.setMethods(new LinkedList<String>());
230258
}
231259

232260
// Copy class file to the script directory for the javac script, so it will be included in the class path
233261
try {
234-
Path destinationPathForTempFile= Path.of(DataStorage.getInstance().getPROJECT_ROOT_WORKING_DIR().toString()+File.separator+className+CLASS_FILE_EXTENSION);
262+
Path destinationPathForTempFile = Path.of(DataStorage.getInstance().getPROJECT_ROOT_WORKING_DIR().toString() + File.separator + className + CLASS_FILE_EXTENSION);
235263
Files.deleteIfExists(destinationPathForTempFile);
236264
DataStorage.getInstance().addPathToTmpFileList(destinationPathForTempFile);
237-
Files.copy(Path.of(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.CLASS_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())),destinationPathForTempFile);
265+
Files.copy(Path.of(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.CLASS_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())), destinationPathForTempFile);
238266
} catch (IOException e) {
239267
throw new RuntimeException(e);
240268
}

0 commit comments

Comments
 (0)