KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > AssemblyInformation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build;
12
13 import java.util.*;
14 import org.eclipse.osgi.service.resolver.BundleDescription;
15 import org.eclipse.pde.internal.build.site.BuildTimeFeature;
16 import org.eclipse.update.core.IFeature;
17
18 public class AssemblyInformation implements IPDEBuildConstants {
19     // List all the features and plugins to assemble sorted on a per config basis
20
// key: string[] representing the tuple of a config
21
// value: (AssemblyLevelConfigInfo) representing the info for the given config
22
private Map assembleInformation = new HashMap(8);
23
24     public AssemblyInformation() {
25         // Initialize the content of the assembly information with the configurations
26
for (Iterator iter = AbstractScriptGenerator.getConfigInfos().iterator(); iter.hasNext();) {
27             assembleInformation.put(iter.next(), new AssemblyLevelConfigInfo());
28         }
29     }
30
31     public void addFeature(Config config, IFeature feature) {
32         AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation.get(config);
33         entry.addFeature(feature);
34     }
35
36     public void removeFeature(Config config, IFeature feature) {
37         AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation.get(config);
38         entry.removeFeature(feature);
39     }
40
41     public void addPlugin(Config config, BundleDescription plugin) {
42         AssemblyLevelConfigInfo entry = (AssemblyLevelConfigInfo) assembleInformation.get(config);
43         entry.addPlugin(plugin);
44     }
45
46     public Collection getPlugins(Config config) {
47         return ((AssemblyLevelConfigInfo) assembleInformation.get(config)).getPlugins();
48     }
49
50     public Collection getBinaryPlugins(Config config) {
51         Collection allPlugins = getPlugins(config);
52         Set result = new HashSet(allPlugins.size());
53         for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
54             BundleDescription bundle = (BundleDescription) iter.next();
55             Properties bundleProperties = ((Properties) bundle.getUserObject());
56             if (bundleProperties == null || bundleProperties.get(IS_COMPILED) == null || Boolean.FALSE == bundleProperties.get(IS_COMPILED))
57                 result.add(bundle);
58         }
59         return result;
60     }
61     
62     public Collection getCompiledPlugins(Config config) {
63         Collection allPlugins = getPlugins(config);
64         Set result = new HashSet(allPlugins.size());
65         for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
66             BundleDescription bundle = (BundleDescription) iter.next();
67             Properties bundleProperties = ((Properties) bundle.getUserObject());
68             if (bundleProperties != null && Boolean.TRUE == bundleProperties.get(IS_COMPILED))
69                 result.add(bundle);
70         }
71         return result;
72     }
73     
74     public Collection getAllCompiledPlugins() {
75         Collection pluginsByConfig = assembleInformation.values();
76         Set result = new HashSet();
77         for (Iterator iter2 = pluginsByConfig.iterator(); iter2.hasNext();) {
78             Collection allPlugins = ((AssemblyLevelConfigInfo) iter2.next()).getPlugins();
79             for (Iterator iter = allPlugins.iterator(); iter.hasNext();) {
80                 BundleDescription bundle = (BundleDescription) iter.next();
81                 if (!Utils.isBinary(bundle)) {
82                     result.add(bundle);
83                 }
84             }
85         }
86         return result;
87     }
88     
89     public Collection getCompiledFeatures(Config config) {
90         Collection allFeatures= getFeatures(config);
91         ArrayList result = new ArrayList(allFeatures.size());
92         for (Iterator iter = allFeatures.iterator(); iter.hasNext();) {
93             Object JavaDoc tmp = iter.next();
94             if (tmp instanceof BuildTimeFeature) {
95                 if (! ((BuildTimeFeature) tmp).isBinary())
96                     result.add(tmp);
97             }
98         }
99         return result;
100     }
101     
102     public Collection getBinaryFeatures(Config config) {
103         Collection allFeatures= getFeatures(config);
104         ArrayList result = new ArrayList(allFeatures.size());
105         for (Iterator iter = allFeatures.iterator(); iter.hasNext();) {
106             Object JavaDoc tmp = iter.next();
107             if (tmp instanceof BuildTimeFeature) {
108                 if (((BuildTimeFeature) tmp).isBinary())
109                     result.add(tmp);
110             } else {
111                 result.add(tmp);
112             }
113         }
114         return result;
115     }
116     
117     public ArrayList getFeatures(Config config) {
118         return ((AssemblyLevelConfigInfo) assembleInformation.get(config)).getFeatures();
119     }
120
121     public boolean copyRootFile(Config config) {
122         return ((AssemblyLevelConfigInfo) assembleInformation.get(config)).hasRootFile();
123     }
124
125     public Collection getRootFileProviders(Config config) {
126         return ((AssemblyLevelConfigInfo) assembleInformation.get(config)).getRootFileProvider();
127     }
128
129     public void addRootFileProvider(Config config, IFeature feature) {
130         ((AssemblyLevelConfigInfo) assembleInformation.get(config)).addRootFileProvider(feature);
131     }
132
133     // All the information that will go into the assemble file for a specific info
134
private class AssemblyLevelConfigInfo {
135         // the plugins that are contained into this config
136
private Collection plugins = new HashSet(20);
137         // the features that are contained into this config
138
private ArrayList features = new ArrayList(7);
139         // indicate whether root files needs to be copied and where they are coming from
140
private LinkedList rootFileProviders = new LinkedList();
141
142         public void addRootFileProvider(IFeature feature) {
143             if (rootFileProviders.contains(feature))
144                 return;
145             for (Iterator iter = rootFileProviders.iterator(); iter.hasNext();) {
146                 BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter.next();
147                 if (feature == featureDescriptor)
148                     return;
149                 if (((BuildTimeFeature) feature).getFeatureIdentifier().equals(featureDescriptor.getFeatureIdentifier()) && ((BuildTimeFeature) feature).getFeatureVersion().equals(featureDescriptor.getFeatureVersion()))
150                     return;
151             }
152             rootFileProviders.add(feature);
153         }
154
155         public Collection getRootFileProvider() {
156             return rootFileProviders;
157         }
158
159         public boolean hasRootFile() {
160             return rootFileProviders.size() > 0;
161         }
162
163         public ArrayList getFeatures() {
164             return features;
165         }
166
167         public Collection getPlugins() {
168             return plugins;
169         }
170
171         public void addFeature(IFeature feature) {
172             for (Iterator iter = features.iterator(); iter.hasNext();) {
173                 BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter.next();
174                 if (((BuildTimeFeature) feature).getFeatureIdentifier().equals(featureDescriptor.getFeatureIdentifier()) && ((BuildTimeFeature) feature).getFeatureVersion().equals(featureDescriptor.getFeatureVersion()))
175                     return;
176             }
177             features.add(feature);
178         }
179
180         public void addPlugin(BundleDescription plugin) {
181             plugins.add(plugin);
182         }
183
184         public void removeFeature(IFeature feature) {
185             for (Iterator iter = features.iterator(); iter.hasNext();) {
186                 BuildTimeFeature featureDescriptor = (BuildTimeFeature) iter.next();
187                 if (((BuildTimeFeature) feature).getFeatureIdentifier().equals(featureDescriptor.getFeatureIdentifier()) && ((BuildTimeFeature) feature).getFeatureVersion().equals(featureDescriptor.getFeatureVersion())) {
188                     features.remove(featureDescriptor);
189                     return;
190                 }
191             }
192         }
193     }
194 }
195
Popular Tags