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.internal.impl;
020
021import java.util.Set;
022
023import org.eclipse.aether.artifact.Artifact;
024import org.eclipse.aether.spi.artifact.ArtifactPredicate;
025import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector;
026
027import static java.util.Objects.requireNonNull;
028
029public final class DefaultArtifactPredicate implements ArtifactPredicate {
030    private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector;
031    private final Set<String> extensionsWithoutChecksums;
032
033    public DefaultArtifactPredicate(
034            ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, Set<String> extensionsWithoutChecksums) {
035        this.checksumAlgorithmFactorySelector = checksumAlgorithmFactorySelector;
036        this.extensionsWithoutChecksums = extensionsWithoutChecksums;
037    }
038
039    @Override
040    public boolean isWithoutChecksum(Artifact artifact) {
041        requireNonNull(artifact);
042        String artifactExtension = artifact.getExtension(); // ie. pom.asc
043        for (String extensionWithoutChecksums : extensionsWithoutChecksums) {
044            if (artifactExtension.endsWith(extensionWithoutChecksums)) {
045                return true;
046            }
047        }
048        return false;
049    }
050
051    @Override
052    public boolean isChecksum(Artifact artifact) {
053        requireNonNull(artifact);
054        return checksumAlgorithmFactorySelector.isChecksumExtension(artifact.getExtension());
055    }
056}