001package org.eclipse.aether.internal.impl.synccontext.named; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.eclipse.aether.RepositorySystemSession; 023import org.eclipse.aether.artifact.Artifact; 024import org.eclipse.aether.metadata.Metadata; 025import org.eclipse.aether.util.ConfigUtils; 026 027import javax.inject.Inject; 028import javax.inject.Named; 029import javax.inject.Singleton; 030import java.util.Collection; 031import java.util.Collections; 032import java.util.Objects; 033 034/** 035 * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "static" sync context. 036 */ 037@Singleton 038@Named( StaticNameMapper.NAME ) 039public class StaticNameMapper implements NameMapper 040{ 041 public static final String NAME = "static"; 042 043 /** 044 * Configuration property to pass in static name 045 */ 046 private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name"; 047 048 private final String name; 049 050 /** 051 * Uses string {@code "static"} for the static name 052 */ 053 @Inject 054 public StaticNameMapper() 055 { 056 this( NAME ); 057 } 058 059 /** 060 * Uses passed in non-{@code null} string for the static name 061 */ 062 public StaticNameMapper( final String name ) 063 { 064 this.name = Objects.requireNonNull( name ); 065 } 066 067 @Override 068 public Collection<String> nameLocks( final RepositorySystemSession session, 069 final Collection<? extends Artifact> artifacts, 070 final Collection<? extends Metadata> metadatas ) 071 { 072 return Collections.singletonList( ConfigUtils.getString( session, name, CONFIG_PROP_NAME ) ); 073 } 074}