1 package org.eclipse.aether.util.repository;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.eclipse.aether.RepositorySystemSession;
23 import org.eclipse.aether.artifact.Artifact;
24 import org.eclipse.aether.metadata.Metadata;
25 import org.eclipse.aether.resolution.ResolutionErrorPolicy;
26 import org.eclipse.aether.resolution.ResolutionErrorPolicyRequest;
27
28 import static java.util.Objects.requireNonNull;
29
30 /**
31 * A resolution error policy that allows to control caching for artifacts and metadata at a global level.
32 */
33 public final class SimpleResolutionErrorPolicy
34 implements ResolutionErrorPolicy
35 {
36
37 private final int artifactPolicy;
38
39 private final int metadataPolicy;
40
41 /**
42 * Creates a new error policy with the specified behavior for both artifacts and metadata.
43 *
44 * @param cacheNotFound {@code true} to enable caching of missing items, {@code false} to disable it.
45 * @param cacheTransferErrors {@code true} to enable chaching of transfer errors, {@code false} to disable it.
46 */
47 public SimpleResolutionErrorPolicy( boolean cacheNotFound, boolean cacheTransferErrors )
48 {
49 this( ( cacheNotFound ? CACHE_NOT_FOUND : 0 ) | ( cacheTransferErrors ? CACHE_TRANSFER_ERROR : 0 ) );
50 }
51
52 /**
53 * Creates a new error policy with the specified bit mask for both artifacts and metadata.
54 *
55 * @param policy The bit mask describing the policy for artifacts and metadata.
56 */
57 public SimpleResolutionErrorPolicy( int policy )
58 {
59 this( policy, policy );
60 }
61
62 /**
63 * Creates a new error policy with the specified bit masks for artifacts and metadata.
64 *
65 * @param artifactPolicy The bit mask describing the policy for artifacts.
66 * @param metadataPolicy The bit mask describing the policy for metadata.
67 */
68 public SimpleResolutionErrorPolicy( int artifactPolicy, int metadataPolicy )
69 {
70 this.artifactPolicy = artifactPolicy;
71 this.metadataPolicy = metadataPolicy;
72 }
73
74 public int getArtifactPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Artifact> request )
75 {
76 requireNonNull( session, "session cannot be null" );
77 requireNonNull( request, "request cannot be null" );
78 return artifactPolicy;
79 }
80
81 public int getMetadataPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Metadata> request )
82 {
83 requireNonNull( session, "session cannot be null" );
84 requireNonNull( request, "request cannot be null" );
85 return metadataPolicy;
86 }
87
88 }