|
Lines 30-35
Link Here
|
| 30 |
import org.apache.tools.ant.BuildException; |
30 |
import org.apache.tools.ant.BuildException; |
| 31 |
import org.apache.tools.ant.Task; |
31 |
import org.apache.tools.ant.Task; |
| 32 |
import org.eclipse.core.runtime.CoreException; |
32 |
import org.eclipse.core.runtime.CoreException; |
|
|
33 |
import org.eclipse.jdt.core.JavaCore; |
| 33 |
import org.eclipse.osgi.util.ManifestElement; |
34 |
import org.eclipse.osgi.util.ManifestElement; |
| 34 |
import org.eclipse.pde.api.tools.internal.ApiDescription; |
35 |
import org.eclipse.pde.api.tools.internal.ApiDescription; |
| 35 |
import org.eclipse.pde.api.tools.internal.ApiSettingsXmlVisitor; |
36 |
import org.eclipse.pde.api.tools.internal.ApiSettingsXmlVisitor; |
|
Lines 40-45
Link Here
|
| 40 |
import org.eclipse.pde.api.tools.internal.provisional.scanner.TagScanner; |
41 |
import org.eclipse.pde.api.tools.internal.provisional.scanner.TagScanner; |
| 41 |
import org.eclipse.pde.api.tools.internal.util.Util; |
42 |
import org.eclipse.pde.api.tools.internal.util.Util; |
| 42 |
import org.osgi.framework.BundleException; |
43 |
import org.osgi.framework.BundleException; |
|
|
44 |
import org.osgi.framework.Constants; |
| 43 |
import org.xml.sax.Attributes; |
45 |
import org.xml.sax.Attributes; |
| 44 |
import org.xml.sax.InputSource; |
46 |
import org.xml.sax.InputSource; |
| 45 |
import org.xml.sax.SAXException; |
47 |
import org.xml.sax.SAXException; |
|
Lines 158-163
Link Here
|
| 158 |
return (path.isFile() && Util.isJavaFileName(path.getName())) || path.isDirectory(); |
160 |
return (path.isFile() && Util.isJavaFileName(path.getName())) || path.isDirectory(); |
| 159 |
} |
161 |
} |
| 160 |
}); |
162 |
}); |
|
|
163 |
File manifestFile = null; |
| 164 |
Map manifestMap = null; |
| 165 |
if (targetProjectFolder.exists() && targetProjectFolder.isDirectory()) { |
| 166 |
File manifestDir = new File(targetProjectFolder, "META-INF"); //$NON-NLS-1$ |
| 167 |
if (manifestDir.exists() && manifestDir.isDirectory()) { |
| 168 |
manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$ |
| 169 |
} |
| 170 |
if (manifestFile.exists()) { |
| 171 |
BufferedInputStream inputStream = null; |
| 172 |
try { |
| 173 |
inputStream = new BufferedInputStream(new FileInputStream(manifestFile)); |
| 174 |
manifestMap = ManifestElement.parseBundleManifest(inputStream, null); |
| 175 |
} catch (FileNotFoundException e) { |
| 176 |
ApiPlugin.log(e); |
| 177 |
} catch (IOException e) { |
| 178 |
ApiPlugin.log(e); |
| 179 |
} catch (BundleException e) { |
| 180 |
ApiPlugin.log(e); |
| 181 |
} finally { |
| 182 |
if (inputStream != null) { |
| 183 |
try { |
| 184 |
inputStream.close(); |
| 185 |
} catch(IOException e) { |
| 186 |
// ignore |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 161 |
ApiDescription apiDescription = new ApiDescription(this.projectName); |
192 |
ApiDescription apiDescription = new ApiDescription(this.projectName); |
| 162 |
TagScanner tagScanner = TagScanner.newScanner(); |
193 |
TagScanner tagScanner = TagScanner.newScanner(); |
| 163 |
if (allFiles != null) { |
194 |
if (allFiles != null) { |
|
Lines 167-173
Link Here
|
| 167 |
System.out.println("Unit name[" + i + "] : " + unit.getName()); //$NON-NLS-1$ //$NON-NLS-2$ |
198 |
System.out.println("Unit name[" + i + "] : " + unit.getName()); //$NON-NLS-1$ //$NON-NLS-2$ |
| 168 |
} |
199 |
} |
| 169 |
try { |
200 |
try { |
| 170 |
tagScanner.scan(unit, apiDescription, classFileContainer); |
201 |
//default to highest, since we have no EE context |
|
|
202 |
//TODO should use EE context to resolve a compliance level |
| 203 |
Map options = JavaCore.getOptions(); |
| 204 |
options.put(JavaCore.COMPILER_COMPLIANCE, resolveCompliance(manifestMap)); |
| 205 |
tagScanner.scan(unit, apiDescription, classFileContainer, options); |
| 171 |
} catch (CoreException e) { |
206 |
} catch (CoreException e) { |
| 172 |
ApiPlugin.log(e); |
207 |
ApiPlugin.log(e); |
| 173 |
} |
208 |
} |
|
Lines 176-250
Link Here
|
| 176 |
// check the manifest file |
211 |
// check the manifest file |
| 177 |
String componentName = this.projectName; |
212 |
String componentName = this.projectName; |
| 178 |
String componentID = this.projectName; |
213 |
String componentID = this.projectName; |
| 179 |
if (targetProjectFolder.exists() && targetProjectFolder.isDirectory()) { |
214 |
if (manifestMap != null && DEBUG) { |
| 180 |
File manifestDir = new File(targetProjectFolder, "META-INF"); //$NON-NLS-1$ |
215 |
for (Iterator iterator = manifestMap.keySet().iterator(); iterator.hasNext(); ) { |
| 181 |
if (manifestDir.exists() && manifestDir.isDirectory()) { |
216 |
Object key = iterator.next(); |
| 182 |
File manifestFile = new File(manifestDir, "MANIFEST.MF"); //$NON-NLS-1$ |
217 |
System.out.print("key = " + key); //$NON-NLS-1$ |
| 183 |
if (manifestFile.exists()) { |
218 |
System.out.println(" value = " + manifestMap.get(key)); //$NON-NLS-1$ |
| 184 |
BufferedInputStream inputStream = null; |
219 |
} |
| 185 |
Map manifestMap = null; |
220 |
String localization = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_LOCALIZATION); |
| 186 |
try { |
221 |
String name = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_NAME); |
| 187 |
inputStream = new BufferedInputStream(new FileInputStream(manifestFile)); |
222 |
String nameKey = (name != null && name.startsWith("%")) ? name.substring(1) : null; //$NON-NLS-1$; |
| 188 |
manifestMap = ManifestElement.parseBundleManifest(inputStream, null); |
223 |
if (nameKey != null) { |
| 189 |
} catch (FileNotFoundException e) { |
224 |
Properties properties = new Properties(); |
| 190 |
ApiPlugin.log(e); |
225 |
BufferedInputStream inputStream = null; |
| 191 |
} catch (IOException e) { |
226 |
try { |
| 192 |
ApiPlugin.log(e); |
227 |
inputStream = new BufferedInputStream(new FileInputStream(new File(targetProjectFolder, localization + ".properties"))); //$NON-NLS-1$ |
| 193 |
} catch (BundleException e) { |
228 |
properties.load(inputStream); |
| 194 |
ApiPlugin.log(e); |
229 |
} catch(IOException e) { |
| 195 |
} finally { |
230 |
ApiPlugin.log(e); |
| 196 |
if (inputStream != null) { |
231 |
} finally { |
| 197 |
try { |
232 |
if (inputStream != null) { |
| 198 |
inputStream.close(); |
|
|
| 199 |
} catch(IOException e) { |
| 200 |
// ignore |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
if (manifestMap != null && DEBUG) { |
| 205 |
for (Iterator iterator = manifestMap.keySet().iterator(); iterator.hasNext(); ) { |
| 206 |
Object key = iterator.next(); |
| 207 |
System.out.print("key = " + key); //$NON-NLS-1$ |
| 208 |
System.out.println(" value = " + manifestMap.get(key)); //$NON-NLS-1$ |
| 209 |
} |
| 210 |
} |
| 211 |
String localization = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_LOCALIZATION); |
| 212 |
String name = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_NAME); |
| 213 |
String nameKey = (name != null && name.startsWith("%")) ? name.substring(1) : null; //$NON-NLS-1$; |
| 214 |
if (nameKey != null) { |
| 215 |
Properties properties = new Properties(); |
| 216 |
inputStream = null; |
| 217 |
try { |
233 |
try { |
| 218 |
inputStream = new BufferedInputStream(new FileInputStream(new File(targetProjectFolder, localization + ".properties"))); //$NON-NLS-1$ |
234 |
inputStream.close(); |
| 219 |
properties.load(inputStream); |
|
|
| 220 |
} catch(IOException e) { |
235 |
} catch(IOException e) { |
| 221 |
ApiPlugin.log(e); |
236 |
// ignore |
| 222 |
} finally { |
|
|
| 223 |
if (inputStream != null) { |
| 224 |
try { |
| 225 |
inputStream.close(); |
| 226 |
} catch(IOException e) { |
| 227 |
// ignore |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
String property = properties.getProperty(nameKey); |
| 232 |
if (property != null) { |
| 233 |
componentName = property.trim(); |
| 234 |
} |
| 235 |
} else { |
| 236 |
componentName = name; |
| 237 |
} |
| 238 |
String symbolicName = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME); |
| 239 |
if (symbolicName != null) { |
| 240 |
int indexOf = symbolicName.indexOf(';'); |
| 241 |
if (indexOf == -1) { |
| 242 |
componentID = symbolicName.trim(); |
| 243 |
} else { |
| 244 |
componentID = symbolicName.substring(0, indexOf).trim(); |
| 245 |
} |
237 |
} |
| 246 |
} |
238 |
} |
| 247 |
} |
239 |
} |
|
|
240 |
String property = properties.getProperty(nameKey); |
| 241 |
if (property != null) { |
| 242 |
componentName = property.trim(); |
| 243 |
} |
| 244 |
} else { |
| 245 |
componentName = name; |
| 246 |
} |
| 247 |
String symbolicName = (String) manifestMap.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME); |
| 248 |
if (symbolicName != null) { |
| 249 |
int indexOf = symbolicName.indexOf(';'); |
| 250 |
if (indexOf == -1) { |
| 251 |
componentID = symbolicName.trim(); |
| 252 |
} else { |
| 253 |
componentID = symbolicName.substring(0, indexOf).trim(); |
| 254 |
} |
| 248 |
} |
255 |
} |
| 249 |
} |
256 |
} |
| 250 |
try { |
257 |
try { |
|
Lines 260-265
Link Here
|
| 260 |
} |
267 |
} |
| 261 |
} |
268 |
} |
| 262 |
|
269 |
|
|
|
270 |
/** |
| 271 |
* Resolves the compiler compliance based on the BREE entry in the MANIFEST.MF file |
| 272 |
* @param manifestmap |
| 273 |
* @return The derived {@link JavaCore#COMPILER_COMPLIANCE} from the BREE in the manifest map, |
| 274 |
* or {@link JavaCore#VERSION_1_3} if there is no BREE entry in the map or if the BREE entry does not directly map |
| 275 |
* to one of {"1.3", "1.4", "1.5", "1.6"}. |
| 276 |
*/ |
| 277 |
private String resolveCompliance(Map manifestmap) { |
| 278 |
if(manifestmap != null) { |
| 279 |
String eename = (String) manifestmap.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); |
| 280 |
if(eename != null) { |
| 281 |
if("J2SE-1.4".equals(eename)) { //$NON-NLS-1$ |
| 282 |
return JavaCore.VERSION_1_4; |
| 283 |
} |
| 284 |
if("J2SE-1.5".equals(eename)) { //$NON-NLS-1$ |
| 285 |
return JavaCore.VERSION_1_5; |
| 286 |
} |
| 287 |
if("JavaSE-1.6".equals(eename)) { //$NON-NLS-1$ |
| 288 |
return JavaCore.VERSION_1_6; |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
return JavaCore.VERSION_1_3; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Resolves if the '.project' file belongs to an API enabled project or not |
| 297 |
* @param dotProjectFile |
| 298 |
* @return true if the '.project' file is for an API enabled project, false otherwise |
| 299 |
*/ |
| 263 |
private boolean isAPIToolsNature(File dotProjectFile) { |
300 |
private boolean isAPIToolsNature(File dotProjectFile) { |
| 264 |
if (!dotProjectFile.exists()) return false; |
301 |
if (!dotProjectFile.exists()) return false; |
| 265 |
BufferedInputStream stream = null; |
302 |
BufferedInputStream stream = null; |