001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM - Initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.build;
011:
012: import java.util.*;
013: import org.eclipse.osgi.service.resolver.BundleDescription;
014: import org.eclipse.pde.internal.build.site.BuildTimeFeature;
015: import org.eclipse.update.core.IFeature;
016:
017: public class AssemblyInformation implements IPDEBuildConstants {
018: // List all the features and plugins to assemble sorted on a per config basis
019: // key: string[] representing the tuple of a config
020: // value: (AssemblyLevelConfigInfo) representing the info for the given config
021: private Map assembleInformation = new HashMap(8);
022:
023: public AssemblyInformation() {
024: // Initialize the content of the assembly information with the configurations
025: for (Iterator iter = AbstractScriptGenerator.getConfigInfos()
026: .iterator(); iter.hasNext();) {
027: assembleInformation.put(iter.next(),
028: new AssemblyLevelConfigInfo());
029: }
030: }
031:
032: public void addFeature(Config config, IFeature feature) {
033: AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation
034: .get(config);
035: entry.addFeature(feature);
036: }
037:
038: public void removeFeature(Config config, IFeature feature) {
039: AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation
040: .get(config);
041: entry.removeFeature(feature);
042: }
043:
044: public void addPlugin(Config config, BundleDescription plugin) {
045: AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation
046: .get(config);
047: entry.addPlugin(plugin);
048: }
049:
050: public Collection getPlugins(Config config) {
051: return ((AssemblyLevelConfigInfo) assembleInformation
052: .get(config)).getPlugins();
053: }
054:
055: public Collection getBinaryPlugins(Config config) {
056: Collection allPlugins = getPlugins(config);
057: Set result = new HashSet(allPlugins.size());
058: for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
059: BundleDescription bundle = (BundleDescription) iter.next();
060: Properties bundleProperties = ((Properties) bundle
061: .getUserObject());
062: if (bundleProperties == null
063: || bundleProperties.get(IS_COMPILED) == null
064: || Boolean.FALSE == bundleProperties
065: .get(IS_COMPILED))
066: result.add(bundle);
067: }
068: return result;
069: }
070:
071: public Collection getCompiledPlugins(Config config) {
072: Collection allPlugins = getPlugins(config);
073: Set result = new HashSet(allPlugins.size());
074: for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
075: BundleDescription bundle = (BundleDescription) iter.next();
076: Properties bundleProperties = ((Properties) bundle
077: .getUserObject());
078: if (bundleProperties != null
079: && Boolean.TRUE == bundleProperties
080: .get(IS_COMPILED))
081: result.add(bundle);
082: }
083: return result;
084: }
085:
086: public Collection getAllCompiledPlugins() {
087: Collection pluginsByConfig = assembleInformation.values();
088: Set result = new HashSet();
089: for (Iterator iter2 = pluginsByConfig.iterator(); iter2
090: .hasNext();) {
091: Collection allPlugins = ((AssemblyLevelConfigInfo) iter2
092: .next()).getPlugins();
093: for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
094: BundleDescription bundle = (BundleDescription) iter
095: .next();
096: if (!Utils.isBinary(bundle)) {
097: result.add(bundle);
098: }
099: }
100: }
101: return result;
102: }
103:
104: public Collection getCompiledFeatures(Config config) {
105: Collection allFeatures = getFeatures(config);
106: ArrayList result = new ArrayList(allFeatures.size());
107: for (Iterator iter = allFeatures.iterator(); iter.hasNext();) {
108: Object tmp = iter.next();
109: if (tmp instanceof BuildTimeFeature) {
110: if (!((BuildTimeFeature) tmp).isBinary())
111: result.add(tmp);
112: }
113: }
114: return result;
115: }
116:
117: public Collection getBinaryFeatures(Config config) {
118: Collection allFeatures = getFeatures(config);
119: ArrayList result = new ArrayList(allFeatures.size());
120: for (Iterator iter = allFeatures.iterator(); iter.hasNext();) {
121: Object tmp = iter.next();
122: if (tmp instanceof BuildTimeFeature) {
123: if (((BuildTimeFeature) tmp).isBinary())
124: result.add(tmp);
125: } else {
126: result.add(tmp);
127: }
128: }
129: return result;
130: }
131:
132: public ArrayList getFeatures(Config config) {
133: return ((AssemblyLevelConfigInfo) assembleInformation
134: .get(config)).getFeatures();
135: }
136:
137: public boolean copyRootFile(Config config) {
138: return ((AssemblyLevelConfigInfo) assembleInformation
139: .get(config)).hasRootFile();
140: }
141:
142: public Collection getRootFileProviders(Config config) {
143: return ((AssemblyLevelConfigInfo) assembleInformation
144: .get(config)).getRootFileProvider();
145: }
146:
147: public void addRootFileProvider(Config config, IFeature feature) {
148: ((AssemblyLevelConfigInfo) assembleInformation.get(config))
149: .addRootFileProvider(feature);
150: }
151:
152: // All the information that will go into the assemble file for a specific info
153: private class AssemblyLevelConfigInfo {
154: // the plugins that are contained into this config
155: private Collection plugins = new HashSet(20);
156: // the features that are contained into this config
157: private ArrayList features = new ArrayList(7);
158: // indicate whether root files needs to be copied and where they are coming from
159: private LinkedList rootFileProviders = new LinkedList();
160:
161: public void addRootFileProvider(IFeature feature) {
162: if (rootFileProviders.contains(feature))
163: return;
164: for (Iterator iter = rootFileProviders.iterator(); iter
165: .hasNext();) {
166: BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter
167: .next();
168: if (feature == featureDescriptor)
169: return;
170: if (((BuildTimeFeature) feature).getFeatureIdentifier()
171: .equals(
172: featureDescriptor
173: .getFeatureIdentifier())
174: && ((BuildTimeFeature) feature)
175: .getFeatureVersion().equals(
176: featureDescriptor
177: .getFeatureVersion()))
178: return;
179: }
180: rootFileProviders.add(feature);
181: }
182:
183: public Collection getRootFileProvider() {
184: return rootFileProviders;
185: }
186:
187: public boolean hasRootFile() {
188: return rootFileProviders.size() > 0;
189: }
190:
191: public ArrayList getFeatures() {
192: return features;
193: }
194:
195: public Collection getPlugins() {
196: return plugins;
197: }
198:
199: public void addFeature(IFeature feature) {
200: for (Iterator iter = features.iterator(); iter.hasNext();) {
201: BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter
202: .next();
203: if (((BuildTimeFeature) feature).getFeatureIdentifier()
204: .equals(
205: featureDescriptor
206: .getFeatureIdentifier())
207: && ((BuildTimeFeature) feature)
208: .getFeatureVersion().equals(
209: featureDescriptor
210: .getFeatureVersion()))
211: return;
212: }
213: features.add(feature);
214: }
215:
216: public void addPlugin(BundleDescription plugin) {
217: plugins.add(plugin);
218: }
219:
220: public void removeFeature(IFeature feature) {
221: for (Iterator iter = features.iterator(); iter.hasNext();) {
222: BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter
223: .next();
224: if (((BuildTimeFeature) feature).getFeatureIdentifier()
225: .equals(
226: featureDescriptor
227: .getFeatureIdentifier())
228: && ((BuildTimeFeature) feature)
229: .getFeatureVersion().equals(
230: featureDescriptor
231: .getFeatureVersion())) {
232: features.remove(featureDescriptor);
233: return;
234: }
235: }
236: }
237: }
238: }
|