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

git.commit.message has linefeeds causng invalid Manifest #554

Closed
peterkronenberg opened this issue May 18, 2021 · 4 comments
Closed

git.commit.message has linefeeds causng invalid Manifest #554

peterkronenberg opened this issue May 18, 2021 · 4 comments
Milestone

Comments

@peterkronenberg
Copy link

Hi,
I'm using the maven-jar-plugin to put some of the git entries in the Manifest. I have the following in my pom file

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <!-- Put some Git info in the Manifest -->
                <configuration>
                    <archive>
                        <manifestEntries>
                            <!--suppress UnresolvedMavenProperty -->
                            <last-commit-id>${git.commit.id.describe}</last-commit-id>
                            <!--suppress UnresolvedMavenProperty -->
                            <last-commit-user>${git.commit.user.name}</last-commit-user>
                            <!--suppress UnresolvedMavenProperty -->
                            <last-commit-msg>${git.commit.message.full}</last-commit-msg>
                            <!--suppress UnresolvedMavenProperty -->
                            <git-branch>${git.branch}</git-branch>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

I end up with the Manifest looking something like this:

Manifest-Version: 1.0
git-branch: main
Implementation-Title: nexus-service-common
last-commit-id: 081c8e4-DEV
Implementation-Version: 1.5.3-SNAPSHOT
last-commit-msg: Merged PR 2359: Update readme

Update readme
Build-Jdk-Spec: 1.8
Created-By: Maven Jar Plugin 3.2.0
last-commit-user: Peter Kronenberg

The commit message sometimes has a linefieed and is multiple lines. I think this is causing the problem I'm seeing which is when I try to use the jar, it complains about an invalid Manifest

Is there a way to encode the lines feeds so I don't get this problem?

@TheSnoozer
Copy link
Collaborator

Hi, thanks for creating an issue for this!
This is indeed an interesting problem and that sounds like another good use-case for the replacementProperties (refs #317).

In specific you'd need to add the following to the configuration of the git-commit-id-plugin:

                            <replacementProperties>
                                <replacementProperty>
                                    <!-- input -->
                                    <property>git.commit.message.full</property>
                                    <propertyOutputSuffix>without-line-feed</propertyOutputSuffix>
                                    <token>[\r|\n|\r\n]+</token>
                                    <value>--</value>
                                    <regex>true</regex>
                                </replacementProperty>
                            </replacementProperties>

With a quick and dirty ant-run test like this:

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <target>
                                        <echo>===========================================================================</echo>
                                        <echo>git.commit.message.full: ${git.commit.message.full}</echo>
                                        <echo>git.commit.message.full.without-line-feed: ${git.commit.message.full.without-line-feed}</echo>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

This yields:

[INFO] --- maven-antrun-plugin:1.8:run (default) @ submodule-two ---
[INFO] Executing tasks

main:
     [echo] ===========================================================================
     [echo] git.commit.message.full: this
     [echo] is
     [echo] some
     [echo] text
     [echo] with
     [echo] line
     [echo] feeds
     [echo] for
     [echo] testing
     [echo] git.commit.message.full.without-line-feed: this--is--some--text--with--line--feeds--for--testing

Note that the <value>--</value> for the replacementProperty is optional. if you leave if empty you'd get a text like:

[INFO] --- maven-antrun-plugin:1.8:run (default) @ submodule-two ---
[INFO] Executing tasks

main:
     [echo] ===========================================================================
     [echo] git.commit.message.full: this
     [echo] is
     [echo] some
     [echo] text
     [echo] with
     [echo] line
     [echo] feeds
     [echo] for
     [echo] testing
     [echo] git.commit.message.full.without-line-feed: thisissometextwithlinefeedsfortesting

Hope that helps.

@peterkronenberg
Copy link
Author

Excellent! That's exactly what I was looking for, a way to replace the linefeeds. I'll give it a shot. Thank you

@TheSnoozer
Copy link
Collaborator

Cool! let me go ahead and close this issue. If you still struggle to get it to work, please feel free to reopen!

@TheSnoozer TheSnoozer added this to the 4.0.5 milestone May 21, 2021
@peterkronenberg
Copy link
Author

Yes, using replacement properties worked perfectly. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants