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 /** 29 * A resolution error policy that allows to control caching for artifacts and metadata at a global level. 30 */ 31 public final class SimpleResolutionErrorPolicy 32 implements ResolutionErrorPolicy 33 { 34 35 private final int artifactPolicy; 36 37 private final int metadataPolicy; 38 39 /** 40 * Creates a new error policy with the specified behavior for both artifacts and metadata. 41 * 42 * @param cacheNotFound {@code true} to enable caching of missing items, {@code false} to disable it. 43 * @param cacheTransferErrors {@code true} to enable chaching of transfer errors, {@code false} to disable it. 44 */ 45 public SimpleResolutionErrorPolicy( boolean cacheNotFound, boolean cacheTransferErrors ) 46 { 47 this( ( cacheNotFound ? CACHE_NOT_FOUND : 0 ) | ( cacheTransferErrors ? CACHE_TRANSFER_ERROR : 0 ) ); 48 } 49 50 /** 51 * Creates a new error policy with the specified bit mask for both artifacts and metadata. 52 * 53 * @param policy The bit mask describing the policy for artifacts and metadata. 54 */ 55 public SimpleResolutionErrorPolicy( int policy ) 56 { 57 this( policy, policy ); 58 } 59 60 /** 61 * Creates a new error policy with the specified bit masks for artifacts and metadata. 62 * 63 * @param artifactPolicy The bit mask describing the policy for artifacts. 64 * @param metadataPolicy The bit mask describing the policy for metadata. 65 */ 66 public SimpleResolutionErrorPolicy( int artifactPolicy, int metadataPolicy ) 67 { 68 this.artifactPolicy = artifactPolicy; 69 this.metadataPolicy = metadataPolicy; 70 } 71 72 public int getArtifactPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Artifact> request ) 73 { 74 return artifactPolicy; 75 } 76 77 public int getMetadataPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Metadata> request ) 78 { 79 return metadataPolicy; 80 } 81 82 }