git-commit-id / git-commit-id-plugin-core

GNU Lesser General Public License v3.0
5 stars 7 forks source link

Generating file in "json" format fails when file in "properties" format already exists #99

Open PontusPih opened 1 year ago

PontusPih commented 1 year ago

Describe the bug (required)

It seems that the code that generates the json formatted file tries to open and parse the existing file. If the existing file is not valid json, it fails.

Tell us about your plugin configuration (required)

            <plugin>
                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>6.0.0</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                    <format>json</format>
                </configuration>
            </plugin>

Tell us about the Plugin version used (required)

6.0.0

Tell us about the Maven version used (required)

mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: /home/pontus/.m2/wrapper/dists/apache-maven-3.5.4-bin/4lcg54ki11c6mp435njk296gm5/apache-maven-3.5.4
Java version: 11.0.19, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.fc37.x86_64
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "6.3.12-100.fc37.x86_64", arch: "amd64", family: "unix"

Steps to Reproduce (required)

  1. Set properties
  2. run mvn io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision
  3. Set json
  4. run mvn io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision

Are there any stacktraces or any error messages? (required)

WARNING You may NOT want to paste all the output that is produced with verbose publicly, since it MAY contain information you deem sensitive. Review this CAREFULLY before posting your issue!

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.877 s
[INFO] Finished at: 2023-09-13T10:55:21+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision (default-cli) on project secret-project: Execution default-cli of goal io.github.git-commit-id:git-commit-id-maven-plugin:6.0.0:revision failed: Unexpected char 35 at (line no=1, column no=1, offset=0) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :secret-project

Is there a (public) project where this issue can be reproduced? (optional)

No response

Your Environment (optional)

No response

Context (optional)

There is an easy work arround: Just delete the generated properties file before generating it again in a different format.

TheSnoozer commented 1 year ago

Thanks for your report. Yeah the idea of "caching" (e.g. not re-run the plugin if the git has not changed) makes this bug a very tricky thing...will take a look.

PontusPih commented 1 year ago

Since the impact is quite mild, an improved error message might be an alternative to an solution.

TheSnoozer commented 8 months ago

I added some extra code to check for this case, but it turns out this is a bit trickier than expected.

If you for example first dump the properties as xml-file and then switch to properties the properties loading process will just happily load the XML as properties object.

Potential options: