1 11 package org.eclipse.pde.internal.build; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 import java.util.HashMap ; 16 import java.util.Map ; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.equinox.app.IApplication; 19 import org.eclipse.equinox.app.IApplicationContext; 20 import org.osgi.framework.Bundle; 21 22 public class BuildApplication implements IApplication { 23 24 class ApplicationContext implements IApplicationContext { 25 26 IApplicationContext parent; 27 Map arguments; 28 29 ApplicationContext(IApplicationContext parent, Map arguments) { 30 this.parent = parent; 31 this.arguments = arguments; 32 } 33 34 37 public void applicationRunning() { 38 parent.applicationRunning(); 39 } 40 41 44 public Map getArguments() { 45 return arguments; 46 } 47 48 51 public String getBrandingApplication() { 52 return parent.getBrandingApplication(); 53 } 54 55 58 public Bundle getBrandingBundle() { 59 return parent.getBrandingBundle(); 60 } 61 62 65 public String getBrandingDescription() { 66 return parent.getBrandingDescription(); 67 } 68 69 72 public String getBrandingId() { 73 return parent.getBrandingId(); 74 } 75 76 79 public String getBrandingName() { 80 return parent.getBrandingName(); 81 } 82 83 86 public String getBrandingProperty(String key) { 87 return parent.getBrandingProperty(key); 88 } 89 } 90 91 94 public Object start(IApplicationContext context) throws Exception { 95 Platform.endSplash(); 96 IExtension extension = Platform.getExtensionRegistry().getExtension("org.eclipse.ant.core.antRunner"); if (extension == null) 98 return null; 99 IConfigurationElement element = extension.getConfigurationElements()[0]; 100 Object ee = element.createExecutableExtension("run"); Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 102 args = updateArgs((String []) args); 103 104 if (ee instanceof IApplication) { 105 Map arguments = new HashMap (context.getArguments()); 107 arguments.put(IApplicationContext.APPLICATION_ARGS, args); 109 IApplicationContext appContext = new ApplicationContext(context, arguments); 110 return ((IApplication) ee).start(appContext); 111 } 112 return doPlatformRunnable(ee, args); 114 } 115 116 125 private Object doPlatformRunnable(Object ee, Object args) throws Exception { 126 if (ee instanceof IPlatformRunnable) 127 return ((IPlatformRunnable) ee).run(args); 128 return null; 129 } 130 131 private Object updateArgs(String [] args) throws IOException { 132 for (int i = 0; i < args.length; i++) { 133 String string = args[i]; 134 if (string.equals("-f") || string.equals("-buildfile")) return args; 136 } 137 int length = args.length; 138 String [] result = new String [length + 2]; 139 System.arraycopy(args, 0, result, 0, length); 140 result[length] = "-f"; URL buildURL = BundleHelper.getDefault().find(new Path("/scripts/build.xml")); result[length + 1] = FileLocator.toFileURL(buildURL).getFile(); 143 return result; 144 } 145 146 149 public void stop() { 150 } 152 } 153 | Popular Tags |