From 321f783d5890265cfe6364c18b472948b8f164c3 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Sun, 26 May 2024 09:20:08 +0200 Subject: [PATCH] Add default `bach-info` repository as a submodule --- .bach/src/run.bach/module-info.java | 2 +- .bach/src/run.bach/run/bach | 2 +- .bach/src/run.bach/run/demo/Ant.java | 58 ------------------- .bach/src/run.bach/run/demo/Maven.java | 58 ------------------- .../run/demo/MavenRepositoryModuleFinder.java | 43 -------------- .../run.bach/run/demo/ModuleResolverDemo.java | 18 +++--- .../src/run.bach/run/demo/ToolFinderDemo.java | 3 +- .../src/run.bach/run/demo/ToolSpaceDemo.java | 3 +- .../run.bach/run/demo/ToolVersionsDemo.java | 1 + .bach/src/run.bach/run/info/bach | 1 + .gitmodules | 3 + .idea/vcs.xml | 1 + 12 files changed, 23 insertions(+), 170 deletions(-) delete mode 100644 .bach/src/run.bach/run/demo/Ant.java delete mode 100644 .bach/src/run.bach/run/demo/Maven.java delete mode 100644 .bach/src/run.bach/run/demo/MavenRepositoryModuleFinder.java create mode 160000 .bach/src/run.bach/run/info/bach diff --git a/.bach/src/run.bach/module-info.java b/.bach/src/run.bach/module-info.java index 31aba3309..d707631b4 100644 --- a/.bach/src/run.bach/module-info.java +++ b/.bach/src/run.bach/module-info.java @@ -1,7 +1,7 @@ /** Defines Bach's API. */ module run.bach { requires jdk.compiler; - requires jdk.jfr; + requires transitive jdk.jfr; exports run.bach; exports run.bach.workflow; diff --git a/.bach/src/run.bach/run/bach b/.bach/src/run.bach/run/bach index 94416e4e9..34932463b 160000 --- a/.bach/src/run.bach/run/bach +++ b/.bach/src/run.bach/run/bach @@ -1 +1 @@ -Subproject commit 94416e4e9fad71e57d5b42911dfd61a8861f9014 +Subproject commit 34932463b6e88f097073b90d06e5335c86878735 diff --git a/.bach/src/run.bach/run/demo/Ant.java b/.bach/src/run.bach/run/demo/Ant.java deleted file mode 100644 index e11a740b4..000000000 --- a/.bach/src/run.bach/run/demo/Ant.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 Christian Stein - * Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl - */ - -package run.demo; - -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.ToolRunner; - -/** - * Apache Ant installer. - * - * @see https://ant.apache.org - */ -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(); - ToolRunner.ofSilence().run(jar, "--extract", "--file", archive); - } - return ToolProgram.java( - "--class-path", - antHome.resolve("lib/ant-launcher.jar").toString(), - "org.apache.tools.ant.launch.Launcher"); - } -} diff --git a/.bach/src/run.bach/run/demo/Maven.java b/.bach/src/run.bach/run/demo/Maven.java deleted file mode 100644 index 90a9843cf..000000000 --- a/.bach/src/run.bach/run/demo/Maven.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 Christian Stein - * Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl - */ - -package run.demo; - -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 https://maven.apache.org - */ -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(); - } -} diff --git a/.bach/src/run.bach/run/demo/MavenRepositoryModuleFinder.java b/.bach/src/run.bach/run/demo/MavenRepositoryModuleFinder.java deleted file mode 100644 index 037cda3c6..000000000 --- a/.bach/src/run.bach/run/demo/MavenRepositoryModuleFinder.java +++ /dev/null @@ -1,43 +0,0 @@ -package run.demo; - -import java.lang.module.ModuleFinder; -import java.lang.module.ModuleReference; -import java.util.Optional; -import java.util.Set; -import run.bach.ModuleFinders; - -public record MavenRepositoryModuleFinder( - String repository, ModuleFinders.ModuleReferenceFinder finder) implements ModuleFinder { - - public static MavenRepositoryModuleFinder ofMavenCentral() { - return ofMavenRepository("https://repo.maven.apache.org/maven2"); - } - - public static MavenRepositoryModuleFinder ofMavenRepository(String repository) { - return new MavenRepositoryModuleFinder(repository, new ModuleFinders.ModuleReferenceFinder()); - } - - @Override - public Optional find(String name) { - return finder.find(name); - } - - @Override - public Set findAll() { - return finder.findAll(); - } - - public MavenRepositoryModuleFinder with(String module, String coordinates) { - var split = coordinates.split(":"); - var group = split[0]; - var artifact = split[1]; - var version = split[2]; - return with(module, group, artifact, version); - } - - public MavenRepositoryModuleFinder with( - String module, String group, String artifact, String version) { - var location = repository + "/"; - return new MavenRepositoryModuleFinder(repository, finder.with(module, location)); - } -} diff --git a/.bach/src/run.bach/run/demo/ModuleResolverDemo.java b/.bach/src/run.bach/run/demo/ModuleResolverDemo.java index 944d7fc4f..a43cf0236 100644 --- a/.bach/src/run.bach/run/demo/ModuleResolverDemo.java +++ b/.bach/src/run.bach/run/demo/ModuleResolverDemo.java @@ -2,6 +2,8 @@ import java.lang.module.ModuleFinder; import java.nio.file.Path; + +import jdk.jfr.consumer.RecordingStream; import run.bach.ModuleFinders; import run.bach.ModuleResolver; import run.bach.ToolFinder; @@ -16,10 +18,15 @@ public static void main(String... args) throws Exception { } 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(); + try (var recording = new RecordingStream()) { + recording.onEvent("run.bach.ModuleResolverResolvedModule", System.out::println); + recording.startAsync(); + 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(); + recording.stop(); + } // // "jreleaser" via the tool provider SPI // var jreleaserHome = @@ -41,7 +48,6 @@ public static void main(String... args) throws Exception { // .withJavaApplication( // "demo/release@all", JReleaser.APPLICATION, // JReleaser.APPLICATION_ASSETS) - .with(new Ant()) // provides "ant" tool ); var junit = tools.get("junit"); @@ -51,7 +57,5 @@ public static void main(String... args) throws Exception { // tools.get("jreleaser").run("--version"); // tools.get("releaser1").run("--version"); // tools.get("releaser2").run("--version"); - - tools.get("ant").run("-version"); } } diff --git a/.bach/src/run.bach/run/demo/ToolFinderDemo.java b/.bach/src/run.bach/run/demo/ToolFinderDemo.java index baf0d1470..f0e25121b 100644 --- a/.bach/src/run.bach/run/demo/ToolFinderDemo.java +++ b/.bach/src/run.bach/run/demo/ToolFinderDemo.java @@ -6,6 +6,7 @@ import java.util.function.Consumer; import java.util.spi.*; import run.bach.*; +import run.info.bach.*; class ToolFinderDemo { public static void main(String... args) { @@ -27,7 +28,7 @@ public static void main(String... args) { // dedicated installer .with(new Ant("1.10.14")) .with(new GoogleJavaFormat("1.22.0")) - .with(new Maven("3.9.6")) + .with(new Maven("3.9.7")) // convenient installer .withJavaApplication( "rife2/bld@1.9.0", diff --git a/.bach/src/run.bach/run/demo/ToolSpaceDemo.java b/.bach/src/run.bach/run/demo/ToolSpaceDemo.java index e4a9ce5cd..421069f57 100644 --- a/.bach/src/run.bach/run/demo/ToolSpaceDemo.java +++ b/.bach/src/run.bach/run/demo/ToolSpaceDemo.java @@ -1,10 +1,11 @@ package run.demo; import run.bach.*; +import run.info.bach.*; class ToolSpaceDemo extends ToolSpace { public static void main(String... args) { - var finder = ToolFinder.ofInstaller().with(new Maven("3.9.6")); + var finder = ToolFinder.ofInstaller().with(new Maven()); var space = new ToolSpaceDemo(finder); var run = space.run("maven", "--version"); diff --git a/.bach/src/run.bach/run/demo/ToolVersionsDemo.java b/.bach/src/run.bach/run/demo/ToolVersionsDemo.java index 3d439b154..e5e09cf14 100644 --- a/.bach/src/run.bach/run/demo/ToolVersionsDemo.java +++ b/.bach/src/run.bach/run/demo/ToolVersionsDemo.java @@ -1,6 +1,7 @@ package run.demo; import run.bach.*; +import run.info.bach.*; class ToolVersionsDemo { public static void main(String... args) { diff --git a/.bach/src/run.bach/run/info/bach b/.bach/src/run.bach/run/info/bach new file mode 160000 index 000000000..2f5ed4513 --- /dev/null +++ b/.bach/src/run.bach/run/info/bach @@ -0,0 +1 @@ +Subproject commit 2f5ed4513a386b9df7f241abc9aca688b99b6ae0 diff --git a/.gitmodules b/.gitmodules index b337d8265..b10a7fc48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "junit"] path = .bach/src/run.bach/run/info/org/junit url = https://github.com/junit-team/bach-info +[submodule "run.info.bach"] + path = .bach/src/run.bach/run/info/bach + url = https://github.com/sormuras/bach-info diff --git a/.idea/vcs.xml b/.idea/vcs.xml index cb5149ebe..870430390 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -16,6 +16,7 @@ + \ No newline at end of file