CommandLineBuilderTests Class — spring-boot Architecture
Architecture documentation for the CommandLineBuilderTests class in CommandLineBuilderTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/CommandLineBuilderTests.java lines 47–150
class CommandLineBuilderTests {
public static final String CLASS_NAME = ClassWithMainMethod.class.getName();
@Test
@SuppressWarnings("NullAway") // Maven can't deal with @Nullable arrays / varargs
void buildWithNullJvmArgumentsIsIgnored() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withJvmArguments((String[]) null).build())
.containsExactly(CLASS_NAME);
}
@Test
void buildWithNullIntermediateJvmArgumentIsIgnored() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME)
.withJvmArguments("-verbose:class", null, "-verbose:gc")
.build()).containsExactly("-verbose:class", "-verbose:gc", CLASS_NAME);
}
@Test
void buildWithJvmArgument() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withJvmArguments("-verbose:class").build())
.containsExactly("-verbose:class", CLASS_NAME);
}
@Test
void buildWithNullSystemPropertyIsIgnored() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withSystemProperties(null).build())
.containsExactly(CLASS_NAME);
}
@Test
void buildWithSystemProperty() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withSystemProperties(Map.of("flag", "enabled")).build())
.containsExactly("-Dflag=enabled", CLASS_NAME);
}
@Test
@SuppressWarnings("NullAway") // Maven can't deal with @Nullable arrays / varargs
void buildWithNullArgumentsIsIgnored() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withArguments((String[]) null).build())
.containsExactly(CLASS_NAME);
}
@Test
void buildWithNullIntermediateArgumentIsIgnored() {
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME).withArguments("--test", null, "--another").build())
.containsExactly(CLASS_NAME, "--test", "--another");
}
@Test
@DisabledOnOs(OS.WINDOWS)
void buildWithClassPath(@TempDir Path tempDir) throws Exception {
Path file = tempDir.resolve("test.jar");
Path file1 = tempDir.resolve("test1.jar");
assertThat(CommandLineBuilder.forMainClass(CLASS_NAME)
.withClasspath(file.toUri().toURL(), file1.toUri().toURL())
.build()).containsExactly("-cp", file + File.pathSeparator + file1, CLASS_NAME);
}
@Test
@EnabledOnOs(OS.WINDOWS)
void buildWithClassPathOnWindows(@TempDir Path tempDir) throws Exception {
Path file = tempDir.resolve("test.jar");
Path file1 = tempDir.resolve("test1.jar");
List<String> args = CommandLineBuilder.forMainClass(CLASS_NAME)
.withClasspath(file.toUri().toURL(), file1.toUri().toURL())
.build();
assertThat(args).hasSize(3);
assertThat(args.get(0)).isEqualTo("-cp");
assertThat(args.get(1)).startsWith("@");
assertThat(args.get(2)).isEqualTo(CLASS_NAME);
assertThat(Paths.get(args.get(1).substring(1)))
.hasContent("\"" + (file + File.pathSeparator + file1).replace("\\", "\\\\") + "\"");
}
@Test
void buildAndRunWithLongClassPath() throws IOException, InterruptedException {
StringBuilder classPath = new StringBuilder(ManagementFactory.getRuntimeMXBean().getClassPath());
// Simulates [CreateProcess error=206, The filename or extension is too long]
while (classPath.length() < 35000) {
classPath.append(File.pathSeparator).append(classPath);
}
URL[] urls = Arrays.stream(classPath.toString().split(File.pathSeparator)).map(this::toURL).toArray(URL[]::new);
List<String> command = CommandLineBuilder.forMainClass(ClassWithMainMethod.class.getName())
.withClasspath(urls)
.build();
ProcessBuilder pb = new JavaExecutable().processBuilder(command.toArray(new String[0]));
Process process = pb.start();
assertThat(process.waitFor()).isEqualTo(0);
try (InputStream inputStream = process.getInputStream()) {
assertThat(inputStream).hasContent("Hello World");
}
}
private URL toURL(String path) {
try {
return Paths.get(path).toUri().toURL();
}
catch (MalformedURLException ex) {
throw new RuntimeException(ex);
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free