forax / pro

A Java build tool that works seamlessly with modules
GNU General Public License v3.0
103 stars 15 forks source link

Add external plugin: "formatter" #34

Closed sormuras closed 6 years ago

sormuras commented 7 years ago

Overview

Based on google-java-format -- a program that reformats Java source code to comply with Google Java Style.

The current implementation uses the --module-path option to launch the program. I didn't managed to make modules via module-fixer out of neither the "-all-deps" distro nor the 3 single jars: google-java-format-1.3.jar, guava-19.0.jar and javac-9-dev-r3297-1-shaded.jar

The "-all-deps" jar is downloaded on-the-fly via Boostrap.download(...) -- a candidate for Pro itself?

The "-all-deps" jar is stored in a subfolder called plugins/formatter/libs/. All jars found in that folder are not resolved, nor module-fixed. They are copied over to the target/pro image as-is.

TODO

sormuras commented 6 years ago

After the perfer addition in release v0.10+44a ... I willl give formatter another chance.

forax commented 6 years ago

For the javac-9-dev-r3297-1-shaded.jar, it would be cool if google-java-format had an option to use javac through the service interface as we do in the compiler plugin instead of using its own version.

sormuras commented 6 years ago

Sure. That would simplify the integration work.

sormuras commented 6 years ago

@forax How can I help resolver with a module name?

java.lang.IllegalArgumentException: javac.shaded.9.dev.r4023: Invalid module name: '9' is not a Java identifier

[resolver] Unable to derive module descriptor for R:\dev\github\forax\pro\.\plugins\formatter\target\deps\maven-local\com\google\errorprone\javac-shaded\9-dev-r4023-3\javac-shaded-9-dev-r4023-3.jar

Using this boot strap commands:

    compileAndPackagePlugin("formatter", () -> {
      String gjfVersion = "1.5";
      String guavaVersion = "24.1";
      String javacShadedVersion = "9+181-r4173-1";
      set("resolver.dependencies", list(
          // "Google Java Format"
          "com.google.googlejavaformat=com.google.googlejavaformat:google-java-format:" + gjfVersion,
          "com.google.guava=com.google.guava:guava:" + guavaVersion,
          "com.google.errorprone=com.google.errorprone:javac-shaded:" + javacShadedVersion,
          "com.google.j2objc=com.google.j2objc:j2objc-annotations:1.1",
          "org.codehaus.animal.sniffer.annotations=org.codehaus.mojo:animal-sniffer-annotations:1.14"
      ));
    });
forax commented 6 years ago

The Manifest of the jar do not contains the property Automatic-Module-Name so the module API try to gess a name and fail. The best is to ask @cushon to add the property Automatic-Module-Name.

In the meantime, the only workaround i see is to download the jar by hand, rename it and commit it in the git repo.

sormuras commented 6 years ago

GJF 1.6 will include it: https://github.com/google/google-java-format/commit/4d728e7cfac4e47f98127576ee14583e1babf8e8

Thought there was a chance to "modulefix" it. :)

sormuras commented 6 years ago

I'll stick with the external java process using google-java-format-1.5-all-deps.jar on the classpath for now.

sormuras commented 6 years ago

Superseded by #57

sormuras commented 6 years ago

@cushon said he'll fix the modular problems within error-prone. Looks like we may move from '-all-deps.jar' and spawing another process to a real module-based plugin.

See https://github.com/google/google-java-format/issues/266#issuecomment-380325034 and a minimal running test at https://github.com/sormuras/bach/tree/master/demo/03-google-java-format-as-library (placing error-prone on the class-path)