You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryValidator.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package org.apache.archiva.repository.validation;
  2. /*
  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
  10. *
  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
  17. * under the License.
  18. */
  19. import org.apache.archiva.repository.Repository;
  20. import org.apache.archiva.repository.RepositoryRegistry;
  21. import org.apache.archiva.repository.RepositoryType;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.function.Function;
  25. /**
  26. * A repository validator validates given repository data against certain rules.
  27. *
  28. * @author Martin Stockhammer <martin_s@apache.org>
  29. */
  30. public interface RepositoryValidator<R extends Repository> extends RepositoryChecker<R, Map<String, List<ValidationError>>>, Comparable<RepositoryValidator<R>>
  31. {
  32. String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
  33. String REPOSITORY_NAME_VALID_EXPRESSION = "^([a-zA-Z0-9.)/_(-]|\\s)+$";
  34. String REPOSITORY_LOCATION_VALID_EXPRESSION = "^[-a-zA-Z0-9._/~:?!&amp;=\\\\]+$";
  35. int DEFAULT_PRIORITY=1000;
  36. /**
  37. * Returns the repository type for which this validator can be used. If the validator is applicable
  38. * to all types, it should return {@link RepositoryType#ALL}
  39. *
  40. * @return the repository type for which this validator is applicable
  41. */
  42. default RepositoryType getType() {
  43. return RepositoryType.ALL;
  44. }
  45. /**
  46. * Returns the priority of this validator. Smaller values mean higher priority.
  47. * All common validators have priority {@link #DEFAULT_PRIORITY}
  48. *
  49. * Validators are called in numerical order of their priority.
  50. *
  51. * @return
  52. */
  53. default int getPriority() {
  54. return DEFAULT_PRIORITY;
  55. }
  56. /**
  57. * Orders by priority
  58. *
  59. * @see Comparable#compareTo(Object)
  60. */
  61. @Override
  62. default int compareTo( RepositoryValidator o ) {
  63. if (o==null) {
  64. return 1;
  65. } else
  66. {
  67. return this.getPriority( ) - o.getPriority( );
  68. }
  69. }
  70. /**
  71. * Sets the repository registry to the given instance.
  72. * @param repositoryRegistry the repository registry
  73. */
  74. void setRepositoryRegistry( RepositoryRegistry repositoryRegistry );
  75. Class<R> getFlavour();
  76. default boolean isFlavour(Class<?> clazz) {
  77. return getFlavour( ).isAssignableFrom( clazz );
  78. }
  79. @SuppressWarnings( "unchecked" )
  80. default <RR extends Repository> RepositoryValidator<RR> narrowTo( Class<RR> clazz ) {
  81. if (isFlavour( clazz )) {
  82. return (RepositoryValidator<RR>) this;
  83. } else {
  84. throw new IllegalArgumentException( "Could not narrow to " + clazz );
  85. }
  86. }
  87. }