1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2009 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 Corporation - initial API and implementation |
10 | *******************************************************************************/ |
11 | package org.eclipse.pde.api.tools.internal.model; |
12 | |
13 | import java.util.ArrayList; |
14 | import java.util.List; |
15 | |
16 | import org.eclipse.core.runtime.CoreException; |
17 | import org.eclipse.jdt.launching.LibraryLocation; |
18 | import org.eclipse.jdt.launching.environments.ExecutionEnvironmentDescription; |
19 | import org.eclipse.osgi.service.resolver.ResolverError; |
20 | import org.eclipse.pde.api.tools.internal.ApiDescription; |
21 | import org.eclipse.pde.api.tools.internal.provisional.Factory; |
22 | import org.eclipse.pde.api.tools.internal.provisional.IApiDescription; |
23 | import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore; |
24 | import org.eclipse.pde.api.tools.internal.provisional.IRequiredComponentDescription; |
25 | import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; |
26 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor; |
27 | import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline; |
28 | |
29 | /** |
30 | * An API component for a system library. |
31 | * |
32 | * @since 1.0.0 |
33 | */ |
34 | public class SystemLibraryApiComponent extends AbstractApiComponent { |
35 | |
36 | /** |
37 | * Execution environment profile symbolic name. |
38 | */ |
39 | protected String[] fExecEnv; |
40 | |
41 | /** |
42 | * Associated library locations. |
43 | */ |
44 | protected LibraryLocation[] fLibraries; |
45 | |
46 | /** |
47 | * Home directory |
48 | */ |
49 | protected String fLocation; |
50 | |
51 | /** |
52 | * List of exported system packages |
53 | */ |
54 | protected String[] fSystemPackages; |
55 | |
56 | /** |
57 | * Language level - i.e. 1.4, 1.5, etc. |
58 | */ |
59 | protected String fVersion; |
60 | |
61 | /** |
62 | * Constructs a system library. |
63 | * |
64 | * @param profile owning profile |
65 | */ |
66 | protected SystemLibraryApiComponent(IApiBaseline profile){ |
67 | super(profile); |
68 | } |
69 | /** |
70 | * Constructs a system library from the given execution environment description file. |
71 | * |
72 | * @param profile owning profile |
73 | * @param description EE file |
74 | * @param systemPackages exported system packages |
75 | * @exception CoreException if unable to read the execution environment description file |
76 | */ |
77 | public SystemLibraryApiComponent(IApiBaseline profile, ExecutionEnvironmentDescription description, String[] systemPackages) throws CoreException { |
78 | super(profile); |
79 | init(description); |
80 | fSystemPackages = systemPackages; |
81 | } |
82 | |
83 | /* (non-Javadoc) |
84 | * @see org.eclipse.pde.api.tools.internal.descriptors.AbstractApiComponent#createApiDescription() |
85 | */ |
86 | protected IApiDescription createApiDescription() throws CoreException { |
87 | IApiDescription api = new ApiDescription(getId()); |
88 | for (int i = 0; i < fSystemPackages.length; i++) { |
89 | IPackageDescriptor pkg = Factory.packageDescriptor(fSystemPackages[i]); |
90 | api.setVisibility(pkg, VisibilityModifiers.API); |
91 | } |
92 | // have to fill in java.* as well |
93 | String[] packageNames = getPackageNames(); |
94 | for (int i = 0; i < packageNames.length; i++) { |
95 | if (packageNames[i].startsWith("java.")) { //$NON-NLS-1$ |
96 | IPackageDescriptor pkg = Factory.packageDescriptor(packageNames[i]); |
97 | api.setVisibility(pkg, VisibilityModifiers.API); |
98 | } |
99 | } |
100 | return api; |
101 | } |
102 | |
103 | /* (non-Javadoc) |
104 | * @see org.eclipse.pde.api.tools.internal.AbstractApiComponent#createApiFilterStore() |
105 | */ |
106 | protected IApiFilterStore createApiFilterStore() { |
107 | //TODO |
108 | return null; |
109 | } |
110 | |
111 | /* (non-Javadoc) |
112 | * @see org.eclipse.pde.api.tools.internal.descriptors.AbstractApiComponent#createClassFileContainers() |
113 | */ |
114 | protected List createApiTypeContainers() throws CoreException { |
115 | List libs = new ArrayList(fLibraries.length); |
116 | for (int i = 0; i < fLibraries.length; i++) { |
117 | LibraryLocation lib = fLibraries[i]; |
118 | libs.add(new ArchiveApiTypeContainer(this, lib.getSystemLibraryPath().toOSString())); |
119 | } |
120 | return libs; |
121 | } |
122 | |
123 | /* (non-Javadoc) |
124 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getExecutionEnvironments() |
125 | */ |
126 | public String[] getExecutionEnvironments() { |
127 | return fExecEnv; |
128 | } |
129 | |
130 | /* (non-Javadoc) |
131 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getId() |
132 | */ |
133 | public String getId() { |
134 | return fExecEnv[0]; |
135 | } |
136 | |
137 | /* (non-Javadoc) |
138 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getLocation() |
139 | */ |
140 | public String getLocation() { |
141 | return fLocation; |
142 | } |
143 | |
144 | /* (non-Javadoc) |
145 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getRequiredComponents() |
146 | */ |
147 | public IRequiredComponentDescription[] getRequiredComponents() { |
148 | return new IRequiredComponentDescription[0]; |
149 | } |
150 | |
151 | /* (non-Javadoc) |
152 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getVersion() |
153 | */ |
154 | public String getVersion() { |
155 | return fVersion; |
156 | } |
157 | |
158 | /** |
159 | * Initializes properties from the EE file. |
160 | * |
161 | * @param description EE file |
162 | */ |
163 | private void init(ExecutionEnvironmentDescription description) throws CoreException { |
164 | fLibraries = description.getLibraryLocations(); |
165 | fExecEnv = new String[]{description.getProperty(ExecutionEnvironmentDescription.CLASS_LIB_LEVEL)}; |
166 | fVersion = fExecEnv[0]; |
167 | setName(fExecEnv[0]); |
168 | fLocation = description.getProperty(ExecutionEnvironmentDescription.JAVA_HOME); |
169 | } |
170 | |
171 | /* (non-Javadoc) |
172 | * @see IApiComponent#isSourceComponent() |
173 | */ |
174 | public boolean isSourceComponent() { |
175 | return false; |
176 | } |
177 | |
178 | /* (non-Javadoc) |
179 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#isSystemComponent() |
180 | */ |
181 | public boolean isSystemComponent() { |
182 | return true; |
183 | } |
184 | |
185 | /* (non-Javadoc) |
186 | * @see org.eclipse.pde.api.tools.IApiComponent#isFragment() |
187 | */ |
188 | public boolean isFragment() { |
189 | return false; |
190 | } |
191 | |
192 | /* (non-Javadoc) |
193 | * @see org.eclipse.pde.api.tools.IApiComponent#hasFragments() |
194 | */ |
195 | public boolean hasFragments() { |
196 | return false; |
197 | } |
198 | |
199 | public String getOrigin() { |
200 | return null; |
201 | } |
202 | |
203 | /* (non-Javadoc) |
204 | * @see org.eclipse.pde.api.tools.internal.provisional.IApiComponent#hasApiDescription() |
205 | */ |
206 | public boolean hasApiDescription() { |
207 | return false; |
208 | } |
209 | |
210 | /* (non-Javadoc) |
211 | * @see org.eclipse.pde.api.tools.internal.provisional.IApiComponent#getSystemApiDescription(int) |
212 | */ |
213 | public IApiDescription getSystemApiDescription(int eeValue) throws CoreException { |
214 | return null; |
215 | } |
216 | |
217 | /* (non-Javadoc) |
218 | * @see org.eclipse.pde.api.tools.internal.provisional.IApiComponent#getLowestEEs() |
219 | */ |
220 | public String[] getLowestEEs() { |
221 | return null; |
222 | } |
223 | /* (non-Javadoc) |
224 | * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent#getErrors() |
225 | */ |
226 | public ResolverError[] getErrors() throws CoreException { |
227 | return null; |
228 | } |
229 | } |