-
Notifications
You must be signed in to change notification settings - Fork 15
/
try_all.java
56 lines (46 loc) · 1.93 KB
/
try_all.java
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
import com.fizzed.blaze.Contexts;
import static com.fizzed.blaze.Contexts.baseDir;
import static com.fizzed.blaze.Systems.exec;
import static com.fizzed.blaze.util.Globber.globber;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
public class try_all {
private final Logger log = Contexts.logger();
public void main() throws Exception {
// find blaze jar to use (same one that is on our classpath)
final Path blazeJarFile = findBlazeJarOnClassPath();
if (blazeJarFile == null) {
Contexts.fail("Unable to find blaze.jar on classpath");
}
final AtomicInteger count = new AtomicInteger();
// use globber to find files to run
globber(baseDir(), "*.{java,groovy,js,kt,kts}")
.exclude("try_all.java")
.stream()
.sorted()
.forEach((p) -> {
log.info("Trying {}", p);
exec("java", "-Dexamples.try_all=true", "-jar", blazeJarFile, "-f", p).run();
count.incrementAndGet();
});
log.info("Ran {} examples!", count);
}
private Path findBlazeJarOnClassPath() throws URISyntaxException {
// does the jar already exist on claspath?
URLClassLoader urlClassLoader = (URLClassLoader)Thread.currentThread().getContextClassLoader();
for (URL u : urlClassLoader.getURLs()) {
Path loadedJarFile = Paths.get(u.toURI());
String loadedJarName = loadedJarFile.getFileName().toString();
if (loadedJarName.startsWith("blaze") && loadedJarName.endsWith(".jar")) {
log.info("Using blaze jar {}", loadedJarFile);
return loadedJarFile;
}
}
return null;
}
}