Skip to content

Commit

Permalink
Merge pull request #167 from pwgit-create/continue_backups
Browse files Browse the repository at this point in the history
Version 2.02
  • Loading branch information
pwgit-create authored Jul 20, 2024
2 parents ce104db + 3b639aa commit 8f09543
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 48 deletions.
2 changes: 1 addition & 1 deletion AppWish/AppWish/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>pn.dev</groupId>
<artifactId>code-generator-gui-ollama</artifactId>
<name>CodeGenerator-GUI</name>
<version>1.8.1</version>
<version>2.0.2</version>
<description>The GUI interface for the pn.dev.code-generator-ollama library is included in this package</description>
<inceptionYear>2024</inceptionYear>
<developers>
Expand Down
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>2.0.1</version>
<version>2.0.2</version>
<name>CodeGenerator-GUI</name>


Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>pn.dev</groupId>
<artifactId>code-generator-ollama</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
Expand Down
2 changes: 1 addition & 1 deletion cg/CodeGenerator/CodeGenerator/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pn.dev</groupId>
<artifactId>code-generator-ollama</artifactId>
<version>1.8.1</version>
<version>2.0.2</version>
<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>
<inceptionYear>2024</inceptionYear>
<developers>
Expand Down
2 changes: 1 addition & 1 deletion cg/CodeGenerator/CodeGenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>pn.dev</groupId>
<artifactId>code-generator-ollama</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>


<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pn.cg.datastorage.DataStorage;
import pn.cg.ollama_ai_remote.OllamaRemoteSystem;
import pn.cg.util.CodeGeneratorUtil;
import pn.cg.util.StringUtil;


