-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnt.java
More file actions
58 lines (52 loc) · 1.83 KB
/
Ant.java
File metadata and controls
58 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2024 Christian Stein
* Licensed under the Universal Permissive License v 1.0 -> https://opensource.org/license/upl
*/
package run.info.bach;
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 is a Java library and command-line tool.
*
* @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();
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");
}
}