Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activate sourcecode formatting #247

Merged
merged 17 commits into from
Feb 9, 2023
Merged

activate sourcecode formatting #247

merged 17 commits into from
Feb 9, 2023

Conversation

mwiede
Copy link
Owner

@mwiede mwiede commented Nov 29, 2022

This will use formatting rules of eclipse-java-google-style.xml to format the source code in maven process-sources phase.
There should be only whitespace changes in java files.

Checkstyle Plugin is added, but not used by default, since current code would have 2640 violations against Google-Style.

$ mvn validate -Pcheckstyle
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  23.848 s
[INFO] Finished at: 2022-11-29T10:34:30Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.2.0:check (validate) on project jsch: You have 2640 Checkstyle violations. -> [Help 1]

Cleaning these up is an additional effort.

@norrisjeremy
Copy link
Contributor

norrisjeremy commented Nov 29, 2022

Have you considered using fmt-maven-plugin?
It directly utilizes Google's google-jave-format library to process sources.
We typically add it's check goal like this to our projects so that non-conforming code causes a build failure during the verify phase:

      <plugin>
        <groupId>com.spotify.fmt</groupId>
        <artifactId>fmt-maven-plugin</artifactId>
        <version>2.19</version>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <phase>verify</phase>
          </execution>
        </executions>
      </plugin>

And to directly use it's format goal to reformat sources, you can manually execute mvn fmt:format.
It may require some additional tweaks to the plugin configuration to pick-up all the non-standard source directories where we put the > Java 8 source code.

@mwiede
Copy link
Owner Author

mwiede commented Nov 29, 2022

i have not compared fmt-maven-plugin, but as far as i can see formatter-maven-plugin offers the same. you can both format source code as well as verify it.

@mwiede
Copy link
Owner Author

mwiede commented Nov 29, 2022

as per github stats, fmt-maven-plugin is used by 185 repos and formatter-maven-plugin is used by 2.5k repos.

@norrisjeremy
Copy link
Contributor

It appears formatter-maven-plugin also has a validate goal: is there a reason to to use maven-checkstyle-plugin instead of that?

Also, do we need to configure these plugins to also handle the > Java 8 code directories (src/main/java9, src/main/java11, etc.)?

@@ -1,36 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may want to also remove all these editor hints at the top of all the files too?

Copy link
Owner Author

Choose a reason for hiding this comment

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

yes makes sense

Copy link
Contributor

@norrisjeremy norrisjeremy Dec 6, 2022

Choose a reason for hiding this comment

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

Did we want to handle removal of these editor hints in this PR or do that separately?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I will add it to this one

pom.xml Outdated Show resolved Hide resolved
pom.xml Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
pom.xml Show resolved Hide resolved
Copy link
Contributor

@norrisjeremy norrisjeremy left a comment

Choose a reason for hiding this comment

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

Do we know what's causing the test failures during CI builds?

pom.xml Outdated Show resolved Hide resolved
@mwiede
Copy link
Owner Author

mwiede commented Dec 5, 2022

Do we know what's causing the test failures during CI builds?

I looked at it. The problem seems to be the docker bind mount of the temporary directory. We need to move the temp directory to the current workspace.

mwiede and others added 5 commits December 6, 2022 09:24
Bumps scala-maven-plugin from 4.7.2 to 4.8.0.

---
updated-dependencies:
- dependency-name: net.alchim31.maven:scala-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [maven-dependency-plugin](https://github.com/apache/maven-dependency-plugin) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/apache/maven-dependency-plugin/releases)
- [Commits](apache/maven-dependency-plugin@maven-dependency-plugin-3.3.0...maven-dependency-plugin-3.4.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-dependency-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
* generate osgi bundle manifest data for jar #248
@mwiede
Copy link
Owner Author

mwiede commented Dec 6, 2022

Do we know what's causing the test failures during CI builds?

I looked at it. The problem seems to be the docker bind mount of the temporary directory. We need to move the temp directory to the current workspace.

that was a problem I had within Github Codespaces environment. The other problem was now resolved by downgrading the runner image to ubuntu 20.04

pom.xml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
pom.xml Show resolved Hide resolved
@norrisjeremy
Copy link
Contributor

norrisjeremy commented Feb 9, 2023

I think we may want to add -Dformatter.skip=true in .github/workflows/maven.yml for the Test with Maven step.
I believe that will prevent Github CI from executing the formatter validation check when it executes the unit & integration tests (since it already would have done this during the prior Build with Maven step).

@norrisjeremy
Copy link
Contributor

I think we may want to add -Dformatter.skip=true in .github/workflows/maven.yml for the Test with Maven step.
I believe that will prevent Github CI from executing the formatter validation check when it executes the unit & integration tests (since it already would have done this during the prior Build with Maven step).

Disregard, I missed that formatter:validate is tied to verify phase, so it has to happen during the Test with Maven step.

pom.xml Outdated Show resolved Hide resolved
Copy link
Contributor

@norrisjeremy norrisjeremy left a comment

Choose a reason for hiding this comment

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

I think we should do a squash merge of this so it's a single commit.

@mwiede mwiede merged commit 72f8a6d into master Feb 9, 2023
@mwiede mwiede deleted the formatting branch February 9, 2023 21:17
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.

3 participants