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

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

Open
PontusPih opened this issue Sep 13, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@PontusPih
Copy link

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.

@PontusPih PontusPih added bug Something isn't working to-triage labels Sep 13, 2023
@TheSnoozer
Copy link
Contributor

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

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

@TheSnoozer TheSnoozer transferred this issue from git-commit-id/git-commit-id-maven-plugin Feb 9, 2024
@TheSnoozer
Copy link
Contributor

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:

  • Check the file-type something along the lines of:
+      if ("application/json".equals(Files.probeContentType(propertiesFile.toPath()))) {
+        throw new IllegalStateException("We should not try reading json or yml files here?");
+      }
  • Have some extra code that validates that the keys of the read properties object look sensible (we can't verify the values, otherwise it defeats the purpose of trying to extract anything from the stored file).

TheSnoozer added a commit that referenced this issue Mar 19, 2024
#99: try to improve error messages when the json properties can't be read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants