-
Notifications
You must be signed in to change notification settings - Fork 29
Refactor DriverResolver to create temporary directory for driver file management #433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,16 +28,23 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
||
| public class DriverResolver { | ||
|
|
||
| private final Path driverImportFile; | ||
| private final String datastore; | ||
| private final Path tempDirectory; | ||
|
|
||
| public DriverResolver(String sourcePath, String datastore) { | ||
| driverImportFile = Paths.get(sourcePath, "persist/driver.bal"); | ||
| this.datastore = datastore; | ||
| public DriverResolver(String datastore) throws BalException { | ||
| try { | ||
| // Create a temporary directory along with some prefix | ||
| this.tempDirectory = Files.createTempDirectory("persist-driver-test-"); | ||
| // Set the driver file path in the temp directory | ||
| this.driverImportFile = this.tempDirectory.resolve("driver.bal"); | ||
| this.datastore = datastore; | ||
| } catch (IOException e) { | ||
| throw new BalException("failed to create temporary directory: " + e.getMessage()); | ||
| } | ||
| } | ||
|
Comment on lines
+38
to
48
|
||
|
|
||
| public Project resolveDriverDependencies() throws BalException { | ||
|
|
@@ -48,25 +55,27 @@ public Project resolveDriverDependencies() throws BalException { | |
| private void createDriverImportFile() throws BalException { | ||
| DbModelGenSyntaxTree dbModelGenSyntaxTree = new DbModelGenSyntaxTree(); | ||
| try { | ||
| writeOutputFile | ||
| (Formatter.format(dbModelGenSyntaxTree.createInitialDriverImportFile(datastore).toSourceCode()), | ||
| driverImportFile); | ||
| writeOutputFile(Formatter.format( | ||
| dbModelGenSyntaxTree.createInitialDriverImportFile(datastore).toSourceCode())); | ||
| } catch (Exception e) { | ||
| throw new BalException("failed to create driver import file: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private void writeOutputFile(String syntaxTree, Path outPath) throws IOException { | ||
| try (PrintWriter writer = new PrintWriter(outPath.toString(), StandardCharsets.UTF_8)) { | ||
| private void writeOutputFile(String syntaxTree) throws IOException { | ||
| try (PrintWriter writer = new PrintWriter(this.driverImportFile.toString(), StandardCharsets.UTF_8)) { | ||
| writer.println(syntaxTree); | ||
| } | ||
| } | ||
|
|
||
| public void deleteDriverFile() throws BalException { | ||
| try { | ||
| Files.deleteIfExists(driverImportFile); | ||
| if (Files.exists(tempDirectory)) { | ||
| Files.delete(tempDirectory); | ||
|
Comment on lines
+74
to
+75
|
||
| } | ||
| } catch (IOException e) { | ||
| throw new BalException("failed to delete driver import file: " + e.getMessage()); | ||
| throw new BalException("failed to delete driver import file and temp directory: " + e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefix "persist-driver-test-" suggests this is for testing purposes, but this class appears to be production code. Consider using a more appropriate prefix like "persist-driver-" instead.