1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.logging.LogDomains; 26 import com.sun.enterprise.diagnostics.DiagnosticException; 27 import com.sun.enterprise.diagnostics.ServiceConfig; 28 import com.sun.enterprise.diagnostics.CLIOptions; 29 import com.sun.enterprise.diagnostics.Constants; 30 import com.sun.enterprise.diagnostics.Data; 31 import com.sun.enterprise.diagnostics.util.FileUtils; 32 import com.sun.enterprise.diagnostics.util.DDFilter; 33 34 import java.io.IOException ; 35 import java.io.File ; 36 import java.io.FilenameFilter ; 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 44 45 public class AppInfoCollector implements Collector { 46 47 private String destFolder; 48 private String repositoryFolder; 49 private ServiceConfig config; 50 private static Logger logger = 51 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 52 57 public AppInfoCollector(String repositoryFolder, String destFolder) { 58 this.destFolder = destFolder; 59 this.repositoryFolder = repositoryFolder; 60 this.config = config; 61 } 62 63 67 public Data capture() throws DiagnosticException { 68 WritableDataImpl dataImpl = new WritableDataImpl(DataType.APPL_INFO); 69 dataImpl.addChild(captureAppRelatedInfo(Constants.GENERATED_DIR)); 70 dataImpl.addChild( 71 captureAppRelatedInfo(Constants.APPLICATIONS_DIR, 72 new DDFilter())); 73 return dataImpl; 74 } 76 82 private Data captureAppRelatedInfo(String relativePath) 83 throws DiagnosticException { 84 try { 85 String sourceFolder = repositoryFolder + File.separator + relativePath; 86 String destFileObj = destFolder + File.separator + relativePath; 87 FileUtils.copyDir(sourceFolder, destFileObj, true); 88 return new FileData(destFileObj, DataType.APPL_INFO); 89 } catch(IOException ioe) { 90 logger.log(Level.WARNING, "diagnostic-service.copy_failed" , 91 new Object []{relativePath, ioe.getMessage()}); 92 } 93 return null; 94 } 95 96 102 private Data captureAppRelatedInfo(String relativePath, 103 FilenameFilter filter) throws DiagnosticException { 104 WritableDataImpl dataImpl = new WritableDataImpl(relativePath); 105 String sourceFolderName = repositoryFolder + File.separator + relativePath; 106 107 File sourceFolder = new File (sourceFolderName); 108 String [] filteredChildren = null; 109 String [] children = null; 110 111 if (filter != null) { 114 filteredChildren = sourceFolder.list(filter); 115 } 116 118 if (filteredChildren != null) { 119 if(filteredChildren.length == 0) { 120 children = sourceFolder.list(); 121 for (int i = 0 ; i < children.length; i++) { 122 String childName = relativePath + File.separator + children[i]; 123 String absoluteChildName = repositoryFolder + File.separator + childName; 124 File child = new File (absoluteChildName); 125 if (child.isDirectory()) 126 dataImpl.addChild(captureAppRelatedInfo(childName, filter)); 127 } 128 } else { 129 for (int i = 0 ; i < filteredChildren.length; i++) { 130 String childName = relativePath + File.separator + 131 filteredChildren[i]; 132 String absoluteChildName = repositoryFolder + 133 File.separator + childName; 134 File child = new File (absoluteChildName); 135 try { 136 String dest = destFolder + File.separator + childName; 137 FileUtils.copyFile(absoluteChildName, dest); 138 dataImpl.addChild(new FileData(dest, DataType.APPL_INFO)); 139 }catch(IOException ioe) { 140 logger.log(Level.WARNING, "diagnostic-service.copy_failed" , 141 new Object []{absoluteChildName, ioe.getMessage()}); 142 } 143 } } } return dataImpl; 147 }} 149 | Popular Tags |