View Javadoc
1   /*
2    * Copyright  2001,2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *
16   */
17  package org.codehaus.plexus.archiver.manager;
18  
19  import javax.inject.Inject;
20  import javax.inject.Named;
21  import javax.inject.Provider;
22  import javax.inject.Singleton;
23  
24  import java.util.Map;
25  import java.util.function.Supplier;
26  import java.util.stream.Collectors;
27  
28  import org.codehaus.plexus.archiver.Archiver;
29  import org.codehaus.plexus.archiver.UnArchiver;
30  import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
31  
32  /**
33   * @author dantran
34   */
35  @Singleton
36  @Named
37  public class DefaultArchiverManager extends AbstractArchiverManager {
38  
39      @Inject
40      public DefaultArchiverManager(
41              Map<String, Provider<Archiver>> archivers,
42              Map<String, Provider<UnArchiver>> unArchivers,
43              Map<String, Provider<PlexusIoResourceCollection>> plexusIoResourceCollections) {
44          super(archivers(archivers), unarchivers(unArchivers), plexusIoResourceCollections(plexusIoResourceCollections));
45      }
46  
47      private static Map<String, Supplier<Archiver>> archivers(Map<String, Provider<Archiver>> archivers) {
48          return archivers.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()::get));
49      }
50  
51      private static Map<String, Supplier<UnArchiver>> unarchivers(Map<String, Provider<UnArchiver>> unArchivers) {
52          return unArchivers.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()::get));
53      }
54  
55      private static Map<String, Supplier<PlexusIoResourceCollection>> plexusIoResourceCollections(
56              Map<String, Provider<PlexusIoResourceCollection>> plexusIoResourceCollections) {
57          return plexusIoResourceCollections.entrySet().stream()
58                  .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()::get));
59      }
60  }