Home / Class/ DependencyFilter Class — spring-boot Architecture

DependencyFilter Class — spring-boot Architecture

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

Entity Profile

Source Code

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/DependencyFilter.java lines 37–104

public abstract class DependencyFilter extends AbstractArtifactsFilter {

	private final List<? extends FilterableDependency> filters;

	/**
	 * Create a new instance with the list of {@link FilterableDependency} instance(s) to
	 * use.
	 * @param dependencies the source dependencies
	 */
	public DependencyFilter(List<? extends FilterableDependency> dependencies) {
		this.filters = dependencies;
	}

	@Override
	public Set<Artifact> filter(Set<Artifact> artifacts) throws ArtifactFilterException {
		Set<Artifact> result = new HashSet<>();
		for (Artifact artifact : artifacts) {
			if (!filter(artifact)) {
				result.add(artifact);
			}
		}
		return result;
	}

	protected abstract boolean filter(Artifact artifact);

	/**
	 * Check if the specified {@link org.apache.maven.artifact.Artifact} matches the
	 * specified {@link org.springframework.boot.maven.FilterableDependency}. Returns
	 * {@code true} if it should be excluded
	 * @param artifact the Maven {@link Artifact}
	 * @param dependency the {@link FilterableDependency}
	 * @return {@code true} if the artifact matches the dependency
	 */
	protected final boolean equals(Artifact artifact, FilterableDependency dependency) {
		if (!dependency.getGroupId().equals(artifact.getGroupId())) {
			return false;
		}
		if (!dependency.getArtifactId().equals(artifact.getArtifactId())) {
			return false;
		}
		return (dependency.getClassifier() == null
				|| artifact.getClassifier() != null && dependency.getClassifier().equals(artifact.getClassifier()));
	}

	protected final List<? extends FilterableDependency> getFilters() {
		return this.filters;
	}

	/**
	 * Return a new {@link DependencyFilter} the excludes artifacts based on the given
	 * predicate.
	 * @param filter the predicate used to filter the artifacts.
	 * @return a new {@link DependencyFilter} instance
	 * @since 3.5.7
	 */
	public static DependencyFilter exclude(Predicate<Artifact> filter) {
		return new DependencyFilter(Collections.emptyList()) {

			@Override
			protected boolean filter(Artifact artifact) {
				return filter.test(artifact);
			}

		};
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free