Repository: groovy Updated Branches: refs/heads/master e56a13056 -> 2fb0075b6
http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/swing/greet/TwitterAPI.groovy ---------------------------------------------------------------------- diff --git a/src/examples/swing/greet/TwitterAPI.groovy b/src/examples/swing/greet/TwitterAPI.groovy index fcc6d06..76d13f4 100644 --- a/src/examples/swing/greet/TwitterAPI.groovy +++ b/src/examples/swing/greet/TwitterAPI.groovy @@ -1,162 +1,162 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Created by IntelliJ IDEA. - * User: Danno.Ferrin - * Date: Apr 25, 2008 - * Time: 9:47:20 PM - */ -package groovy.swing.greet - -import groovy.beans.Bindable - -class TwitterAPI { - - @Bindable String status = "\u00a0" - def authenticatedUser - XmlSlurper slurper = new XmlSlurper() - def imageMap = [:] - - def withStatus(status, c) { - setStatus(status) - try { - def o = c() - setStatus("\u00a0") - return o - } catch (Throwable t) { - setStatus("Error $status : ${t.message =~ '400'?'Rate Limit Reached':t}") - throw t - } - } - - - boolean login(def name, def password) { - withStatus("Logging in") { - Authenticator.setDefault( - [getPasswordAuthentication : { - return new PasswordAuthentication(name, password) } - ] as Authenticator) - authenticatedUser = getUser(name) - return true - } - } - - def getFriends() { - getFriends(authenticatedUser) - } - - def getFriends(String user) { - return getFriends(getUser(user)) - } - - def getFriends(user) { - def friends = [user] - withStatus("Loading Friends") { - def page = 1 - def list = slurper.parse(new URL("http://twitter.com/statuses/friends/${user.screen_name}.xml").openStream()) - while (list.length) { - list.user.collect(friends) {it} - page++ - try { - list = slurper.parse("http://twitter.com/statuses/friends/${user.screen_name}.xml&page=$page") - } catch (Exception e) { break } - } - } - withStatus("Loading Friends Images") { - return friends.each { - loadImage(it.profile_image_url as String) - } - } - } - - def getFriendsTimeline() { - getFriendsTimeline(user) - } - - def getFriendsTimeline(String friend) { - getFriendsTimeline(getUser(friend)) - } - - def getFriendsTimeline(user) { - def timeline = [] - withStatus("Loading Timeline") { - timeline = slurper.parse( - new URL("http://twitter.com/statuses/friends_timeline/${user.screen_name}.xml").openStream() - ).status.collect{it} - } - withStatus("Loading Timeline Images") { - return timeline.each { - loadImage(it.user.profile_image_url as String) - } - } - } - - def getTweets() { - return getTweets(user) - } - - def getTweets(String friend) { - return getTweets(getUser(frield)) - } - - def getTweets(friend) { - def tweets = [] - withStatus("Loading Tweets") { - tweets = slurper.parse( - new URL("http://twitter.com/statuses/user_timeline/${friend.screen_name}.xml").openStream() - ).status.collect{it} - } - withStatus("Loading Tweet Images") { - return tweets.each { - loadImage(it.user.profile_image_url as String) - } - } - } - - def getUser(String screen_name) { - withStatus("Loading User $screen_name") { - if (screen_name.contains('@')) { - return slurper.parse( - new URL("http://twitter.com/users/show.xml?email=${screen_name}").openStream() - ) - } else { - return slurper.parse( - new URL("http://twitter.com/users/show/${screen_name}.xml").openStream() - ) - } - } - } - - def tweet(message) { - withStatus("Tweeting") { - def urlConnection = new URL("http://twitter.com/statuses/update.xml").openConnection() - urlConnection.doOutput = true - urlConnection.outputStream << "status=${URLEncoder.encode(message, 'UTF-8')}" - return slurper.parse(urlConnection.inputStream) - } - } - - // no need to read these, swing seems to cache these so the EDT won't stall - def loadImage(image) { - if (!imageMap[image]) { - Thread.start {imageMap[image] = new javax.swing.ImageIcon(new URL(image))} - } - } - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * Created by IntelliJ IDEA. + * User: Danno.Ferrin + * Date: Apr 25, 2008 + * Time: 9:47:20 PM + */ +package groovy.swing.greet + +import groovy.beans.Bindable + +class TwitterAPI { + + @Bindable String status = "\u00a0" + def authenticatedUser + XmlSlurper slurper = new XmlSlurper() + def imageMap = [:] + + def withStatus(status, c) { + setStatus(status) + try { + def o = c() + setStatus("\u00a0") + return o + } catch (Throwable t) { + setStatus("Error $status : ${t.message =~ '400'?'Rate Limit Reached':t}") + throw t + } + } + + + boolean login(def name, def password) { + withStatus("Logging in") { + Authenticator.setDefault( + [getPasswordAuthentication : { + return new PasswordAuthentication(name, password) } + ] as Authenticator) + authenticatedUser = getUser(name) + return true + } + } + + def getFriends() { + getFriends(authenticatedUser) + } + + def getFriends(String user) { + return getFriends(getUser(user)) + } + + def getFriends(user) { + def friends = [user] + withStatus("Loading Friends") { + def page = 1 + def list = slurper.parse(new URL("http://twitter.com/statuses/friends/${user.screen_name}.xml").openStream()) + while (list.length) { + list.user.collect(friends) {it} + page++ + try { + list = slurper.parse("http://twitter.com/statuses/friends/${user.screen_name}.xml&page=$page") + } catch (Exception e) { break } + } + } + withStatus("Loading Friends Images") { + return friends.each { + loadImage(it.profile_image_url as String) + } + } + } + + def getFriendsTimeline() { + getFriendsTimeline(user) + } + + def getFriendsTimeline(String friend) { + getFriendsTimeline(getUser(friend)) + } + + def getFriendsTimeline(user) { + def timeline = [] + withStatus("Loading Timeline") { + timeline = slurper.parse( + new URL("http://twitter.com/statuses/friends_timeline/${user.screen_name}.xml").openStream() + ).status.collect{it} + } + withStatus("Loading Timeline Images") { + return timeline.each { + loadImage(it.user.profile_image_url as String) + } + } + } + + def getTweets() { + return getTweets(user) + } + + def getTweets(String friend) { + return getTweets(getUser(frield)) + } + + def getTweets(friend) { + def tweets = [] + withStatus("Loading Tweets") { + tweets = slurper.parse( + new URL("http://twitter.com/statuses/user_timeline/${friend.screen_name}.xml").openStream() + ).status.collect{it} + } + withStatus("Loading Tweet Images") { + return tweets.each { + loadImage(it.user.profile_image_url as String) + } + } + } + + def getUser(String screen_name) { + withStatus("Loading User $screen_name") { + if (screen_name.contains('@')) { + return slurper.parse( + new URL("http://twitter.com/users/show.xml?email=${screen_name}").openStream() + ) + } else { + return slurper.parse( + new URL("http://twitter.com/users/show/${screen_name}.xml").openStream() + ) + } + } + } + + def tweet(message) { + withStatus("Tweeting") { + def urlConnection = new URL("http://twitter.com/statuses/update.xml").openConnection() + urlConnection.doOutput = true + urlConnection.outputStream << "status=${URLEncoder.encode(message, 'UTF-8')}" + return slurper.parse(urlConnection.inputStream) + } + } + + // no need to read these, swing seems to cache these so the EDT won't stall + def loadImage(image) { + if (!imageMap[image]) { + Thread.start {imageMap[image] = new javax.swing.ImageIcon(new URL(image))} + } + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/swing/greet/View.groovy ---------------------------------------------------------------------- diff --git a/src/examples/swing/greet/View.groovy b/src/examples/swing/greet/View.groovy index 7b72715..3f8597c 100644 --- a/src/examples/swing/greet/View.groovy +++ b/src/examples/swing/greet/View.groovy @@ -1,175 +1,175 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -/** - * Created by IntelliJ IDEA. - * User: Danno.Ferrin - * Date: Apr 26, 2008 - * Time: 8:31:21 AM - */ -package groovy.swing.greet - -import java.awt.Cursor -import java.beans.PropertyChangeListener -import javax.swing.* - -lookAndFeel('nimbus', 'mac', ['metal', [boldFonts: false]]) - -actions() { - loginAction = action( - name: 'Login', - enabled: bind(source: controller, sourceProperty: 'allowLogin'), - closure: controller.&login - ) - - filterTweets = action( - name: 'Filter', - enabled: bind(source: controller, sourceProperty: 'allowSelection'), - closure: controller.&filterTweets - ) - - userSelected = action( - name: 'Select User', - enabled: bind(source: controller, sourceProperty: 'allowSelection'), - closure: controller.&userSelected - ) - - tweetAction = action( - name: 'Update', - enabled: bind(source: controller, sourceProperty: 'allowTweet'), - closure: controller.&tweet - ) -} - -tweetLineFont = new java.awt.Font("Ariel", 0, 12) -tweetLine = panel(border: emptyBorder(3), preferredSize:[250,84]) { - gridBagLayout() - tweetIcon = label(verticalTextPosition:SwingConstants.BOTTOM, - horizontalTextPosition:SwingConstants.CENTER, - //anchor: BASELINE, insets: [3, 3, 3, 3]) - anchor: CENTER, insets: [3, 3, 3, 3]) - tweetText = textArea(rows: 4, lineWrap: true, wrapStyleWord: true, - opaque: false, editable: false, font: tweetLineFont, - gridwidth: REMAINDER, weightx: 1.0, fill: BOTH, insets: [3, 3, 3, 3]) -} -tweetRenderer = {list, tweet, index, isSelected, isFocused -> - if (tweet?.user as String) { - tweetIcon.icon = controller.api.imageMap[tweet.user.profile_image_url as String] - tweetIcon.text = tweet.user.screen_name - tweetText.text = tweet.text - } else if (tweet?.text as String) { - tweetIcon.icon = controller.api.imageMap[tweet.parent().profile_image_url as String] - tweetIcon.text = tweet.parent().screen_name - tweetText.text = tweet.text - } else { - tweetIcon.icon = null - tweetIcon.text = null - tweetText.text = null - } - tweetLine -} as ListCellRenderer - - -userCell = label(border: emptyBorder(3)) -userCellRenderer = {list, user, index, isSelected, isFocused -> - if (user) { - userCell.icon = controller.api.imageMap[user.profile_image_url as String] - userCell.text = "<html>$user.screen_name<br>$user.name<br>$user.location<br>" - } else { - userCell.icon = null - userCell.text = null - } - userCell -} as ListCellRenderer - -greetFrame = frame(title: "Greet - A Groovy Twitter Client", - defaultCloseOperation: javax.swing.JFrame.DISPOSE_ON_CLOSE, size: [320, 480], - locationByPlatform:true) -{ - panel(cursor: bind(source: controller, sourceProperty: 'allowSelection', - converter: {it ? null : Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)}) - ) { - - gridBagLayout() - users = comboBox(renderer: userCellRenderer, action: userSelected, - gridwidth: REMAINDER, insets: [6, 6, 3, 6], fill: HORIZONTAL) - label('Search:', insets: [3, 6, 3, 3]) - searchField = textField(columns: 20, action: filterTweets, - insets: [3, 3, 3, 3], weightx: 1.0, fill: BOTH) - button(action: filterTweets, - gridwidth: REMAINDER, insets: [3, 3, 3, 6], fill:HORIZONTAL) - tabbedPane(gridwidth: REMAINDER, weighty: 1.0, fill: BOTH) { - scrollPane(title: 'Timeline') { - timelineList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) - } - scrollPane(title: 'Tweets') { - tweetList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) - } - scrollPane(title: 'Statuses') { - statusList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) - } - // add data change listeners - [timeline:timelineList, tweets:tweetList, statuses:statusList].each {p, w -> - controller.addPropertyChangeListener(p, - {evt -> w.listData = evt.newValue as Object[]} as PropertyChangeListener - ) - } - } - separator(fill: HORIZONTAL, gridwidth: REMAINDER) - tweetBox = textField(action:tweetAction, - fill:BOTH, weightx:1.0, insets:[3,3,3,3], gridwidth:2) - tweetButton = button(tweetAction, - enabled:bind(source:tweetBox, sourceProperty:'text', converter:{it.length() < 140}), - gridwidth:REMAINDER, insets:[3,3,3,3]) - separator(fill: HORIZONTAL, gridwidth: REMAINDER) - statusLine = label(text: bind(source: controller.api, sourceProperty: 'status'), - gridwidth: REMAINDER, insets: [3, 6, 3, 6], anchor: WEST - ) - } - - - loginDialog = dialog( - title: "Login to Greet", pack: true, resizable: false, - defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE, - locationByPlatform:true) - { - panel(border: emptyBorder(3), - cursor: bind(source: controller, sourceProperty: 'allowLogin', - converter: {it ? null : Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)}) - ) { - gridBagLayout() - label("Username:", - anchor: EAST, insets: [3, 3, 3, 3]) - twitterNameField = textField(action:loginAction, columns: 20, - gridwidth: REMAINDER, insets: [3, 3, 3, 3]) - label("Password:", - anchor: EAST, insets: [3, 3, 3, 3]) - twitterPasswordField = passwordField(action:loginAction, columns: 20, - gridwidth: REMAINDER, insets: [3, 3, 3, 3]) - panel() - button(loginAction, defaultButton: true, - anchor: EAST, insets: [3, 3, 3, 3]) - } - } -} - -controller.addPropertyChangeListener("friends", {evt -> - view.edt { users.model = new DefaultComboBoxModel(evt.newValue as Object[]) } -} as PropertyChangeListener) - -new Timer(120000, filterTweets).start() +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * Created by IntelliJ IDEA. + * User: Danno.Ferrin + * Date: Apr 26, 2008 + * Time: 8:31:21 AM + */ +package groovy.swing.greet + +import java.awt.Cursor +import java.beans.PropertyChangeListener +import javax.swing.* + +lookAndFeel('nimbus', 'mac', ['metal', [boldFonts: false]]) + +actions() { + loginAction = action( + name: 'Login', + enabled: bind(source: controller, sourceProperty: 'allowLogin'), + closure: controller.&login + ) + + filterTweets = action( + name: 'Filter', + enabled: bind(source: controller, sourceProperty: 'allowSelection'), + closure: controller.&filterTweets + ) + + userSelected = action( + name: 'Select User', + enabled: bind(source: controller, sourceProperty: 'allowSelection'), + closure: controller.&userSelected + ) + + tweetAction = action( + name: 'Update', + enabled: bind(source: controller, sourceProperty: 'allowTweet'), + closure: controller.&tweet + ) +} + +tweetLineFont = new java.awt.Font("Ariel", 0, 12) +tweetLine = panel(border: emptyBorder(3), preferredSize:[250,84]) { + gridBagLayout() + tweetIcon = label(verticalTextPosition:SwingConstants.BOTTOM, + horizontalTextPosition:SwingConstants.CENTER, + //anchor: BASELINE, insets: [3, 3, 3, 3]) + anchor: CENTER, insets: [3, 3, 3, 3]) + tweetText = textArea(rows: 4, lineWrap: true, wrapStyleWord: true, + opaque: false, editable: false, font: tweetLineFont, + gridwidth: REMAINDER, weightx: 1.0, fill: BOTH, insets: [3, 3, 3, 3]) +} +tweetRenderer = {list, tweet, index, isSelected, isFocused -> + if (tweet?.user as String) { + tweetIcon.icon = controller.api.imageMap[tweet.user.profile_image_url as String] + tweetIcon.text = tweet.user.screen_name + tweetText.text = tweet.text + } else if (tweet?.text as String) { + tweetIcon.icon = controller.api.imageMap[tweet.parent().profile_image_url as String] + tweetIcon.text = tweet.parent().screen_name + tweetText.text = tweet.text + } else { + tweetIcon.icon = null + tweetIcon.text = null + tweetText.text = null + } + tweetLine +} as ListCellRenderer + + +userCell = label(border: emptyBorder(3)) +userCellRenderer = {list, user, index, isSelected, isFocused -> + if (user) { + userCell.icon = controller.api.imageMap[user.profile_image_url as String] + userCell.text = "<html>$user.screen_name<br>$user.name<br>$user.location<br>" + } else { + userCell.icon = null + userCell.text = null + } + userCell +} as ListCellRenderer + +greetFrame = frame(title: "Greet - A Groovy Twitter Client", + defaultCloseOperation: javax.swing.JFrame.DISPOSE_ON_CLOSE, size: [320, 480], + locationByPlatform:true) +{ + panel(cursor: bind(source: controller, sourceProperty: 'allowSelection', + converter: {it ? null : Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)}) + ) { + + gridBagLayout() + users = comboBox(renderer: userCellRenderer, action: userSelected, + gridwidth: REMAINDER, insets: [6, 6, 3, 6], fill: HORIZONTAL) + label('Search:', insets: [3, 6, 3, 3]) + searchField = textField(columns: 20, action: filterTweets, + insets: [3, 3, 3, 3], weightx: 1.0, fill: BOTH) + button(action: filterTweets, + gridwidth: REMAINDER, insets: [3, 3, 3, 6], fill:HORIZONTAL) + tabbedPane(gridwidth: REMAINDER, weighty: 1.0, fill: BOTH) { + scrollPane(title: 'Timeline') { + timelineList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) + } + scrollPane(title: 'Tweets') { + tweetList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) + } + scrollPane(title: 'Statuses') { + statusList = list(visibleRowCount: 20, cellRenderer: tweetRenderer) + } + // add data change listeners + [timeline:timelineList, tweets:tweetList, statuses:statusList].each {p, w -> + controller.addPropertyChangeListener(p, + {evt -> w.listData = evt.newValue as Object[]} as PropertyChangeListener + ) + } + } + separator(fill: HORIZONTAL, gridwidth: REMAINDER) + tweetBox = textField(action:tweetAction, + fill:BOTH, weightx:1.0, insets:[3,3,3,3], gridwidth:2) + tweetButton = button(tweetAction, + enabled:bind(source:tweetBox, sourceProperty:'text', converter:{it.length() < 140}), + gridwidth:REMAINDER, insets:[3,3,3,3]) + separator(fill: HORIZONTAL, gridwidth: REMAINDER) + statusLine = label(text: bind(source: controller.api, sourceProperty: 'status'), + gridwidth: REMAINDER, insets: [3, 6, 3, 6], anchor: WEST + ) + } + + + loginDialog = dialog( + title: "Login to Greet", pack: true, resizable: false, + defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE, + locationByPlatform:true) + { + panel(border: emptyBorder(3), + cursor: bind(source: controller, sourceProperty: 'allowLogin', + converter: {it ? null : Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)}) + ) { + gridBagLayout() + label("Username:", + anchor: EAST, insets: [3, 3, 3, 3]) + twitterNameField = textField(action:loginAction, columns: 20, + gridwidth: REMAINDER, insets: [3, 3, 3, 3]) + label("Password:", + anchor: EAST, insets: [3, 3, 3, 3]) + twitterPasswordField = passwordField(action:loginAction, columns: 20, + gridwidth: REMAINDER, insets: [3, 3, 3, 3]) + panel() + button(loginAction, defaultButton: true, + anchor: EAST, insets: [3, 3, 3, 3]) + } + } +} + +controller.addPropertyChangeListener("friends", {evt -> + view.edt { users.model = new DefaultComboBoxModel(evt.newValue as Object[]) } +} as PropertyChangeListener) + +new Timer(120000, filterTweets).start() http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/swing/timelog/TimeLogMain.groovy ---------------------------------------------------------------------- diff --git a/src/examples/swing/timelog/TimeLogMain.groovy b/src/examples/swing/timelog/TimeLogMain.groovy index 71e9d03..31acefa 100644 --- a/src/examples/swing/timelog/TimeLogMain.groovy +++ b/src/examples/swing/timelog/TimeLogMain.groovy @@ -1,46 +1,46 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package groovy.swing.timelog - -import groovy.swing.SwingBuilder - -SwingBuilder swing = new SwingBuilder(); -swing.lookAndFeel('system') - -swing.model = new TimeLogModel() - -swing.actions() { - action(name:'Start', id:'startAction') { - stopButton.requestFocusInWindow() - doOutside { - model.startRecording(tfClient.text) - } - } - action(name:'Stop', id:'stopAction') { - doOutside { - model.stopRecording(); - clientsTable.revalidate() - } - } -} - -frame = swing.build(TimeLogView) -frame.pack() -frame.show() - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.swing.timelog + +import groovy.swing.SwingBuilder + +SwingBuilder swing = new SwingBuilder(); +swing.lookAndFeel('system') + +swing.model = new TimeLogModel() + +swing.actions() { + action(name:'Start', id:'startAction') { + stopButton.requestFocusInWindow() + doOutside { + model.startRecording(tfClient.text) + } + } + action(name:'Stop', id:'stopAction') { + doOutside { + model.stopRecording(); + clientsTable.revalidate() + } + } +} + +frame = swing.build(TimeLogView) +frame.pack() +frame.show() + http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/swing/timelog/TimeLogModel.groovy ---------------------------------------------------------------------- diff --git a/src/examples/swing/timelog/TimeLogModel.groovy b/src/examples/swing/timelog/TimeLogModel.groovy index 6813a76..bb93772 100644 --- a/src/examples/swing/timelog/TimeLogModel.groovy +++ b/src/examples/swing/timelog/TimeLogModel.groovy @@ -1,62 +1,62 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package groovy.swing.timelog - -import groovy.beans.Bindable - -class TimeLogRow { - String client - long start - long stop - - long getDuration() { - return stop - start - } -} - -class TimeLogModel { - - String currentClient - long currentStart - List<TimeLogRow> entries = [] - - @Bindable boolean running - @Bindable long elapsedTime - - public synchronized startRecording(String client) { - if (running) throw new RuntimeException("Currently Running") - currentClient = client - currentStart = System.currentTimeMillis() - setRunning(true) - - while (running) { - setElapsedTime(System.currentTimeMillis() - currentStart) - this.wait(1000) - } - } - - public synchronized stopRecording() { - if (!running) throw new RuntimeException("Not Running") - setRunning(false) - this.notifyAll() - entries.add(new TimeLogRow(client:currentClient, start:currentStart, stop:System.currentTimeMillis())) - } - - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.swing.timelog + +import groovy.beans.Bindable + +class TimeLogRow { + String client + long start + long stop + + long getDuration() { + return stop - start + } +} + +class TimeLogModel { + + String currentClient + long currentStart + List<TimeLogRow> entries = [] + + @Bindable boolean running + @Bindable long elapsedTime + + public synchronized startRecording(String client) { + if (running) throw new RuntimeException("Currently Running") + currentClient = client + currentStart = System.currentTimeMillis() + setRunning(true) + + while (running) { + setElapsedTime(System.currentTimeMillis() - currentStart) + this.wait(1000) + } + } + + public synchronized stopRecording() { + if (!running) throw new RuntimeException("Not Running") + setRunning(false) + this.notifyAll() + entries.add(new TimeLogRow(client:currentClient, start:currentStart, stop:System.currentTimeMillis())) + } + + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/swing/timelog/TimeLogView.groovy ---------------------------------------------------------------------- diff --git a/src/examples/swing/timelog/TimeLogView.groovy b/src/examples/swing/timelog/TimeLogView.groovy index 218ce1f..91f711d 100644 --- a/src/examples/swing/timelog/TimeLogView.groovy +++ b/src/examples/swing/timelog/TimeLogView.groovy @@ -1,67 +1,67 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package groovy.swing.timelog - -import java.text.SimpleDateFormat -import javax.swing.JFrame -import java.awt.Font -import java.awt.Color - -SimpleDateFormat timeFormat = new SimpleDateFormat('HH:mm:ss') -timeFormat.setTimeZone(TimeZone.getTimeZone('GMT')) -SimpleDateFormat dateFormat = new SimpleDateFormat('dd MMM yyyy HH:mm:ss') -def convertTime = {it -> timeFormat.format new Date(it) } -def convertDate = {it -> dateFormat.format new Date(it) } - -frame(title: 'Time Log Demo', - defaultCloseOperation : JFrame.EXIT_ON_CLOSE) -{ - gridBagLayout() - - label('Client:', insets:[6,6,3,3]) - textField('', id: 'tfClient', - enabled: bind( source: model, sourceProperty: 'running', converter: {!it} ), - gridwidth: REMAINDER, fill: HORIZONTAL, insets: [6,3,3,6]) - - label('00:00:00', font: new Font('Ariel', Font.BOLD, 42), - foreground: bind(source: model, sourceProperty: 'running', converter: {it ? Color.GREEN : Color.RED}), - text: bind(source: model, sourceProperty: 'elapsedTime', converter: convertTime), - gridwidth: 2, gridheight: 2, anchor: EAST, weightx: 1.0, insets: [3,6,3,3]) - button(startAction, id: 'startButton', - enabled: bind(source: model, sourceProperty: 'running', converter: {!it}), - gridwidth: REMAINDER, insets: [3,3,3,6]) - button(stopAction, id: 'stopButton', - enabled: bind(source: model, sourceProperty: 'running'), - gridwidth: REMAINDER, insets: [3,3,3,6]) - - separator(gridwidth: REMAINDER, fill: HORIZONTAL, insets: [9,6,9,6]) - - scrollPane(minimumSize: [100, 100], - gridwidth: REMAINDER, weighty: 1.0, fill: BOTH, insets: [3,6,6,6]) - { - table(id: 'clientsTable') { - tableModel(list: model.entries) { - propertyColumn(header: 'Client', propertyName: 'client') - closureColumn( header: 'Start', read: {convertDate it.start}) - closureColumn( header: 'Stop', read: {convertDate it.stop}) - closureColumn( header: 'Duration', read: {convertTime it.stop - it.start}) - } - } - } +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.swing.timelog + +import java.text.SimpleDateFormat +import javax.swing.JFrame +import java.awt.Font +import java.awt.Color + +SimpleDateFormat timeFormat = new SimpleDateFormat('HH:mm:ss') +timeFormat.setTimeZone(TimeZone.getTimeZone('GMT')) +SimpleDateFormat dateFormat = new SimpleDateFormat('dd MMM yyyy HH:mm:ss') +def convertTime = {it -> timeFormat.format new Date(it) } +def convertDate = {it -> dateFormat.format new Date(it) } + +frame(title: 'Time Log Demo', + defaultCloseOperation : JFrame.EXIT_ON_CLOSE) +{ + gridBagLayout() + + label('Client:', insets:[6,6,3,3]) + textField('', id: 'tfClient', + enabled: bind( source: model, sourceProperty: 'running', converter: {!it} ), + gridwidth: REMAINDER, fill: HORIZONTAL, insets: [6,3,3,6]) + + label('00:00:00', font: new Font('Ariel', Font.BOLD, 42), + foreground: bind(source: model, sourceProperty: 'running', converter: {it ? Color.GREEN : Color.RED}), + text: bind(source: model, sourceProperty: 'elapsedTime', converter: convertTime), + gridwidth: 2, gridheight: 2, anchor: EAST, weightx: 1.0, insets: [3,6,3,3]) + button(startAction, id: 'startButton', + enabled: bind(source: model, sourceProperty: 'running', converter: {!it}), + gridwidth: REMAINDER, insets: [3,3,3,6]) + button(stopAction, id: 'stopButton', + enabled: bind(source: model, sourceProperty: 'running'), + gridwidth: REMAINDER, insets: [3,3,3,6]) + + separator(gridwidth: REMAINDER, fill: HORIZONTAL, insets: [9,6,9,6]) + + scrollPane(minimumSize: [100, 100], + gridwidth: REMAINDER, weighty: 1.0, fill: BOTH, insets: [3,6,6,6]) + { + table(id: 'clientsTable') { + tableModel(list: model.entries) { + propertyColumn(header: 'Client', propertyName: 'client') + closureColumn( header: 'Start', read: {convertDate it.start}) + closureColumn( header: 'Stop', read: {convertDate it.stop}) + closureColumn( header: 'Duration', read: {convertTime it.stop - it.start}) + } + } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/CompiledAtASTTransformation.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/CompiledAtASTTransformation.groovy b/src/examples/transforms/global/CompiledAtASTTransformation.groovy index 153bf20..f94e444 100755 --- a/src/examples/transforms/global/CompiledAtASTTransformation.groovy +++ b/src/examples/transforms/global/CompiledAtASTTransformation.groovy @@ -1,66 +1,66 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.global - -import org.codehaus.groovy.ast.* -import org.codehaus.groovy.transform.* -import org.codehaus.groovy.control.* -import org.codehaus.groovy.ast.expr.* -import org.codehaus.groovy.ast.stmt.* -import java.lang.annotation.* -import org.codehaus.groovy.ast.builder.AstBuilder - -/** -* This ASTTransformation adds a static getCompiledTime() : String method to every class. -* -* @author Hamlet D'Arcy -*/ -@GroovyASTTransformation(phase=CompilePhase.CONVERSION) -public class CompiledAtASTTransformation implements ASTTransformation { - - private static final compileTime = new Date().toString() - - public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { - - List classes = sourceUnit.ast?.classes - classes?.each { ClassNode clazz -> - clazz.addMethod(makeMethod()) - } - } - - /** - * OpCodes should normally be referenced, but in a standalone example I don't want to have to include - * the jar at compile time. - */ - MethodNode makeMethod() { - def ast = new AstBuilder().buildFromSpec { - method('getCompiledTime', /*OpCodes.ACC_PUBLIC*/1 | /*OpCodes.ACC_STATIC*/8, String) { - parameters {} - exceptions {} - block { - returnStatement { - constant(compileTime) - } - } - annotations {} - } - } - ast[0] - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.global + +import org.codehaus.groovy.ast.* +import org.codehaus.groovy.transform.* +import org.codehaus.groovy.control.* +import org.codehaus.groovy.ast.expr.* +import org.codehaus.groovy.ast.stmt.* +import java.lang.annotation.* +import org.codehaus.groovy.ast.builder.AstBuilder + +/** +* This ASTTransformation adds a static getCompiledTime() : String method to every class. +* +* @author Hamlet D'Arcy +*/ +@GroovyASTTransformation(phase=CompilePhase.CONVERSION) +public class CompiledAtASTTransformation implements ASTTransformation { + + private static final compileTime = new Date().toString() + + public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { + + List classes = sourceUnit.ast?.classes + classes?.each { ClassNode clazz -> + clazz.addMethod(makeMethod()) + } + } + + /** + * OpCodes should normally be referenced, but in a standalone example I don't want to have to include + * the jar at compile time. + */ + MethodNode makeMethod() { + def ast = new AstBuilder().buildFromSpec { + method('getCompiledTime', /*OpCodes.ACC_PUBLIC*/1 | /*OpCodes.ACC_STATIC*/8, String) { + parameters {} + exceptions {} + block { + returnStatement { + constant(compileTime) + } + } + annotations {} + } + } + ast[0] + } +} http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/CompiledAtExample.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/CompiledAtExample.groovy b/src/examples/transforms/global/CompiledAtExample.groovy index ec20202..dffbf4f 100755 --- a/src/examples/transforms/global/CompiledAtExample.groovy +++ b/src/examples/transforms/global/CompiledAtExample.groovy @@ -1,33 +1,33 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.global - -/** -* Demonstrates how a global transformation works. -* -* @author Hamlet D'Arcy -*/ - -println 'Script compiled at: ' + compiledTime - -class MyClass { - -} - -println 'Class compiled at: ' + MyClass.compiledTime +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.global + +/** +* Demonstrates how a global transformation works. +* +* @author Hamlet D'Arcy +*/ + +println 'Script compiled at: ' + compiledTime + +class MyClass { + +} + +println 'Class compiled at: ' + MyClass.compiledTime http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/LoggingASTTransformation.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/LoggingASTTransformation.groovy b/src/examples/transforms/global/LoggingASTTransformation.groovy index a22ed4b..c6a2903 100644 --- a/src/examples/transforms/global/LoggingASTTransformation.groovy +++ b/src/examples/transforms/global/LoggingASTTransformation.groovy @@ -1,73 +1,73 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.global - -import org.codehaus.groovy.transform.ASTTransformation -import org.codehaus.groovy.ast.ASTNode -import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.transform.GroovyASTTransformation -import org.codehaus.groovy.control.CompilePhase -import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.ast.AnnotationNode -import org.codehaus.groovy.ast.expr.ConstantExpression -import org.codehaus.groovy.ast.expr.MethodCallExpression -import org.codehaus.groovy.ast.expr.VariableExpression -import org.codehaus.groovy.ast.expr.ArgumentListExpression -import org.codehaus.groovy.ast.stmt.BlockStatement -import java.lang.annotation.Annotation -import org.codehaus.groovy.ast.expr.Expression -import org.codehaus.groovy.ast.stmt.Statement -import org.codehaus.groovy.ast.stmt.ExpressionStatement - -/** -* This ASTTransformation adds a start and stop message to every single method call. -* -* @author Hamlet D'Arcy -*/ -@GroovyASTTransformation(phase=CompilePhase.CONVERSION) -public class LoggingASTTransformation implements ASTTransformation { - - - public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { - List methods = sourceUnit.getAST()?.getMethods() - methods?.each { MethodNode method -> - Statement startMessage = createPrintlnAst("Starting $method.name") - Statement endMessage = createPrintlnAst("Ending $method.name") - - List existingStatements = method.getCode().getStatements() - existingStatements.add(0, startMessage) - existingStatements.add(endMessage) - } - } - - /** - * Creates the AST for a println invocation. - */ - private Statement createPrintlnAst(String message) { - return new ExpressionStatement( - new MethodCallExpression( - new VariableExpression("this"), - new ConstantExpression("println"), - new ArgumentListExpression( - new ConstantExpression(message) - ) - ) - ) - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.global + +import org.codehaus.groovy.transform.ASTTransformation +import org.codehaus.groovy.ast.ASTNode +import org.codehaus.groovy.control.SourceUnit +import org.codehaus.groovy.transform.GroovyASTTransformation +import org.codehaus.groovy.control.CompilePhase +import org.codehaus.groovy.ast.MethodNode +import org.codehaus.groovy.ast.AnnotationNode +import org.codehaus.groovy.ast.expr.ConstantExpression +import org.codehaus.groovy.ast.expr.MethodCallExpression +import org.codehaus.groovy.ast.expr.VariableExpression +import org.codehaus.groovy.ast.expr.ArgumentListExpression +import org.codehaus.groovy.ast.stmt.BlockStatement +import java.lang.annotation.Annotation +import org.codehaus.groovy.ast.expr.Expression +import org.codehaus.groovy.ast.stmt.Statement +import org.codehaus.groovy.ast.stmt.ExpressionStatement + +/** +* This ASTTransformation adds a start and stop message to every single method call. +* +* @author Hamlet D'Arcy +*/ +@GroovyASTTransformation(phase=CompilePhase.CONVERSION) +public class LoggingASTTransformation implements ASTTransformation { + + + public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { + List methods = sourceUnit.getAST()?.getMethods() + methods?.each { MethodNode method -> + Statement startMessage = createPrintlnAst("Starting $method.name") + Statement endMessage = createPrintlnAst("Ending $method.name") + + List existingStatements = method.getCode().getStatements() + existingStatements.add(0, startMessage) + existingStatements.add(endMessage) + } + } + + /** + * Creates the AST for a println invocation. + */ + private Statement createPrintlnAst(String message) { + return new ExpressionStatement( + new MethodCallExpression( + new VariableExpression("this"), + new ConstantExpression("println"), + new ArgumentListExpression( + new ConstantExpression(message) + ) + ) + ) + } +} http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/LoggingExample.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/LoggingExample.groovy b/src/examples/transforms/global/LoggingExample.groovy index 8b9bcea..2d9f38e 100644 --- a/src/examples/transforms/global/LoggingExample.groovy +++ b/src/examples/transforms/global/LoggingExample.groovy @@ -1,48 +1,48 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.global - -/** -* Demonstrates how a global transformation works. -* -* @author Hamlet D'Arcy -*/ - -def greet() { - println "Hello World" -} - -// this prints out Hello World along with the extra compile time logging -greet() - - -// -// The rest of this script is asserting that this all works correctly. -// - -// redirect standard out so we can make assertions on it -def standardOut = new ByteArrayOutputStream(); -System.setOut(new PrintStream(standardOut)); - -greet() -def result = standardOut.toString("ISO-8859-1").split('\n') -assert "Starting greet" == result[0].trim() -assert "Hello World" == result[1].trim() -assert "Ending greet" == result[2].trim() -standardOut.close() +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.global + +/** +* Demonstrates how a global transformation works. +* +* @author Hamlet D'Arcy +*/ + +def greet() { + println "Hello World" +} + +// this prints out Hello World along with the extra compile time logging +greet() + + +// +// The rest of this script is asserting that this all works correctly. +// + +// redirect standard out so we can make assertions on it +def standardOut = new ByteArrayOutputStream(); +System.setOut(new PrintStream(standardOut)); + +greet() +def result = standardOut.toString("ISO-8859-1").split('\n') +assert "Starting greet" == result[0].trim() +assert "Hello World" == result[1].trim() +assert "Ending greet" == result[2].trim() +standardOut.close() http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/build.xml ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/build.xml b/src/examples/transforms/global/build.xml index d187157..5bc8409 100644 --- a/src/examples/transforms/global/build.xml +++ b/src/examples/transforms/global/build.xml @@ -1,52 +1,52 @@ -<?xml version="1.0"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<project name="groovy-global-ast-transformation-example" default="jar-transform"> - - <!-- groovy-all .jar is assumed to be on your classpath. --> - <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" /> - - <target name="init" description="cleanup old class files"> - <delete dir="examples"/> - <delete> - <fileset dir="." includes="**/*.jar"/> - </delete> - </target> - - <target name="compile-transform" depends="init" description="Compiles the AST Transformation"> - - <groovyc destdir="." - srcdir="." - includes="*Transformation.groovy" - listfiles="true"> - </groovyc> - - </target> - - <target name="jar-transform" depends="compile-transform" description="Creates a .jar file for the global transform" > - <jar destfile="LoggingTransform.jar" - basedir="." - includes="**/*.class,META-INF/**" /> - - <echo>You can now run "groovy -cp LoggingTransform.jar LoggingExample.groovy" or "groovy -cp LoggingTransform.jar CompiledAtExample.groovy" to see that the transformation worked.</echo> - </target> -</project> - +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<project name="groovy-global-ast-transformation-example" default="jar-transform"> + + <!-- groovy-all .jar is assumed to be on your classpath. --> + <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" /> + + <target name="init" description="cleanup old class files"> + <delete dir="examples"/> + <delete> + <fileset dir="." includes="**/*.jar"/> + </delete> + </target> + + <target name="compile-transform" depends="init" description="Compiles the AST Transformation"> + + <groovyc destdir="." + srcdir="." + includes="*Transformation.groovy" + listfiles="true"> + </groovyc> + + </target> + + <target name="jar-transform" depends="compile-transform" description="Creates a .jar file for the global transform" > + <jar destfile="LoggingTransform.jar" + basedir="." + includes="**/*.class,META-INF/**" /> + + <echo>You can now run "groovy -cp LoggingTransform.jar LoggingExample.groovy" or "groovy -cp LoggingTransform.jar CompiledAtExample.groovy" to see that the transformation worked.</echo> + </target> +</project> + http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/global/readme.txt ---------------------------------------------------------------------- diff --git a/src/examples/transforms/global/readme.txt b/src/examples/transforms/global/readme.txt index 5fadd49..e774984 100644 --- a/src/examples/transforms/global/readme.txt +++ b/src/examples/transforms/global/readme.txt @@ -1,48 +1,48 @@ -==== - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -==== - -Global AST Transformation Example - -This example shows how to wire together a global transformation. - -The example requires ant in your path and the Groovy 1.6 (or greater) -Jar in your classpath. The current directory must *not* be on your -classpath, otherwise ant will try to read the META-INF directory and -apply the transformations prematurely. - -To build the example run "ant" from the current directory. The default -target will compile the classes needed. The last step of the build -script prints out the command needed to run the example. - -To run the first example perform the following from the command line: - groovy -cp LoggingTransform.jar LoggingExample.groovy - -The example should print: - Starting greet - Hello World - Ending greet - -To run the second example perform the following from the command line: - groovy -cp LoggingTransform.jar CompiledAtExample.groovy - -The example should print: - Scripted compiled at: [recently] - Class compiled at: [recently] - -No exceptions should occur. +==== + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +==== + +Global AST Transformation Example + +This example shows how to wire together a global transformation. + +The example requires ant in your path and the Groovy 1.6 (or greater) +Jar in your classpath. The current directory must *not* be on your +classpath, otherwise ant will try to read the META-INF directory and +apply the transformations prematurely. + +To build the example run "ant" from the current directory. The default +target will compile the classes needed. The last step of the build +script prints out the command needed to run the example. + +To run the first example perform the following from the command line: + groovy -cp LoggingTransform.jar LoggingExample.groovy + +The example should print: + Starting greet + Hello World + Ending greet + +To run the second example perform the following from the command line: + groovy -cp LoggingTransform.jar CompiledAtExample.groovy + +The example should print: + Scripted compiled at: [recently] + Class compiled at: [recently] + +No exceptions should occur. http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/local/LoggingASTTransformation.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/local/LoggingASTTransformation.groovy b/src/examples/transforms/local/LoggingASTTransformation.groovy index 0752e96..bd19b95 100644 --- a/src/examples/transforms/local/LoggingASTTransformation.groovy +++ b/src/examples/transforms/local/LoggingASTTransformation.groovy @@ -1,74 +1,74 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.local - -import org.codehaus.groovy.transform.ASTTransformation -import org.codehaus.groovy.ast.ASTNode -import org.codehaus.groovy.control.SourceUnit -import org.codehaus.groovy.transform.GroovyASTTransformation -import org.codehaus.groovy.control.CompilePhase -import org.codehaus.groovy.ast.MethodNode -import org.codehaus.groovy.ast.ClassNode -import org.codehaus.groovy.ast.stmt.ExpressionStatement -import org.codehaus.groovy.ast.expr.MethodCallExpression -import org.codehaus.groovy.ast.expr.VariableExpression -import org.codehaus.groovy.ast.expr.ConstantExpression -import org.codehaus.groovy.ast.expr.ArgumentListExpression -import org.codehaus.groovy.ast.stmt.Statement - -/** -* This transformation finds all the methods defined in a script that have -* the @WithLogging annotation on them, and then weaves in a start and stop -* message that is logged using println. -* -* @author Hamlet D'Arcy -*/ -@GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) -public class LoggingASTTransformation implements ASTTransformation { - - public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { - List methods = sourceUnit.getAST()?.getMethods() - // find all methods annotated with @WithLogging - methods.findAll { MethodNode method -> - method.getAnnotations(new ClassNode(WithLogging)) - }.each { MethodNode method -> - Statement startMessage = createPrintlnAst("Starting $method.name") - Statement endMessage = createPrintlnAst("Ending $method.name") - - List existingStatements = method.getCode().getStatements() - existingStatements.add(0, startMessage) - existingStatements.add(endMessage) - } - } - - /** - * This creates the ASTNode for a println statement. - */ - private Statement createPrintlnAst(String message) { - return new ExpressionStatement( - new MethodCallExpression( - new VariableExpression("this"), - new ConstantExpression("println"), - new ArgumentListExpression( - new ConstantExpression(message) - ) - ) - ) - } +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.local + +import org.codehaus.groovy.transform.ASTTransformation +import org.codehaus.groovy.ast.ASTNode +import org.codehaus.groovy.control.SourceUnit +import org.codehaus.groovy.transform.GroovyASTTransformation +import org.codehaus.groovy.control.CompilePhase +import org.codehaus.groovy.ast.MethodNode +import org.codehaus.groovy.ast.ClassNode +import org.codehaus.groovy.ast.stmt.ExpressionStatement +import org.codehaus.groovy.ast.expr.MethodCallExpression +import org.codehaus.groovy.ast.expr.VariableExpression +import org.codehaus.groovy.ast.expr.ConstantExpression +import org.codehaus.groovy.ast.expr.ArgumentListExpression +import org.codehaus.groovy.ast.stmt.Statement + +/** +* This transformation finds all the methods defined in a script that have +* the @WithLogging annotation on them, and then weaves in a start and stop +* message that is logged using println. +* +* @author Hamlet D'Arcy +*/ +@GroovyASTTransformation(phase=CompilePhase.SEMANTIC_ANALYSIS) +public class LoggingASTTransformation implements ASTTransformation { + + public void visit(ASTNode[] nodes, SourceUnit sourceUnit) { + List methods = sourceUnit.getAST()?.getMethods() + // find all methods annotated with @WithLogging + methods.findAll { MethodNode method -> + method.getAnnotations(new ClassNode(WithLogging)) + }.each { MethodNode method -> + Statement startMessage = createPrintlnAst("Starting $method.name") + Statement endMessage = createPrintlnAst("Ending $method.name") + + List existingStatements = method.getCode().getStatements() + existingStatements.add(0, startMessage) + existingStatements.add(endMessage) + } + } + + /** + * This creates the ASTNode for a println statement. + */ + private Statement createPrintlnAst(String message) { + return new ExpressionStatement( + new MethodCallExpression( + new VariableExpression("this"), + new ConstantExpression("println"), + new ArgumentListExpression( + new ConstantExpression(message) + ) + ) + ) + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/local/LoggingExample.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/local/LoggingExample.groovy b/src/examples/transforms/local/LoggingExample.groovy index 2d0dd2b..4d47a64 100644 --- a/src/examples/transforms/local/LoggingExample.groovy +++ b/src/examples/transforms/local/LoggingExample.groovy @@ -1,64 +1,64 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.local - -/** -* Demonstrates how a local transformation works. -* -* @author Hamlet D'Arcy -*/ - -def greet() { - println "Hello World" -} - -@WithLogging //this should trigger extra logging -def greetWithLogging() { - println "Hello World" -} - -// this prints out a simple Hello World -greet() - -// this prints out Hello World along with the extra compile time logging -greetWithLogging() - - -// -// The rest of this script is asserting that this all works correctly. -// - -// redirect standard out so we can make assertions on it -def standardOut = new ByteArrayOutputStream(); -System.setOut(new PrintStream(standardOut)); - -greet() -assert "Hello World" == standardOut.toString("ISO-8859-1").trim() - -// reset standard out and redirect it again -standardOut.close() -standardOut = new ByteArrayOutputStream(); -System.setOut(new PrintStream(standardOut)); - -greetWithLogging() -def result = standardOut.toString("ISO-8859-1").split('\n') -assert "Starting greetWithLogging" == result[0].trim() -assert "Hello World" == result[1].trim() -assert "Ending greetWithLogging" == result[2].trim() - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.local + +/** +* Demonstrates how a local transformation works. +* +* @author Hamlet D'Arcy +*/ + +def greet() { + println "Hello World" +} + +@WithLogging //this should trigger extra logging +def greetWithLogging() { + println "Hello World" +} + +// this prints out a simple Hello World +greet() + +// this prints out Hello World along with the extra compile time logging +greetWithLogging() + + +// +// The rest of this script is asserting that this all works correctly. +// + +// redirect standard out so we can make assertions on it +def standardOut = new ByteArrayOutputStream(); +System.setOut(new PrintStream(standardOut)); + +greet() +assert "Hello World" == standardOut.toString("ISO-8859-1").trim() + +// reset standard out and redirect it again +standardOut.close() +standardOut = new ByteArrayOutputStream(); +System.setOut(new PrintStream(standardOut)); + +greetWithLogging() +def result = standardOut.toString("ISO-8859-1").split('\n') +assert "Starting greetWithLogging" == result[0].trim() +assert "Hello World" == result[1].trim() +assert "Ending greetWithLogging" == result[2].trim() + http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/local/WithLogging.groovy ---------------------------------------------------------------------- diff --git a/src/examples/transforms/local/WithLogging.groovy b/src/examples/transforms/local/WithLogging.groovy index 51b2521..03611f2 100644 --- a/src/examples/transforms/local/WithLogging.groovy +++ b/src/examples/transforms/local/WithLogging.groovy @@ -1,37 +1,37 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package transforms.local -import java.lang.annotation.Retention -import java.lang.annotation.Target -import org.codehaus.groovy.transform.GroovyASTTransformationClass -import java.lang.annotation.ElementType -import java.lang.annotation.RetentionPolicy - -/** -* This is just a marker interface that will trigger a local transformation. -* The 3rd Annotation down is the important one: @GroovyASTTransformationClass -* The parameter is the String form of a fully qualified class name. -* -* @author Hamlet D'Arcy -*/ -@Retention(RetentionPolicy.SOURCE) -@Target([ElementType.METHOD]) -@GroovyASTTransformationClass(["transforms.local.LoggingASTTransformation"]) -public @interface WithLogging { +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package transforms.local +import java.lang.annotation.Retention +import java.lang.annotation.Target +import org.codehaus.groovy.transform.GroovyASTTransformationClass +import java.lang.annotation.ElementType +import java.lang.annotation.RetentionPolicy + +/** +* This is just a marker interface that will trigger a local transformation. +* The 3rd Annotation down is the important one: @GroovyASTTransformationClass +* The parameter is the String form of a fully qualified class name. +* +* @author Hamlet D'Arcy +*/ +@Retention(RetentionPolicy.SOURCE) +@Target([ElementType.METHOD]) +@GroovyASTTransformationClass(["transforms.local.LoggingASTTransformation"]) +public @interface WithLogging { } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/local/build.xml ---------------------------------------------------------------------- diff --git a/src/examples/transforms/local/build.xml b/src/examples/transforms/local/build.xml index 8f19de3..b66a3ad 100644 --- a/src/examples/transforms/local/build.xml +++ b/src/examples/transforms/local/build.xml @@ -1,44 +1,44 @@ -<?xml version="1.0"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> -<project name="groovy-local-ast-transformation-example" default="compile-transform"> - - <!-- groovy-all .jar is assumed to be on your classpath. --> - <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" /> - - - <target name="init" description="cleanup old class files"> - <delete dir="examples"/> - </target> - - <target name="compile-transform" depends="init" description="Compiles the AST Transformation"> - - <groovyc destdir="." - srcdir="." - includes="LoggingASTTransformation.groovy,WithLogging.groovy" - listfiles="true"> - </groovyc> - - <echo>You can now run "groovy LoggingExample.groovy" to see that the transformation worked.</echo> - </target> - -</project> - +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<project name="groovy-local-ast-transformation-example" default="compile-transform"> + + <!-- groovy-all .jar is assumed to be on your classpath. --> + <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" /> + + + <target name="init" description="cleanup old class files"> + <delete dir="examples"/> + </target> + + <target name="compile-transform" depends="init" description="Compiles the AST Transformation"> + + <groovyc destdir="." + srcdir="." + includes="LoggingASTTransformation.groovy,WithLogging.groovy" + listfiles="true"> + </groovyc> + + <echo>You can now run "groovy LoggingExample.groovy" to see that the transformation worked.</echo> + </target> + +</project> + http://git-wip-us.apache.org/repos/asf/groovy/blob/2fb0075b/src/examples/transforms/local/readme.txt ---------------------------------------------------------------------- diff --git a/src/examples/transforms/local/readme.txt b/src/examples/transforms/local/readme.txt index 57be14c..2daade2 100644 --- a/src/examples/transforms/local/readme.txt +++ b/src/examples/transforms/local/readme.txt @@ -1,40 +1,40 @@ -==== - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -==== - -Local AST Transformation Example - -This example shows how to wire together a local transformation. - -The example requires ant in your path and the Groovy 1.6 (or greater) -Jar in your classpath. - -To build the example run "ant" from the current directory. The default -target will compile the classes needed. The last step of the build -script prints out the command needed to run the example. - -To run the example perform the following from the command line: - groovy LoggingExample.groovy - -The example should print: - Hello World - Starting greetWithLogging - Hello World - Ending greetWithLogging - +==== + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +==== + +Local AST Transformation Example + +This example shows how to wire together a local transformation. + +The example requires ant in your path and the Groovy 1.6 (or greater) +Jar in your classpath. + +To build the example run "ant" from the current directory. The default +target will compile the classes needed. The last step of the build +script prints out the command needed to run the example. + +To run the example perform the following from the command line: + groovy LoggingExample.groovy + +The example should print: + Hello World + Starting greetWithLogging + Hello World + Ending greetWithLogging + No exceptions should occur. \ No newline at end of file