Package scalaExec.ClassLoaders

Examples of scalaExec.ClassLoaders.ExtensionClassLoader


         fileStr.append(File.pathSeparator+(String)ce);
    }
    GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString());
   
      ClassLoader parentClassLoader = getClass().getClassLoader();
      GlobalValues.extensionClassLoader = new  ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader);
      
      // update GUI components to account for the updated ScalaSci classpath
                scalaExec.scalaLab.scalaLab.updateTree();
               
      boolean compilationSucccess = true;
  
      String tempFileName = "";
tempFileName = javaFile+".java";   // public classes and Java files should have the same name

      String [] command  = new String[6];
       command[0] "javac";
       command[1] = "-cp";
       command[2] =  GlobalValues.jarFilePath+File.pathSeparator+GlobalValues.homeDir;
       command[3] = "-d";   // where to place output class files
       command[4] = SelectedFilePathOnly;   //  the path to save the compiled class files
       command[5] =  javaFile;  // full filename to compile

       String compileCommandString = command[0]+"  "+command[1]+"  "+command[2]+" "+command[3]+" "+command[4]+" "+command[5];

       System.out.println("compileCommand Java= "+compileCommandString);

            try {
                Runtime rt = Runtime.getRuntime();
                Process javaProcess = rt.exec(command);
                // an error message?
                StreamGobbler errorGobbler = new StreamGobbler(javaProcess.getErrorStream(), "ERROR");

                // any output?
                StreamGobbler outputGobbler = new StreamGobbler(javaProcess.getInputStream(), "OUTPUT");

                // kick them off
                errorGobbler.start();
                outputGobbler.start();

                // any error???
                javaProcess.waitFor();
                int rv = javaProcess.exitValue();
                String commandString = command[0]+"  "+command[1]+"  "+command[2];
                if (rv==0) {
                 System.out.println("Process:  "+commandString+"  exited successfully ");
                  generateScriptCodeButton.setEnabled(true);
                   statusAreaBottom.setText("Step5:  You can proceed now to create a draft script that utilizes your Java-based  ODE integrator");
                }
                else
                 System.out.println("Process:  "+commandString+"  exited with error, error value = "+rv);

                } catch (IOException exio) {
                    System.out.println("IOException trying to executing "+command);
                    exio.printStackTrace();

                }
               catch (InterruptedException ie) {
                    System.out.println("Interrupted Exception  trying to executing "+command);
                    ie.printStackTrace();
                }
  
                    }
         });
        
                 // Compile with the internal compiler
                 compileJavaInternalCompilerButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
        String currentWorkingDirectory = GlobalValues.workingDir;
          JFileChooser chooser = new JFileChooser(currentWorkingDirectory);
          int ret = chooser.showOpenDialog(ODEWizardFrame);

          if (ret != JFileChooser.APPROVE_OPTION) {
                return;
              }
         File f = chooser.getSelectedFile();
         String javaFile=null;
         try {
            javaFile = f.getCanonicalPath();
            }
         catch (IOException ex) {
               System.out.println("I/O Exception in getCanonicalPath");
               ex.printStackTrace();
         }

   //   extract the path specification of the generated Java class that implements the ODE solution method,
  //    in order to update the ScalaSci class path
      String SelectedFileWithPath = f.getAbsolutePath();
      String SelectedFilePathOnly = SelectedFileWithPath.substring(0, SelectedFileWithPath.lastIndexOf(File.separatorChar));

      if (GlobalValues.ScalaSciClassPath.length()==0)
          GlobalValues.ScalaSciClassPath=".";
      if (GlobalValues.ScalaSciClassPath.indexOf(SelectedFilePathOnly)==-1)  {
        GlobalValues.ScalaSciClassPathComponents.add(0,SelectedFilePathOnly);
        GlobalValues.ScalaSciClassPath = GlobalValues.ScalaSciClassPath+File.pathSeparator+SelectedFilePathOnly;
        }
          // update also the ScalaSciClassPath property
      StringBuilder fileStr = new StringBuilder();
      Enumeration enumDirs = GlobalValues.ScalaSciClassPathComponents.elements();
      while (enumDirs.hasMoreElements())  {
         Object ce = enumDirs.nextElement();
         fileStr.append(File.pathSeparator+(String)ce);
    }
    GlobalValues.settings.setProperty("ScalaSciClassPath", fileStr.toString());

      ClassLoader parentClassLoader = getClass().getClassLoader();
      GlobalValues.extensionClassLoader = new  ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader);

      // update GUI components to account for the updated ScalaSci classpath
                scalaExec.scalaLab.scalaLab.updateTree();
               
      String [] command  = new String[11];
