Changeset 2422
- Timestamp:
- 11/06/09 17:32:16 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molgenis/3.3/src/org/molgenis/generators/server/MolgenisResourceCopyGen.java
r2347 r2422 1 1 package org.molgenis.generators.server; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.File; 4 5 import java.io.FileInputStream; 5 6 import java.io.FileOutputStream; 7 import java.io.FileWriter; 6 8 import java.io.IOException; 7 9 import java.io.InputStream; 10 import java.io.InputStreamReader; 8 11 import java.io.OutputStream; 9 12 13 import java.io.StringReader; 14 import java.net.URL; 15 import java.nio.channels.Channel; 16 import java.nio.channels.FileChannel; 17 import java.nio.channels.ReadableByteChannel; 18 import java.util.Enumeration; 19 import java.util.jar.Attributes; 20 import java.util.jar.JarEntry; 21 import java.util.jar.JarFile; 22 import java.util.zip.ZipEntry; 10 23 import org.molgenis.Molgenis; 11 24 import org.molgenis.MolgenisOptions; … … 16 29 public class MolgenisResourceCopyGen extends Generator 17 30 { 31 public static final String RESOURCE_FOLDER = "org/molgenis/framework/ui/res/"; 18 32 @Override 19 33 public String getDescription() … … 25 39 public void generate(Model model, MolgenisOptions options) throws Exception 26 40 { 27 // copy the images/scripts/css 28 File source = new File(MolgenisOriginalStyle.class.getResource("res").getFile()); 29 File target = new File(this.getWebserverPath(options) + "/generated-res"); 41 String jarPath = getClass().getResource("").getFile(); 42 jarPath = jarPath.split("!")[0].split("file:")[1]; 43 44 // copy the images/scripts/css 45 File source = new File(jarPath); 46 File target = new File(this.getWebserverPath(options) + "/generated-res"); 30 47 31 // deledeleteDirectory(target); 32 copyDirectory(source, target); 33 logger.info("generated " + target); 48 URL url = MolgenisOriginalStyle.class.getResource(""); 49 url.toString(); 34 50 35 // copy the libs etc 36 // source = new File(new 37 // File(MolgenisFactory.class.getResource("").getFile()).getParentFile().getParentFile() 38 // .getParentFile() 39 // + "/lib"); 40 // // check folder lib 41 // if (source.exists()) 42 // { 43 // target = new File(this.getWebserverPath(options) + "/WEB-INF/lib/"); 44 // copyDirectory(source, target); 45 // } 51 //check if the target exists otherwise it's created 52 if(!target.exists()) { 53 boolean succes = target.mkdirs(); 54 if(!succes) 55 throw new Exception("can't create /generated-res directory!"); 56 } 46 57 47 logger.info("generated " + target); 58 JarFile jar = new JarFile(jarPath); 59 Enumeration entries = jar.entries(); 60 while(entries.hasMoreElements()) { 61 JarEntry file = (JarEntry) entries.nextElement(); 62 if(file.getName().contains(RESOURCE_FOLDER)) { 63 if(!file.isDirectory()) { 64 ZipEntry zipEntry = jar.getEntry(file.getName()); 65 InputStream is = jar.getInputStream(zipEntry); 66 String outFilePath = file.getName().replace(RESOURCE_FOLDER, target.getPath() + File.separator); 67 System.out.println(outFilePath); 68 69 File dst = new File(outFilePath); 70 dst.mkdirs(); 71 if(dst.exists()) { 72 dst.delete(); 73 } 74 dst.createNewFile(); 75 copyFile(outFilePath, is, dst); 76 } 77 } 78 } 79 logger.info("generated " + target); 80 } 81 82 public void copyFile(String srcPath, InputStream in, File dst) throws IOException { 83 OutputStream out = new FileOutputStream(dst); 84 85 // Transfer bytes from in to out 86 byte[] buf = new byte[1024]; 87 int len; 88 while ((len = in.read(buf)) > 0) 89 { 90 out.write(buf, 0, len); 91 } 92 in.close(); 93 out.close(); 94 logger.debug("copied " + srcPath + " to " + dst); 48 95 } 49 96 … … 89 136 public void copyFile(File src, File dst) throws IOException 90 137 { 138 139 91 140 if (!src.getAbsolutePath().contains(".svn") && !dst.exists()) 92 141 {
Note: See TracChangeset
for help on using the changeset viewer.