1 19 20 package org.netbeans.modules.j2ee.sun.ide.j2ee; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileReader ; 25 import java.io.FileWriter ; 26 import javax.enterprise.deploy.spi.DeploymentManager ; 27 import org.w3c.dom.Document ; 28 29 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 30 34 public class ConfigureProfiler { 35 36 37 private static final String ASENV_INSERTION_POINT_WIN_STRING = "set AS_JAVA"; 38 private static final String ASENV_INSERTION_POINT_NOWIN_STRING = "AS_JAVA"; 39 40 public static boolean instrumentProfilerInDOmain(DeploymentManager dm, String nativeLibraryPath, String [] jvmOptions) { 42 DomainEditor dEditor = new DomainEditor(dm); 43 44 Document domainDocument = dEditor.getDomainDocument(); 46 if (domainDocument == null) { 47 return false; 48 } 49 50 return dEditor.addProfilerElements(domainDocument, nativeLibraryPath, jvmOptions); 51 } 52 53 public static boolean removeProfilerFromDomain(DeploymentManager dm) { 55 DomainEditor dEditor = new DomainEditor(dm); 56 57 Document domainDocument = dEditor.getDomainDocument(); 59 if (domainDocument == null) { 60 return false; 61 } 62 63 return dEditor.removeProfilerElements(domainDocument); 64 } 65 66 public static boolean modifyAsEnvScriptFile( SunDeploymentManagerInterface dm, String targetJavaHomePath) { 68 69 String ext = (isUnix() ? "conf" : "bat"); 70 File irf = dm.getPlatformRoot(); 71 if (null == irf || !irf.exists()) { 72 return false; 73 } 74 String installRoot = irf.getAbsolutePath(); String asEnvScriptFilePath = installRoot+"/config/asenv." + ext; 76 File asEnvScriptFile = new File (asEnvScriptFilePath); 78 String lineBreak = System.getProperty("line.separator"); 79 80 try { 81 82 String line; 83 FileReader fr = new FileReader (asEnvScriptFile); 84 BufferedReader br = new BufferedReader (fr); 85 StringBuffer buffer = new StringBuffer (); 86 87 String asJavaString = (isUnix() ? ASENV_INSERTION_POINT_NOWIN_STRING : ASENV_INSERTION_POINT_WIN_STRING); 88 89 while ((line = br.readLine()) != null) { 91 if (line.trim().startsWith(asJavaString)) { 92 buffer.append(asJavaString + "=" + targetJavaHomePath); 93 } else { 94 buffer.append(line); 95 } 96 buffer.append(lineBreak); 97 } 98 br.close(); 99 100 FileWriter fw = new FileWriter (asEnvScriptFile); 102 fw.write(buffer.toString()); 103 fw.flush(); 104 fw.close(); 105 106 if (isUnix()) { 107 Runtime.getRuntime().exec("chmod a+r " + asEnvScriptFile.getAbsolutePath()); } 109 110 return true; 111 112 } catch (Exception ex) { 113 114 System.err.println("Modifying " + asEnvScriptFilePath + " failed!\n" + ex.getMessage()); 115 return false; 116 117 } 118 119 } 120 121 public static boolean isUnix() { 122 return File.separatorChar == '/'; 123 } 124 125 126 } 127 | Popular Tags |