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

AOSP configuration not working #75

Open
rozagerardo opened this issue Jul 21, 2021 · 1 comment
Open

AOSP configuration not working #75

rozagerardo opened this issue Jul 21, 2021 · 1 comment

Comments

@rozagerardo
Copy link

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>
  1. Run a maven command for the plugin to create the git hook
  2. add a change in a file (indented with 4 spaces)
  3. 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:

  • OS: Windows 10
  • Git version: 2.21.0.windows.1
  • git-code-format-maven-plugin version: 3.1
  • Maven version: 3.6.3

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
Copy link

I have exact same issue with release 5.3, please fix 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

No branches or pull requests

2 participants