-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to use latest
run.bach
module
- Loading branch information
Showing
23 changed files
with
321 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/bin/ | ||
/out/ | ||
/src/run/ | ||
/tool/*/ | ||
/tool/*/** | ||
/tmp/ | ||
/var/ | ||
|
||
*.jfr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule bach
updated
17 files
+128 −0 | ModuleFinders.java | |
+143 −0 | ModuleResolver.java | |
+3 −4 | ToolInstaller.java | |
+0 −59 | external/Ant.java | |
+0 −53 | external/GoogleJavaFormat.java | |
+0 −58 | external/Maven.java | |
+0 −62 | external/ModuleLookup.java | |
+0 −33 | external/ModuleLookupTable.java | |
+0 −102 | external/OperatingSystem.java | |
+0 −7 | external/package-info.java | |
+0 −113 | internal/JavaToolInstaller.java | |
+4 −8 | internal/ModuleDescriptorSupport.java | |
+4 −1 | internal/PathSupport.java | |
+5 −5 | workflow/Folders.java | |
+7 −88 | workflow/Restorer.java | |
+7 −7 | workflow/Structure.java | |
+3 −1 | workflow/Workflow.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.