Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license |
| 3 | * agreements. See the NOTICE file distributed with this work for additional information regarding |
| 4 | * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 5 | * "License"); you may not use this file except in compliance with the License. You may obtain a |
| 6 | * copy of the License at |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 7 | * |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 9 | * |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 11 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 12 | * or implied. See the License for the specific language governing permissions and limitations under |
| 13 | * the License. |
| 14 | */ |
Richard S. Hall | 01a56ce | 2007-05-20 22:31:11 +0000 | [diff] [blame] | 15 | package org.apache.felix.bundleplugin; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 16 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 17 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 18 | import java.util.HashMap; |
| 19 | import java.util.HashSet; |
| 20 | import java.util.Iterator; |
| 21 | import java.util.Map; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import org.apache.maven.artifact.Artifact; |
| 25 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 26 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 27 | /** |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 28 | * Information result of the bundling process |
| 29 | * |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 30 | * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> |
| 31 | * @version $Id$ |
| 32 | */ |
| 33 | public class BundleInfo |
| 34 | { |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 35 | /** |
| 36 | * {@link Map} < {@link String}, {@link Set} < {@link Artifact} > > |
| 37 | * Used to check for duplicated exports. Key is package name and value list of artifacts where it's exported. |
| 38 | */ |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 39 | private Map<String, Set<Artifact>> m_exportedPackages = new HashMap<String, Set<Artifact>>(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 40 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 41 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 42 | public void addExportedPackage( String packageName, Artifact artifact ) |
| 43 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 44 | Set<Artifact> artifacts = getExportedPackages().get( packageName ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 45 | if ( artifacts == null ) |
| 46 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 47 | artifacts = new HashSet<Artifact>(); |
Stuart McCulloch | 9366a82 | 2008-01-29 07:45:57 +0000 | [diff] [blame] | 48 | m_exportedPackages.put( packageName, artifacts ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 49 | } |
| 50 | artifacts.add( artifact ); |
| 51 | } |
| 52 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 53 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 54 | protected Map<String, Set<Artifact>> getExportedPackages() |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 55 | { |
Stuart McCulloch | 9366a82 | 2008-01-29 07:45:57 +0000 | [diff] [blame] | 56 | return m_exportedPackages; |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 59 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 60 | /** |
| 61 | * Get a list of packages that are exported in more than one bundle. |
| 62 | * Key is package name and value list of artifacts where it's exported. |
| 63 | * @return {@link Map} < {@link String}, {@link Set} < {@link Artifact} > > |
| 64 | */ |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 65 | public Map<String, Set<Artifact>> getDuplicatedExports() |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 66 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 67 | Map<String, Set<Artifact>> duplicatedExports = new HashMap<String, Set<Artifact>>(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 68 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 69 | for ( Iterator<Map.Entry<String, Set<Artifact>>> it = getExportedPackages().entrySet().iterator(); it.hasNext(); ) |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 70 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 71 | Map.Entry<String, Set<Artifact>> entry = it.next(); |
| 72 | Set<Artifact> artifacts = entry.getValue(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 73 | if ( artifacts.size() > 1 ) |
| 74 | { |
| 75 | /* remove warnings caused by different versions of same artifact */ |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 76 | Set<String> artifactKeys = new HashSet<String>(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 77 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 78 | String packageName = entry.getKey(); |
| 79 | for ( Iterator<Artifact> it2 = artifacts.iterator(); it2.hasNext(); ) |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 80 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 81 | Artifact artifact = it2.next(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 82 | artifactKeys.add( artifact.getGroupId() + "." + artifact.getArtifactId() ); |
| 83 | } |
| 84 | |
| 85 | if ( artifactKeys.size() > 1 ) |
| 86 | { |
| 87 | duplicatedExports.put( packageName, artifacts ); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return duplicatedExports; |
| 93 | } |
| 94 | |
Stuart McCulloch | 5ae5914 | 2008-01-29 06:21:05 +0000 | [diff] [blame] | 95 | |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 96 | public void merge( BundleInfo bundleInfo ) |
| 97 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 98 | for ( Iterator<Map.Entry<String, Set<Artifact>>> it = bundleInfo.getExportedPackages().entrySet().iterator(); it.hasNext(); ) |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 99 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 100 | Map.Entry<String, Set<Artifact>> entry = it.next(); |
| 101 | String packageName = entry.getKey(); |
| 102 | Set<Artifact> artifacts = entry.getValue(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 103 | |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 104 | Set<Artifact> artifactsWithPackage = getExportedPackages().get( packageName ); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 105 | if ( artifactsWithPackage == null ) |
| 106 | { |
Carsten Ziegeler | 82d8740 | 2015-03-04 13:26:21 +0000 | [diff] [blame] | 107 | artifactsWithPackage = new HashSet<Artifact>(); |
Richard S. Hall | 6cf6f0b | 2007-04-10 16:50:31 +0000 | [diff] [blame] | 108 | getExportedPackages().put( packageName, artifactsWithPackage ); |
| 109 | } |
| 110 | artifactsWithPackage.addAll( artifacts ); |
| 111 | } |
| 112 | } |
| 113 | } |