Cosium / git-code-format-maven-plugin

A maven plugin that automatically deploys code formatters as pre-commit git hook
MIT License
201 stars 39 forks source link

AOSP configuration not working #75

Open rozagerardo opened 3 years ago

rozagerardo commented 3 years ago

Steps to reproduce the behavior:

  1. Enable AOSP in the plugin configuration as per the documentation:
    <build>
    <plugins>
        <plugin>
            <groupId>com.cosium.code</groupId>
            <artifactId>git-code-format-maven-plugin</artifactId>
            <version>${git-code-format-maven-plugin.version}</version>
            <executions>
                <!-- On commit, format the modified java files -->
                <execution>
                    <id>install-formatter-hook</id>
                    <goals>
                        <goal>install-hooks</goal>
                    </goals>
                </execution>
                <!-- On Maven verify phase, fail if any file (including 
                    unmodified) is badly formatted -->
                <execution>
                    <id>validate-code-format</id>
                    <goals>
                        <goal>validate-code-format</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <googleJavaFormatOptions>
                    <aosp>true</aosp>
                    <fixImportsOnly>false</fixImportsOnly>
                    <skipSortingImports>false</skipSortingImports>
                    <skipRemovingUnusedImports>false</skipRemovingUnusedImports>
                </googleJavaFormatOptions>
                <propertiesToAdd>
                    <prop>-X</prop>
                </propertiesToAdd>
            </configuration>
        </plugin>
    </plugins>
    </build>
  2. Run a maven command for the plugin to create the git hook
  3. add a change in a file (indented with 4 spaces)
  4. git add . and git commit -m 'a message'

What is the expected output? The modified file should be indented using a 4-spaces indentation.

What happens instead? The file is still formatted using a 2-spaces indentation.

The debug logs look ok:

[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <currentProject default-value="${project}"/>
  <excludedModules>${gcf.excludedModules}</excludedModules>
  <googleJavaFormatOptions>
    <aosp>true</aosp>
    <fixImportsOnly>false</fixImportsOnly>
    <skipSortingImports>false</skipSortingImports>
    <skipRemovingUnusedImports>false</skipRemovingUnusedImports>
  </googleJavaFormatOptions>
  <includedModules>${gcf.includedModules}</includedModules>
  <skip default-value="false">${gcf.skip}</skip>
  <sourceEncoding default-value="${project.build.sourceEncoding}"/>
</configuration>
[DEBUG] =======================================================================
[INFO]
[INFO] --- git-code-format-maven-plugin:3.1:on-pre-commit (default-cli) @ learn-spring-data.spring-data-custom-queries ---
[DEBUG] Configuring mojo com.cosium.code:git-code-format-maven-plugin:3.1:on-pre-commit from plugin realm ClassRealm[plugin>com.cosium.code:git-code-format-maven-plugin:3.1, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44]
[DEBUG] Configuring mojo 'com.cosium.code:git-code-format-maven-plugin:3.1:on-pre-commit' with basic configurator -->
[DEBUG]   (f) currentProject = MavenProject: com.baeldung:learn-spring-data.spring-data-custom-queries:0.1.0-SNAPSHOT @ C:\Baeldung\internal\lessons\private\learnspringdata\pom.xml
[DEBUG]   (f) excludedModules = []
[DEBUG]   (s) aosp = true
[DEBUG]   (s) fixImportsOnly = false
[DEBUG]   (s) skipSortingImports = false
[DEBUG]   (s) skipRemovingUnusedImports = false
[DEBUG]   (f) googleJavaFormatOptions = com.cosium.code.format.MavenGoogleJavaFormatOptions@d70f722
[DEBUG]   (f) includedModules = []
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = UTF-8
[DEBUG] -- end configuration --
[DEBUG] Goal enabled
[INFO] Executing pre-commit hooks

And here the resulting modifications (using git log -p):

-    private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
+  private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
+
+  @Autowired EntityManager entityManager;

-    @Autowired
-    EntityManager entityManager;

Environment:

Link to a git repository that can be cloned to reproduce the problem: https://github.com/rozagerardo/samples/tree/cosium--git-code-format-maven-plugin

206746517 commented 6 months ago

I have exact same issue with release 5.3, please fix it.