Fork me on GitHub
#announcements
<
2022-01-06
>
emccue03:01:35

Ever wanted to build Java programs with Java - no maven or gradle? I made a very basic wrapper around tools.build that should make it easier to write build programs for deps.edn in Java Super alpha. Functionality may be broken or missing entirely. https://github.com/bowbahdoe/jproject https://github.com/bowbahdoe/jproject-example

🎉 3
👏 2
🚀 2
seancorfield03:01:09

The example seems to suggest you still need the Clojure CLI installed for this to work?

emccue04:01:01

yep. Still nowhere near a state i could walk up to a stock Java dev and convince them, but enough to show the concept imo

emccue04:01:05

the next steps would be 1. Think way more about how to expose the basis concept 2. Fill out and document the build tools wrapper 3. Wrap the clojure CLI’s functionality - probably making a graalvm executable with a “simplified” api probably along the lines of

jproject --help
jproject --tree
jproject --pom
jproject run src/Something.java
jproject run --alias=build build/Build.java
jproject run --alias=build build/Build.java --argForBuildProgram 123

Alex Miller (Clojure team)04:01:51

I feel bad that you're spending time making it

👆 1
Alex Miller (Clojure team)04:01:34

just pouring concrete over all that lovely clojure

😂 5
emccue04:01:08

makes for good rebar

Alex Miller (Clojure team)04:01:13

I've added options to those build tasks at least a dozen times in the last 6 months. every time I do that, you'll have to add new fields and methods and whatever

emccue04:01:20

if anyone uses it, which i doubt

emccue04:01:36

and if i get it into a workable/marketable state, which is doubtful. Especially considering that no IDE resolves deps.edn dependencies without a clojure plugin so any effort to make it seem “java native” is probably moot

emccue04:01:36

and anyone who is comfortable installing a clojure plugin might as well just write the build program in clojure

emccue05:01:12

NOW you can feel bad

seancorfield05:01:59

You sure are dedicated to this 🙂

gklijs06:01:43

Not really, and if I did I would use jbang, https://jbang.dev/

👍 1
👀 1
emccue15:01:20

but can jbang let me stay up until 4am writing a script for test coverage

public final class GenerateCoverage {
    public static void main(String[] args) throws IOException {
        var execFileLoader = new ExecFileLoader();
        execFileLoader.load(new File("jacoco.exec"));
        var htmlFormatter = new HTMLFormatter();
        var fileMultiReportOutput = new FileMultiReportOutput(new File("target/coverage/html"));
        var visitor = htmlFormatter.createVisitor(fileMultiReportOutput);

        var coverageBuilder = new CoverageBuilder();

        for (var file : Files.walk(Path.of("target", "src"))
                .filter(Files::isRegularFile)
                .map(Path::toFile)
                .toList()
        ) {
            var analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
            analyzer.analyzeAll(file);
        }

        var bundle = coverageBuilder.getBundle("project");
        visitor.visitInfo(
                execFileLoader.getSessionInfoStore().getInfos(),
                execFileLoader.getExecutionDataStore().getContents()
        );
        visitor.visitBundle(bundle, new ISourceFileLocator() {
            @Override
            public Reader getSourceFile(String packageName, String fileName) throws IOException {
                var resource = GenerateCoverage.class.getResourceAsStream(
                        packageName.replace(".", "/") + "/" + fileName
                );
                if (resource == null) {
                    return null;
                }
                return new InputStreamReader(resource);
            }

            @Override
            public int getTabWidth() {
                return 4;
            }
        });
        visitor.visitEnd();
    }
}
Which as horrible as it sounds and looks - a team of 10 engineers could not figure out how to properly filter certain files out of coverage for a week with the maven plugin (actual story, not an overstatement for dramatic effect)

ericdallo15:01:15

Amazing! I'll certainly change my java code on clojure-lsl to use that!

borkdude19:01:06

This reminds me of a Java API I once wrote for SCI. After 2 months I just gave up and told people to make their own dedicated Clojure wrapper and call that from Java.

AJ Jaro19:01:25

What a terrifying adventure!