Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D174118AAA for ; Mon, 7 Sep 2015 21:52:53 +0000 (UTC) Received: (qmail 10319 invoked by uid 500); 7 Sep 2015 21:52:53 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 10291 invoked by uid 500); 7 Sep 2015 21:52:53 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 10275 invoked by uid 99); 7 Sep 2015 21:52:53 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Sep 2015 21:52:53 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 4D1C8180428 for ; Mon, 7 Sep 2015 21:52:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.214 X-Spam-Level: * X-Spam-Status: No, score=1.214 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H2=-0.001, URIBL_BLOCKED=0.001, URI_HEX=1.313, WEIRD_QUOTING=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=googlemail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id mn8ZFv8lR09Q for ; Mon, 7 Sep 2015 21:52:38 +0000 (UTC) Received: from mail-ob0-f175.google.com (mail-ob0-f175.google.com [209.85.214.175]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 5DF0E43AF9 for ; Mon, 7 Sep 2015 21:52:38 +0000 (UTC) Received: by obbbh8 with SMTP id bh8so69307764obb.0 for ; Mon, 07 Sep 2015 14:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ViNIUoK8AOUeX7htE/q6+Xu6kkyDjQuvzQa12NANu7M=; b=rS4yXX1FFf8VV6djSC22k/uihrVIBTwne8AMdx5LYoo2XF+wQTwE+0ddOa/4e22OfI B7msXLDPZTGioSSihyg2NVmo8472YU/YF71J6eB7L4rUBMXsbYC93BsfApZezj2kzVEv 1Mgs54a1TE1HsRxLpUilg2W+CDxnPNvYmT1WmYGfAXKFg3P5b7gAw60vyv57fzO4T4vK Gs0DQvlQWaU55a92Bnu/cyZiAhV8ZZh3J4Lp8UwFI6ZVuIPxwTlIP0Smq7/j1wbo99eR ermKDmdqAsdXSNPDUeRXcLvpDXUFbqdJYRj/0kCMZYX1RhL2DnbBqgqE6AyN9d+ZGCY1 TccA== MIME-Version: 1.0 X-Received: by 10.182.142.39 with SMTP id rt7mr16207057obb.3.1441662752151; Mon, 07 Sep 2015 14:52:32 -0700 (PDT) Received: by 10.182.241.65 with HTTP; Mon, 7 Sep 2015 14:52:32 -0700 (PDT) In-Reply-To: <55EE069B.3030806@gmx.net> References: <1542008187.2943561.1441662219706.JavaMail.yahoo@mail.yahoo.com> <55EE069B.3030806@gmx.net> Date: Mon, 7 Sep 2015 23:52:32 +0200 Message-ID: Subject: Re: Wanted: Help converting groovy script to "groovy -e" From: Thibault Kruse To: users@groovy.incubator.apache.org Content-Type: text/plain; charset=UTF-8 The Pull Request is here: https://github.com/apache/incubator-groovy/pull/104 To get it, you would have to clone my fork on github (or use it as alternative remote), then switch to the groovysh-grab branch, run gradle dist. That should create the version 2.5.0-SNAPSHOT, which you could then use. On Mon, Sep 7, 2015 at 11:43 PM, Richard Heintze wrote: > Thibault: > Can you help me reproduce your environment? > (1) I cannot find groovy 2.5.0-Snapshot on > http://groovy-lang.org/download.html#distro . Do I need 2.5.0-Snapshot or > will 2.4.4 do? Can I download 2.5.0 without having to build it myself? Is it > difficult to build on windows? Where do I download it from? > (2) I'm confused about that link: it just takes me to the mailing list page. > Can you give a link to the patch? > Thanks > siegfried > > > > On Saturday, September 5, 2015 10:41 AM, Thibault Kruse > wrote: > > > Actually, sorry, this was using Groovy 2.5.0-SNAPSHOT from master. > With my patch to Grape classloading. > http://groovy.329449.n5.nabble.com/groovysh-import-completion-for-Grape-loaded-classes-td5727025.html > > With 2.4.x, I get Caught: java.sql.SQLException: No suitable driver > found for jdbc:h2:mem:test_mem > > So I guess my patch for grapes does the same as you do. > > On Sat, Sep 5, 2015 at 7:12 PM, Richard Heintze > wrote: >> Well shucks! I just cut and pasted your code to windows/Cygwin and then to >> Ubuntu. I got the exact same results on both machines! >> >> What version and which Linux are you using? What version of groovy? >> >> Can anyone else detect what I am doing wrong? >> >> >> groovy -e "import groovy.xml.MarkupBuilder; >> import groovy.sql.Sql >> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >> version:'1.4.188') >> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >> 'org.h2.Driver'); >> println(sql) >> " >> Caught: java.lang.ClassNotFoundException: org.h2.Driver >> java.lang.ClassNotFoundException: org.h2.Driver >> at script_from_command_line.run(script_from_command_line:4) >> >> Process compilation exited abnormally with code 1 >> >> >> >> On Saturday, September 5, 2015 2:07 AM, Thibault Kruse >> wrote: >> >> >> I am not sure what the classloader business is about. I get your -e >> examplke running on Linux: >> >> $ groovy -e "import groovy.xml.MarkupBuilder; >> import groovy.sql.Sql >> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >> version:'1.4.188') >> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >> 'org.h2.Driver'); >> println(sql) >> " >> groovy.sql.Sql@6ba2507 >> >> On Fri, Sep 4, 2015 at 6:13 PM, Richard Heintze >> wrote: >>> >>> The script below works with groovy 2.3.0-beta-2 with the groovy program. >>> I >>> want to move the SQL code to separate text files and execute it from (1) >>> "groovy -e" (2) groovy-console and (3) groovysh. >>> >>> After looking at >>> >>> >>> http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/ >>> here is my first attempt using Cygwin on windows 8 and groovy that is not >>> working: >>> >>> >>> groovy -e "import groovy.sql.Sql >>> import groovy.xml.MarkupBuilder; >>> import groovy.sql.Sql >>> >>> def classLoader = this.getClass().getClassLoader(); >>> while >>> >>> >>> (!classLoader.getClass().getName().equals('org.codehaus.groovy.tools.RootLoader')) >>> { >>> classLoader = classLoader.getParent() >>> } >>> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >>> version:'1.4.188') >>> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >>> 'org.h2.Driver');" >>> Caught: java.lang.ClassNotFoundException: org.h2.Driver >>> java.lang.ClassNotFoundException: org.h2.Driver >>> at script_from_command_line.run(script_from_command_line:10) >>> >>> >>> As you can see, I'm trying to convert the @GrabConfig which does not seem >>> to >>> work with "groovy -e". >>> >>> >>> Thanks >>> Siegfried >>> >>> >>> >>> >>> This works: >>> >>> import groovy.sql.Sql >>> import groovy.xml.MarkupBuilder >>> @GrabConfig(systemClassLoader=true) >>> @Grab(group='com.h2database', module='h2', version='1.4.188') >>> sqltext = [""" >>> create table gov_unit ( >>> id integer NOT NULL, >>> parent_id integer DEFAULT 3, >>> name varchar(10), >>> type varchar(8), >>> constraint gov_unit_pk >>> primary key (id), >>> constraint gov_unit_type_chk >>> check (type in ('County','Township','City','State')), >>> constraint gov_unit_loop >>> foreign key (parent_id) >>> references gov_unit >>> ); >>> insert into gov_unit values (3,null,'Michigan','State'); >>> insert into gov_unit values (2,3,'Alger','County'); >>> insert into gov_unit values (1,2,'Munising','City'); >>> insert into gov_unit values (4,2,'Munising','Township'); >>> insert into gov_unit values (5,2,'Au Train','Township'); >>> insert into gov_unit values (6,3,'Baraga','County'); >>> insert into gov_unit values (7,3,'Ontonagon','County'); >>> insert into gov_unit values (8,7,'Interior','Township'); >>> insert into gov_unit values (9,3,'Dickinson','County'); >>> insert into gov_unit values (10,3,'Gogebic','County'); >>> insert into gov_unit values (11,3,'Delta','County'); >>> insert into gov_unit values (12,11,'Masonville','Township'); >>> """,""" >>> WITH RECURSIVE gov (depth, id, parent_id, name, type) AS( >>> SELECT 1 AS depth, parent.* FROM gov_unit parent WHERE >>> parent.parent_id >>> IS NULL >>> UNION ALL >>> SELECT parent.depth+1 AS depth, child.* FROM gov parent, gov_unit >>> child >>> WHERE child.parent_id = parent.id >>> ) >>> SELECT * FROM gov ; >>> """] >>> >>> def sql = Sql.newInstance("jdbc:h2:mem:test_mem", "sa", "", >>> "org.h2.Driver") >>> sql.execute sqltext[0] >>> >>> def xml = new groovy.xml.MarkupBuilder(new >>> FileWriter(java.io.FileDescriptor.out)) >>> >>> xml.table (name:"gov_unit") { >>> sql.rows(sqltext[1]).each{ row-> >>> xml.gov_unit ( >>> row >>> ) } >>> } >> >> > > On Mon, Sep 7, 2015 at 11:50 PM, Pascal Schumacher wrote: > Hi Richard, > > you can download groovy snapshots from > https://oss.jfrog.org/oss-snapshot-local/org/codehaus/groovy/ > > -Pascal > > > Am 07.09.2015 um 23:43 schrieb Richard Heintze: > > Thibault: > Can you help me reproduce your environment? > (1) I cannot find groovy 2.5.0-Snapshot on > http://groovy-lang.org/download.html#distro . Do I need 2.5.0-Snapshot or > will 2.4.4 do? Can I download 2.5.0 without having to build it myself? Is it > difficult to build on windows? Where do I download it from? > (2) I'm confused about that link: it just takes me to the mailing list page. > Can you give a link to the patch? > Thanks > siegfried > > > > On Saturday, September 5, 2015 10:41 AM, Thibault Kruse > wrote: > > > Actually, sorry, this was using Groovy 2.5.0-SNAPSHOT from master. > With my patch to Grape classloading. > http://groovy.329449.n5.nabble.com/groovysh-import-completion-for-Grape-loaded-classes-td5727025.html > > With 2.4.x, I get Caught: java.sql.SQLException: No suitable driver > found for jdbc:h2:mem:test_mem > > So I guess my patch for grapes does the same as you do. > > On Sat, Sep 5, 2015 at 7:12 PM, Richard Heintze > wrote: >> Well shucks! I just cut and pasted your code to windows/Cygwin and then to >> Ubuntu. I got the exact same results on both machines! >> >> What version and which Linux are you using? What version of groovy? >> >> Can anyone else detect what I am doing wrong? >> >> >> groovy -e "import groovy.xml.MarkupBuilder; >> import groovy.sql.Sql >> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >> version:'1.4.188') >> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >> 'org.h2.Driver'); >> println(sql) >> " >> Caught: java.lang.ClassNotFoundException: org.h2.Driver >> java.lang.ClassNotFoundException: org.h2.Driver >> at script_from_command_line.run(script_from_command_line:4) >> >> Process compilation exited abnormally with code 1 >> >> >> >> On Saturday, September 5, 2015 2:07 AM, Thibault Kruse >> wrote: >> >> >> I am not sure what the classloader business is about. I get your -e >> examplke running on Linux: >> >> $ groovy -e "import groovy.xml.MarkupBuilder; >> import groovy.sql.Sql >> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >> version:'1.4.188') >> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >> 'org.h2.Driver'); >> println(sql) >> " >> groovy.sql.Sql@6ba2507 >> >> On Fri, Sep 4, 2015 at 6:13 PM, Richard Heintze >> wrote: >>> >>> The script below works with groovy 2.3.0-beta-2 with the groovy program. >>> I >>> want to move the SQL code to separate text files and execute it from (1) >>> "groovy -e" (2) groovy-console and (3) groovysh. >>> >>> After looking at >>> >>> >>> http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/ >>> here is my first attempt using Cygwin on windows 8 and groovy that is not >>> working: >>> >>> >>> groovy -e "import groovy.sql.Sql >>> import groovy.xml.MarkupBuilder; >>> import groovy.sql.Sql >>> >>> def classLoader = this.getClass().getClassLoader(); >>> while >>> >>> >>> (!classLoader.getClass().getName().equals('org.codehaus.groovy.tools.RootLoader')) >>> { >>> classLoader = classLoader.getParent() >>> } >>> groovy.grape.Grape.grab(group:'com.h2database', module:'h2', >>> version:'1.4.188') >>> def sql = Sql.newInstance('jdbc:h2:mem:test_mem', 'sa', '', >>> 'org.h2.Driver');" >>> Caught: java.lang.ClassNotFoundException: org.h2.Driver >>> java.lang.ClassNotFoundException: org.h2.Driver >>> at script_from_command_line.run(script_from_command_line:10) >>> >>> >>> As you can see, I'm trying to convert the @GrabConfig which does not seem >>> to >>> work with "groovy -e". >>> >>> >>> Thanks >>> Siegfried >>> >>> >>> >>> >>> This works: >>> >>> import groovy.sql.Sql >>> import groovy.xml.MarkupBuilder >>> @GrabConfig(systemClassLoader=true) >>> @Grab(group='com.h2database', module='h2', version='1.4.188') >>> sqltext = [""" >>> create table gov_unit ( >>> id integer NOT NULL, >>> parent_id integer DEFAULT 3, >>> name varchar(10), >>> type varchar(8), >>> constraint gov_unit_pk >>> primary key (id), >>> constraint gov_unit_type_chk >>> check (type in ('County','Township','City','State')), >>> constraint gov_unit_loop >>> foreign key (parent_id) >>> references gov_unit >>> ); >>> insert into gov_unit values (3,null,'Michigan','State'); >>> insert into gov_unit values (2,3,'Alger','County'); >>> insert into gov_unit values (1,2,'Munising','City'); >>> insert into gov_unit values (4,2,'Munising','Township'); >>> insert into gov_unit values (5,2,'Au Train','Township'); >>> insert into gov_unit values (6,3,'Baraga','County'); >>> insert into gov_unit values (7,3,'Ontonagon','County'); >>> insert into gov_unit values (8,7,'Interior','Township'); >>> insert into gov_unit values (9,3,'Dickinson','County'); >>> insert into gov_unit values (10,3,'Gogebic','County'); >>> insert into gov_unit values (11,3,'Delta','County'); >>> insert into gov_unit values (12,11,'Masonville','Township'); >>> """,""" >>> WITH RECURSIVE gov (depth, id, parent_id, name, type) AS( >>> SELECT 1 AS depth, parent.* FROM gov_unit parent WHERE >>> parent.parent_id >>> IS NULL >>> UNION ALL >>> SELECT parent.depth+1 AS depth, child.* FROM gov parent, gov_unit >>> child >>> WHERE child.parent_id = parent.id >>> ) >>> SELECT * FROM gov ; >>> """] >>> >>> def sql = Sql.newInstance("jdbc:h2:mem:test_mem", "sa", "", >>> "org.h2.Driver") >>> sql.execute sqltext[0] >>> >>> def xml = new groovy.xml.MarkupBuilder(new >>> FileWriter(java.io.FileDescriptor.out)) >>> >>> xml.table (name:"gov_unit") { >>> sql.rows(sqltext[1]).each{ row-> >>> xml.gov_unit ( >>> row >>> ) } >>> } >> >> > > >