Home / Class/ BuildInfoProperties Class — spring-boot Architecture

BuildInfoProperties Class — spring-boot Architecture

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

Entity Profile

Source Code

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java lines 46–185

@SuppressWarnings("serial")
public abstract class BuildInfoProperties implements Serializable {

	private final SetProperty<String> excludes;

	private final Supplier<@Nullable String> creationTime = () -> DateTimeFormatter.ISO_INSTANT.format(Instant.now());

	@Inject
	public BuildInfoProperties(Project project, SetProperty<String> excludes) {
		this.excludes = excludes;
		getGroup().convention(project.provider(() -> project.getGroup().toString()));
		getVersion().convention(project.provider(() -> project.getVersion().toString()));
		getArtifact()
			.convention(project.provider(() -> project.findProperty("archivesBaseName")).map(Object::toString));
		getName().convention(project.provider(project::getName));
	}

	/**
	 * Returns the {@code build.group} property. Defaults to the {@link Project#getGroup()
	 * Project's group}.
	 * @return the group property
	 */
	@Internal
	public abstract Property<String> getGroup();

	/**
	 * Returns the {@code build.artifact} property.
	 * @return the artifact property
	 */
	@Internal
	public abstract Property<String> getArtifact();

	/**
	 * Returns the {@code build.version} property. Defaults to the
	 * {@link Project#getVersion() Project's version}.
	 * @return the version
	 */
	@Internal
	public abstract Property<String> getVersion();

	/**
	 * Returns the {@code build.name} property. Defaults to the {@link Project#getName()
	 * Project's name}.
	 * @return the name
	 */
	@Internal
	public abstract Property<String> getName();

	/**
	 * Returns the {@code build.time} property.
	 * @return the time
	 */
	@Internal
	public abstract Property<String> getTime();

	/**
	 * Returns the additional properties that will be included. When written, the name of
	 * each additional property is prefixed with {@code build.}.
	 * @return the additional properties
	 */
	@Internal
	public abstract MapProperty<String, Object> getAdditional();

	@Input
	@Optional
	@Nullable String getArtifactIfNotExcluded() {
		return getIfNotExcluded(getArtifact(), "artifact");
	}

	@Input
	@Optional
	@Nullable String getGroupIfNotExcluded() {
		return getIfNotExcluded(getGroup(), "group");
	}

	@Input
	@Optional
	@Nullable String getNameIfNotExcluded() {
		return getIfNotExcluded(getName(), "name");
	}

	@Input
	@Optional
	@Nullable Instant getTimeIfNotExcluded() {
		String time = getIfNotExcluded(getTime(), "time", this.creationTime);
		return (time != null) ? Instant.parse(time) : null;
	}

	@Input
	@Optional
	@Nullable String getVersionIfNotExcluded() {
		return getIfNotExcluded(getVersion(), "version");
	}

	@Input
	Map<String, String> getAdditionalIfNotExcluded() {
		return coerceToStringValues(applyExclusions(getAdditional().getOrElse(Collections.emptyMap())));
	}

	private <T> @Nullable T getIfNotExcluded(Property<T> property, String name) {
		Supplier<@Nullable T> supplier = () -> null;
		return getIfNotExcluded(property, name, supplier);
	}

	private <T> @Nullable T getIfNotExcluded(Property<T> property, String name, Supplier<@Nullable T> defaultValue) {
		if (this.excludes.getOrElse(Collections.emptySet()).contains(name)) {
			return null;
		}
		if (property.isPresent()) {
			return property.get();
		}
		return defaultValue.get();
	}

	private Map<String, String> coerceToStringValues(Map<String, Object> input) {
		Map<String, String> output = new HashMap<>();
		input.forEach((key, value) -> {
			if (value instanceof Provider<?> provider) {
				value = provider.getOrNull();
			}
			if (value != null) {
				output.put(key, value.toString());
			}
		});
		return output;
	}

	private Map<String, Object> applyExclusions(Map<String, Object> input) {
		Map<String, Object> output = new HashMap<>();
		Set<String> exclusions = this.excludes.getOrElse(Collections.emptySet());
		input.forEach((key, value) -> {
			boolean isExcluded = exclusions.contains(key);
			if (!isExcluded) {
				output.put(key, value);
			}
		});
		return output;
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free