You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by DECLOEDT Loic EVADERIS <Lo...@cea.fr> on 2016/03/23 10:01:57 UTC

Groovy runtime issue with multiple directories install

Hi,
I have a problem starting up a groovy project structured like this:
project/
 classes/
   person/
      C1.groovy
  scripts
   run.groovy

The C1.groovy file contains the following code:
package person
import groovy.transform.ToString

@ToString
class C1 {
  enum Gender { M, F}

  String name
  Sex gender
}

And the run.groovy file contains the following code:
import person.C1
//import person.C1.Gender
def m = person.C1.Gender.M
def f = person.C1.Gender.F
println "genders: ${m}, ${f}"

abstract class CScript extends groovy.lang.Script {
  public C1 addC1(String name, person.C1.Gender g) {
    return new C1(name:name, gender:g)
  }
}

def c = new C1(name: "max", gender: person.C1.Gender.M)

println "c = ${c}"

I have the following error when executing this code with the following command from the project dir:
groovy -cp $PWD/classes scripts/run.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/ldecloed/Groovy/workspace/issueImportEnum/scripts/run.groovy: 13: unable to resolve class person.C1.Sex
 @ line 13, column 32.
     public C1 addC1(String name, person.C1.Sex g) {
                                  ^

1 error

However, all errors disapear when commenting out the whole CScript class declaration.  As a result, the person.C1.Sex enum can be used outside the CScript class declaration but not inside.
In addtion, I tested a static compilation of the whole code and it works correctly in this case.
Can you clarify whether this code is valid ? If so, do you plan to improve groovy to support it ?
This test has been made with groovy 2.4.6. I can provide the sources if you want a test-case.

Regards,
Loïc.

--
Loïc Decloedt
CAD & Software Manager
eVaderis
[eVaderis-logo-CMJN-small1]

Minatec Entreprise BHT
7, Parvis Louis Néel
38054 Grenoble Cedex 9
France
Office : 04 38 7 80874


RE: Groovy runtime issue with multiple directories install

Posted by DECLOEDT Loic EVADERIS <Lo...@cea.fr>.
Joechen,
I am executing groovy directly on the .groovy files without prior compilation. Therefore, there is no intermediate class files that can mess around, unless I am missing something. You will find my project in the attached archive to allow you testing it.
Apart from that, I have been able to make it work by following these steps:
- compile each groovy file with groovyc.
- execute Java on the compiled files with the groovy jar in the class-path.

Hope this helps,
Loïc


On 23.03.2016 10:35, DECLOEDT Loic EVADERIS wrote:
> Hi Joechen, Simon,
> Yes, my first e-mail contained some typos. Please refer to the second one for a consistent explanation. Sorry for the confusion.
> I can also join my source project if you wish.
[...]
> -----Message d'origine-----
> De : Jochen Theodorou [mailto:blackdrag@gmx.org] Envoyé : mercredi 23 
> mars 2016 10:28 À : users@groovy.apache.org Objet : Re: Groovy runtime 
> issue with multiple directories install
[...]
> So did you ensure that there are no .class files of the classes you want to execute in the directories you include in the class path?
[...]

This part of the message is still valid and open. Sharing the source would help though

bye Jochen

Re: Groovy runtime issue with multiple directories install

Posted by Jochen Theodorou <bl...@gmx.org>.

On 23.03.2016 10:35, DECLOEDT Loic EVADERIS wrote:
> Hi Joechen, Simon,
> Yes, my first e-mail contained some typos. Please refer to the second one for a consistent explanation. Sorry for the confusion.
> I can also join my source project if you wish.
[...]
> -----Message d'origine-----
> De : Jochen Theodorou [mailto:blackdrag@gmx.org]
> Envoyé : mercredi 23 mars 2016 10:28
> À : users@groovy.apache.org
> Objet : Re: Groovy runtime issue with multiple directories install
[...]
> So did you ensure that there are no .class files of the classes you want to execute in the directories you include in the class path?
[...]

This part of the message is still valid and open. Sharing the source 
would help though

bye Jochen

RE: Groovy runtime issue with multiple directories install

Posted by DECLOEDT Loic EVADERIS <Lo...@cea.fr>.
Hi Joechen, Simon,
Yes, my first e-mail contained some typos. Please refer to the second one for a consistent explanation. Sorry for the confusion.
I can also join my source project if you wish.

Regards,

Loïc

-----Message d'origine-----
De : Jochen Theodorou [mailto:blackdrag@gmx.org] 
Envoyé : mercredi 23 mars 2016 10:28
À : users@groovy.apache.org
Objet : Re: Groovy runtime issue with multiple directories install



On 23.03.2016 10:01, DECLOEDT Loic EVADERIS wrote:
> Hi,
>
> I have a problem starting up a groovy project structured like this:
>
> project/
>
>   classes/
>
>     person/
>
>        C1.groovy
>
>    scripts
>
>     run.groovy
>
> The C1.groovy file contains the following code:
>
> package person
>
> import groovy.transform.ToString
>
> @ToString
>
> class C1 {
>
>    enum Gender { M, F}
>
>    String name
>
>    Sex gender
>
> }
[...]
>    public C1 addC1(String name, person.C1.Gender g) {
[...]
> org.codehaus.groovy.control.MultipleCompilationErrorsException: 
> startup
> failed:
>
> /home/ldecloed/Groovy/workspace/issueImportEnum/scripts/run.groovy: 13:
> unable to resolve class person.C1.Sex
>
>   @ line 13, column 32.
>
>       public C1 addC1(String name, person.C1.Sex g) {
>
>                                    ^

the code you show here and the code the error marks are clearly different ones. The class Sex is missing in C1 and the add method you showed uses Gender instead of Sex. If you compiled against an old version with partial changes such an error would not be surprising at all.

And actually that can be more than just differing version in source, it can also be caused by old class files. So did you ensure that there are no .class files of the classes you want to execute in the directories you include in the class path? Because if there are class files laying around it is very possible groovy will pick them up instead of the source. Normally this is controlled by the modification date of the files, but I don't know if that information is reliable on your system.

bye Jochen


Re: Groovy runtime issue with multiple directories install

Posted by Jochen Theodorou <bl...@gmx.org>.

On 23.03.2016 10:01, DECLOEDT Loic EVADERIS wrote:
> Hi,
>
> I have a problem starting up a groovy project structured like this:
>
> project/
>
>   classes/
>
>     person/
>
>        C1.groovy
>
>    scripts
>
>     run.groovy
>
> The C1.groovy file contains the following code:
>
> package person
>
> import groovy.transform.ToString
>
> @ToString
>
> class C1 {
>
>    enum Gender { M, F}
>
>    String name
>
>    Sex gender
>
> }
[...]
>    public C1 addC1(String name, person.C1.Gender g) {
[...]
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
>
> /home/ldecloed/Groovy/workspace/issueImportEnum/scripts/run.groovy: 13:
> unable to resolve class person.C1.Sex
>
>   @ line 13, column 32.
>
>       public C1 addC1(String name, person.C1.Sex g) {
>
>                                    ^

the code you show here and the code the error marks are clearly 
different ones. The class Sex is missing in C1 and the add method you 
showed uses Gender instead of Sex. If you compiled against an old 
version with partial changes such an error would not be surprising at all.

And actually that can be more than just differing version in source, it 
can also be caused by old class files. So did you ensure that there are 
no .class files of the classes you want to execute in the directories 
you include in the class path? Because if there are class files laying 
around it is very possible groovy will pick them up instead of the 
source. Normally this is controlled by the modification date of the 
files, but I don't know if that information is reliable on your system.

bye Jochen


RE: Groovy runtime issue with multiple directories install

Posted by "Marshall, Simon" <Si...@misys.com>.
The name of the enum is Gender, not Sex, so the decl of gender in C1 looks dubious.  The error message (referring to Sex) doesn’t match the code (using Gender), so I’m wondering if the error message wasn’t a result of the version of the code you pasted below?

From: DECLOEDT Loic EVADERIS [mailto:Loic.DECLOEDT@cea.fr]
Sent: 23 March 2016 09:02
To: users@groovy.apache.org
Cc: PAOLI Pierre EVADERIS; GUIU Vincent EVADERIS
Subject: Groovy runtime issue with multiple directories install

Hi,
I have a problem starting up a groovy project structured like this:
project/
 classes/
   person/
      C1.groovy
  scripts
   run.groovy

The C1.groovy file contains the following code:
package person
import groovy.transform.ToString

@ToString
class C1 {
  enum Gender { M, F}

  String name
  Sex gender
}

And the run.groovy file contains the following code:
import person.C1
//import person.C1.Gender
def m = person.C1.Gender.M
def f = person.C1.Gender.F
println "genders: ${m}, ${f}"

abstract class CScript extends groovy.lang.Script {
  public C1 addC1(String name, person.C1.Gender g) {
    return new C1(name:name, gender:g)
  }
}

def c = new C1(name: "max", gender: person.C1.Gender.M)

println "c = ${c}"

I have the following error when executing this code with the following command from the project dir:
groovy -cp $PWD/classes scripts/run.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/ldecloed/Groovy/workspace/issueImportEnum/scripts/run.groovy: 13: unable to resolve class person.C1.Sex
 @ line 13, column 32.
     public C1 addC1(String name, person.C1.Sex g) {
                                  ^

1 error

However, all errors disapear when commenting out the whole CScript class declaration.  As a result, the person.C1.Sex enum can be used outside the CScript class declaration but not inside.
In addtion, I tested a static compilation of the whole code and it works correctly in this case.
Can you clarify whether this code is valid ? If so, do you plan to improve groovy to support it ?
This test has been made with groovy 2.4.6. I can provide the sources if you want a test-case.

Regards,
Loïc.

--
Loïc Decloedt
CAD & Software Manager
eVaderis
[eVaderis-logo-CMJN-small1]

Minatec Entreprise BHT
7, Parvis Louis Néel
38054 Grenoble Cedex 9
France
Office : 04 38 7 80874

"Misys" is the trade name of the Misys group of companies. This email and any attachments have been scanned for known viruses using multiple scanners. This email message is intended for the named recipient only. It may be privileged and/or confidential. If you are not the named recipient of this email please notify us immediately and do not copy it or use it for any purpose, nor disclose its contents to any other person. This email does not constitute the commencement of legal relations between you and Misys. Please refer to the executed contract between you and the relevant member of the Misys group for the identity of the contracting party with which you are dealing.