001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.util.repository;
020
021import org.eclipse.aether.RepositorySystemSession;
022import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
023import org.eclipse.aether.resolution.ArtifactDescriptorPolicyRequest;
024
025import static java.util.Objects.requireNonNull;
026
027/**
028 * An artifact descriptor error policy that allows to control error handling at a global level.
029 */
030public final class SimpleArtifactDescriptorPolicy implements ArtifactDescriptorPolicy {
031
032    private final int policy;
033
034    /**
035     * Creates a new error policy with the specified behavior.
036     *
037     * @param ignoreMissing {@code true} to ignore missing descriptors, {@code false} to fail resolution.
038     * @param ignoreInvalid {@code true} to ignore invalid descriptors, {@code false} to fail resolution.
039     */
040    public SimpleArtifactDescriptorPolicy(boolean ignoreMissing, boolean ignoreInvalid) {
041        this((ignoreMissing ? IGNORE_MISSING : 0) | (ignoreInvalid ? IGNORE_INVALID : 0));
042    }
043
044    /**
045     * Creates a new error policy with the specified bit mask.
046     *
047     * @param policy The bit mask describing the policy.
048     */
049    public SimpleArtifactDescriptorPolicy(int policy) {
050        this.policy = policy;
051    }
052
053    public int getPolicy(RepositorySystemSession session, ArtifactDescriptorPolicyRequest request) {
054        requireNonNull(session, "session cannot be null");
055        requireNonNull(request, "request cannot be null");
056        return policy;
057    }
058}