1 package com.jahia.opentools.advancedapprunner; 2 3 import java.io.File ; 4 import java.util.Map ; 5 6 import com.borland.jbuilder.node.JBProject; 7 import com.borland.jbuilder.runtime.JavaRunner; 8 import com.borland.primetime.PrimeTime; 9 import com.borland.primetime.ide.Browser; 10 import com.borland.primetime.node.Project; 11 import com.borland.primetime.properties.MapArrayProperty; 12 import com.borland.primetime.properties.MapProperty; 13 import com.borland.primetime.properties.PropertyPage; 14 import com.borland.primetime.properties.PropertyPageFactory; 15 import com.borland.primetime.runtime.RuntimeManager; 16 import com.borland.primetime.properties.PropertyManager; 17 import com.borland.jbuilder.paths.ProjectPathSet; 18 import com.borland.jbuilder.paths.JDKPathSet; 19 import com.borland.primetime.properties.MapBooleanProperty; 20 21 29 public class AdvancedAppRunner extends JavaRunner { 30 31 public static final String CATEGORY = "runtime"; 32 33 private static final MapProperty CUSTOM_JDK_PROP = new MapProperty(CATEGORY, "custom.jdk"); 34 private static final MapProperty CUSTOM_OVERRIDE_JDK_PROP = new MapBooleanProperty(CATEGORY, "custom.override_jdk"); 35 36 public static final MapProperty MAIN_CLASS = new MapProperty( 37 CATEGORY, "opentools.mainclass", 38 "org.apache.catalina.startup.Bootstrap"); 39 public static final MapProperty VM_PARAMS = new MapProperty( 40 CATEGORY, "opentools.vmparameters", ""); 41 public static final MapProperty JB_PARAMS = new MapProperty( 42 CATEGORY, "opentools.parameters", ""); 43 public static final MapArrayProperty OTHER_DIRS = new MapArrayProperty( 44 CATEGORY, "opentools.otherDirs"); 45 46 private static final String VERSION = "2.0"; 47 48 54 public static void initOpenTool(byte majorVersion, byte minorVersion) { 55 if (majorVersion != PrimeTime.CURRENT_MAJOR_VERSION) { 56 return; 57 } 58 RuntimeManager.registerRunner(new AdvancedAppRunner()); 59 if (PrimeTime.isVerbose()) { 60 System.out.println("Loaded Advanced Application runtime v" + VERSION); 61 System.out.println("Written by Serge Huber (shuber@jahia.com)"); 62 } 63 } 64 65 68 public boolean isValid(Browser browser, Project project, Map propertyMap, 69 boolean debug) { 70 return true; 71 } 72 73 76 public PropertyPageFactory getPageFactory(Project project, Map propertyMap) { 77 if (project instanceof JBProject) { 78 final Project aProject = project; 79 final Map aPropertyMap = propertyMap; 80 return new PropertyPageFactory("Advanced Application", 81 "Run an advanced application") { 82 public PropertyPage createPropertyPage() { 83 return new AdvancedAppRunnerPropertyPage(aProject, 84 aPropertyMap); 85 } 86 }; 87 } else { 88 return null; 89 } 90 } 91 92 96 public String getClassPath(JBProject project, Map propertyMap) { 97 String classPath = super.getClassPath(project, propertyMap); 98 StringBuffer buffer = new StringBuffer (); 99 SysEnvPropertiesProvider envProvider = SysEnvPropertiesProvider.getInstance(); 103 envProvider.setProperty("JBUILDER_HOME", PropertyManager.getInstallRootUrl().getFileObject().toString()); 104 105 ProjectPathSet projectPathSet = project.getPaths(); 106 JDKPathSet jdkPathSet = projectPathSet.getJDKPathSet(); 107 if (propertyMap.containsKey(CUSTOM_JDK_PROP)) { 110 String overrideJDK = (String ) propertyMap.get(CUSTOM_OVERRIDE_JDK_PROP); 111 String customJDK = (String ) propertyMap.get(CUSTOM_JDK_PROP); 112 if ("1".equals(overrideJDK)) { 113 JDKPathSet newJDKPathSet = projectPathSet.getJDK(customJDK); 115 if (newJDKPathSet != null) { 116 jdkPathSet = newJDKPathSet; 117 } 118 } 119 } 120 121 String jdkHomePath = jdkPathSet.getHomePath().getFileObject().toString(); 122 envProvider.setProperty("JBUILDER_RUNTIME_JDK", jdkHomePath); 123 124 String [] otherDirs = OTHER_DIRS.getValues(propertyMap); 125 for (int index = 0; index < otherDirs.length; index++) { 126 String curDirEntry = otherDirs[index]; 127 curDirEntry = envProvider.replaceEnvVariables(curDirEntry); 128 File dir = new File (curDirEntry); 129 134 if (buffer.length() > 0) { 135 buffer.append(File.pathSeparatorChar); 136 } 137 buffer.append(dir.toString()); 138 } 139 return buffer.toString(); 140 } 141 142 143 150 private void addAllDirLibsToClassPath(StringBuffer buffer, File directory) { 151 String classPath = buffer.toString(); 152 File [] files = directory.listFiles(); 153 for (int index = 0; index < files.length; index++) { 154 if (files[index].getName().toLowerCase().endsWith("jar") || 155 files[index].getName().toLowerCase().endsWith("zip")) { 156 if (classPath.indexOf(files[index].getAbsolutePath()) == -1) { 157 buffer.append(File.pathSeparatorChar). 158 append(files[index].getAbsolutePath()); 159 } 160 } 161 } 162 } 163 164 167 public String getMainClassName(JBProject project, Map propertyMap) { 168 return MAIN_CLASS.getValue(propertyMap); 169 } 170 171 174 public String getParameters(JBProject project, Map propertyMap) { 175 return SysEnvPropertiesProvider.getInstance().replaceEnvVariables(JB_PARAMS.getValue(propertyMap)); 176 } 177 178 181 public String getVMParameters(JBProject project, Map propertyMap) { 182 return SysEnvPropertiesProvider.getInstance().replaceEnvVariables(VM_PARAMS.getValue(propertyMap)); 183 } 184 } 185 | Popular Tags |