Skip to content

Empty argument tag should add empty string instead of null#150

Merged
olamy merged 2 commits into
mojohaus:masterfrom
Anders-E:master
Aug 19, 2020
Merged

Empty argument tag should add empty string instead of null#150
olamy merged 2 commits into
mojohaus:masterfrom
Anders-E:master

Conversation

@Anders-E

Copy link
Copy Markdown
Contributor

Created new PR since I could not update the old one (#133, issue #132 ) due to the fork being deleted.

An empty argument tag such as:

<argument></argument>

Now adds an empty string instead of null to String[] args.

@ctubbsii ctubbsii left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it works as expected. It preserves an empty argument.

My test case was (pom.xml):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>none</groupId>
  <artifactId>tester</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.0.0-SNAPSHOT</version>
        <executions>
          <execution>
            <id>testitnow</id>
            <phase>validate</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>./exec-test-script.sh</executable>
              <arguments>
                <argument>a</argument>
                <argument>b</argument>
                <argument />
                <argument>d</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The script, exec-test-script.sh contained:

#! /usr/bin/bash
echo Number of args is "${#@}"
for x in "$@"; do
  echo " ->$x<-"
done

I verified that the third argument was omitted before the PR, and that it was included as an empty argument after the PR.


However, there still doesn't appear to be any way to preserve whitespace, if you want an argument consisting of a space, as in:

  <configuration>
    <executable>tr</executable>
    <arguments>
      <argument> </argument>
      <argument>_</argument>
      <argument>&lt;filename</argument>
    </arguments>
  </configuration>

This might be an limit of Maven itself. It seems there may have been a regression of: https://issues.apache.org/jira/browse/MNG-5380

@Anders-E

Copy link
Copy Markdown
Contributor Author

Noticed this was still open while checking my PRs. Should this be merged? @ctubbsii

@ctubbsii

Copy link
Copy Markdown

Noticed this was still open while checking my PRs. Should this be merged? @ctubbsii

I think it should, but I don't have commit access to this project.

@Anders-E

Copy link
Copy Markdown
Contributor Author

@ctubbsii oh sorry, I just figured you did for some reason.

@olamy would this PR be of interest or should I close it?

@ctubbsii

Copy link
Copy Markdown

@ctubbsii oh sorry, I just figured you did for some reason.

No big deal. It's probably because GitHub says I "approved" it by giving a code review.

Pro tip: the gray checkmark next to an approval indicates the person submitted an approval as a non-committer performing a code review. A green checkmark would be displayed (like those at the bottom, by the status checks), if the reviewer had write access. It's a very subtle difference. Also the green checkmarks at the bottom can often be misinterpreted as a code review checkmark... I wish they used a different color for those.

@Anders-E

Copy link
Copy Markdown
Contributor Author

Pro tip: the gray checkmark next to an approval indicates the person submitted an approval as a non-committer performing a code review. A green checkmark would be displayed (like those at the bottom, by the status checks), if the reviewer had write access. It's a very subtle difference. Also the green checkmarks at the bottom can often be misinterpreted as a code review checkmark... I wish they used a different color for those.

Ah I've never noticed that before, thank you for the tip!

@olamy olamy added the bug label Aug 19, 2020
@olamy olamy merged commit d0e13ba into mojohaus:master Aug 19, 2020
@tisonkun

tisonkun commented Apr 30, 2025

Copy link
Copy Markdown

I wonder if Windows performs differently in this case. See apache/opendal#6059 (comment)

We have:

<properties>
  <cargo-build.target/>
</properties>
<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>${exec-maven-plugin.version}</version>
    <executions>
        <execution>
            <id>compile-native-code</id>
            <phase>compile</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>python3</executable>
                <arguments>
                    <argument>${project.basedir}/tools/build.py</argument>
                    <argument>--target</argument>
                    <argument>${cargo-build.target}</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

This works on my Linux and macOS platform, but seems when running with mvnw.cmd on Windows, it doesn't work:

[INFO] --- exec:3.1.0:exec (compile-native-code) @ opendal ---
usage: build.py [-h] --classifier CLASSIFIER [--target TARGET]
                [--profile PROFILE] [--features FEATURES]
                [--enable-zigbuild ENABLE_ZIGBUILD]
build.py: error: argument --target: expected one argument
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)

@slawekjaranowski

Copy link
Copy Markdown
Member

@tisonkun please create new issue, this one is closed 😄

@tisonkun

Copy link
Copy Markdown

@slawekjaranowski Yes and sorry I'm a bit lazy just now - here it is: #471

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants