1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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 package org.apache.maven.internal.aether;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import org.eclipse.aether.RepositorySystemSession;
25 import org.eclipse.aether.spi.validator.Validator;
26 import org.eclipse.aether.spi.validator.ValidatorFactory;
27 import org.eclipse.aether.util.ConfigUtils;
28
29 @Named
30 @Singleton
31 public class MavenValidatorFactory implements ValidatorFactory {
32 /**
33 * Resolver validation control.
34 * Can be <code>default</code> (full validation), <code>mild</code> (only uninterpolated placeholders) or
35 * <code>off</code> (no validation, as in Maven 3.9.x).
36 * This configuration provides "escape hatch" for those projects, that are forced to use non-conformant solutions.
37 * Default value is {@code default}.
38 *
39 * @since 3.10.0
40 */
41 public static final String MAVEN_RESOLVER_VALIDATION = "maven.resolver.validation";
42
43 public enum ValidationLevel {
44 DEFAULT,
45 MILD,
46 OFF;
47 }
48
49 private final MavenValidator defaultValidator = new MavenValidator(true);
50 private final MavenValidator mildValidator = new MavenValidator(false);
51
52 @Override
53 public Validator newInstance(RepositorySystemSession session) {
54 switch (ConfigUtils.getEnum(
55 session, ValidationLevel.class, ValidationLevel.DEFAULT, MAVEN_RESOLVER_VALIDATION)) {
56 case DEFAULT:
57 return defaultValidator;
58 case MILD:
59 return mildValidator;
60 case OFF:
61 return NOOP;
62 default:
63 throw new IllegalArgumentException("Unknown validation level");
64 }
65 }
66 }