1 11 package org.eclipse.pde.internal.core.converter; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.FileNotFoundException ; 16 import java.io.IOException ; 17 import java.util.Dictionary ; 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.resources.IResource; 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.osgi.service.pluginconversion.PluginConversionException; 27 import org.eclipse.osgi.util.ManifestElement; 28 import org.eclipse.pde.internal.core.ICoreConstants; 29 import org.eclipse.pde.internal.core.TargetPlatformHelper; 30 import org.osgi.framework.BundleException; 31 32 public class PDEPluginConverter { 33 34 public static void convertToOSGIFormat(IProject project, String target, Dictionary dictionary, IProgressMonitor monitor) throws CoreException { 35 convertToOSGIFormat(project, target, dictionary, null, monitor); 36 } 37 38 public static void convertToOSGIFormat(IProject project, String target, Dictionary dictionary, HashMap newProps, IProgressMonitor monitor) throws CoreException { 39 try { 40 File outputFile = new File (project.getLocation().append( 41 "META-INF/MANIFEST.MF").toOSString()); File inputFile = new File (project.getLocation().toOSString()); 43 PluginConverter converter = PluginConverter.getDefault(); 44 converter.convertManifest(inputFile, outputFile, false, target, true, dictionary); 45 46 if (newProps != null && newProps.size() > 0) 47 converter.writeManifest(outputFile, getProperties(outputFile, newProps), false); 48 49 project.refreshLocal(IResource.DEPTH_INFINITE, null); 50 } catch (PluginConversionException e) { 51 } finally { 52 monitor.done(); 53 } 54 } 55 56 public static void createBundleForFramework(IProject project, HashMap newProps, IProgressMonitor monitor) throws CoreException { 57 try { 58 File outputFile = new File (project.getLocation().append( 59 "META-INF/MANIFEST.MF").toOSString()); File inputFile = new File (project.getLocation().toOSString()); 61 PluginConverter converter = PluginConverter.getDefault(); 62 double version = TargetPlatformHelper.getTargetVersion(); 63 String versionString = version <= 3.1 ? ICoreConstants.TARGET31 : TargetPlatformHelper.getTargetVersionString(); 64 converter.convertManifest(inputFile, outputFile, false, versionString, true, null); 65 66 Map prop = getProperties(outputFile, newProps); 67 prop.remove(ICoreConstants.ECLIPSE_AUTOSTART); 68 prop.remove(ICoreConstants.ECLIPSE_LAZYSTART); 69 converter.writeManifest(outputFile, prop, false); 70 project.refreshLocal(IResource.DEPTH_INFINITE, null); 71 } catch (PluginConversionException e) { 72 } catch (CoreException e) { 73 } finally { 74 monitor.done(); 75 } 76 } 77 78 private static Map getProperties(File file, HashMap newProps) { 79 try { 80 Map prop = ManifestElement.parseBundleManifest(new FileInputStream (file), null); 81 if (newProps != null && newProps.size() > 0) { 82 Iterator iter = newProps.keySet().iterator(); 83 while (iter.hasNext()) { 84 String key = iter.next().toString(); 85 prop.put(key, newProps.get(key)); 86 } 87 } 88 return prop; 89 } catch (FileNotFoundException e) { 90 } catch (BundleException e) { 91 } catch (IOException e) { 92 } 93 return new HashMap (); 94 } 95 96 } 97 | Popular Tags |