1 package org.apache.archiva.repository.validation;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.repository.Repository;
21 import org.apache.archiva.repository.RepositoryRegistry;
22 import org.apache.archiva.repository.RepositoryType;
24 import java.util.List;
26 import java.util.function.Function;
29 * A repository validator validates given repository data against certain rules.
31 * @author Martin Stockhammer <martin_s@apache.org>
33 public interface RepositoryValidator<R extends Repository> extends RepositoryChecker<R, Map<String, List<ValidationError>>>, Comparable<RepositoryValidator<R>>
36 String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
37 String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
38 String REPOSITORY_LOCATION_VALID_EXPRESSION = "^[-a-zA-Z0-9._/~:?!&=\\\\]+$";
41 int DEFAULT_PRIORITY=1000;
44 * Returns the repository type for which this validator can be used. If the validator is applicable
45 * to all types, it should return {@link RepositoryType#ALL}
47 * @return the repository type for which this validator is applicable
49 default RepositoryType getType() {
50 return RepositoryType.ALL;
54 * Returns the priority of this validator. Smaller values mean higher priority.
55 * All common validators have priority {@link #DEFAULT_PRIORITY}
57 * Validators are called in numerical order of their priority.
61 default int getPriority() {
62 return DEFAULT_PRIORITY;
69 * @see Comparable#compareTo(Object)
72 default int compareTo( RepositoryValidator o ) {
77 return this.getPriority( ) - o.getPriority( );
82 * Sets the repository registry to the given instance.
83 * @param repositoryRegistry the repository registry
85 void setRepositoryRegistry( RepositoryRegistry repositoryRegistry );
87 Class<R> getFlavour();
89 default boolean isFlavour(Class<?> clazz) {
90 return getFlavour( ).isAssignableFrom( clazz );
93 @SuppressWarnings( "unchecked" )
94 default <RR extends Repository> RepositoryValidator<RR> narrowTo( Class<RR> clazz ) {
95 if (isFlavour( clazz )) {
96 return (RepositoryValidator<RR>) this;
98 throw new IllegalArgumentException( "Could not narrow to " + clazz );