View Javadoc
1   /*-
2    * #%L
3    * io.earcam.instrumental.archive.osgi
4    * %%
5    * Copyright (C) 2018 earcam
6    * %%
7    * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8    * 
9    * You <b>must</b> choose to accept, in full - any individual or combination of 
10   * the following licenses:
11   * <ul>
12   * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13   * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14   * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15   * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16   * </ul>
17   * #L%
18   */
19  package io.earcam.instrumental.archive.osgi.auto;
20  
21  import java.util.Arrays;
22  import java.util.List;
23  import java.util.Optional;
24  import java.util.stream.Collectors;
25  
26  import io.earcam.instrumental.archive.Archive;
27  import io.earcam.instrumental.module.osgi.BundleInfo;
28  import io.earcam.instrumental.module.osgi.BundleInfoBuilder;
29  
30  public final class ArchivePackageBundleMapper extends AbstractPackageBundleMapper {
31  
32  	private final List<BundleInfo> bundles;
33  
34  
35  	private ArchivePackageBundleMapper(List<BundleInfo> bundles)
36  	{
37  		this.bundles = bundles;
38  
39  	}
40  
41  
42  	public static ArchivePackageBundleMapper byMappingBundleArchives(Archive... archives)
43  	{
44  		return byMappingBundleArchives(Arrays.asList(archives));
45  	}
46  
47  
48  	public static ArchivePackageBundleMapper byMappingBundleArchives(List<Archive> archives)
49  	{
50  		List<BundleInfo> bundles = archives.stream()
51  				.map(Archive::manifest)
52  				.filter(Optional::isPresent)
53  				.map(Optional::get)
54  				.map(BundleInfoBuilder::bundleFrom)
55  				.map(BundleInfoBuilder::construct)
56  				.collect(Collectors.toList());
57  
58  		return new ArchivePackageBundleMapper(bundles);
59  	}
60  
61  
62  	@Override
63  	protected List<BundleInfo> bundles()
64  	{
65  		return bundles;
66  	}
67  
68  }