Home / Class/ JavaCompilerPluginConfiguration Class — spring-boot Architecture

JavaCompilerPluginConfiguration Class — spring-boot Architecture

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

Entity Profile

Source Code

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/JavaCompilerPluginConfiguration.java lines 33–111

class JavaCompilerPluginConfiguration {

	private final MavenProject project;

	JavaCompilerPluginConfiguration(MavenProject project) {
		this.project = project;
	}

	@Nullable String getSourceMajorVersion() {
		String version = getConfigurationValue("source");

		if (version == null) {
			version = getPropertyValue("maven.compiler.source");
		}

		return majorVersionFor(version);
	}

	@Nullable String getTargetMajorVersion() {
		String version = getConfigurationValue("target");

		if (version == null) {
			version = getPropertyValue("maven.compiler.target");
		}

		return majorVersionFor(version);
	}

	@Nullable String getReleaseVersion() {
		String version = getConfigurationValue("release");

		if (version == null) {
			version = getPropertyValue("maven.compiler.release");
		}

		return majorVersionFor(version);
	}

	private @Nullable String getConfigurationValue(String propertyName) {
		Plugin plugin = this.project.getPlugin("org.apache.maven.plugins:maven-compiler-plugin");
		if (plugin != null) {
			Object pluginConfiguration = plugin.getConfiguration();
			if (pluginConfiguration instanceof Xpp3Dom dom) {
				return getNodeValue(dom, propertyName);
			}
		}
		return null;
	}

	private @Nullable String getPropertyValue(String propertyName) {
		if (this.project.getProperties().containsKey(propertyName)) {
			return this.project.getProperties().get(propertyName).toString();
		}
		return null;
	}

	private @Nullable String getNodeValue(Xpp3Dom dom, String... childNames) {
		Xpp3Dom childNode = dom.getChild(childNames[0]);

		if (childNode == null) {
			return null;
		}

		if (childNames.length > 1) {
			return getNodeValue(childNode, Arrays.copyOfRange(childNames, 1, childNames.length));
		}

		return childNode.getValue();
	}

	@Contract("!null -> !null")
	private @Nullable String majorVersionFor(@Nullable String version) {
		if (version != null && version.startsWith("1.")) {
			return version.substring("1.".length());
		}
		return version;
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free