View Javadoc
1   package org.eclipse.aether.internal.impl.synccontext.named;
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.util.ConfigUtils;
26  
27  import javax.inject.Inject;
28  import javax.inject.Named;
29  import javax.inject.Singleton;
30  import java.util.Collection;
31  import java.util.Collections;
32  import java.util.Objects;
33  
34  /**
35   * Static {@link NameMapper}, always assigns one same name, effectively becoming equivalent to "static" sync context.
36   */
37  @Singleton
38  @Named( StaticNameMapper.NAME )
39  public class StaticNameMapper implements NameMapper
40  {
41      public static final String NAME = "static";
42  
43      /**
44       * Configuration property to pass in static name
45       */
46      private static final String CONFIG_PROP_NAME = "aether.syncContext.named.static.name";
47  
48      private final String name;
49  
50      /**
51       * Uses string {@code "static"} for the static name
52       */
53      @Inject
54      public StaticNameMapper()
55      {
56          this( NAME );
57      }
58  
59      /**
60       * Uses passed in non-{@code null} string for the static name
61       */
62      public StaticNameMapper( final String name )
63      {
64          this.name = Objects.requireNonNull( name );
65      }
66  
67      @Override
68      public Collection<String> nameLocks( final RepositorySystemSession session,
69                                           final Collection<? extends Artifact> artifacts,
70                                           final Collection<? extends Metadata> metadatas )
71      {
72          return Collections.singletonList( ConfigUtils.getString( session, name, CONFIG_PROP_NAME ) );
73      }
74  }