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.transport.http; 020 021import javax.inject.Named; 022import javax.inject.Singleton; 023 024import java.util.Collections; 025import java.util.Map; 026import java.util.function.Function; 027 028import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; 029import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractorStrategy; 030import org.eclipse.aether.spi.connector.transport.http.HttpConstants; 031 032/** 033 * Sonatype Nexus2 checksum extractor. 034 */ 035@Singleton 036@Named(Nx2ChecksumExtractor.NAME) 037public final class Nx2ChecksumExtractor extends ChecksumExtractorStrategy { 038 public static final String NAME = "nx2"; 039 040 @Override 041 public Map<String, String> extractChecksums(Function<String, String> headerGetter) { 042 // Nexus-style, ETag: "{SHA1{d40d68ba1f88d8e9b0040f175a6ff41928abd5e7}}" 043 String etag = headerGetter.apply(HttpConstants.ETAG); 044 if (etag != null) { 045 int start = etag.indexOf("SHA1{"), end = etag.indexOf("}", start + 5); 046 if (start >= 0 && end > start) { 047 return Collections.singletonMap(Sha1ChecksumAlgorithmFactory.NAME, etag.substring(start + 5, end)); 048 } 049 } 050 return null; 051 } 052}