blob: d42ab743a08f109d4ba844bd6659692d3914b4bc [file] [log] [blame]
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +00001/*
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 Ziegeler82d87402015-03-04 13:26:21 +00007 *
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +00008 * http://www.apache.org/licenses/LICENSE-2.0
Carsten Ziegeler82d87402015-03-04 13:26:21 +00009 *
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000010 * 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. Hall01a56ce2007-05-20 22:31:11 +000015package org.apache.felix.bundleplugin;
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000016
Stuart McCulloch5ae59142008-01-29 06:21:05 +000017
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000018import java.util.HashMap;
19import java.util.HashSet;
20import java.util.Iterator;
21import java.util.Map;
22import java.util.Set;
23
24import org.apache.maven.artifact.Artifact;
25
Stuart McCulloch5ae59142008-01-29 06:21:05 +000026
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000027/**
Carsten Ziegeler82d87402015-03-04 13:26:21 +000028 * Information result of the bundling process
29 *
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000030 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
31 * @version $Id$
32 */
33public class BundleInfo
34{
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000035 /**
36 * {@link Map} &lt; {@link String}, {@link Set} &lt; {@link Artifact} > >
37 * Used to check for duplicated exports. Key is package name and value list of artifacts where it's exported.
38 */
Carsten Ziegeler82d87402015-03-04 13:26:21 +000039 private Map<String, Set<Artifact>> m_exportedPackages = new HashMap<String, Set<Artifact>>();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000040
Stuart McCulloch5ae59142008-01-29 06:21:05 +000041
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000042 public void addExportedPackage( String packageName, Artifact artifact )
43 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000044 Set<Artifact> artifacts = getExportedPackages().get( packageName );
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000045 if ( artifacts == null )
46 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000047 artifacts = new HashSet<Artifact>();
Stuart McCulloch9366a822008-01-29 07:45:57 +000048 m_exportedPackages.put( packageName, artifacts );
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000049 }
50 artifacts.add( artifact );
51 }
52
Stuart McCulloch5ae59142008-01-29 06:21:05 +000053
Carsten Ziegeler82d87402015-03-04 13:26:21 +000054 protected Map<String, Set<Artifact>> getExportedPackages()
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000055 {
Stuart McCulloch9366a822008-01-29 07:45:57 +000056 return m_exportedPackages;
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000057 }
58
Stuart McCulloch5ae59142008-01-29 06:21:05 +000059
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000060 /**
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} &lt; {@link String}, {@link Set} &lt; {@link Artifact} > >
64 */
Carsten Ziegeler82d87402015-03-04 13:26:21 +000065 public Map<String, Set<Artifact>> getDuplicatedExports()
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000066 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000067 Map<String, Set<Artifact>> duplicatedExports = new HashMap<String, Set<Artifact>>();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000068
Carsten Ziegeler82d87402015-03-04 13:26:21 +000069 for ( Iterator<Map.Entry<String, Set<Artifact>>> it = getExportedPackages().entrySet().iterator(); it.hasNext(); )
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000070 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000071 Map.Entry<String, Set<Artifact>> entry = it.next();
72 Set<Artifact> artifacts = entry.getValue();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000073 if ( artifacts.size() > 1 )
74 {
75 /* remove warnings caused by different versions of same artifact */
Carsten Ziegeler82d87402015-03-04 13:26:21 +000076 Set<String> artifactKeys = new HashSet<String>();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000077
Carsten Ziegeler82d87402015-03-04 13:26:21 +000078 String packageName = entry.getKey();
79 for ( Iterator<Artifact> it2 = artifacts.iterator(); it2.hasNext(); )
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000080 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000081 Artifact artifact = it2.next();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000082 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 McCulloch5ae59142008-01-29 06:21:05 +000095
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000096 public void merge( BundleInfo bundleInfo )
97 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +000098 for ( Iterator<Map.Entry<String, Set<Artifact>>> it = bundleInfo.getExportedPackages().entrySet().iterator(); it.hasNext(); )
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +000099 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +0000100 Map.Entry<String, Set<Artifact>> entry = it.next();
101 String packageName = entry.getKey();
102 Set<Artifact> artifacts = entry.getValue();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +0000103
Carsten Ziegeler82d87402015-03-04 13:26:21 +0000104 Set<Artifact> artifactsWithPackage = getExportedPackages().get( packageName );
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +0000105 if ( artifactsWithPackage == null )
106 {
Carsten Ziegeler82d87402015-03-04 13:26:21 +0000107 artifactsWithPackage = new HashSet<Artifact>();
Richard S. Hall6cf6f0b2007-04-10 16:50:31 +0000108 getExportedPackages().put( packageName, artifactsWithPackage );
109 }
110 artifactsWithPackage.addAll( artifacts );
111 }
112 }
113}