Skip to content

Commit

Permalink
Create java argument files on installation
Browse files Browse the repository at this point in the history
  • Loading branch information
sormuras committed Apr 16, 2024
1 parent 87943f7 commit d1fff99
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/bach.run/BachInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,52 @@ static void listInstallableVersions() {
this(version, DEFAULT_HOME);
}

void install() throws Exception {
void install() {
try {
installSources();
installArgumentFiles();
} catch (Exception exception) {
System.err.println("Install failed: " + exception.getMessage());
}
}

private void installSources() throws Exception {
var uris =
List.of(
"https://github.com/sormuras/run.bach/archive/refs/tags/" + version + ".zip",
"https://github.com/sormuras/run.bach/archive/refs/heads/" + version + ".zip");
for (var uri : uris) {
if (Internal.head(uri)) {
install(uri);
installSourcesFromUri(uri);
return;
}
}
}

void install(String uri) throws Exception {
private void installSourcesFromUri(String uri) throws Exception {
System.out.println("Install Bach " + version + " to " + home.toUri() + "...");
var tmp = Files.createTempDirectory("run.bach-" + version + "-");
var dir = Files.createDirectories(home.resolve("src/run.bach/run/bach"));
var zip = tmp.resolve("run.bach-" + version + ".zip");
// download and unzip
Internal.copy(uri, zip, StandardCopyOption.REPLACE_EXISTING);
Internal.unzip(zip, dir, 1);

// clean up
Internal.delete(tmp);
}

void installArgumentFiles() throws Exception {
var run = home.resolve("run");
if (!Files.exists(run)) {
var program = home.resolve(".bach/src/run.bach/run/bach/internal/RunTool.java");
var lines =
List.of(
"# Call tool by name or uri: NAME [ARGS...]",
home.relativize(program).toString().replace('\\', '/'));
Files.write(run, lines);
}
}

private interface Internal {
boolean DEBUG = Boolean.getBoolean("-Debug".substring(2));

Expand Down

0 comments on commit d1fff99

Please sign in to comment.