Skip to content

Commit

Permalink
Provide default groupId for AOT processing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
scottfrederick committed Oct 18, 2022
1 parent 9d07a09 commit 76c7263
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -27,6 +27,7 @@
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;

/**
Expand Down Expand Up @@ -68,7 +69,8 @@ public static void main(String[] args) throws Exception {
+ " <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();
Expand Down
Expand Up @@ -63,7 +63,7 @@ void processApplicationWithMainMethodThatDoesNotRun(@TempDir Path directory) {
}

@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" };
Expand All @@ -72,6 +72,16 @@ void invokeMainParseArgumentsAndInvokesRunMethod(@TempDir Path directory) throws
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()
Expand Down

0 comments on commit 76c7263

Please sign in to comment.