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

* Allow gnuConfigureArgs to accept configure arguments with spaces. #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/it/it0013-gnu-executable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<run>true</run>
</library>
</libraries>
<gnuConfigureArgs>
"--with-pkginfo=GNU Executable Integration Test"
</gnuConfigureArgs>
</configuration>
</plugin>
</plugins>
Expand Down
9 changes: 9 additions & 0 deletions src/it/it0013-gnu-executable/src/gnu/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@ AM_INIT_AUTOMAKE

AC_PROG_CC

AC_ARG_WITH(pkginfo,
AC_HELP_STRING([--with-pkginfo=PKG],
[Package information string]),
[case "$withval" in
(yes) AC_MSG_ERROR([package information not specified]) ;;
(*) PKG_INFO="$withval" ;;
esac])
AC_SUBST(PKG_INFO)

AC_OUTPUT(Makefile src/Makefile)

12 changes: 11 additions & 1 deletion src/main/java/com/github/maven_nar/NarGnuConfigureMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.regex.*;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -154,7 +157,14 @@ public final void narExecute() throws MojoExecutionException, MojoFailureExcepti

// create the array to hold constant and additional args
if (this.gnuConfigureArgs != null) {
final String[] a = this.gnuConfigureArgs.split(" ");
List<String> list = new ArrayList<String>();
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(this.gnuConfigureArgs);
// strip double quotes
while (m.find()) {
list.add(m.group(1).replace("\"", ""));
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit imprecise removing any "
Maybe you wouldn't use a " in gnuconfigure arg, or escape one in an arg?

Copy link
Author

@sraza1 sraza1 Nov 6, 2017

Choose a reason for hiding this comment

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

So, keeping in view #291 would searching for the starting " and ending " and stripping them only (if found) be the better way of doing this ?

Copy link
Member

@GregDomjan GregDomjan Mar 20, 2019

Choose a reason for hiding this comment

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

Sorry, totally forgot to come back to this.
Maybe I misread the regex, or it changed?

Could the args include an escaped \" quote? does it even need to be handled, I don't know.

taking the unit test and expanding with some other junk

<gnuConfigureArgs>
		"--with-pkginfo=GNU Executable Integration Test"  arg2 "arg 3"
"arg\" 4"
	</gnuConfigureArgs>

Expected 4 args

  • --with-pkginfo=GNU Executable Integration Test
  • arg2
  • arg 3
  • arg\" 4

Regex provided will come back with 6 matches
1 that's empty spaces/newlines
2-4 that need the leading/trailing " removed
5/6 should actually just be 5 and needing " removed.

I don't do much regex in Java, but I believe from doc this should work, and the capture group should already exclude the "
\s*\"(.*?)(?<!\\)\"\s* or as Java string "\\s*\\"(.*?)(?<!\\\\)\\"\\s*
Checked using https://regex101.com/

}
String[] a = new String[list.size()];
a = list.toArray(a);
args = new String[a.length + 2];

System.arraycopy(a, 0, args, 2, a.length);
Expand Down