Skip to content

Commit

Permalink
Introduce Bach's main application
Browse files Browse the repository at this point in the history
  • Loading branch information
sormuras committed Apr 16, 2024
1 parent 68164a0 commit 5ae5bc0
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
1 change: 1 addition & 0 deletions .bach/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/bin/
/out/
/src/run/
/var/

*.jfr
3 changes: 1 addition & 2 deletions .bach/install.jshell
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ System.out.println("| Source Bach's installer from " + Path.of("src/bach.run/Bac

int code = 0
try {
// BachInstaller.installDefaultVersionIntoDefaultDirectory();
new BachInstaller("main", Path.of(".bach/var/tmp/installed")).install();
BachInstaller.installDefaultVersionIntoDefaultDirectory();
}
catch(Throwable throwable) {
System.err.println(throwable);
Expand Down
2 changes: 0 additions & 2 deletions .bach/run

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
release: 22
- name: 'Print various versions'
run: |
java @.bach/run jar --version
java @.bach/run jfr --version
java @.bach/run https://raw.githubusercontent.com/openjdk/jdk/jdk-22-ga/test/jdk/java/lang/System/Versions.java
java @bach jar --version
java @bach jfr --version
java @bach https://raw.githubusercontent.com/openjdk/jdk/jdk-22-ga/test/jdk/java/lang/System/Versions.java
java .bach/src/run.bach/run/Versions.java
- name: 'Build Bach with Bach'
run: java .bach/src/run.bach/run/Build.java
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ Install Bach's basic tool framework using its sources via `git` and Java 22 or h

First time:
```shell
mkdir myproject
cd myproject
mkdir example && cd example
git init
git submodule add https://github.com/sormuras/run.bach .bach/src/run.bach/run/bach
echo .bach/src/run.bach/run/bach/internal/RunTool.java > .bach/run
git submodule add https://github.com/sormuras/run.bach .bach/src/run/bach
echo .bach/src/run/bach/Main.java > bach
```

Subsequent times:
```shell
cd myproject
cd example
git submodule update --remote --recursive
```

Run time:
```shell
java @.bach/run jar --version
java @.bach/run java --version
java @.bach/run https://raw.githubusercontent.com/sormuras/hello/main/Hello.java World
java @.bach/run https://github.com/sormuras/hello/releases/download/1-M3/hello-1-M3.jar World
java @bach jar --version
java @bach java --version
java @bach https://raw.githubusercontent.com/sormuras/hello/main/Hello.java World
java @bach https://github.com/sormuras/hello/releases/download/1-M3/hello-1-M3.jar World
```
Consult the following manual pages for details of `git` and `java` tools:
- [git init](https://git-scm.com/docs/git-init) - Create an empty Git repository or reinitialize an existing one
Expand Down
2 changes: 2 additions & 0 deletions bach
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# java [VM-OPTIONS...] @bach [OPTIONS...] TOOL [ARGS...]
.bach/src/run.bach/run/bach/Main.java
34 changes: 18 additions & 16 deletions src/bach.run/BachInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@
import java.nio.file.*;
import java.util.*;

record BachInstaller(String version, Path home) {
static String DEFAULT_VERSION = System.getProperty("-Default.version".substring(2), "main");
static Path DEFAULT_HOME = Path.of(System.getProperty("-Default.home".substring(2), ".bach"));
record BachInstaller(String version, Path home, Path path) {
// defaults to git head reference of the `main` branch
static String VERSION = System.getProperty("-Dversion".substring(2), "main");
// defaults to the current working directory
static Path HOME = Path.of(System.getProperty("-Dhome".substring(2), ""));
// git submodule add <repository> [<path>] <- .bach/src[/run.bach]/run/bach
static Path PATH = Path.of(System.getProperty("-Dpath".substring(2), ".bach/src/run/bach"));

@SuppressWarnings("unused")
static void installDefaultVersionIntoDefaultDirectory() throws Exception {
var installer = new BachInstaller(DEFAULT_VERSION);
static void installDefaultVersionIntoDefaultDirectory() {
var installer = new BachInstaller(VERSION);
installer.install();
}

@SuppressWarnings("unused")
static void listInstallableVersions() {
System.out.println("- Default version: " + DEFAULT_VERSION);
System.out.println("- Default version: " + VERSION);
System.out.println("- Released versions: https://github.com/sormuras/run.bach/releases");
System.out.println("- Head revisions: https://github.com/sormuras/run.bach/branches");
}

BachInstaller(String version) {
this(version, DEFAULT_HOME);
this(version, HOME, PATH);
}

void install() {
Expand Down Expand Up @@ -53,7 +57,7 @@ private void installSources() 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 dir = Files.createDirectories(home.resolve(path));
var zip = tmp.resolve("run.bach-" + version + ".zip");
// download and unzip
Internal.copy(uri, zip, StandardCopyOption.REPLACE_EXISTING);
Expand All @@ -63,14 +67,12 @@ private void installSourcesFromUri(String uri) throws Exception {
}

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);
var bach = home.resolve("bach");
if (!Files.exists(bach)) {
var program = home.resolve(path).resolve("Main.java");
var command = home.relativize(program).toString().replace('\\', '/');
var lines = List.of("# Argument file for launching Bach's main application", command);
Files.write(bach, lines);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bach.run/Hello.java → src/bach.run/Hi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl
*/

class Hello {
class Hi {
public static void main(String... args) {
String name = args.length == 0 ? System.getProperty("user.name") : String.join(" ", args);
System.out.printf("Hello %s!%n", name);
System.out.printf("Hi %s!%n", name);
}
}

0 comments on commit 5ae5bc0

Please sign in to comment.