View Full Code Here


                return;
            }
       File f = chooser.getSelectedFile();
      
                JavaCompile javaCompileObj = new JavaCompile();
                ExtensionClassLoader  extClassLoader = GlobalValues.extensionClassLoader;
                String javaFile = f.getAbsolutePath();
                String packageName = "";   // do not place the new Java Classes within some package !!
               if (javaFile.indexOf(".java")!=-1)  {   // file is a Java source file
         boolean compilationResult = javaCompileObj.compileFile(javaFile);
         if (compilationResult == true// success
         {
             System.out.println("Compilation success for file "+packageName+"."+javaFile);
             int lastPos = javaFile.length()-5// for ".java"
             String withoutExtJavaStr = javaFile.substring(0, lastPos);

                     // the class name without the path component
             String  classNameToLoad =withoutExtJavaStr.substring(withoutExtJavaStr.lastIndexOf(File.separatorChar)+1, withoutExtJavaStr.length());
             int javaNameIdx = javaFile.indexOf(classNameToLoad);
             String pathToAdd = javaFile.substring(0, javaNameIdx-1);   // path to add the the extension class loader class path
             extClassLoader.extendClassPath(pathToAdd)// append the path
                      
           try {   // try to load the class
                        Class  loadedClass = extClassLoader.loadClass(classNameToLoad);
                        Method m = null;
                        // used for invoking the main method of a Java class
                        try {
                            m = loadedClass.getMethod("main", formals);
                        }
View Full Code Here

           JMenuItem compileRunItem = new JMenuItem("Compile .java file and run");
           compileRunItem.setFont(scalaExec.Interpreter.GlobalValues.puifont);
           compileRunItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                GlobalValues.extensionClassLoader = new ExtensionClassLoader(GlobalValues.ScalaSciClassPath);
                JavaCompile javaCompileObj = new JavaCompile();
                ExtensionClassLoader  extClassLoader = GlobalValues.extensionClassLoader;
                String selectedValue = scalaLabPathsListener.selectedValue;
                String  pathComponent = selectedValue.substring(0, selectedValue.lastIndexOf(File.separatorChar));
                GlobalValues.selectedExplorerPath = pathComponent;
                String javaFile = selectedValue;
                String packageName = "";   // do not place the new Java Classes within some package !!
View Full Code Here

        super("Load  All Classes from ScalaSciClassPath");
    }
   
    public  void actionPerformed(ActionEvent e)  {
       
                 ExtensionClassLoader  extClassLoader = new ExtensionClassLoader(GlobalValues.ScalaSciClassPath);
                
                 Enumeration enumElem = GlobalValues.ScalaSciClassPathComponents.elements();
        while  (enumElem.hasMoreElements())  {   // for all ScalaSciClassPath Components
               Object next = (Object)enumElem.nextElement();
                    String pathName = next.toString().trim();
                     File dir = new File(pathName);
                     String[] files = dir.list();
                     if (files != null) { 
              for (int k=0; k<files.length; k++)  {   // for all files in the current directory
                      String currentFile = files[k];
                     
                    int idx  = currentFile.indexOf(".class");
                    int idxOfBackup = currentFile.indexOf("~")// avoid using backup UNIX style files
                    if (idx != -1 && idxOfBackup==-1)  {  // file is a .class file
                        String  classNameToLoad = currentFile.substring(0, idx);
                        try {
                        Class  loadedClass = extClassLoader.loadClass(classNameToLoad);
                        Method m = null;
                        try {
                            m = loadedClass.getMethod("main", scalaExec.scalaLab.scalaLab.formals);
                        }
                        catch (NoSuchMethodException exc) {
                            System.out.println(" no main in  "+classNameToLoad);
                            exc.printStackTrace();
                            break;
                        }
                       
                        try {
                            m.invoke(null, scalaExec.scalaLab.scalaLab.actuals);
                        }
                        catch (Exception exc)  {
                            exc.printStackTrace();
                          }
                        }
                       
                        catch (ClassNotFoundException ex)  {
                            System.out.println("Class: "+classNameToLoad+" not found");
                            ex.printStackTrace();
                        }
                        System.out.println("pathName ="+pathName);
                    }   // file is a .class file
                   
                    int javaIdx = currentFile.indexOf(".java");
                    idxOfBackup = currentFile.indexOf("~");
                    if (javaIdx != -1 && idxOfBackup==-1)  {
                      JavaCompile javaCompileObj = new JavaCompile();
       
         String packageName = "";
         String javaFile = pathName+File.separatorChar+currentFile; 
         boolean compilationResult = javaCompileObj.compileFile(javaFile);
         if (compilationResult == true// success
         {
             System.out.println("Compilation success for file "+packageName+"."+javaFile);
             int lastPos = javaFile.length()-5// for ".java"
             String  classNameToLoad = javaFile.substring(javaFile.lastIndexOf(File.separatorChar)+1, lastPos);
                      
           try {   // try to load the class
                        Class  loadedClass = extClassLoader.loadClass(classNameToLoad);
                        Method m = null;
                        try {
                            m = loadedClass.getMethod("main", scalaExec.scalaLab.scalaLab.formals);
                        }
                        catch (NoSuchMethodException exc) {
View Full Code Here

         fileStr.append(File.pathSeparator+(String)ce.toString().trim());
    }
    GlobalValues.settings.setProperty("ScalaSciClassPathProp", fileStr.toString());
   
      ClassLoader parentClassLoader = getClass().getClassLoader();
      GlobalValues.extensionClassLoader = new  ExtensionClassLoader(GlobalValues.ScalaSciClassPath, parentClassLoader);
     
   
                    scalaExec.scalaLab.scalaLab.updateTree();
                   
                }
View Full Code Here

TOP

Related Classes of scalaExec.ClassLoaders.ExtensionClassLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.