Duplicate class exception: Bug with yeti ant task?

83 views
Skip to first unread message

chrisichris

unread,
Feb 17, 2011, 1:01:10 AM2/17/11
to yeti-lang
Hi,

It would be great if you could help with the following problem with
the ant-task.

I get a strange error "Duplicate class: org.yeb.json" when I use
srcdir="src/main/java" includes="**/*.yeti".

However when I use srcdir="src/main/java/org/yeb" includes="*.yeti"
everything works fine.

So the includes="**/*.yeti" does not work on a root directory. However
I organize my modules similar to java classes in different directories
depending on the modules package. And it would be great if you could
give some advice how to work around that.



I have to two yeti modules to compile in the following files:
- src/main/java/org/yeb/httpClient.yeti
- src/main/java/org/yeb/json.yeti


The httpclient module only loads the json-module.

content of org.yeb.httpclient

module org.yeb.httpclient;
load org.yeb.json;
"somm dummy string"

The json module just returns a string:
module org.yeb.json;
"some dummy string json-module";


I am using Windows.

The printed stacktrace from ant is this:

BUILD FAILED
C:\programmierung\myprojects\yeti\CompilerTest\build.xml:93:
java.lang.IllegalStateException: Duplicate class: org.yeb.json
at yeti.lang.compiler.CompileCtx.addClass(YetiCode.java:444)
at yeti.lang.compiler.YetiAnalyzer.toCode(YetiAnalyzer.java:
1543)
at yeti.lang.compiler.CompileCtx.compile(YetiCode.java:346)
at yeti.lang.compiler.CompileCtx.compile(YetiCode.java:322)
at yeti.lang.compiler.CompileCtx.compileAll(YetiCode.java:267)
at yeti.lang.compiler.YetiTask.execute(YetiTask.java:105)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
at org.apache.tools.ant.Project.executeTarget(Project.java:
1329)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
41)
at org.apache.tools.ant.Project.executeTargets(Project.java:
1212)
at org.apache.tools.ant.Main.runBuild(Main.java:801)
at org.apache.tools.ant.Main.startAnt(Main.java:218)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:
109)

Madis

unread,
Feb 18, 2011, 12:42:15 AM2/18/11
to yeti-lang

On Wed, 16 Feb 2011, chrisichris wrote:

> I get a strange error "Duplicate class: org.yeb.json" when I use
> srcdir="src/main/java" includes="**/*.yeti".
>
> However when I use srcdir="src/main/java/org/yeb" includes="*.yeti"
> everything works fine.

...


> I have to two yeti modules to compile in the following files:
> - src/main/java/org/yeb/httpClient.yeti
> - src/main/java/org/yeb/json.yeti
>
> The httpclient module only loads the json-module.
>
> content of org.yeb.httpclient
>
> module org.yeb.httpclient;
> load org.yeb.json;
> "somm dummy string"

I couldn't reproduce on Linux.

Probable workaround: make sure that module name and filename have same
capitalization (currently you have httpclient / httpClient). Let me know,
if this helps.

chrisichris

unread,
Feb 18, 2011, 1:42:46 AM2/18/11
to yeti-lang
Thanks for testing it and finding the spelling-bug but this was only
in the e-mail.

It does also here not happen always but I think only in certain file
load orders (wheter the file is first compiled because of the source-
file or because of a load module).

Anyway I thing I found the reason: it is the \ separator on windows. I
think it is (again) the windows file-separator. When the *.yeti
pattern is used no file-separator is used in the sourcename however
when **/*.yeti is used the windows separator is usedin the source-file-
names. And I guess then the filename with windows separator gets
stored as key in the CompileCtx.compiled map however when the filename
is looked up through an "load module" then the / separator is used.

Anyway if I replace all the \ in the source files with / in the
execute() method of the Ant-Task than it works.
for(int i=0;i<files.length;i++) {
files[i] = files[i].replace(File.separator, "/");
}

Btw: Why do you loop the compilation in the ant-task over the files
with compileAll?:
for (int i = 0; i < files.length; ++i)
compilation.compileAll(files, 0,
(String[]) javaOpt.toArray(new String[0]));

I am writing a MavenMojo and just want to know wheter this is
necessery.

Madis

unread,
Feb 18, 2011, 3:00:39 AM2/18/11
to yeti-lang

On Thu, 17 Feb 2011, chrisichris wrote:

> names. And I guess then the filename with windows separator gets
> stored as key in the CompileCtx.compiled map however when the filename
> is looked up through an "load module" then the / separator is used.
>
> Anyway if I replace all the \ in the source files with / in the
> execute() method of the Ant-Task than it works.
> for(int i=0;i<files.length;i++) {
> files[i] = files[i].replace(File.separator, "/");
> }

Quite a hack, but afaik shouldn't hurt.

> Btw: Why do you loop the compilation in the ant-task over the files
> with compileAll?:
> for (int i = 0; i < files.length; ++i)
> compilation.compileAll(files, 0,
> (String[]) javaOpt.toArray(new String[0]));
>

Nice catch, I've done really stupid refactoring.

commit b47a35de202ff7ad88d530a802558c9ed7181750

try {
+ String[] javaOpt = { "-encoding", "utf-8", "-d",
+ target.length() > 1 ? target : ">" };
for (int i = 0; i < files.length; ++i) {
- compilation.compile(files[i], 0);
+ compilation.compileAll(files, 0, javaOpt);
}

Commited fixes, try if the head is now ok.

chrisichris

unread,
Feb 18, 2011, 3:17:16 AM2/18/11
to yeti-lang
Thanks for the fast fix. Unfortunately I get now a "Duplicate module
name" instead of a "Duplicate class.." exception:

C:\programmierung\myprojects\yeti\CompilerTest\build.xml:93:
java.lang.RuntimeException: Duplicate module name: org/yeb/json
at yeti.lang.compiler.CompileCtx.compile(YetiCode.java:331)
at yeti.lang.compiler.CompileCtx.compile(YetiCode.java:322)
at yeti.lang.compiler.CompileCtx.compileAll(YetiCode.java:267)
at yeti.lang.compiler.YetiTask.execute(YetiTask.java:104)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)

....

By the way I have just uploaded a YetiClassLoader which compiles yeti
sources from the classpath on the fly. (I use that in a yeti-servlet
but this is not ready yet):
https://github.com/chrisichris/yeticl
Reply all
Reply to author
Forward
0 new messages