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

Support commas embedded in command line arguments from Maven plugin #18711

Closed
wants to merge 2 commits into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Oct 23, 2019

see gh-18688

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2019
@nosan nosan changed the title Add support commas embedded in command line arguments from Maven plugin Support commas embedded in command line arguments from Maven plugin Oct 23, 2019
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 23, 2019
@philwebb philwebb added this to the 2.2.x milestone Oct 23, 2019
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @nosan. I am not sure we want to tokenize on ,--. I'd like to make sure we are consistent with other core maven plugins before making this change and I haven't researched yet if there is one.

}
List<String> result = new ArrayList<>();
for (String line : new RunArguments(String.join(",", args)).getArgs()) {
String[] tokens = line.split(",--");
Copy link
Member

Choose a reason for hiding this comment

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

I think that's a bit fragile. I think the plan is more to stop binding the property as a String[] but rather introduce another one that we would map to the command-line property. Existing plugins use a space-delimited feature and I haven't checked how they skip spaces within valuesL

@@ -0,0 +1 @@
invoker.mavenOpts=-Dspring-boot.run.arguments='--management.endpoints.web.exposure.include=prometheus,info,health,metrics,--spring.profiles.active=foo,bar'
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more natural if the arguments were separated by a space rather than a comma.

@nosan
Copy link
Contributor Author

nosan commented Oct 25, 2019

Thanks, @snicoll

We can't change the type String[] to String at least in the current version:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.BUILD-SNAPSHOT:run (default) on project run-arguments: Unable to parse configuration of mojo org.springframework.boot:spring-boot-maven-plugin:2.2.1.BUILD-SNAPSHOT:run: Basic element 'arguments' must not contain child elements -> [Help 1]

Steps to reproduce:

<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<version>${version}</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<arguments>
					<argument>--management.endpoints.web.exposure.include=prometheus,info</argument>
					<argument>--spring.profiles.active=foo,bar</argument>
				</arguments>
			</configuration>
		</execution>
	</executions>
</plugin>

UPD:

$ mvn spring-boot:run -Dspring-boot.run.arguments='--management.endpoints.web.exposure.include=prometheus,info,health,metrics --spring.profiles.active=foo,bar'

Works fine if we change the type for arguments field from array to String or just introduce a separate field to map system property.

	/**
	 * Arguments from command line that should be passed to the application.
	 * @since 2.2.1
	 */
	@Parameter(property = "spring-boot.run.arguments", readonly = true)
	private String args;

@snicoll
Copy link
Member

snicoll commented Oct 25, 2019

We can't change the type String[] to String at least in the current version:

Thanks for the feedback but that's not what I was suggesting

I think the plan is more to stop binding the property as a String[] but rather introduce another one that we would map to the command-line property.

In other words, keep the property that we have but remove the binding to command line and introduce a new property of type String that we would bound. Anyway, I haven't looked in details so just sharing what I would do without looking in more details.

@nosan
Copy link
Contributor Author

nosan commented Oct 25, 2019

I've pushed an additional commit with @snicoll suggestions.

}
String endpoints = args[0].split("=")[1];
String profile = args[1].split("=")[1];
System.out.println("I haz been run with profile(s) '" + profile + "' and endpoint(s) '" + endpoints + "'");

Choose a reason for hiding this comment

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

one typo, haz -> has

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it was done on purpose.

@@ -0,0 +1,2 @@
def file = new File(basedir, "build.log")
return file.text.contains("I haz been run with profile(s) 'foo,bar' and endpoint(s) 'prometheus,info'")

Choose a reason for hiding this comment

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

typo, haz -> has

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it was done on purpose.

@snicoll snicoll self-assigned this Dec 26, 2019
@snicoll snicoll modified the milestones: 2.2.x, 2.2.3 Dec 26, 2019
snicoll added a commit that referenced this pull request Dec 26, 2019
@snicoll snicoll closed this in 83e594a Dec 26, 2019
@snicoll
Copy link
Member

snicoll commented Dec 26, 2019

Well done once again @nosan!

@nosan nosan deleted the gh-18688 branch December 26, 2019 10:26
@nosan
Copy link
Contributor Author

nosan commented Dec 26, 2019

Thank you @snicoll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants