Different GWT compilation from Eclipse and command line

2011-11-16 Thread jogo
Hi,

I'm getting really frustrated from this, so any advice is highly
appreciated.

In my GWT project, there is a java native method that calls eval
function inside. All worked fine till I updated from 2.3.0 to 2.4.0
(on Windows XP in Eclipse). After that, when I compiled the project in
Eclipse (GWT 2.4.0) the native method stopped working and I spent
quite a lot of time figuring out what was the cause of this problem.

It turned out, that the update form 2.3.0 to 2.4.0 caused it. Then I
downgraded back to GWT SDK 2.3.0, re-configured Eclipse and then again
all worked fine.

Today I created a simple ant build script (generated from
webAppCreator app using SDK 2.3.0) and used it. And again, the problem
re-surfaced, the native method doesn't work! The ant script uses SDK
2.3.0.

The surprising thing is, that when I compile the project from Eclipse
with SDK 2.3.0 all works fine. When I compile the project from command
line using the same SDK and JRE compiled code is different and doesn't
work.

Any idea where the problem might be? Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-16 Thread Gal Dolber
I'm compiling projects using gwt trunk from ant without problem

this is my base ant script http://pastebin.com/prRQEETz

and this is how I extend it for each project http://pastebin.com/t7RLmd29

the script asume you are using lombok and it support annotation processors,
but you should be able to extract the gwt compilation part.

Hope it helps

On Wed, Nov 16, 2011 at 4:48 PM, jogo  wrote:

> Hi,
>
> I'm getting really frustrated from this, so any advice is highly
> appreciated.
>
> In my GWT project, there is a java native method that calls eval
> function inside. All worked fine till I updated from 2.3.0 to 2.4.0
> (on Windows XP in Eclipse). After that, when I compiled the project in
> Eclipse (GWT 2.4.0) the native method stopped working and I spent
> quite a lot of time figuring out what was the cause of this problem.
>
> It turned out, that the update form 2.3.0 to 2.4.0 caused it. Then I
> downgraded back to GWT SDK 2.3.0, re-configured Eclipse and then again
> all worked fine.
>
> Today I created a simple ant build script (generated from
> webAppCreator app using SDK 2.3.0) and used it. And again, the problem
> re-surfaced, the native method doesn't work! The ant script uses SDK
> 2.3.0.
>
> The surprising thing is, that when I compile the project from Eclipse
> with SDK 2.3.0 all works fine. When I compile the project from command
> line using the same SDK and JRE compiled code is different and doesn't
> work.
>
> Any idea where the problem might be? Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
Guit: Elegant, beautiful, modular and *production ready* gwt applications.

http://code.google.com/p/guit/

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-18 Thread jogo
Hi Gal, thank you for sharing the gwt ant build script.

The script wasn't the problem, I was able to compile the source with
the default ant build script. The problem was that compiled code from
Eclipse worked but from command line didn't.

Today I made some other tests and I finally I identified the problem.

I compiled the source code in Eclipse using DETAILED, PRETTY and
OBFUSCATED output. And I did the same with the ant script. Then I
compared them.

I was hoping to see some differences in Eclipse generated code and in
command line, but to my surprise all generated files were binary
identical!  => it was not problem of compiling.

Then I deployed to the test environment each version. OBFUSCATED
version failed with error. But, when I deployed PRETTY and DETAILED
versions the code worked!

So it also explains, why I wasn't getting errors from Eclipse build,
because output might have been set to PRETTY / DETAILED. Ant script by
default produces obfuscated code.


Here is a code snippet from the native method, that fails:

public static native String parseJSON(String json) /*-{
var retval = [];

try {
var x = 0;

if (json != null) {
var obj = eval( '(' + json + ')' );  < HERE IT
FAILS
var entries = obj.feed.entry;

I was getting error 'Can't find variable obj'.

I've replaced the eval function with JSON.parse method (http://
www.json.org/js.html) and included json2.js file in the entry html
file, but it is still the same. Obfuscated version doesn't work and
I'm getting the same error 'Can't find variable obj' while detailed
version works.

Any ideas?


On Nov 17, 4:08 am, Gal Dolber  wrote:
> I'm compiling projects using gwt trunk from ant without problem
>
> this is my base ant scripthttp://pastebin.com/prRQEETz
>
> and this is how I extend it for each projecthttp://pastebin.com/t7RLmd29
>
> the script asume you are using lombok and it support annotation processors,
> but you should be able to extract the gwt compilation part.
>
> Hope it helps
>
>
>
>
>
>
>
>
>
> On Wed, Nov 16, 2011 at 4:48 PM, jogo  wrote:
> > Hi,
>
> > I'm getting really frustrated from this, so any advice is highly
> > appreciated.
>
> > In my GWT project, there is a java native method that calls eval
> > function inside. All worked fine till I updated from 2.3.0 to 2.4.0
> > (on Windows XP in Eclipse). After that, when I compiled the project in
> > Eclipse (GWT 2.4.0) the native method stopped working and I spent
> > quite a lot of time figuring out what was the cause of this problem.
>
> > It turned out, that the update form 2.3.0 to 2.4.0 caused it. Then I
> > downgraded back to GWT SDK 2.3.0, re-configured Eclipse and then again
> > all worked fine.
>
> > Today I created a simple ant build script (generated from
> > webAppCreator app using SDK 2.3.0) and used it. And again, the problem
> > re-surfaced, the native method doesn't work! The ant script uses SDK
> > 2.3.0.
>
> > The surprising thing is, that when I compile the project from Eclipse
> > with SDK 2.3.0 all works fine. When I compile the project from command
> > line using the same SDK and JRE compiled code is different and doesn't
> > work.
>
> > Any idea where the problem might be? Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-web-toolkit@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-toolkit+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
> Guit: Elegant, beautiful, modular and *production ready* gwt applications.
>
> http://code.google.com/p/guit/

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-20 Thread jogo
Ok. Finally I've found the sneaky bug.

The code was failing actually later in the code where was another eval
function referencing the obj variable eval('var title =
obj.feed.entry[' + i + '].title');

Then I checked the obfuscated code and I realized that the obj
variable gets obfuscated and renamed!

Here is how to fix it:
http://code.google.com/webtoolkit/doc/1.6/FAQ_Client.html#Help!_I'm_having_problems_with_eval()_in_my_JSNI_method!

Eval function is really evil, so be careful using it in the JSNI code.
I've spent a lot of time with figuring out what caused the problem,
but lesson learned ;o)


On Nov 18, 11:50 am, jogo  wrote:
> Hi Gal, thank you for sharing the gwt ant build script.
>
> The script wasn't the problem, I was able to compile the source with
> the default ant build script. The problem was that compiled code from
> Eclipse worked but from command line didn't.
>
> Today I made some other tests and I finally I identified the problem.
>
> I compiled the source code in Eclipse using DETAILED, PRETTY and
> OBFUSCATED output. And I did the same with the ant script. Then I
> compared them.
>
> I was hoping to see some differences in Eclipse generated code and in
> command line, but to my surprise all generated files were binary
> identical!  => it was not problem of compiling.
>
> Then I deployed to the test environment each version. OBFUSCATED
> version failed with error. But, when I deployed PRETTY and DETAILED
> versions the code worked!
>
> So it also explains, why I wasn't getting errors from Eclipse build,
> because output might have been set to PRETTY / DETAILED. Ant script by
> default produces obfuscated code.
>
> Here is a code snippet from the native method, that fails:
>
>     public static native String parseJSON(String json) /*-{
>         var retval = [];
>
>         try {
>             var x = 0;
>
>             if (json != null) {
>                 var obj = eval( '(' + json + ')' );  < HERE IT
> FAILS
>                 var entries = obj.feed.entry;
>
> I was getting error 'Can't find variable obj'.
>
> I've replaced the eval function with JSON.parse method 
> (http://www.json.org/js.html) and included json2.js file in the entry html
> file, but it is still the same. Obfuscated version doesn't work and
> I'm getting the same error 'Can't find variable obj' while detailed
> version works.
>
> Any ideas?
>
> On Nov 17, 4:08 am, Gal Dolber  wrote:
>
>
>
>
>
>
>
> > I'm compiling projects using gwt trunk from ant without problem
>
> > this is my base ant scripthttp://pastebin.com/prRQEETz
>
> > and this is how I extend it for each projecthttp://pastebin.com/t7RLmd29
>
> > the script asume you are using lombok and it support annotation processors,
> > but you should be able to extract the gwt compilation part.
>
> > Hope it helps
>
> > On Wed, Nov 16, 2011 at 4:48 PM, jogo  wrote:
> > > Hi,
>
> > > I'm getting really frustrated from this, so any advice is highly
> > > appreciated.
>
> > > In my GWT project, there is a java native method that calls eval
> > > function inside. All worked fine till I updated from 2.3.0 to 2.4.0
> > > (on Windows XP in Eclipse). After that, when I compiled the project in
> > > Eclipse (GWT 2.4.0) the native method stopped working and I spent
> > > quite a lot of time figuring out what was the cause of this problem.
>
> > > It turned out, that the update form 2.3.0 to 2.4.0 caused it. Then I
> > > downgraded back to GWT SDK 2.3.0, re-configured Eclipse and then again
> > > all worked fine.
>
> > > Today I created a simple ant build script (generated from
> > > webAppCreator app using SDK 2.3.0) and used it. And again, the problem
> > > re-surfaced, the native method doesn't work! The ant script uses SDK
> > > 2.3.0.
>
> > > The surprising thing is, that when I compile the project from Eclipse
> > > with SDK 2.3.0 all works fine. When I compile the project from command
> > > line using the same SDK and JRE compiled code is different and doesn't
> > > work.
>
> > > Any idea where the problem might be? Thanks.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Google Web Toolkit" group.
> > > To post to this group, send email to google-web-toolkit@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-web-toolkit+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > Guit: Elegant, beautiful, modular and *production ready* gwt applications.
>
> >http://code.google.com/p/guit/

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-20 Thread Thomas Broyer


On Sunday, November 20, 2011 12:14:46 PM UTC+1, jogo wrote:
>
> Ok. Finally I've found the sneaky bug.
>
> The code was failing actually later in the code where was another eval
> function referencing the obj variable eval('var title =
> obj.feed.entry[' + i + '].title');
>

Any reason you're not coding this directly in JSNI, without the eval()?

var title = obj.feed.entry[i].title;

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/5oBIPEUxq9UJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-20 Thread jogo
Hi Thomas,

> Any reason you're not coding this directly in JSNI, without the eval()?
Great point. I was able to fix one JSNI function (mentioned above)
that just gets the title & id with the solution you suggested. Thank
you.

But unfortunately, there is one even more complex method, that gets
data from Google Spreadsheet feed and here I have to use the "evil"
function. These feeds are quite complex and keys in these feeds are
dynamically generated based on the names of columns in a spreadsheet.

Here is an example JSON feed:
https://spreadsheets.google.com/feeds/list/o03712292828507838454.6243940683656382600/od6/public/values?alt=json

If you check that feed you will notice, that keys where are stored
spreadsheet values are prefixed with 'gsx' + name of the column. There
are three columns in the spreadsheet - year, revenue and profit and
three corresponding JSON keys gsx$year, gsx$revenue and gsx$profit.

My code looks like this:
public static native String parseSpreadsheetFeed(String json) /*-{
if (json != null) {
var obj = JSON.parse(json);
var entries = obj.feed.entry;

// iterate over entries
for (var i in entries) {

// iterate over keys
for (var j in entries[i]) {
var prefix = j.split('$')[0];

// process only keys prefixed with 'gsx'
if (prefix == 'gsx') {
eval('var data = obj.feed.entry[' + i + '].' +
j + '.$t');
...

And here I can't just replace the eval method with:
var data = obj.feed.entry[i].j.$t;

That wouldn't work.

I could probably rewrite that method using GWT, but in Javacript it is
much more elegant code and easy to understand.

The quick & dirty solution would be to check the obfuscated code and
use the renamed variable name in eval function, e.g.:
eval('var data = f.feed.entry[' + i + '].' + j + '.$t');

And pray that the name won't change in future :o) For now it is quite
acceptable solution, because this the only place in my code where I
use this and I can put there some checks, so in future builds I will
get immediate error saying the variable name has change during
compilation.

If anyone else has a better solution, please let me know.

The ideal solution would be, if we could annotate some JSNI variables
so the GWT compiler will not rename them during the obfuscation
process. The we could easily reference them in the code, typically
from eval function. Is there anything like this?


On Nov 20, 3:46 pm, Thomas Broyer  wrote:
> On Sunday, November 20, 2011 12:14:46 PM UTC+1, jogo wrote:
>
> > Ok. Finally I've found the sneaky bug.
>
> > The code was failing actually later in the code where was another eval
> > function referencing the obj variable eval('var title =
> > obj.feed.entry[' + i + '].title');
>
> Any reason you're not coding this directly in JSNI, without the eval()?
>
>     var title = obj.feed.entry[i].title;

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-20 Thread Thomas Broyer


On Sunday, November 20, 2011 5:39:04 PM UTC+1, jogo wrote:
>
> Hi Thomas,
>
> > Any reason you're not coding this directly in JSNI, without the eval()?
> Great point. I was able to fix one JSNI function (mentioned above)
> that just gets the title & id with the solution you suggested. Thank
> you.
>
> But unfortunately, there is one even more complex method, that gets
> data from Google Spreadsheet feed and here I have to use the "evil"
> function. These feeds are quite complex and keys in these feeds are
> dynamically generated based on the names of columns in a spreadsheet.
>
> Here is an example JSON feed:
>
> https://spreadsheets.google.com/feeds/list/o03712292828507838454.6243940683656382600/od6/public/values?alt=json
>
> If you check that feed you will notice, that keys where are stored
> spreadsheet values are prefixed with 'gsx' + name of the column. There
> are three columns in the spreadsheet - year, revenue and profit and
> three corresponding JSON keys gsx$year, gsx$revenue and gsx$profit.
>
> My code looks like this:
> public static native String parseSpreadsheetFeed(String json) /*-{
> if (json != null) {
> var obj = JSON.parse(json);
> var entries = obj.feed.entry;
>
> // iterate over entries
> for (var i in entries) {
>
> // iterate over keys
> for (var j in entries[i]) {
> var prefix = j.split('$')[0];
>
> // process only keys prefixed with 'gsx'
> if (prefix == 'gsx') {
> eval('var data = obj.feed.entry[' + i + '].' +
> j + '.$t');
> ...
>
> And here I can't just replace the eval method with:
> var data = obj.feed.entry[i].j.$t;
>
> That wouldn't work.
>

var data = obj.feed.entry[i][j].$t;

>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/gChaVP41OcwJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Different GWT compilation from Eclipse and command line

2011-11-20 Thread jogo
Man, you made my day :o) Thanks!

On Nov 20, 6:49 pm, Thomas Broyer  wrote:
> On Sunday, November 20, 2011 5:39:04 PM UTC+1, jogo wrote:
>
> > Hi Thomas,
>
> > > Any reason you're not coding this directly in JSNI, without the eval()?
> > Great point. I was able to fix one JSNI function (mentioned above)
> > that just gets the title & id with the solution you suggested. Thank
> > you.
>
> > But unfortunately, there is one even more complex method, that gets
> > data from Google Spreadsheet feed and here I have to use the "evil"
> > function. These feeds are quite complex and keys in these feeds are
> > dynamically generated based on the names of columns in a spreadsheet.
>
> > Here is an example JSON feed:
>
> >https://spreadsheets.google.com/feeds/list/o03712292828507838454.6243...
>
> > If you check that feed you will notice, that keys where are stored
> > spreadsheet values are prefixed with 'gsx' + name of the column. There
> > are three columns in the spreadsheet - year, revenue and profit and
> > three corresponding JSON keys gsx$year, gsx$revenue and gsx$profit.
>
> > My code looks like this:
> >     public static native String parseSpreadsheetFeed(String json) /*-{
> >         if (json != null) {
> >             var obj = JSON.parse(json);
> >             var entries = obj.feed.entry;
>
> >             // iterate over entries
> >             for (var i in entries) {
>
> >                 // iterate over keys
> >                 for (var j in entries[i]) {
> >                     var prefix = j.split('$')[0];
>
> >                     // process only keys prefixed with 'gsx'
> >                     if (prefix == 'gsx') {
> >                         eval('var data = obj.feed.entry[' + i + '].' +
> > j + '.$t');
> >                         ...
>
> > And here I can't just replace the eval method with:
> > var data = obj.feed.entry[i].j.$t;
>
> > That wouldn't work.
>
> var data = obj.feed.entry[i][j].$t;
>
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.