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

[choreolib] Fix issue with using reader twice in Java project file #815

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
11 changes: 8 additions & 3 deletions choreolib/src/main/java/choreo/Choreo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,18 +74,22 @@ public static ProjectFile getProjectFile() {
} else if (projectFiles.length > 1) {
throw new RuntimeException("Found multiple project files in deploy directory");
}
FileReader reader = new FileReader(projectFiles[0]);
JsonObject json = GSON.fromJson(reader, JsonObject.class);
BufferedReader reader = new BufferedReader(new FileReader(projectFiles[0]));
String str = reader.lines().reduce("", (a, b) -> a + b);
reader.close();
JsonObject json = GSON.fromJson(str, JsonObject.class);
String version = json.get("version").getAsString();
if (!SPEC_VERSION.equals(version)) {
throw new RuntimeException(
".chor project file: Wrong version " + version + ". Expected " + SPEC_VERSION);
}
LAZY_PROJECT_FILE = Optional.of(GSON.fromJson(reader, ProjectFile.class));
LAZY_PROJECT_FILE = Optional.of(GSON.fromJson(str, ProjectFile.class));
} catch (JsonSyntaxException ex) {
throw new RuntimeException("Could not parse project file", ex);
} catch (FileNotFoundException ex) {
throw new RuntimeException("Could not find project file", ex);
} catch (IOException ex) {
throw new RuntimeException("Could not find project file", ex);
}
return LAZY_PROJECT_FILE.get();
}
Expand Down
Loading