Provide default groupId for AOT processing
Framework requires the `groupId` passed to the AOT processing to be non-empty, so a default should be used if the build system does not provide a value. See gh-32696
This commit is contained in:
parent
9d07a09ed4
commit
76c7263eff
|
|
@ -27,6 +27,7 @@ import org.springframework.context.aot.ContextAotProcessor;
|
|||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.function.ThrowingSupplier;
|
||||
|
||||
/**
|
||||
|
|
@ -68,7 +69,8 @@ public class SpringApplicationAotProcessor extends ContextAotProcessor {
|
|||
+ " <applicationName> <sourceOutput> <resourceOutput> <classOutput> <groupId> <artifactId> <originalArgs...>");
|
||||
Class<?> application = Class.forName(args[0]);
|
||||
Settings settings = Settings.builder().sourceOutput(Paths.get(args[1])).resourceOutput(Paths.get(args[2]))
|
||||
.classOutput(Paths.get(args[3])).groupId(args[4]).artifactId(args[5]).build();
|
||||
.classOutput(Paths.get(args[3])).groupId((StringUtils.hasText(args[4])) ? args[4] : "unspecified")
|
||||
.artifactId(args[5]).build();
|
||||
String[] applicationArgs = (args.length > requiredArgs) ? Arrays.copyOfRange(args, requiredArgs, args.length)
|
||||
: new String[0];
|
||||
new SpringApplicationAotProcessor(application, settings, applicationArgs).process();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class SpringApplicationAotProcessorTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void invokeMainParseArgumentsAndInvokesRunMethod(@TempDir Path directory) throws Exception {
|
||||
void invokeMainParsesArgumentsAndInvokesRunMethod(@TempDir Path directory) throws Exception {
|
||||
String[] mainArguments = new String[] { SampleApplication.class.getName(),
|
||||
directory.resolve("source").toString(), directory.resolve("resource").toString(),
|
||||
directory.resolve("class").toString(), "com.example", "example", "1", "2" };
|
||||
|
|
@ -72,6 +72,16 @@ class SpringApplicationAotProcessorTests {
|
|||
assertThat(SampleApplication.postRunInvoked).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeMainParsesArgumentsAndInvokesRunMethodWithoutGroupId(@TempDir Path directory) throws Exception {
|
||||
String[] mainArguments = new String[] { SampleApplication.class.getName(),
|
||||
directory.resolve("source").toString(), directory.resolve("resource").toString(),
|
||||
directory.resolve("class").toString(), "", "example", "1", "2" };
|
||||
SpringApplicationAotProcessor.main(mainArguments);
|
||||
assertThat(SampleApplication.argsHolder).containsExactly("1", "2");
|
||||
assertThat(SampleApplication.postRunInvoked).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeMainWithMissingArguments() {
|
||||
assertThatIllegalArgumentException()
|
||||
|
|
|
|||
Loading…
Reference in New Issue