1 22 package org.jboss.services.deployment; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.URL ; 27 28 import org.jboss.logging.Logger; 29 import org.jboss.system.server.ServerConfig; 30 import org.jboss.system.server.ServerConfigLocator; 31 import org.jboss.util.file.Files; 32 33 39 public final class LibraryManager 40 { 41 43 44 private static final Logger log = Logger.getLogger(LibraryManager.class); 45 46 47 private static final LibraryManager INSTANCE = new LibraryManager(); 48 49 51 52 File serverLibDir; 53 54 55 File serverTmpDir; 56 57 59 65 private LibraryManager() 66 { 67 ServerConfig config = ServerConfigLocator.locate(); 69 URL serverLibURL = config.getServerLibraryURL(); 70 71 if (serverLibURL != null && serverLibURL.getProtocol().startsWith("file")) 72 { 73 this.serverLibDir = new File (serverLibURL.getFile()); 74 this.serverTmpDir = config.getServerTempDir(); 75 log.debug("Using serverLibDir: " + this.serverLibDir); 76 log.debug("Using serverTmpDir: " + this.serverTmpDir); 77 } 78 else 79 { 80 log.info("Cannot manage remote serverLibraryURL: " + serverLibURL); 81 } 82 } 83 84 86 89 public static LibraryManager getInstance() 90 { 91 return INSTANCE; 92 } 93 94 104 public boolean uploadLibrary(URL src, String filename) 105 { 106 if (src != null) 107 { 108 log.debug("Uploading from URL: " + src); 109 if (filename == null || filename.equals("")) 110 { 111 filename = (new File (src.getPath())).getName(); 113 log.debug("Null or empty target filename, using basename: " + filename); 114 } 115 else 116 { 117 log.debug("Using target filename: " + filename); 118 } 119 File target = new File (this.serverLibDir, filename); 121 if (!target.exists()) 122 { 123 try 124 { 125 Files.copy(src, target); 126 return true; } 128 catch (IOException e) 129 { 130 log.warn("Could not upload target library: " + filename, e); 131 } 132 } 133 else 134 { 135 log.warn("Target library exists: " + filename); 136 } 137 } 138 else 139 { 140 log.warn("Null src URL"); 141 } 142 return false; 144 } 145 } 146 | Popular Tags |