Home / Class/ CommandLineBuilder Class — spring-boot Architecture

CommandLineBuilder Class — spring-boot Architecture

Architecture documentation for the CommandLineBuilder class in CommandLineBuilder.java from the spring-boot codebase.

Entity Profile

Source Code

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CommandLineBuilder.java lines 36–100

final class CommandLineBuilder {

	private final List<String> options = new ArrayList<>();

	private final List<URL> classpathElements = new ArrayList<>();

	private final String mainClass;

	private final List<String> arguments = new ArrayList<>();

	private CommandLineBuilder(String mainClass) {
		this.mainClass = mainClass;
	}

	static CommandLineBuilder forMainClass(String mainClass) {
		return new CommandLineBuilder(mainClass);
	}

	// Do not use String @Nullable ... jvmArguments, Maven can't deal with that
	CommandLineBuilder withJvmArguments(@Nullable String... jvmArguments) {
		if (jvmArguments != null) {
			this.options.addAll(Arrays.stream(jvmArguments).filter(Objects::nonNull).toList());
		}
		return this;
	}

	CommandLineBuilder withSystemProperties(@Nullable Map<String, String> systemProperties) {
		if (systemProperties != null) {
			for (Entry<String, String> systemProperty : systemProperties.entrySet()) {
				String option = SystemPropertyFormatter.format(systemProperty.getKey(), systemProperty.getValue());
				if (StringUtils.hasText(option)) {
					this.options.add(option);
				}
			}
		}
		return this;
	}

	CommandLineBuilder withClasspath(URL... elements) {
		this.classpathElements.addAll(Arrays.asList(elements));
		return this;
	}

	// Do not use String @Nullable ... arguments, Maven can't deal with that
	CommandLineBuilder withArguments(@Nullable String... arguments) {
		if (arguments != null) {
			this.arguments.addAll(Arrays.stream(arguments).filter(Objects::nonNull).toList());
		}
		return this;
	}

	List<String> build() {
		List<String> commandLine = new ArrayList<>();
		if (!this.options.isEmpty()) {
			commandLine.addAll(this.options);
		}
		commandLine.addAll(ClassPath.of(this.classpathElements).args(true));
		commandLine.add(this.mainClass);
		if (!this.arguments.isEmpty()) {
			commandLine.addAll(this.arguments);
		}
		return commandLine;
	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free