View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.internal.impl.synccontext.named;
20  
21  import java.util.Collection;
22  import java.util.List;
23  import java.util.stream.Collectors;
24  
25  import org.eclipse.aether.RepositorySystemSession;
26  import org.eclipse.aether.artifact.Artifact;
27  import org.eclipse.aether.metadata.Metadata;
28  import org.eclipse.aether.named.NamedLockKey;
29  import org.eclipse.aether.spi.locking.LockingInhibitor;
30  
31  import static java.util.Objects.requireNonNull;
32  
33  /**
34   * Wrapping {@link NameMapper} class that applies discovered {@link org.eclipse.aether.spi.locking.LockingInhibitor}.
35   *
36   * @since 2.0.14
37   */
38  public class InhibitingNameMapper implements NameMapper {
39      private final NameMapper delegate;
40      private final List<LockingInhibitor> lockingInhibitors;
41  
42      public InhibitingNameMapper(NameMapper delegate, List<LockingInhibitor> lockingInhibitors) {
43          this.delegate = requireNonNull(delegate);
44          this.lockingInhibitors = requireNonNull(lockingInhibitors);
45      }
46  
47      @Override
48      public boolean isFileSystemFriendly() {
49          return delegate.isFileSystemFriendly();
50      }
51  
52      @Override
53      public Collection<NamedLockKey> nameLocks(
54              RepositorySystemSession session,
55              Collection<? extends Artifact> artifacts,
56              Collection<? extends Metadata> metadatas) {
57          if (artifacts != null) {
58              artifacts = artifacts.stream()
59                      .filter(a -> lockingInhibitors.stream().noneMatch(i -> i.preventArtifactLocking(a)))
60                      .collect(Collectors.toList());
61          }
62          if (metadatas != null) {
63              metadatas = metadatas.stream()
64                      .filter(m -> lockingInhibitors.stream().noneMatch(i -> i.preventMetadataLocking(m)))
65                      .collect(Collectors.toList());
66          }
67          return delegate.nameLocks(session, artifacts, metadatas);
68      }
69  }