Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Proposed enhancement for working with directories using JAIG #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified JAIG/JAIG.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ JAIG is based on the OpenAI GPT models used for the code generation.

[JAIG Main ideas](docs/JAIGideas.pdf)

[JAIG Integration with APIs](docs/JAIGIntegration.pdf)

## JAIG main features

- Generate a code in IntelliJ IDEA
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/app/jtutor/jaig/InsertFolderProcessor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app.jtutor.jaig;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -38,6 +41,18 @@ public void insertFolder(String folder) {
// Creating a new file in the new folder
File newFile = new File(newFolderPath.toFile(), newName + ".txt");
if (newFile.createNewFile()) {
//Write a template content to the new file
String content = """
/path(s)/to/your/inputFiles

Please provide a request for your specific needs within your project.

#directives (src, package, test, merge etc.)
""";

BufferedWriter writer = new BufferedWriter(new FileWriter(newFile));
writer.write(content);

System.out.println("New file created: " + newFile);
} else {
System.out.println("File already exists.");
Expand Down
90 changes: 83 additions & 7 deletions src/main/java/app/jtutor/jaig/JAIGUseCasesProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -42,22 +43,60 @@ public void process(String inputFileOrFolder) {
if (inputFileFile.isDirectory()) {
// check that inputFileFile starts with 2 digits and _, like 01_
if (inputFileFile.getName().matches("\\d\\d_.*")) {
// insert new folder
InsertFolderProcessor.INSTANCE.insertFolder(inputFileOrFolder);
return;
// show menu
System.out.printf("""
What do you want to do with the folder %s?
1) Insert a new folder
2) Create a prompt (.txt file) in the folder
3) Create batch file with all prompts (.txt files) in the folder
4) Cleanup the folder from all artifacts except prompts

Enter nothing if you want to finish the program:
""", inputFileOrFolder);

String answer = new Scanner(System.in).nextLine();

if (answer.equals("1")) {
// insert new folder
InsertFolderProcessor.INSTANCE.insertFolder(inputFileOrFolder);
return;
} else if (answer.equals("2")) {
createPromptFile(inputFileOrFolder);
return;
} else if (answer.equals("3")){
if (processFolderCreateBatch(inputFileOrFolder)) return;
} else if (answer.equals("4")){
FolderCleanup.cleanFolder(inputFileOrFolder);
return;
}
else if (answer.isEmpty()) {
System.out.println("Finishing the conversation...");
return;
}
} else {
// show menu
System.out.printf("""
What do you want to do with the folder %s?
1) Create batch file with all prompts (.txt files) in the folder
2) Cleanup the folder from all artifacts except prompts
""", inputFileOrFolder);
What do you want to do with the folder %s?
1) Create batch file with all prompts (.txt files) in the folder
2) Create a prompt (.txt file) in the folder
3) Cleanup the folder from all artifacts except prompts

Enter nothing if you want to finish the program:
""", inputFileOrFolder);

String answer = new Scanner(System.in).nextLine();

if (answer.equals("1")) {
if (processFolderCreateBatch(inputFileOrFolder)) return;
} else if (answer.equals("2")) {
createPromptFile(inputFileOrFolder);
return;
} else if (answer.equals("3")) {
FolderCleanup.cleanFolder(inputFileOrFolder);
return;
} else if (answer.isEmpty()) {
System.out.println("Finishing the conversation...");
return;
}
}
}
Expand Down Expand Up @@ -321,6 +360,43 @@ static boolean processRollback(String rollbackFile, String srcFolder) {
return false;
}

private static void createPromptFile(String inputFileOrFolder) {
Path folderPath = Paths.get(inputFileOrFolder);

// Reading the new file name from the console
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the new prompt file name (part before .txt): ");
String newName = scanner.nextLine();
scanner.close();

try {
// Creating a new file in the folder
File newFile = new File(folderPath.toFile(), newName + ".txt");
if (newFile.createNewFile()) {
//Write template content to the new file
String content = """
/path(s)/to/your/inputFiles

Please provide a request for your specific needs within your project.

#directives (src, package, test, merge etc.)
""";

BufferedWriter writer = new BufferedWriter(new FileWriter(newFile));
writer.write(content);

System.out.println("New file created: " + newFile);
} else {
System.out.println("File already exists.");
}

} catch (Exception e) {
System.out.println("An error occurred while creating the folder or file.");
e.printStackTrace();
}

}

private static void deleteFolder(String folder) {
if (FileUtils.deleteQuietly(new File(folder))) {
System.out.println("Deleted folder "+ folder +".");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/app/jtutor/jaig/LifecyclePhasesProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
final_targetFolder);
try {
if (!Files.exists(Path.of(srcFolderFilePath))) {
System.out.println("The path - "+srcFolderFilePath+" - "+"does not exist."
+" Creating the directory...");
Files.createDirectories(Path.of(srcFolderFilePath));
}
Files.copy(file, Path.of(srcFolderFilePath), StandardCopyOption.REPLACE_EXISTING);
Expand Down