-
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.
- Loading branch information
Showing
10 changed files
with
204 additions
and
85 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package run; | ||
|
||
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.ToolCall; | ||
import run.bach.ToolFinder; | ||
import run.bach.ToolInstaller; | ||
import run.bach.ToolProgram; | ||
import run.bach.ToolSpace; | ||
|
||
/** | ||
* Apache Ant. | ||
* | ||
* @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 installInto(Path folder) { | ||
var title = "apache-ant-" + version; | ||
var archive = title + "-bin.zip"; | ||
var target = folder.resolve(archive); | ||
if (!Files.exists(target)) { | ||
var source = "https://dlcdn.apache.org/ant/binaries/" + archive; | ||
download(target, URI.create(source)); | ||
} | ||
var antHome = folder.resolve(title); | ||
if (!Files.isDirectory(antHome)) { | ||
var jar = | ||
ToolProgram.findJavaDevelopmentKitTool("jar") | ||
.orElseThrow() | ||
.withProcessBuilderTweaker(builder -> builder.directory(folder.toFile())) | ||
.withProcessWaiter(process -> process.waitFor(1, TimeUnit.MINUTES) ? 0 : 1) | ||
.tool(); | ||
var silent = | ||
new ToolSpace(ToolFinder.compose()) { | ||
@Override | ||
protected void announce(ToolCall call) {} | ||
}; | ||
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
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,53 @@ | ||
package run; | ||
|
||
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 is a software project management and comprehension tool. | ||
* | ||
* @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 installInto(Path into) { | ||
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.2.0/maven-wrapper-3.2.0.jar#SIZE=62547"); | ||
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(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
package run; | ||
|
||
import run.bach.ToolCall; | ||
import run.bach.ToolFinder; | ||
import run.bach.ToolRun; | ||
import run.bach.ToolSpace; | ||
|
||
class ToolSpaceDemo extends ToolSpace { | ||
public static void main(String... args) { | ||
var finder = ToolFinder.ofInstaller().with(new Maven("3.9.6")); | ||
var space = new ToolSpaceDemo(finder); | ||
|
||
var run = space.run("maven", "--version"); | ||
|
||
run.out().lines().filter(line -> line.startsWith("Apache Maven")).forEach(System.out::println); | ||
if (run.code() != 0) throw new Error("Non-zero error code: " + run.code()); | ||
} | ||
|
||
ToolSpaceDemo(ToolFinder finder) { | ||
super(finder); | ||
} | ||
|
||
@Override | ||
protected void announce(ToolCall call) { | ||
System.out.println("BEGIN -> " + call.tool().name()); | ||
} | ||
|
||
@Override | ||
protected void verify(ToolRun run) { | ||
System.out.println("<-- END. " + run.call().tool().name()); | ||
} | ||
} |
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
5 files
+26 −3 | Tool.java | |
+112 −52 | ToolInstaller.java | |
+13 −4 | ToolProgram.java | |
+53 −0 | internal/JavaApplicationInstaller.java | |
+31 −0 | internal/RunTool.java |