import java.io.File;
Expand Down Expand Up @@ -54,6 +55,13 @@ private static void StartCodeGenerator(String appWish, boolean isFirstRun, boole
if (isCreateAppGeneration) {
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, "", null);
} else {
DataStorage.getInstance().setContinueAnAppDirectoryName(CodeGeneratorUtil.getIncrementedContinueOnAppDirectoryName(StringUtil.extractClassNameFromTextWithJavaClasses(javaFileContentInLines)));
try {
Files.createDirectory(new File(COMPILE_CLASS_STORAGE + File.separator + DataStorage.getInstance().getContinueAnAppDirectoryName()).toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}

appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, pathOfJavaFileIfModifyRequest, javaFileContentInLines);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public class DataStorage {
/**
* Data holder for the current Super App Directory name
*/
private String SuperAppDirectoryName;
private String superAppDirectoryName;

/**
* Data holder for the current Continue an App Directory
*/
private String continueAnAppDirectoryName;
/**
* The class that is selected for implementation tries in a super app creation process
*/
Expand All @@ -52,15 +56,15 @@ public class DataStorage {
* The path for the project root directory
*/
private final Path PROJECT_ROOT_WORKING_DIR;
private DataStorage() {
private DataStorage() {

this.compilationJob = getCompilationJob();
this.isSuperAppCreated = false;
this.PROJECT_ROOT_WORKING_DIR = Path.of(System.getProperty("user.dir"));
}


synchronized public static DataStorage getInstance() {
synchronized public static DataStorage getInstance() {
if (instance == null) {

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


public CompilationJob getCompilationJob() {
public final CompilationJob getCompilationJob() {
return compilationJob;
}

public void setCompilationJob(CompilationJob compilationJob) {
public final void setCompilationJob(CompilationJob compilationJob) {
this.compilationJob = compilationJob;
}

public String getJavaExecutionPath() {
public final String getJavaExecutionPath() {
return javaExecutionPath;
}

public void setJavaExecutionPath(String javaExecutionPath) {
public final void setJavaExecutionPath(String javaExecutionPath) {
this.javaExecutionPath = javaExecutionPath;
}

public SuperApp getCurrentSuperClass() {
public final SuperApp getCurrentSuperClass() {
return currentSuperClass;
}

public void setCurrentSuperClass(SuperApp currentSuperClass) {
public final void setCurrentSuperClass(SuperApp currentSuperClass) {
this.currentSuperClass = currentSuperClass;
}

public boolean isSuperAppCreated() {
public final boolean isSuperAppCreated() {
return isSuperAppCreated;
}

public void setSuperAppCreated(boolean superAppCreated) {
public final void setSuperAppCreated(boolean superAppCreated) {
isSuperAppCreated = superAppCreated;
}

public String getSuperAppDirectoryName() {
return SuperAppDirectoryName;
public final String getSuperAppDirectoryName() {
return superAppDirectoryName;
}

public void setSuperAppDirectoryName(String superAppDirectoryName) {
SuperAppDirectoryName = superAppDirectoryName;
public final void setSuperAppDirectoryName(String superAppDirectoryName) {
this.superAppDirectoryName = superAppDirectoryName;
}

public List<SuperApp> getListOfCurrentSuperAppClasses() {
public final List<SuperApp> getListOfCurrentSuperAppClasses() {
return listOfCurrentSuperAppClasses;
}

public void setListOfCurrentSuperAppClasses(List<SuperApp> listOfCurrentSuperAppClasses) {
public final void setListOfCurrentSuperAppClasses(List<SuperApp> listOfCurrentSuperAppClasses) {
this.listOfCurrentSuperAppClasses = listOfCurrentSuperAppClasses;
}

public List<Path> getListOfPathsToTmpFiles() {
public final List<Path> getListOfPathsToTmpFiles() {
return listOfPathsToTmpFiles;
}

public void setListOfPathsToTmpFiles(List<Path> listOfPathsToTmpFiles) {
public final void setListOfPathsToTmpFiles(List<Path> listOfPathsToTmpFiles) {
this.listOfPathsToTmpFiles = listOfPathsToTmpFiles;
}

public void addPathToTmpFileList(Path path){
public final void addPathToTmpFileList(Path path){

this.listOfPathsToTmpFiles.add(path);
}

public Path getPROJECT_ROOT_WORKING_DIR() {
public final Path getPROJECT_ROOT_WORKING_DIR() {
return PROJECT_ROOT_WORKING_DIR;
}

public final String getContinueAnAppDirectoryName() {
return continueAnAppDirectoryName;
}

public final void setContinueAnAppDirectoryName(String continueAnAppDirectoryName) {
this.continueAnAppDirectoryName = continueAnAppDirectoryName;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import pn.cg.app_wish.QuestionBuilder;
import pn.cg.datastorage.DataStorage;
import pn.cg.datastorage.constant.CommonStringConstants;
import pn.cg.datastorage.constant.PathConstants;
import pn.cg.datastorage.constant.QuestionConstants;
import pn.cg.datastorage.constant.ScriptConstants;
import pn.cg.ollama_ai_remote.request.*;
import pn.cg.util.CodeGeneratorUtil;
import pn.cg.util.FileUtil;
Expand Down Expand Up @@ -112,8 +110,8 @@ public synchronized boolean CreateApp(String appWish, boolean firstRun, String i


log.info("Java source code after modification = {}", javaSourceCode);
// Create file instance with class name and file extension
File file = new File(TaskUtil.addFilePathToClassName(className + JAVA_FILE_EXTENSION));

File file = getFileForJavaFileOutput(isCreateNewApp, className);

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

/**
* Gets a File that is initialized with the correct path
*
* @param isCreateNewApp A new app will be stationed in the default resource folder while a continue an app will
* be stationed in its designated folder
* @param className The name of the Class
* @return File
*/
private static File getFileForJavaFileOutput(boolean isCreateNewApp, String className) {

// Placeholder for the output .java file
File file = null;

if (isCreateNewApp) {
// Create file instance with class name and file extension
file = new File(TaskUtil.addFilePathToClassName(className + JAVA_FILE_EXTENSION));

}

// Continue on existing application
else {

// Create file instance with class name and file extension
file = new File(TaskUtil.AddFilePathToContinueOnApplication(className + JAVA_FILE_EXTENSION, DataStorage.getInstance().getContinueAnAppDirectoryName()));

}
return file;
}

/**
* Get a list of classes needed for the creation of the super app and sets the output list as reference in the shared singleton
*
Expand Down Expand Up @@ -193,9 +220,10 @@ public synchronized boolean CreateSuperApp(SuperApp classInSuperAppDesign, boole
// Create file instance with class name and file extension
File file = new File(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName()));

if(className.equals("Main")){
// Save the path to shared storage (if user wants to execute the java app after the build
DataStorage.getInstance().setJavaExecutionPath(file.getAbsolutePath());}
if (className.equals("Main")) {
// Save the path to shared storage (if user wants to execute the java app after the build
DataStorage.getInstance().setJavaExecutionPath(file.getAbsolutePath());
}

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

// Copy class file to the script directory for the javac script, so it will be included in the class path
try {
Path destinationPathForTempFile= Path.of(DataStorage.getInstance().getPROJECT_ROOT_WORKING_DIR().toString()+File.separator+className+CLASS_FILE_EXTENSION);
Path destinationPathForTempFile = Path.of(DataStorage.getInstance().getPROJECT_ROOT_WORKING_DIR().toString() + File.separator + className + CLASS_FILE_EXTENSION);
Files.deleteIfExists(destinationPathForTempFile);
DataStorage.getInstance().addPathToTmpFileList(destinationPathForTempFile);
Files.copy(Path.of(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.CLASS_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())),destinationPathForTempFile);
Files.copy(Path.of(TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.CLASS_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())), destinationPathForTempFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Loading

0 comments on commit 8f09543

Please sign in to comment.