001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.util.graph.version; 020 021import java.util.function.Predicate; 022 023import org.eclipse.aether.util.version.GenericQualifiers; 024 025/** 026 * A version filter that (unconditionally) blocks based on qualifiers, as defined by {@link GenericQualifiers}. 027 * Note: while SNAPSHOT string is also a qualifier, this filter does not deal with them, see {@link SnapshotVersionFilter}, 028 * {@link ContextualSnapshotVersionFilter} and {@link ContextualAncestorSnapshotVersionFilter}. 029 * 030 * @since 2.0.17 031 * @see GenericQualifiers 032 * @see SnapshotVersionFilter 033 * @see ContextualSnapshotVersionFilter 034 * @see ContextualAncestorSnapshotVersionFilter 035 */ 036public class GenericQualifiersVersionFilter extends VersionPredicateVersionFilter { 037 /** 038 * Filters any version that contains "preview" qualifiers (alpha, beta, milestone). 039 */ 040 public static GenericQualifiersVersionFilter previewVersionFilter() { 041 return new GenericQualifiersVersionFilter(i -> i > GenericQualifiers.QUALIFIER_MILESTONE); 042 } 043 044 /** 045 * Filters any version that contains "pre-release" qualifiers (alpha, beta, milestone, rc/cr). 046 */ 047 public static GenericQualifiersVersionFilter preReleaseVersionFilter() { 048 return new GenericQualifiersVersionFilter(i -> i > GenericQualifiers.QUALIFIER_RC); 049 } 050 051 /** 052 * Filters any version that contains any qualifiers. 053 */ 054 public static GenericQualifiersVersionFilter anyQualifierVersionFilter() { 055 return new GenericQualifiersVersionFilter(i -> false); 056 } 057 058 /** 059 * Constructor that is able to select which qualifier to accept. Passed in predicate is invoked for version with 060 * detected qualifiers only, while versions without qualifiers are accepted. 061 * 062 * @see GenericQualifiers 063 */ 064 public GenericQualifiersVersionFilter(Predicate<Integer> qualifierPredicate) { 065 super(v -> GenericQualifiers.qualifier(v.toString()) 066 .map(qualifierPredicate::test) 067 .orElse(true)); 068 } 069}