Changeset 2430


Ignore:
Timestamp:
11/08/09 21:18:37 (2 years ago)
Author:
mswertz
Message:

bugfix: works now for eclipse (file) and netbeans/maven (jar)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molgenis/3.3/src/org/molgenis/generators/server/MolgenisResourceCopyGen.java

    r2423 r2430  
    2929public class MolgenisResourceCopyGen extends Generator 
    3030{ 
    31     public static final String RESOURCE_FOLDER = "org/molgenis/framework/ui/res/"; 
     31        public static final String RESOURCE_FOLDER = "org/molgenis/framework/ui/res/"; 
     32 
    3233        @Override 
    3334        public String getDescription() 
     
    3940        public void generate(Model model, MolgenisOptions options) throws Exception 
    4041        { 
    41             String jarPath = getClass().getResource("").getFile(); 
    42             jarPath = jarPath.split("!")[0].split("file:")[1]; 
     42                String jarPath = getClass().getResource("").getFile(); 
    4343 
    44             File target = new File(this.getWebserverPath(options) + "/generated-res"); 
     44                // System.out.println(jarPath); 
     45                if (jarPath.contains("!")) 
     46                { 
    4547 
     48                        jarPath = jarPath.split("!")[0].split("file:")[1]; 
    4649 
    47             //check if the target exists otherwise it's created 
    48             if(!target.exists()) { 
    49                 boolean succes = target.mkdirs(); 
    50                 if(!succes) 
    51                     throw new Exception("can't create /generated-res directory!"); 
    52             } 
     50                        File target = new File(this.getWebserverPath(options) + "/generated-res"); 
    5351 
    54             JarFile jar = new JarFile(jarPath); 
    55             Enumeration entries = jar.entries(); 
    56             while(entries.hasMoreElements()) { 
    57                 JarEntry file = (JarEntry) entries.nextElement(); 
    58                 if(file.getName().contains(RESOURCE_FOLDER)) { 
    59                     if(!file.isDirectory()) { 
    60                         ZipEntry zipEntry = jar.getEntry(file.getName()); 
    61                         InputStream is = jar.getInputStream(zipEntry); 
    62                         String outFilePath = file.getName().replace(RESOURCE_FOLDER, target.getPath() + File.separator); 
    63                         System.out.println(outFilePath); 
     52                        // check if the target exists otherwise it's created 
     53                        if (!target.exists()) 
     54                        { 
     55                                boolean succes = target.mkdirs(); 
     56                                if (!succes) throw new Exception("can't create /generated-res directory!"); 
     57                        } 
    6458 
    65                         File dst = new File(outFilePath); 
    66                         dst.mkdirs(); 
    67                         if(dst.exists()) { 
    68                             dst.delete(); 
     59                        JarFile jar = new JarFile(jarPath); 
     60                        Enumeration entries = jar.entries(); 
     61                        while (entries.hasMoreElements()) 
     62                        { 
     63                                JarEntry file = (JarEntry) entries.nextElement(); 
     64                                if (file.getName().contains(RESOURCE_FOLDER)) 
     65                                { 
     66                                        if (!file.isDirectory()) 
     67                                        { 
     68                                                ZipEntry zipEntry = jar.getEntry(file.getName()); 
     69                                                InputStream is = jar.getInputStream(zipEntry); 
     70                                                String outFilePath = file.getName().replace(RESOURCE_FOLDER, target.getPath() + File.separator); 
     71                                                System.out.println(outFilePath); 
     72 
     73                                                File dst = new File(outFilePath); 
     74                                                dst.mkdirs(); 
     75                                                if (dst.exists()) 
     76                                                { 
     77                                                        dst.delete(); 
     78                                                } 
     79                                                dst.createNewFile(); 
     80                                                copyFile(outFilePath, is, dst); 
     81                                        } 
     82                                } 
    6983                        } 
    70                         dst.createNewFile(); 
    71                         copyFile(outFilePath, is, dst); 
    72                     } 
     84 
     85                        logger.info("generated " + target); 
    7386                } 
    74             } 
    75             logger.info("generated " + target); 
     87                else 
     88                { 
     89                        // copy the images/scripts/css 
     90                        File source = new File(MolgenisOriginalStyle.class.getResource("res").getFile()); 
     91                        File target = new File(this.getWebserverPath(options) + "/generated-res"); 
     92 
     93                        // deledeleteDirectory(target); 
     94                        copyDirectory(source, target); 
     95                        logger.info("generated " + target); 
     96                } 
    7697        } 
    7798 
    78         public void copyFile(String srcPath, InputStream in, File dst) throws IOException { 
     99        public void copyFile(String srcPath, InputStream in, File dst) throws IOException 
     100        { 
    79101                OutputStream out = new FileOutputStream(dst); 
    80102 
     
    133155        { 
    134156 
    135  
    136157                if (!src.getAbsolutePath().contains(".svn") && !dst.exists()) 
    137158                { 
Note: See TracChangeset for help on using the changeset viewer.