Skip to content

Commit

Permalink
Update to use latest run.bach module
Browse files Browse the repository at this point in the history
  • Loading branch information
sormuras committed May 23, 2024
1 parent a5d96d7 commit 185cf27
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 65 deletions.
5 changes: 2 additions & 3 deletions .bach/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/bin/
/out/
/src/run/
/tool/*/
/tool/*/**
/tmp/
/var/

*.jfr
1 change: 1 addition & 0 deletions .bach/src/run.bach/bach/info/org/jreleaser
Submodule jreleaser added at c71297
1 change: 1 addition & 0 deletions .bach/src/run.bach/bach/info/org/junit
Submodule junit added at 58d65e
2 changes: 1 addition & 1 deletion .bach/src/run.bach/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
requires jdk.jfr;

exports run.bach;
exports run.bach.external;
exports run.bach.workflow;
exports run.external;

uses java.util.spi.ToolProvider;
}
2 changes: 1 addition & 1 deletion .bach/src/run.bach/run/Format.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package run;

import run.bach.external.GoogleJavaFormat;
import run.external.GoogleJavaFormat;

class Format {
public static void main(String... args) {
Expand Down
2 changes: 1 addition & 1 deletion .bach/src/run.bach/run/Greeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record Greeter(String version) implements ToolInstaller {
public static void main(String... args) throws Exception {
var greeter = new Greeter("99");
System.out.println("[1]");
greeter.install().run(); // "run.bach/greeter@99"
greeter.install().run(); // "run.bach/greeter@99" in ".bach/tmp/tool"

var folders = Folders.ofTemporaryDirectory();
System.out.println("\n[2]");
Expand Down
57 changes: 57 additions & 0 deletions .bach/src/run.bach/run/ModuleResolverDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package run;

import bach.info.org.jreleaser.JReleaser;
import bach.info.org.junit.JUnit;
import java.lang.module.ModuleFinder;
import java.nio.file.Path;
import run.bach.ModuleFinders;
import run.bach.ModuleResolver;
import run.bach.ToolFinder;
import run.bach.workflow.Folders;
import run.external.Ant;

public class ModuleResolverDemo {
public static void main(String... args) throws Exception {
var libraries = ModuleFinder.compose(ModuleFinders.ofProperties(JUnit.MODULES));

try (var reader = libraries.find("org.junit.jupiter").orElseThrow().open()) {
reader.list().forEach(System.out::println);
}

var lib = Path.of("lib");
var resolver = ModuleResolver.ofSingleDirectory(lib, libraries);
resolver.resolveModule("org.junit.jupiter"); // to write and discover tests
resolver.resolveModule("org.junit.platform.console"); // to run tests
resolver.resolveMissingModules();

// "jreleaser" via the tool provider SPI
var jreleaserHome =
Folders.ofCurrentWorkingDirectory().tool(JReleaser.NAME + "@" + JReleaser.VERSION);
var jreleaserResolver = ModuleResolver.ofSingleDirectory(jreleaserHome, JReleaser.MODULES);
jreleaserResolver.resolveModule("org.jreleaser.tool");
jreleaserResolver.resolveMissingModules();

var tools =
ToolFinder.compose(
ToolFinder.of("jar"), // provides "jar" tool
ToolFinder.of("java"), // provides "java" tool
ToolFinder.of(ModuleFinder.of(lib)), // provides "junit" tool
ToolFinder.of(ModuleFinder.of(jreleaserHome)), // provides "jreleaser" tool
ToolFinder.ofInstaller()
.withJavaApplication("demo/release@uri", JReleaser.APPLICATION)
.withJavaApplication(
"demo/release@all", JReleaser.APPLICATION, JReleaser.APPLICATION_ASSETS)
.with(new Ant()) // provides "ant" tool
);

var junit = tools.get("junit");
junit.run("--version");
junit.run("engines");

tools.get("jreleaser").run("--version");
tools.get("releaser1").run("--version");
tools.get("releaser2").run("--version");

tools.get("ant").run("-version");
}
}
18 changes: 14 additions & 4 deletions .bach/src/run.bach/run/Project.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package run;

import bach.info.org.junit.JUnit;
import java.lang.module.ModuleFinder;
import java.nio.file.Files;
import java.util.Optional;
import run.bach.ModuleFinders;
import run.bach.ToolCall;
import run.bach.ToolRunner;
import run.bach.workflow.Builder;
Expand Down Expand Up @@ -31,15 +34,22 @@ static Project ofCurrentWorkingDirectory() {
.withLauncher("tests=test.bach/test.bach.Tests")
.withModule("src/test.bach", "src/test.bach/test/java/module-info.java")
.withModule("src/test.junit", "src/test.junit/test/java/module-info.java");
var structure = new Structure(basics, new Spaces(main, test));
var libraries =
ModuleFinder.compose(
ModuleFinders.ofProperties(JUnit.MODULES),
ModuleFinders.ofProperties(
"org.junitpioneer=https://repo.maven.apache.org/maven2/org/junit-pioneer/junit-pioneer/2.2.0/junit-pioneer-2.2.0.jar#SIZE=191032"));
var structure = new Structure(basics, new Spaces(main, test), libraries);
var runner = ToolRunner.ofSystem();
return new Project(verbose, new Workflow(folders, structure, runner));
}

void printStatus() {
System.out.println(workflow.structure().toNameAndVersion());
System.out.println(workflow.structure().basics());
System.out.println(workflow.structure().modules());
var structure = workflow.structure();
System.out.println(structure.toNameAndVersion());
System.out.println(structure.basics());
structure.spaces().forEach(System.out::println);
structure.libraries().findAll().stream().sorted().forEach(System.out::println);
System.out.println(workflow.folders());
System.out.println(workflow.runner());
}
Expand Down
4 changes: 3 additions & 1 deletion .bach/src/run.bach/run/ToolFinderDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.function.Consumer;
import java.util.spi.*;
import run.bach.*;
import run.bach.external.*;
import run.external.Ant;
import run.external.GoogleJavaFormat;
import run.external.Maven;

class ToolFinderDemo {
public static void main(String... args) {
Expand Down
2 changes: 1 addition & 1 deletion .bach/src/run.bach/run/ToolSpaceDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package run;

import run.bach.*;
import run.bach.external.*;
import run.external.Maven;

class ToolSpaceDemo extends ToolSpace {
public static void main(String... args) {
Expand Down
6 changes: 3 additions & 3 deletions .bach/src/run.bach/run/Versions.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package run;

import run.bach.*;
import run.bach.external.*;
import run.external.*;

class Versions {
public static void main(String... args) {
Expand All @@ -14,13 +14,12 @@ public static void main(String... args) {
// 1-shot, tool installer
Tool.of("https://github.com/rife2/bld/releases/download/1.9.1/bld-1.9.1.jar").run("version");
Tool.of(new Ant(), ToolInstaller.Mode.INSTALL_IMMEDIATE).run("-version");
Tool.of("jreleaser").run("--version");
Tool.of("jresolve").run("--version");

// multi-shot, tool finder
var finder =
ToolFinder.ofInstaller(ToolInstaller.Mode.INSTALL_IMMEDIATE)
.with(new Ant())
.withJavaApplication(JResolve.ID, JResolve.URI)
.withJavaApplication(
"rife2/bld@1.9.1",
"https://github.com/rife2/bld/releases/download/1.9.1/bld-1.9.1.jar")
Expand All @@ -35,6 +34,7 @@ public static void main(String... args) {
runner.run("ant", "-version");
runner.run("bld", "version");
runner.run("junit", "--version");
runner.run("jresolve", "--version");
runner.run("google-java-format", "--version");
runner.run("google-java-format@1.19", "--version");
runner.run("maven", "--version");
Expand Down
59 changes: 59 additions & 0 deletions .bach/src/run.bach/run/external/Ant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 Christian Stein
* Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl
*/

package run.external;

import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import java.util.spi.ToolProvider;
import run.bach.ToolInstaller;
import run.bach.ToolProgram;
import run.bach.ToolSpace;

/**
* Apache Ant installer.
*
* @see <a href="https://ant.apache.org">https://ant.apache.org</a>
*/
public record Ant(String version) implements ToolInstaller {
public static final String DEFAULT_VERSION = "1.10.14";

public static void main(String... args) {
var version = System.getProperty("version", DEFAULT_VERSION);
new Ant(version).install().run(args.length == 0 ? new String[] {"-version"} : args);
}

public Ant() {
this(DEFAULT_VERSION);
}

@Override
public ToolProvider install(Path into) throws Exception {
var title = "apache-ant-" + version;
var archive = title + "-bin.zip";
var target = into.resolve(archive);
if (!Files.exists(target)) {
var source = "https://dlcdn.apache.org/ant/binaries/" + archive;
download(target, URI.create(source));
}
var antHome = into.resolve(title);
if (!Files.isDirectory(antHome)) {
var jar =
ToolProgram.findJavaDevelopmentKitTool("jar")
.orElseThrow()
.withProcessBuilderTweaker(builder -> builder.directory(into.toFile()))
.withProcessWaiter(process -> process.waitFor(1, TimeUnit.MINUTES) ? 0 : 1)
.tool();
var silent = new ToolSpace(ToolSpace.Flag.SILENT);
silent.run(jar, "--extract", "--file", archive);
}
return ToolProgram.java(
"--class-path",
antHome.resolve("lib/ant-launcher.jar").toString(),
"org.apache.tools.ant.launch.Launcher");
}
}
53 changes: 53 additions & 0 deletions .bach/src/run.bach/run/external/GoogleJavaFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2024 Christian Stein
* Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl
*/

package run.external;

import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.spi.ToolProvider;
import run.bach.ToolInstaller;
import run.bach.ToolProgram;

/**
* Google Java Format installer.
*
* @see <a href="https://github.com/google/google-java-format">Google Java Format</a>
*/
public record GoogleJavaFormat(String version) implements ToolInstaller {
/**
* @see <a href="https://github.com/google/google-java-format/releases/latest">Latest release</a>
*/
public static final String DEFAULT_VERSION = "1.22.0";

public static void main(String... args) {
var version = System.getProperty("version", DEFAULT_VERSION);
new GoogleJavaFormat(version)
.install()
.run(args.length == 0 ? new String[] {"--version"} : args);
}

public GoogleJavaFormat() {
this(DEFAULT_VERSION);
}

@Override
public String name() {
return "google-java-format";
}

@Override
public ToolProvider install(Path into) throws Exception {
var filename = "google-java-format-" + version + "-all-deps.jar";
var target = into.resolve(filename);
if (!Files.exists(target)) {
var releases = "https://github.com/google/google-java-format/releases/download/";
var source = releases + "v" + version + "/" + filename;
download(target, URI.create(source));
}
return ToolProgram.java("-jar", target.toString());
}
}
13 changes: 13 additions & 0 deletions .bach/src/run.bach/run/external/JResolve.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package run.external;

/**
* JResolve - a command line tool for resolving dependencies on the JVM.
*
* @see <a href="https://github.com/bowbahdoe/jresolve-cli/releases/tag/v2024.05.10">Release
* Notes</a>
*/
public interface JResolve {
String ID = "bowbahdoe/jresolve@2024.05.10";
String URI =
"https://github.com/bowbahdoe/jresolve-cli/releases/download/v2024.05.10/jresolve.jar#SIZE=754432";
}
58 changes: 58 additions & 0 deletions .bach/src/run.bach/run/external/Maven.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 Christian Stein
* Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl
*/

package run.external;

import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.spi.ToolProvider;
import run.bach.ToolInstaller;
import run.bach.ToolProgram;

/**
* Apache Maven installer.
*
* @see <a href="https://maven.apache.org">https://maven.apache.org</a>
*/
public record Maven(String version) implements ToolInstaller {
public static final String DEFAULT_VERSION = "3.9.6";

public static void main(String... args) {
var version = System.getProperty("version", DEFAULT_VERSION);
new Maven(version).install().run(args.length == 0 ? new String[] {"--version"} : args);
}

public Maven() {
this(DEFAULT_VERSION);
}

@Override
public ToolProvider install(Path into) throws Exception {
var base = "https://repo.maven.apache.org/maven2/org/apache/maven";
var mavenWrapperProperties = into.resolve("maven-wrapper.properties");
if (!Files.exists(mavenWrapperProperties))
try {
Files.writeString(
mavenWrapperProperties,
// language=properties
"""
distributionUrl=%s/apache-maven/%s/apache-maven-%s-bin.zip
"""
.formatted(base, version, version));
} catch (Exception exception) {
throw new RuntimeException(exception);
}
var uri = URI.create(base + "/wrapper/maven-wrapper/3.3.1/maven-wrapper-3.3.1.jar#SIZE=63030");
var mavenWrapperJar = into.resolve("maven-wrapper.jar");
download(mavenWrapperJar, uri);
return ToolProgram.findJavaDevelopmentKitTool(
"java",
"-D" + "maven.multiModuleProjectDirectory=.",
"--class-path=" + mavenWrapperJar,
"org.apache.maven.wrapper.MavenWrapperMain")
.orElseThrow();
}
}
Loading

0 comments on commit 185cf27

Please sign in to comment.