Using external class files within a script.

Help
ajaynad
2008-07-01
2013-05-08
  • ajaynad

    ajaynad - 2008-07-01

    Hello,
    First of all, let me congratulate you for creating an excellent scripting for eclipse. I love groovy and your plugin rocks! I was thinking of coming up with something similar to that and I find yours. Hats off!! once again.

    I was playing with your plugin and there were some issues I faced. I am elucidating them below,

    *) Static imports dont work. They throw up compilation issues.
    *) I want to access some classes in a jar file. How do I do that ? I tried adding the jar to
    the PATH variable it did not work. How can I solve this situation ?

    Thanks,
    Ajay

     
    • James E. Ervin

      James E. Ervin - 2008-07-01

      First off thanks for giving groovy monkey a look.  Ok I want you to check a couple of things.

      Things to check:
      1. Make sure the you don't have the plugin Eclipse Monkey installed.  This is probably not your problem, but it bears mentioning.
      2. I am not sure static imports are supported.  Check your version of the org.codehaus.groovy plugin and see it matches the version of Groovy that supports that feature.
      3. This one is easy.  Groovy Monkey has an 'Include' metadata keyword.  From there you can add class folders or jars.  The only limitation is that the jar file must be in the workspace.  You can include it in a project in your workspace or externally link it in.  From the groovy monkey editor, just right click and select the 'Include' option and it should work.  Btw, I have unit tests to back this one up.

      Thanks again,
      James

       
  • François Rey

    François Rey - 2011-03-09

    Hello,
    I'm having issues using external classes even though I used the Include: directive to include the build dir or the jar from a workspace project. It's like the Include directive is broken.
    I finally copied the code I needed inside my gm script and got it working this way. But I shouldn't really.
    I'm on eclipse 3.6.2 on linux 64bit.
    Groovy Monkey 0.6.1
    Groovy-Eclipse Feature 2.1.2.xx-20110307-1500-e36
      which includes org.codehouse.groovy 1.6.7 and 1.7.8
    Maybe some incompatibility with latest groovy or groovy-eclipse plugin?

     
  • François Rey

    François Rey - 2011-03-10

    Here's how to reproduce my case where Include does not work.
    1. Import the JSAP project in the workspace.
    2. Add the following script:

    /*
     * Menu: UseJSAP
     * Script-Path: /GroovyMonkeyScripts/monkey/UseJSAP.gm
     * Kudos: fmjrey
     * License: EPL 1.0
     * Include: /JSAP/build
     */
    import com.martiansoftware.jsap.stringparsers.ColorStringParser
    

    3. run the script and obserbve failure:

    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    UseJSAP.groovy: 9: unable to resolve class com.martiansoftware.jsap.stringparsers.ColorStringParser
     @ line 9, column 1.
       import com.martiansoftware.jsap.stringparsers.ColorStringParser
       ^
    1 error
        at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
        at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:828)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:511)
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:487)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
        at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:297)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:279)
        at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:614)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:595)
        at org.codehaus.groovy.bsf.GroovyEngine.eval(GroovyEngine.java:95)
        at org.codehaus.groovy.bsf.GroovyEngine.apply(GroovyEngine.java:73)
        at org.apache.bsf.BSFManager$1.run(BSFManager.java:215)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.bsf.BSFManager.apply(BSFManager.java:212)
        at net.sf.groovyMonkey.lang.MonkeyScript.run(MonkeyScript.java:233)
        at net.sf.groovyMonkey.RunMonkeyScript.runScript(RunMonkeyScript.java:238)
        at net.sf.groovyMonkey.RunMonkeyScript.runScript(RunMonkeyScript.java:214)
        at net.sf.groovyMonkey.RunMonkeyScript$3.run(RunMonkeyScript.java:175)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
    
     
  • François Rey

    François Rey - 2011-03-10

    I solved my problem.
    First, the JSAP project was located outside my workspace. I knew that for "Include:" to work the target should be in a project from the workspace, but I didn't know I had to take this literally: it should be under the workspace directory on the file system, not elsewhere.
    To remove this limitation I looked up the code and managed to remove this limitation.
    The change is limited to the function net.sf.groovyMonkey.lang.MonkeyScript.getIncludes(ScriptMetadata) which should have the following code:

                final IFile ifile = getWorkspace().getRoot().getFile(new Path(include));
                try
                {
                    final URI uri = ifile.getRawLocationURI();
                    final File file = new File( uri );
                    final URL url = file.isDirectory() ? new URL( addSlash( uri.toString() ) ): uri.toURL();
                    includes.add( url );
                }
    
     
  • James E. Ervin

    James E. Ervin - 2011-04-27

    Thanks for the heads up, I am sorry I did not reply sooner.  I will look at your patch and see about including it in a new release.

    I have also been wanting better integration with the Eclipse JDT to allow you to just specify an eclipse java project in your workspace as a dependency and then automatically slurp in all its dependencies through its classpath configuration.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks