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

Manual formatting/validating misses files #27

Closed
djcooke opened this issue Nov 6, 2019 · 5 comments
Closed

Manual formatting/validating misses files #27

djcooke opened this issue Nov 6, 2019 · 5 comments

Comments

@djcooke
Copy link

djcooke commented Nov 6, 2019

Hello,

My build was failing due to incorrectly formatted code in files under .../src/it/java/. When I manually ran the formatter (mvn git-code-format:format-code -DglobPattern=**/*), it did not format these files. When I manually ran the validator (mvn git-code-format:validate-code-format -DglobPattern=**/*), it did not check these files, and completed successfully.

I was able to get around the issue by changing each of the affected files and then committing them. The formatter run by pre-commit hook did format the affected files.

My plugin config from pom.xml:

            <plugin>
              <groupId>com.cosium.code</groupId>
              <artifactId>maven-git-code-format</artifactId>
              <version>1.32</version>
              <executions>
                <execution>
                  <id>install-formatter-hook</id>
                  <goals>
                    <goal>install-hooks</goal>
                  </goals>
                </execution>
                <execution>
                  <id>validate-code-format</id>
                  <goals>
                    <goal>validate-code-format</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
@reda-alaoui
Copy link
Member

reda-alaoui commented Nov 7, 2019

Manual formatter and validator browse directories provided by MavenProject#getCompileSourceRoots and MavenProject#getTestCompileSourceRoots.
MavenProject class is part of maven core.

You have to make Maven consider your .../src/it/java/ as a test source root.

Found on https://www.testwithspring.com/lesson/running-integration-tests-with-maven/ :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
        <execution>
            <id>add-integration-test-sources</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/integration-test/java</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

@djcooke
Copy link
Author

djcooke commented Nov 7, 2019

Hi, thanks for the response.

I did have build-helper-maven-plugin configured that way, though I was using an older version of it (1.9.1). I tried updating to 1.12, and also to the newest version (3.0.0), but got the same results with all versions.

When I run mvn clean install, build fails with this error:

[ERROR] Failed to execute goal com.cosium.code:maven-git-code-format:1.32:validate-code-format (validate-code-format) on project pinery-client: .../pinery/pinery-client/src/it/java/ca/on/oicr/pinery/client/AttributeNameClientIT.java is not correctly formatted ! -> [Help 1]

When I run mvn git-code-format:validate-code-format -DglobPattern=**/*, it is successful, and none of the files in src/it/java/ are checked.

Project: https://github.com/oicr-gsi/pinery

@reda-alaoui reda-alaoui reopened this Nov 7, 2019
@reda-alaoui
Copy link
Member

reda-alaoui commented Nov 7, 2019 via email

@reda-alaoui
Copy link
Member

reda-alaoui commented Nov 8, 2019

I just performed tests on your project.
If you bind build-helper-maven-plugin to initialize phase, running:

$ mvn initialize git-code-format:validate-code-format -DglobPattern=**/*` 

includes it test classes.
Notice the additional initialize in the executed command.

If you are looking for a more elegant solution, I suggest you bring the subject to the Maven team.

@djcooke
Copy link
Author

djcooke commented Nov 8, 2019

Thanks for the info. I just tried leaving the build-helper-maven-plugin in the generate-test-sources phase and running with the below commands, which each worked and included the integration test sources as well.

mvn test git-code-format:validate-code-format -DglobPattern=**/*

or

mvn generate-test-sources git-code-format:validate-code-format -DglobPattern=**/*

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