Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 4214

Show
Ignore:
Timestamp:
05/15/08 13:00:39 (8 months ago)
Author:
tmdugan
Message:

-- dss

* made changes to use the standard java 1.6 compiler interface to compile on the fly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/dss/metadata/config.xml

    r4102 r4214  
    77        <id>dss</id> 
    88        <name>Dss</name> 
    9         <version>2.13</version> 
     9        <version>2.14</version> 
    1010        <package>org.openmrs.module.@MODULE_ID@</package> 
    1111        <author>Vibha Anand and Tammy Dugan</author> 
  • openmrs-modules/dss/src/org/openmrs/module/dss/CompilingClassLoader.java

    r3726 r4214  
    55import java.net.URLClassLoader; 
    66import java.text.SimpleDateFormat; 
     7import java.util.ArrayList; 
     8import java.util.Arrays; 
    79import java.util.Collection; 
    810import java.util.Date; 
    911import java.util.HashSet; 
    1012import java.util.Iterator; 
     13 
     14import javax.tools.JavaCompiler; 
     15import javax.tools.JavaFileObject; 
     16import javax.tools.StandardJavaFileManager; 
     17import javax.tools.ToolProvider; 
    1118 
    1219import org.apache.commons.logging.Log; 
     
    4653        // specified in the 'javaFile' parameter. Return a true if 
    4754        // the compilation worked, false otherwise. 
    48         private boolean compile(String javaFile)  
    49         { 
     55        private boolean compile(String javaFile) 
     56        { 
     57                System.out.println("CCL: Compiling " + javaFile + "..."); 
     58 
     59                AdministrationService adminService = Context.getAdministrationService(); 
     60                String property = adminService 
     61                                .getGlobalProperty("dss.classRuleDirectory"); 
     62                String classDirectory = Util.processFileDirectory(property); 
     63 
    5064                String classpath = getClasspath(); 
    51          
    52                 // Let the user know what's going on 
    53                 System.out.println("CCL: Compiling " + javaFile + "..."); 
    54                 AdministrationService adminService = Context.getAdministrationService(); 
    55                 String property = adminService.getGlobalProperty("dss.classRuleDirectory"); 
    56                  
    57                 String classDirectory = Util.processFileDirectory(property); 
    58  
    59                 int errorCode = -1; 
     65 
    6066                try 
    6167                { 
    62                         errorCode = com.sun.tools.javac.Main.compile(new String[] 
    63                         { "-classpath", classpath, "-d", classDirectory, javaFile }); 
     68                        String[] options = new String[] 
     69                        { "-classpath", classpath, "-d", classDirectory }; 
     70 
     71                        File file = new File(javaFile); 
     72 
     73                        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 
     74                        StandardJavaFileManager fileManager = compiler 
     75                                        .getStandardFileManager(null, null, null); 
     76 
     77                        Iterable<? extends JavaFileObject> fileObjects = fileManager 
     78                                        .getJavaFileObjects(file); 
     79                        boolean success = compiler.getTask(null, fileManager, null, 
     80                                        Arrays.asList(options), null, fileObjects).call(); 
     81 
     82                        fileManager.close(); 
     83                        return success; 
    6484                } catch (Exception e) 
    6585                { 
    66                         log.error("Error compiling java rule file: "+javaFile,e); 
    67                 } 
    68  
    69                 return errorCode == 0; 
     86                        log.error("Error compiling java rule file: " + javaFile, e); 
     87                } 
     88                return false; 
    7089        } 
    7190