Skip to content

Commit

Permalink
Add google-java-format to devenv as javafmt (digital-asset#8687)
Browse files Browse the repository at this point in the history
Add the https://github.com/google/google-java-format code formatting tool to dev-env.

Uses the name javafmt to call it, to mirror scalafmt.

Making it part of our checks will be done in a follow-up PR to make this easy to review.

changelog_begin
changelog_end
  • Loading branch information
stefanobaghino-da authored Jan 29, 2021
1 parent 69b28d2 commit 8ec9bc7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev-env/bin/javafmt
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ in rec {
jstack = jdk;
jar = jdk;

javafmt = pkgs.callPackage ./tools/google-java-format {};

# The package itself is called bazel-watcher. However, the executable is
# called ibazel. We call the attribute ibazel so that the default dev-env
# wrapper works.
Expand Down
17 changes: 17 additions & 0 deletions nix/tools/google-java-format/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ stdenv, fetchurl, jdk11, pkgs }:

let version = "1.9"; in
stdenv.mkDerivation rec {
buildInputs = [ pkgs.makeWrapper ];
name = "google-java-format";
dontUnpack = true;
src = fetchurl {
url = "https://github.com/google/${name}/releases/download/${name}-${version}/${name}-${version}-all-deps.jar";
sha256 = "1d98720a5984de85a822aa32a378eeacd4d17480d31cba6e730caae313466b97";
};
installPhase = ''
mkdir -pv $out/share/java $out/bin
cp ${src} $out/share/java/${name}-${version}.jar
makeWrapper ${jdk11}/bin/java $out/bin/javafmt --add-flags "-jar $out/share/java/${name}-${version}.jar"
'';
}

0 comments on commit 8ec9bc7

Please sign in to comment.