Jump to content

Difference between file and scriptmaster RegisterGroovy


This topic is 3535 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello
( excuse my english, I'm French ;) )
I use scriptmaster file to develop functions.
However, I observe that sometimes a function works fine in the file and not when I record with RegisterGroovy, and the reverse is also true.
for example this function works properly when it is saved with RegisterGroovy, not in the file.
how to develop functions properly in this uncertain environment
?
what is this error ?
the code example :
 

    import java.util.zip.ZipOutputStream  
    import java.util.zip.ZipEntry  
    import java.nio.channels.FileChannel  
     
    String zipFileName = Zip_path
    String inputDir = Dir_path  

     Try { 
    ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFileName))  
    new File(inputDir).eachFile() { file ->  
    zipFile.putNextEntry(new ZipEntry(file.getName()))  
    def buffer = new byte[1024]  
    file.withInputStream { i ->  
    def l = i.read(buffer)  
    // check whether the file is empty  
    if (l > 0) {  
    zipFile.write(buffer, 0, l)  
    }  
    } 
    zipFile.closeEntry()  
    } 
    zipFile.close()
} catch(Exception e){
         // if any error occurs
         e.printStackTrace()
}

and the error of scriptmaster file

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script1.groovy: 24: expecting EOF, found 'catch' @ line 24, column 7.

       } catch(Exception e) {

         ^
Link to comment
Share on other sites

Yes it is > thanks Clem
Now I try to inject a wrong dir path and scriptmaster file does't return any error
why ?
you develop codes preferentially with an IDE?
I just tried the groovy console and it looks to be working well


 

Link to comment
Share on other sites

removing the "e.printStackTrace ()" and replacing it with "return 'erreur'" it works and if I put 'error' scriptmaster opens an empty window :)


but it does not prevent to create an empty zip
I will see controlling the directory before with an if

Link to comment
Share on other sites

well
this code works fine without writing the zip if there's error
 

//ZipFolder ( Dir_path ; Zip_path )
    import java.util.zip.ZipOutputStream  
    import java.util.zip.ZipEntry  
    import java.nio.channels.FileChannel  
     
    try { 
   
   File f = new File ( Dir_path )
   
   if ( f.isDirectory() ) {
   
    ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(Zip_path))  
    new File(Dir_path).eachFile() { file ->  
    zipFile.putNextEntry(new ZipEntry(file.getName()))  
    def buffer = new byte[1024]  
    file.withInputStream { i ->  
    def l = i.read(buffer)  
    // check whether the file is empty  
    if (l > 0) {  
    zipFile.write(buffer, 0, l)  
    }  
    } 
    zipFile.closeEntry()  
    } 
    zipFile.close()
    }
    else {
    return "erreur"
    }
    }
    catch(Exception e) {
         // if any error occurs
    return "erreur" //e.printStackTrace()
    }
Link to comment
Share on other sites

  • 3 weeks later...

This topic is 3535 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.