Skip to content

Conversation

@wfouche
Copy link
Member

@wfouche wfouche commented Oct 13, 2025

No description provided.

@wfouche wfouche changed the title Moved Java files to src folder Eclipse Java Formatter Oct 13, 2025
@wfouche wfouche marked this pull request as draft October 14, 2025 07:09
@wfouche wfouche changed the title Eclipse Java Formatter Formatting Java source code Oct 14, 2025
Copy link
Member

@jeff5 jeff5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spotless appears to do a perfectly fine job of formatting to project standards. Some comments on how this is implemented, scattered around the files, for your consideration.

@@ -0,0 +1,36 @@
// Apply the standard Java plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gradle potentially confers some advantages in terms of editing and debugging from the IDE, which has always been a pain point when reviewing. VSCode recognises this as a Gradle project, which means the Gradle menu has just appeared, and the spotlessApply task may be run from it.

However, it is not properly set up as a Gradle Java project with the right structure and dependencies, so VSCode does not recognise the source as belonging to the project, and continues to give me red ink about the imports and won't debug the cli.

I think a little more work (and letting Gradle bully you into main and test source trees) will yield a lot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an initial step, I've moved both Java files to src/main/java.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first step. With that change, I find I can finally stop the IDE grumbling at me, with some additions to just this file, which I'll pass on next.

@wfouche wfouche marked this pull request as ready for review October 22, 2025 18:07
@wfouche
Copy link
Member Author

wfouche commented Nov 1, 2025

@jeff5 , please review the changes. I implemented all the improvements that you recommended.

Copy link
Member

@jeff5 jeff5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this is looking good. I propose a few changes that make the Gradle and IDE experiences better.

@@ -0,0 +1,36 @@
// Apply the standard Java plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good first step. With that change, I find I can finally stop the IDE grumbling at me, with some additions to just this file, which I'll pass on next.

repositories {
mavenCentral()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then here, we need to specify these dependencies:

dependencies {
    implementation 'org.tomlj:tomlj:1.1.1'
    testImplementation 'org.junit.platform:junit-platform-console'
}

and to minimally configure the jvm-test-suite plug-in like this:

// Configure the jvm-test-suite plug-in
testing {
    suites {
        // The pre-defined test suite.
        test {
            useJUnitJupiter()
        }
    }
}

Copy link
Member Author

@wfouche wfouche Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following a slightly different approach by using the JBang Gradle plugin

https://plugins.gradle.org/plugin/dev.jbang

and then just running TestJythonCli.java as we run it currently. Created new task runTests for this purpose.

tasks.register("runTests", JBangTask) {
    // Specify the script file to run
    script = "src/test/java/TestJythonCli.java"

    // Optional: Pass arguments to the script
    jbangArgs = ["--java", "17"]
    args = ["execute", "--disable-ansi-colors", "--select-class=TestJythonCli"]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to have a target that runs the tests the way we do on GitHub. I confirm this target runs at the console for me.

It is not a substitute for the changes I suggested.

// Apply the standard Java plugin
plugins {
id 'java'
// Apply the Spotless plugin (using the same version as in the Kotlin DSL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the Gradle test target to work, add this plug-in (and config lower down).

id 'jvm-test-suite'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed in the revised implementation.

@wfouche
Copy link
Member Author

wfouche commented Nov 8, 2025

@jeff5 , ready for review again.

I followed a different approach which is more natural for JBang script by adding a gradle JBang Task to run TestJythonCli.

It works really well.

tasks.register("runTests", JBangTask) {
...
}

Copy link
Member

@jeff5 jeff5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has always been difficult to review PRs on this project because the IDE cannot find the libraries it references. The changes I suggested make it possible to work with the code in an IDE. Without them it looks like:
Image
and we cannot get pop-up documentation, run unit tests, and so on in the expected way. Also the well-known Gradle tasks fail (like check).

repositories {
mavenCentral()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to have a target that runs the tests the way we do on GitHub. I confirm this target runs at the console for me.

It is not a substitute for the changes I suggested.

@wfouche
Copy link
Member Author

wfouche commented Nov 10, 2025

It is not a substitute for the changes I suggested.

I agree. I'll try again.

@wfouche
Copy link
Member Author

wfouche commented Nov 11, 2025

@jeff5, there is a new Java formatter availalbe that also uses the Eclipse Java Formatter.

https://github.com/bmarwell/jfmt

and does require Spotless or Gradle/Maven

@jeff5
Copy link
Member

jeff5 commented Nov 11, 2025

I looked, but I see no advantage to be gained from a change.

Probably the worst thing about Spotless and VSCode is shared by jfmt: bmarwell/jfmt#94 (comment) . (Except VSCode makes it slightly worse by not implementing some of it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants