You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/08/12 06:07:21 UTC
[1/4] groovy git commit: move examples to their own repo
Repository: groovy
Updated Branches:
refs/heads/master 87839a294 -> ed3814a05
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/codehaus-style.css
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/codehaus-style.css b/src/examples/webapps/groovlet-examples/codehaus-style.css
deleted file mode 100644
index 86667ce..0000000
--- a/src/examples/webapps/groovlet-examples/codehaus-style.css
+++ /dev/null
@@ -1,626 +0,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.
- */
-body {
- font-family: Verdana, Helvetica, Arial, sans-serif;
- font-size: small;
- margin: 0;
-}
-
-div {
- /* line-height: 1.5em; */
-}
-
-a {
- color: #008800;
- text-decoration: none;
- font-weight: bold;
-}
-
-.navLink a {
- font-weight: normal;
-}
-
-.navLink {
- margin-left: 5px;
-}
-
-.navLink:first-line {
- margin-left: -5px;
-}
-
-
-a:link.selfref, a:visited.selfref {
-}
-
-a:link, a:visited {
-}
-
-a:active, a:hover {
- text-decoration: underline;
-}
-
-a.plain:active, a.plain:hover {
- text-decoration: none;
-}
-
-.sectionTitle a {
- text-decoration: underline;
-}
-.subsectionTitle a {
- text-decoration: underline;
-}
-
-span.highlight {
- font-weight: bold;
- color: #990000;
-}
-
-#layout {
- margin: 0px;
- padding: 0px;
-}
-
-#banner {
- padding: 8px;
-}
-
-#breadcrumbs {
- border-top: 1px solid #009900;
- border-bottom: 1px solid #009900;
- padding-left: 12px;
- padding-right: 12px;
- padding-top: 2px;
- padding-bottom: 2px;
- font-size: x-small;
- background-color: #dddddd;
-}
-
-#breadcrumbs td {
- font-size: x-small;
-}
-
-#breadcrumbs a {
- font-weight: bold;
-}
-
-#layout {
- /*border-top: 1px solid #009900;*/
- padding: 0px;
- margin: 0px;
-
-}
-
-.navSection {
- background-color: #ffffff;
- border: 1px solid #999999;
- border-top: none;
- padding: 0px;
- margin-bottom: 8px;
- font-size: small;
-}
-
-.navSection a {
- font-weight: normal;
-}
-
-.navSectionHead {
- border-top: 1px solid #999999;
- border-bottom: 1px solid #999999;
- color: #555555;
- padding: 4px;
- margin-left: 0px;
- margin-right: 0px;
- background-color: #eeeeee;
- font-weight: bold;
- font-size: x-small;
-}
-
-.navLink {
- padding-top: 2px;
- padding-bottom: 2px;
- padding-left: 14px;
- font-size: small;
-}
-
-.section {
- padding-bottom: 16px;
-}
-
-* + h1 {
- margin-top: 1.5em;
-}
-
-* + h2 {
- margin-top: 1.5em;
-}
-
-.sectionTitle, h1 {
- padding: 4px;
- border: 1px solid #aaaaaa;
- color: #007700;
- font-size: larger;
- background-color: #eee;
- color: #007700;
- font-weight: bold;
- margin-bottom: .5em;
- /* margin-top: 1em; */
-}
-
-.subsection {
- padding-left: 20px;
- margin-top: 10px;
- margin-bottom: 10px;
-}
-
-body:first-child {
- padding-top: 0px;
-}
-
-.subsectionTitle, h2 {
- padding-left: .2em;
- /* margin-top: 1em; */
- margin-bottom: .5em;
- border-bottom: 1px solid #999;
- border-left: 1px solid #999;
- background-color: white;
- font-weight: bold;
- font-size: larger;
-}
-
-.sectionTitle a {
- font-weight: normal;
-}
-
-.subsectionTitle a {
- font-weight: normal;
-}
-
-.subsubsection {
- padding-left: 30px;
-}
-
-.subsubsectionTitle, h3, .blogheading {
- font-weight: bold;
- border-bottom: 1px solid #bbb;
- padding: .1em;
- color: #555;
- margin-bottom: .5em;
-}
-
-h4 {
- margin-bottom: .5em;
- padding: .1em;
- border: 1px solid #ddd;
-
-}
-
-ins.inserted {
- text-decoration: none;
- font-weight: bold;
-}
-
-#leftColumn {
- width: 12em;
-}
-
-#leftColumn h3 {
- background-color: #ddd;
- border: 1px solid #ccc;
- border-bottom: 1px solid #070;
- margin-bottom: .5em;
-}
-
-#leftColumn a {
- font-weight: inherit;
-}
-
-#breadcrumbs a {
- font-weight: inherit;
-}
-
-
-p {
- margin: 0px;
- margin-bottom: .5em;
- line-height: 1.2em;
- padding-right: 20px;
- padding-left: 0px;
-}
-
-blockquote p {
- padding-left: 0px;
- padding-right: 0px;
-}
-
-ul {
- margin-top: 1em;
- margin-bottom: 1em;
- padding-left: 1.5em;
-}
-
-ul ul {
- margin: 0px;
- padding-left: 1em;
-}
-
-li {
- margin: 0px;
- margin-right: 15%;
- line-height: 1.2em;
-}
-
-#leftColumn {
- border-right: 1px solid #cccccc;
- background-color: #eeeeee;
- padding: 12px;
- font-size: small;
-}
-
-#leftColumn a {
- font-size: smaller;
-}
-
-#leftColumn tt a {
- font-size: inherit;
-}
-
-#leftColumn h3 a {
- font-size: inherit;
-}
-
-tt {
- font-size: larger;
-}
-
-
-#extraColumn {
- padding: 12px;
-}
-
-#navBox {
-}
-
-#rightColumn {
- padding: 12px;
- border-right: 1px solid #cccccc;
- font-size: small;
- padding-left: 16px;
- padding-right: 16px;
-}
-
-#contentBox {
-
-}
-
-table.bodyTable, table.wikitable {
- margin: 10px;
- border-collapse: collapse;
- border-spacing: 0pt;
- background-color: #eeeeee;
-}
-
-#Content table.grid {
- border: 1px solid #bbbbbb;
-}
-
-table.grid {
- padding: 0px;
- border-collapse: collapse;
- border-spacing: 0pt;
- margin-left: 1em;
- margin-right: 1em;
-}
-
-table.grid th {
- background-color: #eeeeee;
- font-size: smaller;
- padding: 4px;
- border: 1px solid #bbbbbb;
-}
-
-table.grid td {
- font-size: x-small;
- border: 1px solid #bbbbbb;
- padding: 3px;
-}
-
-table.bodyTable th, table.bodyTable td, table.wikitable th, table.wikitable td {
- border: 1px solid #999999;
- font-size: smaller;
- padding: 4px;
-}
-
-
-table.bodyTable th, table.wikitable th {
- text-align: left;
- background-color: #dddddd;
- border: 2px solid #999999;
- padding: 4px;
-}
-
-.nobr
- white-space: nowrap;
-}
-
-table.bodyTable td {
- padding: 4px;
-}
-
-/*
-table.bodyTable th, table.wikitable th {
- border-bottom: 2px solid #999999;
-}
-
-table.bodyTable tr.a {
- background-color: #dedede;
-}
-
-table.bodyTable tr.b {
- background-color: #efefef;
-}
-*/
-
-.source, .code {
- padding: 12px;
- margin: 1em;
- border: 1px solid #007700;
- border-left: 2px solid #007700;
- border-right: 2px solid #007700;
- color: #555555;
-}
-
-pre {
- padding: 12px;
- font-size: larger;
-}
-
-.java-keyword {
- color: #009900;
-}
-
-.java-object {
- color: #000099;
-}
-
-.java-quote {
- color: #990000;
-}
-
-
-.source, .code pre {
- margin: 0px;
- margin-left: 8px;
- padding: 0px;
-}
-
-#footer {
- padding-left: 4px;
- border-top: 1px solid #009900;
- color: #888888;
- font-size: x-small;
-}
-
-blockquote {
- border-top: 1px solid #bbbbbb;
- border-bottom: 1px solid #bbbbbb;
- border-left: 3px solid #bbbbbb;
- border-right: 3px solid #bbbbbb;
- padding: 12px;
- margin-left: 3em;
- margin-right: 3em;
- color: #666666;
- background-color: white;
- line-height: 1.5em;
-}
-
-input[type="text"] {
- margin: 0px;
- border: 1px solid #999999;
- background-color: #dddddd;
-}
-
-input.required {
- margin: 0px;
- border: 1px solid #990000;
-}
-
-input {
- border: 1px solid #999999;
-}
-
-textarea {
- border: 1px solid #999999;
-}
-
-textarea.required {
- border: 1px solid #990000;
-}
-
-label {
- font-size: smaller;
-}
-
-label.required {
- color: #990000;
-}
-
-.searchResults {
- color: black;
-}
-
-.searchResults b {
- color: #007700;
-}
-
-
-.linecomment { color: #bbbbbbb; }
-.blockcomment { color: #bbbbbbb; }
-.prepro { color: #0000BB; }
-.select {}
-.quote { color: #770000; }
-.category1 { color: #007700; }
-.category2 { color: #0000BB; }
-.category3 { color: #0000BB; }
-
-#page_title {
- border-bottom: 1px solid black;
- font-weight: bold;
- font-size: x-large;
- margin-bottom: .5em;
-}
-
-.greenbar {
- background-color: green;
-}
-
-.redbar {
- background-color: red;
-}
-
-tr.testpassed td {
- padding: 0px;
- padding-left: 1px;
- padding-right: 1px;
- margin: 0px;
-}
-
-tr td.noformatting {
- border: none;
- padding: 0px;
- padding-left: 4px;
- padding-right: 4px;
- margin: 0px;
-}
-
-.greybox {
- font-style: italic;
- font-weight: bold;
- margin-top: .5em;
- margin-bottom: .5em;
- background-color: #ddd;
- border: 1px solid #bbb;
- padding: .3em;
-}
-
-.panelContent {
- border: 1px solid #999;
- padding: 1em;
- margin: 1em;
-}
-
-.header_name {
- font-size: smaller;
- padding: 2px;
- padding-right: 1ex;
- border-right: 1px solid #555;
- background-color: #ccc;
-}
-
-.header_value {
- font-size: smaller;
- background-color: #ddd;
- padding: 2px;
-}
-
-.header_fields {
- width: 100%;
- border: 1px solid #999;
- background-color: #fff;
-}
-
-.email_body {
- margin: 2ex;
- padding: 1ex;
- padding-left: 2ex;
- padding-right: 2ex;
- border: 1px solid #999;
- font-size: smaller;
-}
-
-.email_body pre {
- padding: 0px;
- margin: 0px;
-}
-
-.email_body blockquote {
- padding: 0px;
- margin: 0px;
- border: 1px solid #ccc;
-}
-
-.msg_navblock {
- margin-bottom: 2ex;
- border: 1px solid #999;
- background-color: #fff;
-}
-
-.msg_navblock th {
- border: 1px solid #ccc;
- font-size: smaller;
-}
-
-.msg_navblock td {
- border: 1px solid #ccc;
- font-size: smaller;
-}
-
-.single_entry {
- border: 1px solid #aaa;
- padding: .5ex;
- padding-left: 1ex;
- border-left: 1px solid #090;
- margin: 2px;
- background-color: #eee;
-}
-
-.root_entry {
- border: 1px solid #aaa;
- padding: .5ex;
- padding-left: 1ex;
- border-left: 1px solid #090;
- margin-top: 8px;
- margin-bottom: 8px;
- background-color: #eee;
-}
-
-.root_entry .sub_entry {
- padding: .5ex;
- padding-left: 1ex;
- margin: 2px;
- margin-left: 1ex;
- border-left: 1px solid #999;
-}
-
-.list_entry {
- border: 1px solid #aaa;
- padding: 1ex;
- margin-top: 1ex;
- margin-bottom: 1ex;
-}
-
-.list_entry td {
- border: 1px solid #999;
-}
-
-.project_entry {
- border: 1px solid #aaa;
- padding: 1ex;
- margin-top: 1ex;
- margin-bottom: 1ex;
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/hello/hello.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/hello/hello.groovy b/src/examples/webapps/groovlet-examples/hello/hello.groovy
deleted file mode 100644
index 85b8617..0000000
--- a/src/examples/webapps/groovlet-examples/hello/hello.groovy
+++ /dev/null
@@ -1,51 +0,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.
- */
-println """
-<html>
- <head>
- <title>Groovy Servlet Example - hello</title>
- </head>
- <body>
- <a href="../"><img src="../images/return.gif" width="24" height="24" border="0"></a><a href="../">Return</a>
- <p>
-"""
-
-session = request.getSession(true);
-
-if (session.counter == null) {
- session.counter = 1
-}
-
-
-println """Hello, ${request.remoteHost}! ${new java.util.Date()}"""
-
-println """
-<dl>
- <dt><b>requestURI</b></dt><dd>${request.requestURI}</dd>
- <dt><b>servletPath</b></dt><dd>${request.servletPath}</dd>
- <dt><b>session.counter</b></dt><dd>${session.counter}</dd>
-</dl>
-"""
-
-println """
- </body>
-</html>
-"""
-
-session.counter = session.counter + 1
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/images/code.gif
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/images/code.gif b/src/examples/webapps/groovlet-examples/images/code.gif
deleted file mode 100644
index 93af2cd..0000000
Binary files a/src/examples/webapps/groovlet-examples/images/code.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/images/execute.gif
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/images/execute.gif b/src/examples/webapps/groovlet-examples/images/execute.gif
deleted file mode 100644
index f64d70f..0000000
Binary files a/src/examples/webapps/groovlet-examples/images/execute.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/images/groovy.png
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/images/groovy.png b/src/examples/webapps/groovlet-examples/images/groovy.png
deleted file mode 100644
index 54af4c1..0000000
Binary files a/src/examples/webapps/groovlet-examples/images/groovy.png and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/images/return.gif
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/images/return.gif b/src/examples/webapps/groovlet-examples/images/return.gif
deleted file mode 100644
index af4f68f..0000000
Binary files a/src/examples/webapps/groovlet-examples/images/return.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/index.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/index.groovy b/src/examples/webapps/groovlet-examples/index.groovy
deleted file mode 100644
index 6a62dc6..0000000
--- a/src/examples/webapps/groovlet-examples/index.groovy
+++ /dev/null
@@ -1,107 +0,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.
- */
-println """
-
-<!-- Groovy Groovlet Examples. -->
-
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="Groovy Developers">
- <title>Groovy - Groovlet Examples</title>
- <link rel="stylesheet" href="codehaus-style.css" type="text/css">
-</head>
-
-<body bgcolor="#FFFFFF">
-
-<a href="http://groovy.codehaus.org"><img src="images/groovy.png" border="0"></a>
-
-<h1>Groovlet examples showing GroovyServlet in action</h1>
-<p>
-These examples will only work when viewed via an http URL. They will not work
-if you are viewing these pages via a <tt>file://...</tt> URL. You need to
-deploy the <tt>war</tt> archive into a servlet container like Tomcat, Jetty or
-any other will do as well.
-</p>
-
-<p>
-To navigate your way through the examples, the following icons will help:
-
-<table border=0>
- <tr>
- <td width="30"><img src="images/execute.gif" ></td>
- <td>Executes the example</td>
-</tr>
-<tr>
- <td width="30"><img src="images/code.gif"></td>
- <td>Look at the source code for the example</td>
-</tr>
-<tr>
- <td width="30"><img src="images/return.gif"></td>
- <td>Return to this screen</td>
-</tr>
-</table>
-</p>
-
-<p>Tip: To see the cookie interactions with your browser, try turning on
-the "notify when setting a cookie" option in your browser preferences.
-This will let you see when a session is created and give some feedback
-when looking at the cookie demo.
-</p>
-
-<h2>Table of content</h2>
-
-"""
-
-println """
-
-<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
-
-<!-- Begin Groovlet -->
-<tr VALIGN=TOP>
-<td>Hello World</td>
-
-<td VALIGN=TOP WIDTH="30%"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP><a href="hello/hello.groovy">Execute</a></td>
-
-<td WIDTH="30%"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP>Source</td>
-</tr>
-<!-- End Groovlet -->
-
-
-<!-- Begin Groovlet -->
-<tr VALIGN=TOP>
-<td>Zoo</td>
-
-<td VALIGN=TOP WIDTH="30%"><img SRC="images/execute.gif" HSPACE=4 BORDER=0 align=TOP><a href="zoo/zoo.groovy">Execute</a></td>
-
-<td WIDTH="30%"><img SRC="images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP>Source</td>
-</tr>
-<!-- End Groovlet -->
-</table>
-
-<h2>Note</h2>
-
-<p>The source code for these examples does not contain all of the
-source code that is actually in the example, only the important sections
-of code. Code not important to understand the example has been removed
-for clarity.
-</body>
-</html>
-"""
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/readme.txt b/src/examples/webapps/groovlet-examples/readme.txt
deleted file mode 100644
index bd57e05..0000000
--- a/src/examples/webapps/groovlet-examples/readme.txt
+++ /dev/null
@@ -1,32 +0,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.
-====
-
-
-GroovyServlet examples
-
-[ / ]
-Only contains the "index.groovy", "codehaus-style.css" and "readme.txt" files.
-
-[ /hello ]
-Contains a single welcome file named "hello.groovy" showing a simple groovlet.
-
-[ /zoo ]
-The zoo demonstrates a groovy setup of scripts, that are partly <i>hidden</i>
-beneath the "WEB-INF/groovy" directory. Note the different package names in the
-script files.
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/xml/index.xhtml
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/xml/index.xhtml b/src/examples/webapps/groovlet-examples/xml/index.xhtml
deleted file mode 100644
index 06c9a17..0000000
--- a/src/examples/webapps/groovlet-examples/xml/index.xhtml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?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.
-
--->
-<!-- DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" -->
-
-<html xmlns:gsp="http://groovy.codehaus.org/2005/gsp">
-
- <head>
- <link rel="stylesheet" href="../codehaus-style.css" type="text/css" />
- </head>
-
- <body>
-
- Name = ${request.getParameter("name")} <br/>
- Name = <gsp:expression>params.get("name")</gsp:expression>
-
- <hr color="#12334" noshade="noshade" />
-
- BEGIN
-
- <br/>
-
- <gsp:scriptlet>
- <![CDATA[
- 3.times {
- ]]>
- </gsp:scriptlet>
-* Hello World! *
- <gsp:scriptlet>
- <![CDATA[ } // 3.times ]]>
- </gsp:scriptlet>
-
- <br/>
-
- END
-
- </body>
-
-</html>
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/zoo/HommingbergerGepardenforelle.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/zoo/HommingbergerGepardenforelle.groovy b/src/examples/webapps/groovlet-examples/zoo/HommingbergerGepardenforelle.groovy
deleted file mode 100644
index 2280e05..0000000
--- a/src/examples/webapps/groovlet-examples/zoo/HommingbergerGepardenforelle.groovy
+++ /dev/null
@@ -1,27 +0,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 zoo
-
-class HommingbergerGepardenforelle extends zoo.fish.Trout {
-
- String saySomething(String something) {
- return something;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/zoo/visit.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/zoo/visit.groovy b/src/examples/webapps/groovlet-examples/zoo/visit.groovy
deleted file mode 100644
index 7c81126..0000000
--- a/src/examples/webapps/groovlet-examples/zoo/visit.groovy
+++ /dev/null
@@ -1,37 +0,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.
- */
-Animal shark = new zoo.fish.Shark()
-Animal trout = new zoo.fish.Trout()
-Animal forelle = new zoo.HommingbergerGepardenforelle()
-
-println """
-<html>
- <head>
- <title>Groovy Servlet Example - Visiting the zoo</title>
- </head>
- <body>
- <p>Shark<br>
- ${shark.saySomething("\"Where is the trout?\"")}
- <p>Trout<br>
- ${trout.saySomething("Here is the trout!")}
- <p>Forelle<br>
- ${forelle.saySomething("\"<a href=\"http://www.hommingberger-forelle.de\">There is no spoon.</a>\"")}
- </body>
-</html>
-"""
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/zoo/zoo.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/zoo/zoo.groovy b/src/examples/webapps/groovlet-examples/zoo/zoo.groovy
deleted file mode 100644
index 38a4c94..0000000
--- a/src/examples/webapps/groovlet-examples/zoo/zoo.groovy
+++ /dev/null
@@ -1,48 +0,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.
- */
-println """
-<html>
- <head>
- <title>Groovy Servlet Example - Visiting the zoo</title>
- </head>
- <body>
- <a href="../"><img src="../images/return.gif" width="24" height="24" border="0"></a><a href="../">Return</a>
- <p>
-"""
-
-Animal shark = new zoo.fish.Shark()
-Animal trout = new zoo.fish.Trout()
-Animal forelle = new zoo.HommingbergerGepardenforelle()
-
-println """
- <p>Shark<br>
- ${shark.saySomething("\"Where is the trout?\"")}
-
- <p>Trout<br>
- ${trout.saySomething("Here is the trout!")}
-
- <p>Forelle<br>
- ${forelle.saySomething("\"<a href=\"http://www.hommingberger-forelle.de\">There is no spoon.</a>\"")}
- <!-- http://en.wikipedia.org/wiki/Nigritude_ultramarine -->
-"""
-
-println """
- </body>
-</html>
-"""
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/gsp-examples/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/webapps/gsp-examples/readme.txt b/src/examples/webapps/gsp-examples/readme.txt
deleted file mode 100644
index 6f197c6..0000000
--- a/src/examples/webapps/gsp-examples/readme.txt
+++ /dev/null
@@ -1,20 +0,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.
-====
-
-TODO Second, setup WEB-INF and examples gsp files.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/template-examples/3.times.HelloWorld.html
----------------------------------------------------------------------
diff --git a/src/examples/webapps/template-examples/3.times.HelloWorld.html b/src/examples/webapps/template-examples/3.times.HelloWorld.html
deleted file mode 100644
index d270530..0000000
--- a/src/examples/webapps/template-examples/3.times.HelloWorld.html
+++ /dev/null
@@ -1,33 +0,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.
-
--->
-<html>
- <body>
-
- <% 3.times { %>
- Hello World!
- <% } %>
-
- <br>
-
- session id = ${session.id}
-
- </body>
-</html>
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/template-examples/WEB-INF/lib/groovy-all-xyz.jar.placeholder
----------------------------------------------------------------------
diff --git a/src/examples/webapps/template-examples/WEB-INF/lib/groovy-all-xyz.jar.placeholder b/src/examples/webapps/template-examples/WEB-INF/lib/groovy-all-xyz.jar.placeholder
deleted file mode 100644
index f0f8ae5..0000000
--- a/src/examples/webapps/template-examples/WEB-INF/lib/groovy-all-xyz.jar.placeholder
+++ /dev/null
@@ -1,18 +0,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.
- */
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/template-examples/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/examples/webapps/template-examples/WEB-INF/web.xml b/src/examples/webapps/template-examples/WEB-INF/web.xml
deleted file mode 100644
index 2345235..0000000
--- a/src/examples/webapps/template-examples/WEB-INF/web.xml
+++ /dev/null
@@ -1,46 +0,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.
-
--->
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
- version="2.4">
-
-<servlet>
- <servlet-name>template</servlet-name>
- <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>template</servlet-name>
- <url-pattern>*.htm</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
- <servlet-name>template</servlet-name>
- <url-pattern>*.html</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
- <servlet-name>template</servlet-name>
- <url-pattern>*.template</url-pattern>
- </servlet-mapping>
-
-</web-app>
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/template-examples/javasystemproperties.htm
----------------------------------------------------------------------
diff --git a/src/examples/webapps/template-examples/javasystemproperties.htm b/src/examples/webapps/template-examples/javasystemproperties.htm
deleted file mode 100644
index fa1f2c5..0000000
--- a/src/examples/webapps/template-examples/javasystemproperties.htm
+++ /dev/null
@@ -1,42 +0,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.
-
--->
-<html>
-<head>
-<title>System properties</title>
-</head>
-<body>
-
-<h1>System properties</h1>
-<% keys = System.getProperties().keySet();
- if (keys.isEmpty()) {
- out.println('No keys.');
- }
- else {
- %>
-<dl>
- <% for (key in keys) { %>
- <dt> <b> ${key} </b> </dt>
- <dd> <tt> ${System.getProperty(key)} </tt> </dd>
- <% } %>
-</dl>
-<% } %>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/template-examples/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/webapps/template-examples/readme.txt b/src/examples/webapps/template-examples/readme.txt
deleted file mode 100644
index 269ffbd..0000000
--- a/src/examples/webapps/template-examples/readme.txt
+++ /dev/null
@@ -1,32 +0,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.
-====
-
-
-TemplateServlet examples
-
-[ /readme.txt ]
-This readme file. For clarity sake, it does not contain a welcome file and
-therefore the servlet container should list all files and subdirectories listed
-below.
-
-[ /3.times.HelloWorld.html ]
-Prints three times "Hello World!" and the session id.
-
-[ /javasystemproperties.htm ]
-Lists Java runtime system properties.
[3/4] groovy git commit: move examples to their own repo
Posted by pa...@apache.org.
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovyShell/BlacklistingShellTest.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovyShell/BlacklistingShellTest.groovy b/src/examples/groovyShell/BlacklistingShellTest.groovy
deleted file mode 100644
index e24e149..0000000
--- a/src/examples/groovyShell/BlacklistingShellTest.groovy
+++ /dev/null
@@ -1,82 +0,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.
- */
-/**
-* Unit test for BlacklistingShell.
-* Requires JUnit to be in path, just like any other GroovyTestCase.
-*
-* @author Jim Driscoll jamesgdriscoll@gmail.com
-*/
-class BlacklistingShellTest extends GroovyTestCase {
-
- private BlacklistingShell shell
-
- void setUp() {
- shell = new BlacklistingShell()
- }
-
- Object evaluate(String text) {
- shell.evaluate(text)
- }
-
- void testEvaluate_SuccessfulPaths() {
- assert 6 == evaluate("++(5)")
- assert 0 == evaluate("5 < 4 ? 1 : 0")
- assert 0 == evaluate("5 != 4 ? 0 : 1")
- assert 0 == evaluate("5 < 4 ?: 0 ")
- }
-
- void testEvaluate_Failures() {
- shouldFail(SecurityException) {
- evaluate('def c = System.class; c.forName("java.lang.System").exit(0)')
- }
- shouldFail(SecurityException) {
- evaluate('Class.forName("java.lang.System").exit(0)')
- }
- shouldFail(SecurityException) {
- evaluate('System.exit(0)')
- }
- shouldFail(SecurityException) {
- evaluate('def e = System.&exit; e.call(0)')
- }
- shouldFail(SecurityException) {
- evaluate('System.&exit.call(0)')
- }
- shouldFail(SecurityException) {
- evaluate('System.getMetaClass().invokeMethod("exit",0)')
- }
- shouldFail(SecurityException) {
- evaluate('evaluate("System.exit(0)")')
- }
- shouldFail(SecurityException) {
- evaluate('(new GroovyShell()).evaluate("System.exit(0)")')
- }
- shouldFail(SecurityException) {
- evaluate('def sh = new GroovyShell(); sh.evaluate("System.exit(0)")')
- }
- shouldFail(SecurityException) {
- evaluate('Eval.me("System.exit(0)")')
- }
- shouldFail(SecurityException) {
- evaluate('def s = System; s.exit(0)')
- }
- shouldFail(SecurityException) {
- evaluate('Script t = this; t.evaluate("System.exit(0)")')
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java
----------------------------------------------------------------------
diff --git a/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java b/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java
deleted file mode 100644
index 848ebf3..0000000
--- a/src/examples/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java
+++ /dev/null
@@ -1,264 +0,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 org.codehaus.groovy.grails.compiler.injection;
-
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.*;
-import org.codehaus.groovy.ast.stmt.ReturnStatement;
-import org.codehaus.groovy.ast.stmt.Statement;
-import org.codehaus.groovy.control.CompilePhase;
-import org.codehaus.groovy.control.SourceUnit;
-import org.codehaus.groovy.transform.ASTTransformation;
-import org.codehaus.groovy.transform.GroovyASTTransformation;
-
-import java.lang.reflect.Modifier;
-import java.net.URL;
-import java.util.*;
-
-/**
- * This is substantially the same code from Grails, except some references de-referenced
- * and the macro class added.
- *
- * Default implementation of domain class injector interface that adds the 'id'
- * and 'version' properties and other previously boilerplate code
- *
- * @author Graeme Rocher
- *
- * @since 0.2
- *
- * Created: 20th June 2006
- */
-@GroovyASTTransformation(phase= CompilePhase.CANONICALIZATION)
-public class DefaultGrailsDomainClassInjector implements ASTTransformation {
- //GrailsDomainClassInjector {
-
- //private static final Log LOG = LogFactory.getLog(DefaultGrailsDomainClassInjector.class);
-
-
- public void visit(ASTNode[] nodes, SourceUnit source) {
- performInjection((ClassNode) nodes[1]);
- }
-
- public void performInjection(ClassNode classNode) {
- if(shouldInject(classNode)) {
- injectIdProperty(classNode);
-
- injectVersionProperty(classNode);
-
- injectToStringMethod(classNode);
-
- injectAssociations(classNode);
-
- }
- }
-
- public boolean shouldInject(URL url) {
- return true; //return GrailsResourceUtils.isDomainClass(url);
- }
-
- private boolean shouldInject(ClassNode classNode) {
- //String fullName = GrailsASTUtils.getFullName(classNode);
- //String mappingFile = GrailsDomainConfigurationUtil.getMappingFileName(fullName);
-
- //if(getClass().getResource(mappingFile)!=null) {
- //if(LOG.isDebugEnabled()) {
- //LOG.debug("[GrailsDomainInjector] Mapping file ["+mappingFile+"] found. Skipping property injection.");
- //}
- //return false;
- //}
- return true;
- }
-
- private void injectAssociations(ClassNode classNode) {
-
- List properties = classNode.getProperties();
- List propertiesToAdd = new ArrayList();
- for (Iterator p = properties.iterator(); p.hasNext();) {
- PropertyNode pn = (PropertyNode) p.next();
- final boolean isHasManyProperty = pn.getName().equals(/*GrailsDomainClassProperty.*/RELATES_TO_MANY) || pn.getName().equals(/*GrailsDomainClassProperty.*/HAS_MANY);
- if(isHasManyProperty) {
- Expression e = pn.getInitialExpression();
- propertiesToAdd.addAll(createPropertiesForHasManyExpression(e,classNode));
- }
- final boolean isBelongsTo = pn.getName().equals(/*GrailsDomainClassProperty.*/BELONGS_TO);
- if(isBelongsTo) {
- Expression e = pn.getInitialExpression();
- propertiesToAdd.addAll(createPropertiesForBelongsToExpression(e,classNode));
- }
- }
- injectAssociationProperties(classNode,propertiesToAdd);
- }
-
- private Collection createPropertiesForBelongsToExpression(Expression e, ClassNode classNode)
- {
- List properties = new ArrayList();
- if(e instanceof MapExpression) {
- MapExpression me = (MapExpression)e;
- List mapEntries = me.getMapEntryExpressions();
- for (Iterator i = mapEntries.iterator(); i.hasNext();) {
- MapEntryExpression mme = (MapEntryExpression) i.next();
- String key = mme.getKeyExpression().getText();
-
- String type = mme.getValueExpression().getText();
-
- properties.add(new PropertyNode(key,Modifier.PUBLIC, ClassHelper.make(type) , classNode, null,null,null));
- }
- }
-
- return properties;
- }
-
- private void injectAssociationProperties(ClassNode classNode, List propertiesToAdd) {
- for (Iterator i = propertiesToAdd.iterator(); i.hasNext();) {
- PropertyNode pn = (PropertyNode) i.next();
- if(!/*GrailsASTUtils.*/hasProperty(classNode, pn.getName())) {
- //if(LOG.isDebugEnabled()) {
- // LOG.debug("[GrailsDomainInjector] Adding property [" + pn.getName() + "] to class [" + classNode.getName() + "]");
- //}
- classNode.addProperty(pn);
- }
- }
- }
-
- private List createPropertiesForHasManyExpression(Expression e, ClassNode classNode) {
- List properties = new ArrayList();
- if(e instanceof MapExpression) {
- MapExpression me = (MapExpression)e;
- List mapEntries = me.getMapEntryExpressions();
- for (Iterator j = mapEntries.iterator(); j.hasNext();) {
- MapEntryExpression mee = (MapEntryExpression) j.next();
- Expression keyExpression = mee.getKeyExpression();
- String key = keyExpression.getText();
- addAssociationForKey(key,properties,classNode);
- }
- }
- return properties;
- }
-
- private void addAssociationForKey(String key, List properties, ClassNode classNode) {
- properties.add(new PropertyNode(key, Modifier.PUBLIC, new ClassNode(Set.class), classNode,null, null, null));
- }
-
- private void injectToStringMethod(ClassNode classNode) {
- final boolean hasToString = /*GrailsASTUtils.*/implementsZeroArgMethod(classNode, "toString");
-
- if(!hasToString) {
- GStringExpression ge = new GStringExpression(classNode.getName() + " : ${id}");
- ge.addString(new ConstantExpression(classNode.getName()+" : "));
- ge.addValue(new VariableExpression("id"));
- Statement s = new ReturnStatement(ge);
- MethodNode mn = new MethodNode("toString",Modifier.PUBLIC,new ClassNode(String.class), new Parameter[0],new ClassNode[0],s);
- //if(LOG.isDebugEnabled()) {
- // LOG.debug("[GrailsDomainInjector] Adding method [toString()] to class [" + classNode.getName() + "]");
- //}
- classNode.addMethod(mn);
- }
- }
-
- private void injectVersionProperty(ClassNode classNode) {
- final boolean hasVersion = /*GrailsASTUtils.*/hasProperty(classNode, /*GrailsDomainClassProperty.*/VERSION);
-
- if(!hasVersion) {
- //if(LOG.isDebugEnabled()) {
- // LOG.debug("[GrailsDomainInjector] Adding property [" + GrailsDomainClassProperty.VERSION + "] to class [" + classNode.getName() + "]");
- //}
- classNode.addProperty( /*GrailsDomainClassProperty.*/VERSION, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
- }
- }
-
- private void injectIdProperty(ClassNode classNode) {
- final boolean hasId = /*GrailsASTUtils.*/hasProperty(classNode,/*GrailsDomainClassProperty.*/IDENTITY);
-
- if(!hasId) {
- //if(LOG.isDebugEnabled()) {
- // LOG.debug("[GrailsDomainInjector] Adding property [" + GrailsDomainClassProperty.IDENTITY + "] to class [" + classNode.getName() + "]");
- //}
- classNode.addProperty( /*GrailsDomainClassProperty.*/IDENTITY, Modifier.PUBLIC, new ClassNode(Long.class), null, null, null);
- }
- }
-
-
- //***************************************************************
- // from GrailsASTUtils
- //***************************************************************
- /**
- * Returns whether a classNode has the specified property or not
- *
- * @param classNode The ClassNode
- * @param propertyName The name of the property
- * @return True if the property exists in the ClassNode
- */
- public static boolean hasProperty(ClassNode classNode, String propertyName) {
- if(classNode == null || propertyName == null || "".equals(propertyName.trim()))
- return false;
-
- List properties = classNode.getProperties();
- for (Iterator i = properties.iterator(); i.hasNext();) {
- PropertyNode pn = (PropertyNode) i.next();
- if(pn.getName().equals(propertyName))
- return true;
- }
- return false;
- }
-
- /**
- * Tests whether the ClasNode implements the specified method name
- *
- * @param classNode The ClassNode
- * @param methodName The method name
- * @return True if it does implement the method
- */
- public static boolean implementsZeroArgMethod(ClassNode classNode, String methodName) {
- return implementsMethod(classNode, methodName, new Class[0]);
- }
-
-
- /**
- * Tests whether the ClassNode implements the specified method name
- *
- * @param classNode The ClassNode
- * @param methodName The method name
- * @param argTypes
- * @return True if it implements the method
- */
- private static boolean implementsMethod(ClassNode classNode, String methodName, Class[] argTypes) {
- List methods = classNode.getMethods();
- if (argTypes == null || argTypes.length ==0) {
- for (Iterator i = methods.iterator(); i.hasNext();) {
- MethodNode mn = (MethodNode) i.next();
- boolean methodMatch = mn.getName().equals(methodName);
- if(methodMatch)return true;
- // TODO Implement further parameter analysis
- }
- }
- return false;
- }
-
- //***************************************************************
- // from GrailsDomainClassProperty
- //***************************************************************
- private static final String RELATES_TO_MANY = "relatesToMany";
- private static final String BELONGS_TO = "belongsTo";
- private static final String HAS_MANY = "hasMany";
- private static final String IDENTITY = "id";
- private static final String VERSION = "version";
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/org/codehaus/groovy/grails/compiler/injection/DomainClass.java
----------------------------------------------------------------------
diff --git a/src/examples/org/codehaus/groovy/grails/compiler/injection/DomainClass.java b/src/examples/org/codehaus/groovy/grails/compiler/injection/DomainClass.java
deleted file mode 100644
index 3494ede..0000000
--- a/src/examples/org/codehaus/groovy/grails/compiler/injection/DomainClass.java
+++ /dev/null
@@ -1,38 +0,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 org.codehaus.groovy.grails.compiler.injection;
-
-import org.codehaus.groovy.transform.GroovyASTTransformationClass;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Created by IntelliJ IDEA.
- * User: Danno
- * Date: Jan 30, 2008
- * Time: 8:11:08 PM
- */
-@Retention(RetentionPolicy.SOURCE)
-@Target(ElementType.TYPE)
-@GroovyASTTransformationClass("org.codehaus.groovy.grails.compiler.injection.DefaultGrailsDomainClassInjector")
-public @interface DomainClass {
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/build.properties
----------------------------------------------------------------------
diff --git a/src/examples/osgi/build.properties b/src/examples/osgi/build.properties
deleted file mode 100644
index bb104c4..0000000
--- a/src/examples/osgi/build.properties
+++ /dev/null
@@ -1,28 +0,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.
-#
-
-# groovy bin dir is required to locate the groovy jar
-# in case it's not on the classpath
-groovy.bin.dir=../../../target/dist
-
-# version is required to locate jar file and build jar manifest
-groovy.version=1.7-beta-1-SNAPSHOT
-
-# osgi jar file location must be specified so code compiles
-osgi.jar=../../../../equinox-3.4/eclipse/plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/build.xml
----------------------------------------------------------------------
diff --git a/src/examples/osgi/build.xml b/src/examples/osgi/build.xml
deleted file mode 100644
index 9d31efb..0000000
--- a/src/examples/osgi/build.xml
+++ /dev/null
@@ -1,140 +0,0 @@
-<?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-osgi-sample" default="print-results">
-
- <property name="build.dir" value="build"/>
- <property file="build.properties"/>
- <property name="groovy.jar" value="groovy-${groovy.version}.jar" />
- <property name="hello.bundle" value="hello-bundle-imports-groovy.jar" />
- <property name="hello.bundle.contains" value="hello-bundle-contains-groovy.jar" />
- <property name="harness.bundle" value="hello-groovy-test-harness.jar" />
-
- <taskdef name="groovyc"
- classname="org.codehaus.groovy.ant.Groovyc"
- classpathref="project.classpath"/>
-
- <target name="init" description="cleanup and reinitialize">
- <path id="project.classpath">
- <pathelement location="${osgi.jar}"/>
- <pathelement location="${groovy.bin.dir}${file.separator}${groovy.jar}"/>
- <pathelement location="${build.dir}${file.separator}${hello.bundle}"/>
- </path>
-
- <delete dir="${build.dir}" />
- <mkdir dir="${build.dir}${file.separator}hello-groovy-bundle" />
- <mkdir dir="${build.dir}${file.separator}hello-groovy-test-harness" />
- </target>
-
- <target name="make-hello-groovy-bundle" description="compile and build the Hello Groovy bundles">
-
- <groovyc destdir="${build.dir}${file.separator}hello-groovy-bundle"
- srcdir=".${file.separator}hello-groovy-bundle"
- listfiles="true">
- <classpath refid="project.classpath"/>
- </groovyc>
-
- <!-- This jar file imports Groovy from the container -->
- <jar destfile="${build.dir}${file.separator}${hello.bundle}">
- <fileset dir="${build.dir}${file.separator}hello-groovy-bundle"/>
- <manifest>
- <attribute name="Built-By" value="${user.name}"/>
- <attribute name="provider" value="org.codehaus.groovy.osgi"/>
- <attribute name="Bundle-ManifestVersion" value="2"/>
- <attribute name="Bundle-Name" value="Groovy OSGi Example Bundle"/>
- <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.hello-groovy-bundle"/>
- <attribute name="Bundle-Version" value="1.0.0"/>
- <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.Activator"/>
- <attribute name="Bundle-Vendor" value="Groovy"/>
- <attribute name="Bundle-Localization" value="plugin"/>
- <attribute name="Import-Package" value="groovy.lang;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.reflection;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime.callsite;version="1.7.0.beta-1-SNAPSHOT",org.w3c.dom,org.osgi.framework;version="1.3.0""/>
- <attribute name="Export-Package" value="org.codehaus.groovy.osgi;version="1.0.0""/>
- <attribute name="Bundle-ClassPath" value="."/>
- </manifest>
- </jar>
-
- <!-- This jar includes the Groovy jar within itself-->
- <jar destfile="${build.dir}${file.separator}${hello.bundle.contains}">
- <fileset dir="${build.dir}${file.separator}hello-groovy-bundle"/>
- <fileset file="${groovy.bin.dir}${file.separator}${groovy.jar}" casesensitive="no" />
- <manifest>
- <attribute name="Built-By" value="${user.name}"/>
- <attribute name="provider" value="org.codehaus.groovy.osgi"/>
- <attribute name="Bundle-ManifestVersion" value="2"/>
- <attribute name="Bundle-Name" value="Groovy OSGi Example Bundle"/>
- <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.hello-groovy-bundle"/>
- <attribute name="Bundle-Version" value="1.0.0"/>
- <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.Activator"/>
- <attribute name="Bundle-Vendor" value="Groovy"/>
- <attribute name="Bundle-Localization" value="plugin"/>
- <attribute name="Import-Package" value="org.w3c.dom,org.osgi.framework;version="1.3.0""/>
- <attribute name="Export-Package" value="org.codehaus.groovy.osgi;version="1.0.0""/>
- <attribute name="Bundle-ClassPath" value=".,${groovy.jar}"/>
- </manifest>
- </jar>
- </target>
-
- <target name="make-harness-bundle" description="Makes the test harness bundle">
-
- <groovyc destdir="${build.dir}${file.separator}hello-groovy-test-harness"
- srcdir=".${file.separator}hello-groovy-test-harness"
- listfiles="true">
- <classpath refid="project.classpath"/>
- </groovyc>
-
- <jar destfile="${build.dir}${file.separator}${harness.bundle}">
- <fileset dir="${build.dir}${file.separator}hello-groovy-test-harness"/>
- <manifest>
- <attribute name="Built-By" value="${user.name}"/>
- <attribute name="provider" value="org.codehaus.groovy.osgi.harness"/>
- <attribute name="Bundle-ManifestVersion" value="2"/>
- <attribute name="Bundle-Name" value="Groovy OSGi Test Harness"/>
- <attribute name="Bundle-SymbolicName" value="org.codehaus.groovy.osgi.harness.hello-groovy-test-harness"/>
- <attribute name="Bundle-Version" value="1.0.0"/>
- <attribute name="Bundle-Activator" value="org.codehaus.groovy.osgi.harness.HarnessActivator"/>
- <attribute name="Bundle-Vendor" value="Groovy"/>
- <attribute name="Bundle-Localization" value="plugin"/>
- <attribute name="Import-Package" value="org.codehaus.groovy.runtime.typehandling;version="1.0.0",org.codehaus.groovy.osgi;version="1.0.0",groovy.lang;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.reflection;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime;version="1.7.0.beta-1-SNAPSHOT",org.codehaus.groovy.runtime.callsite;version="1.7.0.beta-1-SNAPSHOT",org.w3c.dom,org.osgi.framework;version="1.3.0""/>
- <attribute name="Bundle-ClassPath" value="."/>
- </manifest>
- </jar>
-
- </target>
-
- <target name="print-results" depends="init,make-hello-groovy-bundle,make-harness-bundle" description="compile and build everything">
- <makeurl file="${basedir}/${groovy.bin.dir}/${groovy.jar}" property="groovy.jar.url"/>
- <makeurl file="${basedir}/${build.dir}/${hello.bundle}" property="hello.jar1.url"/>
- <makeurl file="${basedir}/${build.dir}/${hello.bundle.contains}" property="hello.jar2.url"/>
- <makeurl file="${basedir}/${build.dir}/${harness.bundle}" property="harness.jar.url"/>
-
- <echo>To run the OSGi console, run the following command:
- java -jar ${osgi.jar} -console
-To install these applications in the container, run the following commands in the OSGi container:
- install ${groovy.jar.url}
- install ${hello.jar1.url}
- install ${hello.jar2.url}
- install ${harness.jar.url}
-To start the applications in the container, run the following commands in the OSGi container:
- start [bundle1] [bundle2]
-Where [bundle1] and [bundle] are the bundle IDs printed by the console in the previous step.</echo>
- </target>
-</project>
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/Activator.groovy
----------------------------------------------------------------------
diff --git a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/Activator.groovy b/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/Activator.groovy
deleted file mode 100644
index e250ec1..0000000
--- a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/Activator.groovy
+++ /dev/null
@@ -1,59 +0,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 org.codehaus.groovy.osgi
-
-import org.osgi.framework.BundleActivator
-import org.osgi.framework.BundleContext
-import org.osgi.framework.ServiceRegistration;
-
-/**
-* This is the OSGi Activator for the Groovy example bundles.
-* Two things happen when the container starts this bundle:
-* 1) a message is printed to standard out
-* 2) a service of type GroovyGreeter is added to the context
-* The service is unregistered when the bundle is stopped.
-*
-* @author Hamlet D'Arcy
-*/
-public class Activator implements BundleActivator {
-
- ServiceRegistration registration
-
- public void start(BundleContext context) {
- println "Groovy BundleActivator started"
-
- // Normally, the classloader code would not need to be run when
- // adding a service to the context. However, this is required when
- // adding a Groovy service because of the way Groovy uses class
- // loaders and reflection.
- ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader()
- try {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader())
- GroovyGreeter myService = new GroovyGreeterImpl()
- registration = context.registerService(GroovyGreeter.class.getName(), myService, null)
- } finally {
- Thread.currentThread().setContextClassLoader(originalClassLoader)
- }
- }
-
- public void stop(BundleContext context) {
- println "Groovy BundleActivator stopped"
- registration.unregister();
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeter.groovy
----------------------------------------------------------------------
diff --git a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeter.groovy b/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeter.groovy
deleted file mode 100644
index 4409cd4..0000000
--- a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeter.groovy
+++ /dev/null
@@ -1,30 +0,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 org.codehaus.groovy.osgi
-
-/**
-* Objects of this type know how to print simple messages to
-* standard out.
-*
-* @author Hamlet D'Arcy
-*/
-public interface GroovyGreeter {
-
- void sayHello();
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeterImpl.groovy
----------------------------------------------------------------------
diff --git a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeterImpl.groovy b/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeterImpl.groovy
deleted file mode 100644
index 209871e..0000000
--- a/src/examples/osgi/hello-groovy-bundle/org/codehaus/groovy/osgi/GroovyGreeterImpl.groovy
+++ /dev/null
@@ -1,31 +0,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 org.codehaus.groovy.osgi
-
-/**
-* A simple POGO that prints a greeting to standard out.
-*
-* @author Hamlet D'Arcy
-*/
-public class GroovyGreeterImpl implements GroovyGreeter {
-
- public void sayHello() {
- println "Hello from the Groovy Greeter!"
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/hello-groovy-test-harness/org/codehaus/groovy/osgi/harness/HarnessActivator.groovy
----------------------------------------------------------------------
diff --git a/src/examples/osgi/hello-groovy-test-harness/org/codehaus/groovy/osgi/harness/HarnessActivator.groovy b/src/examples/osgi/hello-groovy-test-harness/org/codehaus/groovy/osgi/harness/HarnessActivator.groovy
deleted file mode 100644
index adccf08..0000000
--- a/src/examples/osgi/hello-groovy-test-harness/org/codehaus/groovy/osgi/harness/HarnessActivator.groovy
+++ /dev/null
@@ -1,50 +0,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 org.codehaus.groovy.osgi.harness
-
-import org.osgi.framework.BundleActivator
-import org.osgi.framework.BundleContext
-import org.osgi.framework.ServiceRegistration
-import org.osgi.framework.ServiceReference
-import org.codehaus.groovy.osgi.GroovyGreeter
-
-/**
- * This OSGi Activator finds all registered services of type GroovyGreeter
- * and then invokes the sayHello() method on any that it finds.
- *
- * @author Hamlet D'Arcy
- */
-public class HarnessActivator implements BundleActivator {
-
- public void start(BundleContext context) {
- String serviceName = GroovyGreeter.class.getName()
- ServiceReference[] references = context.getAllServiceReferences(serviceName, null)
-
- println "${ references ? references.size() : 0 } GroovyGreeter services found."
-
- references?.each { ServiceReference ref ->
- Object serviceHandle = context.getService(ref)
- GroovyGreeter service = (GroovyGreeter) serviceHandle
- service.sayHello()
- }
- }
-
- public void stop(BundleContext context) {
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/osgi/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/osgi/readme.txt b/src/examples/osgi/readme.txt
deleted file mode 100644
index 7ee164c..0000000
--- a/src/examples/osgi/readme.txt
+++ /dev/null
@@ -1,140 +0,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.
-====
-
-About this Example
-------------------
-This example demonstrates two different usages of OSGi. The "hello-groovy-bundle"
-service demonstrates how to write an OSGi bundle using Groovy. It is a simple
-service that does two things when started within an OSGi container: 1) it prints
-out a message to the console, and 2) it adds a Groovy service to the OSGi context
-that can be consumed by the second example.
-
-The "hello-groovy-test-harness" service, also written in Groovy, demonstrates how
-to import and use the previous "hello-groovy-bundle" OSGi service. It locates and
-invokes the service from the first example, which results in a message being
-written to the console.
-
-
-Building this Example
----------------------
-IMPORTANT: You must edit build.properties before building the example. There are
-three properties that must be set in build.properties:
- groovy.bin.dir - The example requires you specify the location of your
- groovy jar. This is how the build finds groovyc.
- groovy.version - The example requires you specify the version of your groovy
- jar. This is so that the jar files can be built correctly.
- osgi.jar - The example requires you specify the location of the OSGi jar.
- This is required to compile the code.
-
-This example was tested using the OSGi jar from Equinox 3.4, the OSGi container
-that ships with Eclipse. You can download the Equinox jar from the Equinox website
-or search for it within your Eclipse directories. The jar will have a name similar
-to : org.eclipse.osgi_3.4.0.v20080605-1900.jar
-
-Once these properties are set, simply run ant to build:
-
- ant
-
-The build creates three jar files:
- hello-bundle-imports-groovy.jar - OSGi bundle written in Groovy that resolves the
- groovy Jar file from the container.
- hello-bundle-contains-groovy.jar - OSGi bundle written in Groovy that resolves the
- groovy Jar file from within itself. The container never sees Groovy.
- hello-groovy-test-harness.jar - OSGi bundle that loads and tests one of the previous
- two services.
-
-The build also prints out the file URLs of the jar files. You need these URLs to
-run the example. Also printed to the console is the command to run the Equinox
-container. The final output of the Ant script may look like this:
-
- [echo] To run the OSGi console, run the following command:
- [echo] java -jar ../../../../equinox-3.4/eclipse/plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar -console
- [echo] To install these applications in the container, run the following commands in the OSGi container:
- [echo] install file:/home/user/dev/groovy-core/target/dist/groovy-all-1.7.0.jar
- [echo] install file:/home/user/dev/groovy-core/src/examples/osgi/build/hello-bundle-imports-groovy.jar
- [echo] install file:/home/user/dev/groovy-core/src/examples/osgi/build/hello-bundle-contains-groovy.jar
- [echo] install file:/home/user/dev/groovy-core/src/examples/osgi/build/hello-groovy-test-harness.jar
- [echo] To start the applications in the container, run the following commands in the OSGi container:
- [echo] start [bundle1] [bundle2]
- [echo] Where [bundle1] and [bundle] are the bundle IDs printed by the console in the previous step.
-
-
-Running this Example
---------------------
-To run the example you must start the OSGi container, install the services, and
-start the services.
-
-To start the Equinox container, invoke the OSGi jar using java:
-
- java -jar ../../../../equinox-3.4/eclipse/plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar -console
-
-This opens an OSGi console. You should be presented with an OSGi prompt:
-
- osgi>
-
-Type the command "ss" to get a system status:
-
- osgi> ss
-
- Framework is launched.
-
- id State Bundle
- 0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
-
-Install the three bundles using the "install" command and the file URLs of the
-jars built by Ant. Remember, the Ant script printed the file URLs to the console
-as part of the build (replace groovy-all with groovy for 2.5+).
-
-osgi> install file:/home/user/dev/groovy-core/target/dist/groovy-all-1.7.0.jar
-Bundle id is 1
-
-osgi> install file:/home/user/dev/groovy-core/src/examples/osgi/build/hello-bundle-imports-groovy.jar
-Bundle id is 2
-
-osgi> install file:/home/user/dev/groovy-core/src/examples/osgi/build/hello-groovy-test-harness.jar
-Bundle id is 3
-
-Run the ss command to verify the bundles loaded correctly:
-
-
-osgi> ss
-
-Framework is launched.
-
-id State Bundle
-0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
-1 INSTALLED groovy-all_1.7.0
-2 INSTALLED org.codehaus.groovy.osgi.hello-groovy-bundle_1.0.0
-3 INSTALLED org.codehaus.groovy.osgi.harness.hello-groovy-test-harness_1.0.0
-
-Start the bundles with the "start" command to see them working:
-
-osgi> start 1 2 3
-Groovy BundleActivator started
-1 GroovyGreeter services found.
-Hello from the Groovy Greeter!
-
-As expected, bundle 2 printed out a message from an object implemented in Groovy,
-and bundle 3 printed out a message from a service implemented in Groovy, which it
-loaded as an OSGi service from the BundleContext.
-
-You may wish to uninstall the services using the "uninstall" command:
-
- osgi> uninstall 3 2 1
- Groovy BundleActivator stopped
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/searchEngine/Indexer.groovy
----------------------------------------------------------------------
diff --git a/src/examples/searchEngine/Indexer.groovy b/src/examples/searchEngine/Indexer.groovy
deleted file mode 100644
index 2709e6a..0000000
--- a/src/examples/searchEngine/Indexer.groovy
+++ /dev/null
@@ -1,83 +0,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.
- */
-import org.apache.lucene.analysis.standard.StandardAnalyzer
-import org.apache.lucene.document.Document
-import org.apache.lucene.document.Field
-import org.apache.lucene.index.IndexWriter
-import org.apache.lucene.util.Version
-import org.apache.lucene.index.IndexWriterConfig
-import org.apache.lucene.store.FSDirectory
-import org.apache.lucene.document.TextField
-import org.apache.lucene.document.StringField
-import static org.apache.lucene.document.Field.Store.*
-
-/**
- * Indexer: traverses a file system and indexes .txt files
- *
- * @author Jeremy Rayner <gr...@ross-rayner.com>
- * based on examples in the wonderful 'Lucene in Action' book
- * by Erik Hatcher and Otis Gospodnetic (https://www.manning.com/books/lucene-in-action-second-edition)
- *
- * June 25th, 2013: Updated for Lucene 4.3.1
- * requires a lucene-4.3.x.jar from http://lucene.apache.org
- */
-
-if (args.size() != 2 ) {
- throw new Exception("Usage: groovy -cp lucene-1.4.3.jar Indexer <index dir> <data dir>")
-}
-def indexDir = FSDirectory.open(new File(args[0])) // Create Lucene index in this directory
-def dataDir = new File(args[1]) // Index files in this directory
-
-def start = new Date().time
-def numIndexed = index(indexDir, dataDir)
-def end = new Date().time
-
-println "Indexing $numIndexed files took ${end - start} milliseconds"
-
-def index(indexDir, dataDir) {
- if (!dataDir.exists() || !dataDir.directory) {
- throw new IOException("$dataDir does not exist or is not a directory")
- }
- def config = new IndexWriterConfig(Version.LUCENE_43, new StandardAnalyzer(Version.LUCENE_43))
- def writer = new IndexWriter(indexDir, config) // Create Lucene index
-
- dataDir.eachFileRecurse {
- if (it.name =~ /.txt$/) { // Index .txt files only
- indexFile(writer,it)
- }
- }
- def numIndexed = writer.numDocs()
- writer.close() // Close index
- return numIndexed
-}
-
-void indexFile(writer, f) {
- if (f.hidden || !f.exists() || !f.canRead() || f.directory) { return }
-
- println "Indexing $f.canonicalPath"
- def doc = new Document()
-
- // Construct a Field that is tokenized and indexed, but is not stored in the index verbatim.
- doc.add(new TextField("contents", f.newReader()))
-
- // Construct a Field that is not tokenized, but is indexed and stored.
- doc.add(new StringField("filename",f.canonicalPath, YES))
-
- writer.addDocument(doc) // Add document to Lucene index
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/searchEngine/Searcher.groovy
----------------------------------------------------------------------
diff --git a/src/examples/searchEngine/Searcher.groovy b/src/examples/searchEngine/Searcher.groovy
deleted file mode 100644
index 4afd145..0000000
--- a/src/examples/searchEngine/Searcher.groovy
+++ /dev/null
@@ -1,61 +0,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.
- */
-import org.apache.lucene.analysis.standard.StandardAnalyzer
-import org.apache.lucene.queryparser.classic.QueryParser
-import org.apache.lucene.search.IndexSearcher
-import org.apache.lucene.store.FSDirectory
-import org.apache.lucene.util.Version
-import org.apache.lucene.index.DirectoryReader
-
-/**
- * Searcher: searches a Lucene index for a query passed as an argument
- *
- * @author Jeremy Rayner <gr...@ross-rayner.com>
- * based on examples in the wonderful 'Lucene in Action' book
- * by Erik Hatcher and Otis Gospodnetic (https://www.manning.com/books/lucene-in-action-second-edition)
- *
- * June 25th, 2013: Updated for Lucene 4.3.1
- * requires a lucene-4.x.x.jar from http://lucene.apache.org
- */
-
-if (args.size() != 2) {
- throw new Exception("Usage: groovy -cp lucene-4.3.1.jar Searcher <index dir> <query>")
-}
-def indexDir = new File(args[0]) // Index directory create by Indexer
-def q = args[1] // Query string
-
-if (!indexDir.exists() || !indexDir.directory) {
- throw new Exception("$indexDir does not exist or is not a directory")
-}
-
-def fsDir = DirectoryReader.open(FSDirectory.open(indexDir))
-def is = new IndexSearcher(fsDir) // Open index
-
-def parser = new QueryParser(Version.LUCENE_43, "contents", new StandardAnalyzer(Version.LUCENE_43))
-def query = parser.parse(q) // Parse query
-def start = new Date().time
-def hits = is.search(query, 10) // Search index
-def end = new Date().time
-
-println "Found ${hits.totalHits} document(s) (in ${end - start} milliseconds) that matched query '$q':"
-
-hits.scoreDocs.each { scoreDoc ->
- println(is.doc(scoreDoc.doc)["filename"]) // Retrieve matching document and display filename
-}
-fsDir.close()
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/BindingExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/BindingExample.groovy b/src/examples/swing/BindingExample.groovy
deleted file mode 100644
index f3c370b..0000000
--- a/src/examples/swing/BindingExample.groovy
+++ /dev/null
@@ -1,62 +0,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.
- */
-/**
- * @author <a href="mailto:shemnon@yahoo.com">Danno Ferrin</a>
- * @since Groovy 1.1
- *
- * The real interesting part of this example are in the three properties of button:
- *
- * text: bind(source:textField, sourceProperty:'text'),
- * margin: bind(source:slider, sourceProperty:'value', converter:{[it, it, it, it] as Insets}),
- * enabled: bind(source:checkBox, sourceProperty:'selected')
- *
- * This is where the real magic goes on, causing the button to react to the changes
- * in the source widgets values.
- */
-
-import groovy.swing.SwingBuilder
-import java.awt.GridBagConstraints as gb
-import java.awt.Insets
-
-sb = SwingBuilder.build() {
- frame = frame(defaultCloseOperation:javax.swing.JFrame.DISPOSE_ON_CLOSE) {
- gridBagLayout()
-
- label("Text:", anchor:gb.WEST, insets:[6,6,3,3] as Insets)
- textField = textField("Change Me!", fill:gb.HORIZONTAL, gridwidth:gb.REMAINDER, insets:[6,3,3,6] as Insets)
-
- label("Margin:", anchor:gb.WEST, insets:[3,6,3,3] as Insets)
- slider = slider(value:5, fill:gb.HORIZONTAL, gridwidth:gb.REMAINDER, insets:[3,3,3,6] as Insets)
-
- panel()
- checkBox = checkBox("Enbled", anchor:gb.WEST, gridwidth:gb.REMAINDER, insets:[3,3,3,6] as Insets)
-
- separator(fill:gb.HORIZONTAL, gridwidth:gb.REMAINDER)
-
- button(anchor:gb.CENTER, gridwidth:gb.REMAINDER, gridheight:gb.REMAINDER, weightx:1.0, weighty:1.0, insets:[3,6,6,6] as Insets,
- text: bind(source:textField, sourceProperty:'text'),
- margin: bind(source:slider, sourceProperty:'value', converter:{[it, it, it, it] as Insets}),
- enabled: bind(source:checkBox, sourceProperty:'selected')
- )
- }
-}
-
-frame.pack()
-frame.setSize(frame.width + 100, frame.height + 200)
-frame.show()
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/BloglinesClient.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/BloglinesClient.groovy b/src/examples/swing/BloglinesClient.groovy
deleted file mode 100644
index 62f3cb5..0000000
--- a/src/examples/swing/BloglinesClient.groovy
+++ /dev/null
@@ -1,187 +0,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.
- */
-/*
- * BloglinesClient.groovy - an example of the Bloglines Web Services
- *
- * Written by Marc Hedlund <ma...@precipice.org>, September 2004.
- *
- * Mangled by John Wilson September 2004
- *
- * Small adaptions to JSR Version by Dierk Koenig, June 2005
- *
- * Used in Marc's article at:
- * http://www.oreillynet.com/pub/a/network/2004/09/28/bloglines.html
- *
- * Requirements:
- * - install Groovy as detailed at <http://groovy.codehaus.org/>.
- * - put commons-httpclient-3.0-rc3.jar into GROOVY_HOME/lib
- * see <http://jakarta.apache.org/commons/httpclient/>.
- * note: this is currently designed for HttpClient2.x and not HttpClient3.x
- *
- * To Launch:
- * groovy BloglinesClient.groovy
- *
- * This work is licensed under the Creative Commons Attribution
- * License. To view a copy of this license, visit
- * <http://creativecommons.org/licenses/by/2.0/> or send a letter to
- * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
- */
-
-import groovy.swing.SwingBuilder
-import java.awt.BorderLayout
-import javax.swing.JOptionPane
-import javax.swing.JSplitPane
-import javax.swing.JTree
-import javax.swing.ListSelectionModel
-import javax.swing.WindowConstants
-import javax.swing.tree.DefaultMutableTreeNode
-import javax.swing.tree.TreeSelectionModel
-import org.apache.commons.httpclient.HttpClient
-import org.apache.commons.httpclient.UsernamePasswordCredentials
-import org.apache.commons.httpclient.methods.GetMethod
-
-//Set up global variables and data types
-server = 'rpc.bloglines.com'
-
-class Feed {
- def name;
- def id;
- def unread;
-
- String toString() { (unread == "0" ? name : "${name} (${unread})") }
-}
-
-class Item {
- def title;
- def description;
-
- String toString() { title }
-}
-
-// Ask the user for account information (using simple dialogs)
-email = JOptionPane.showInputDialog(null, "Email address:", "Log in to Bloglines",
- JOptionPane.QUESTION_MESSAGE)
-password = JOptionPane.showInputDialog(null, "Password:", "Log in to Bloglines",
- JOptionPane.QUESTION_MESSAGE)
-
-//Use HTTPClient for web requests since the server requires authentication
-client = new HttpClient()
-credentials = new UsernamePasswordCredentials(email, password)
-client.state.setCredentials("Bloglines RPC", server, credentials)
-
-abstractCallBloglines = { method, parameters ->
- url = "http://${server}/${method}${parameters}"
- try {
- get = new GetMethod(url)
- get.doAuthentication = true
- client.executeMethod(get)
- return get.responseBodyAsStream
- } catch (Exception e) {
- println "Error retrieving <${url}>: ${e}"
- }
-}
-
-callBloglinesListsub = abstractCallBloglines.curry('listsubs', '')
-callBloglinesGetItems = abstractCallBloglines.curry('getitems')
-
-//Get the list of subscriptions and parse it into a GPath structure
-opml = new XmlSlurper().parse(callBloglinesListsub())
-
-//Descend into the subscription outline, adding to the feed tree as we go
-treeTop = new DefaultMutableTreeNode("My Feeds")
-parseOutline(opml.body.outline.outline, treeTop)
-
-def parseOutline(parsedXml, treeLevel) {
- parsedXml.each { outline ->
- if (outline['@xmlUrl'] != null) { // this is an individual feed
- feed = new Feed(name: outline['@title'], id: outline['@BloglinesSubId'],
- unread: outline['@BloglinesUnread'])
- treeLevel.add(new DefaultMutableTreeNode(feed))
- } else { // this is a folder of feeds
- folder = new DefaultMutableTreeNode(outline['@title'])
- parseOutline(outline.outline, folder)
- treeLevel.add(folder)
- }
- }
-}
-
-//Build the base user interface objects and configure them
-swing = new SwingBuilder()
-feedTree = new JTree(treeTop)
-itemList = swing.list()
-itemText = swing.textPane(contentType: 'text/html', editable: false)
-model = feedTree.selectionModel
-model.selectionMode = TreeSelectionModel.SINGLE_TREE_SELECTION
-itemList.selectionMode = ListSelectionModel.SINGLE_SELECTION
-
-//Set up the action closures that will react to user selections
-listItems = { feed ->
- rssStream = callBloglinesGetItems("?s=${feed.id}&n=0")
- if (rssStream != null) {
- try {
- rss = new XmlSlurper().parse(rssStream)
- itemList.listData = rss.channel.item.collect(new Vector()) {
- new Item(title: it.title, description: it.description)
- }
- feed.unread = "0" // update the unread item count in the feed list
- } catch (Exception e) {
- println "Error during <${feed.name}> RSS parse: ${e}"
- }
- }
-}
-
-feedTree.valueChanged = { event ->
- itemText.text = "" // clear any old item text
- node = (DefaultMutableTreeNode) feedTree.getLastSelectedPathComponent()
- if (node != null) {
- feed = node.userObject
- if (feed instanceof Feed && feed.unread != "0") {
- listItems(feed)
- }
- }
-}
-
-itemList.valueChanged = { event ->
- item = event.source.selectedValue
- if (item instanceof Item && item?.description != null) {
- itemText.text = "<html><body>${item.description}</body></html>"
- }
-}
-
-//Put the user interface together and display it
-gui = swing.frame(title: 'Bloglines Client', location: [100, 100], size: [800, 600],
- defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE) {
- panel(layout: new BorderLayout()) {
- splitPane(orientation: JSplitPane.HORIZONTAL_SPLIT, dividerLocation: 200) {
- scrollPane {
- widget(feedTree)
- }
- splitPane(orientation: JSplitPane.VERTICAL_SPLIT, dividerLocation: 150) {
- scrollPane(constraints: BorderLayout.CENTER) {
- widget(itemList)
- }
- scrollPane(constraints: BorderLayout.CENTER) {
- widget(itemText)
- }
- }
- }
- }
-}
-
-gui.show()
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/ModelNodeExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/ModelNodeExample.groovy b/src/examples/swing/ModelNodeExample.groovy
deleted file mode 100644
index d402f65..0000000
--- a/src/examples/swing/ModelNodeExample.groovy
+++ /dev/null
@@ -1,87 +0,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.
- */
-import groovy.swing.SwingBuilder
-import static javax.swing.WindowConstants.*
-import static java.awt.GridBagConstraints.*
-
-def bean = new ObservableMap([name:'Alice', phone:'719-555-1212', addr:'42 Other Way'])
-
-SwingBuilder.build {
- frame = frame(
- pack:true,
- show:true,
- defaultCloseOperation:DISPOSE_ON_CLOSE)
- {
- beanModel = model(bean, bind:false)
-
- gridBagLayout()
-
- label('Name:', constraints:gbc(insets:[6,6,3,3]))
- textField(text:beanModel.name,
- columns:20,
- gridwidth:REMAINDER,
- fill:HORIZONTAL,
- weightx:1,
- insets:[6,3,3,6])
-
- label('Phone:', constraints:gbc(insets:[3,6,3,3]))
- textField(text:beanModel.phone,
- columns:20,
- gridwidth:REMAINDER,
- fill:HORIZONTAL,
- weightx:1,
- insets:[3,3,3,6])
-
- label('Address:', constraints:gbc(insets:[3,6,3,3]))
- textField(text:beanModel.addr,
- columns:20,
- gridwidth:REMAINDER,
- fill:HORIZONTAL,
- weightx:1,
- insets:[3,3,3,6])
-
- button('Reset', actionPerformed:{beanModel.update()},
- constraints:gbc(gridwidth:2,
- anchor:EAST,
- weightx:1,
- insets:[9,0,0,6]))
- button('Submit',
- insets:[9,0,0,0],
- actionPerformed: {
- beanModel.reverseUpdate()
- output.text = ("name = '$bean.name'\nphone = '$bean.phone'\naddr = '$bean.addr'\n\n")
- })
-
- separator(gridwidth:REMAINDER,
- fill:HORIZONTAL,
- insets:[3,6,3,6])
- label('Output:',
- gridwidth:REMAINDER,
- anchor:WEST,
- insets:[3,6,3,6])
- scrollPane(preferredSize:[100, 100],
- gridwidth:REMAINDER,
- fill:BOTH,
- weighty:1,
- insets:[3,6,6,6])
- {
- output = textArea()
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/RegexCoach.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/RegexCoach.groovy b/src/examples/swing/RegexCoach.groovy
deleted file mode 100644
index 4e9bde2..0000000
--- a/src/examples/swing/RegexCoach.groovy
+++ /dev/null
@@ -1,125 +0,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.
- */
-// inspired by http://weitz.de/regex-coach/
-
-import java.awt.*
-import java.awt.event.*
-import java.util.regex.*
-import javax.swing.*
-import javax.swing.text.DefaultHighlighter
-import groovy.swing.SwingBuilder
-
-// define the view
-def swing = new SwingBuilder()
-def gui = swing.frame(title: 'The Groovy Regex Coach', location: [20, 40], size: [600, 500], defaultCloseOperation: WindowConstants.EXIT_ON_CLOSE) {
- panel(layout: new BorderLayout()) {
- splitPane(orientation: JSplitPane.VERTICAL_SPLIT, dividerLocation: 150) {
- panel(layout: new BorderLayout()) {
- label(constraints: BorderLayout.NORTH, text: 'Regular expression:')
- scrollPane(constraints: BorderLayout.CENTER) {textPane(id: 'regexPane')}
- label(constraints: BorderLayout.SOUTH, id: 'regexStatus', text: ' ')
- }
- panel(layout: new BorderLayout()) {
- label(constraints: BorderLayout.NORTH, text: 'Target string:')
- scrollPane(constraints: BorderLayout.CENTER) {textPane(id: 'targetPane')}
- panel(constraints: BorderLayout.SOUTH, layout: new BorderLayout()) {
- label(constraints: BorderLayout.NORTH, id: 'targetStatus', text: ' ')
- panel(constraints: BorderLayout.SOUTH, layout: new FlowLayout()) {
- button('<<-', id: 'scanLeft')
- button('->>', id: 'scanRight')
- }
- }
- }
- }
- }
-}
-def highlighter = new RegexHighlighter(swing: swing)
-swing.regexPane.addKeyListener(highlighter)
-swing.targetPane.addKeyListener(highlighter)
-swing.scanLeft.addActionListener(highlighter)
-swing.scanRight.addActionListener(highlighter)
-gui.show()
-
-class RegexHighlighter extends KeyAdapter implements ActionListener {
- def swing // reference to the view
- int scanIndex // how many times to execute matcher.find()
- def orange = new DefaultHighlighter.DefaultHighlightPainter(Color.ORANGE)
- def yellow = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW)
- def red = new DefaultHighlighter.DefaultHighlightPainter(Color.RED)
-
- // react to user actions
-
- public void actionPerformed(ActionEvent event) {
- if (event.actionCommand == '<<-') {scanIndex = Math.max(scanIndex - 1, 0)}
- if (event.actionCommand == '->>') {scanIndex++}
- doHighlights()
- }
-
- public void keyReleased(KeyEvent event) {
- scanIndex = 0
- doHighlights()
- }
-
- private resetView() {
- swing.regexPane.highlighter.removeAllHighlights()
- swing.targetPane.highlighter.removeAllHighlights()
- swing.regexStatus.text = ' '
- swing.targetStatus.text = ' '
- }
-
- // the main regex logic
-
- private doHighlights() {
- try {
- resetView()
- // note: get the text from the underlying document,
- // otherwise carriage return/line feeds different when using the JTextPane text
- def regex = swing.regexPane.document.getText(0, swing.regexPane.document.length)
- def target = swing.targetPane.document.getText(0, swing.targetPane.document.length)
-
- def matcher = (target =~ regex)
-
- // scan past the matches before the match we want
- int scan = 0
- while (scan < scanIndex) {
- matcher.find()
- scan++
- }
- if (matcher.find()) {
- // highlight any captured groups
- int i = 0
- while (i++ < matcher.groupCount()) {
- swing.targetPane.highlighter.addHighlight(matcher.start(i), matcher.end(i), orange)
- }
- // highlight whole match
- swing.targetPane.highlighter.addHighlight(matcher.start(), matcher.end(), yellow)
- if (regex.length() != 0) {
- swing.targetStatus.text = "Match #${scanIndex + 1} from ${matcher.start()} to ${matcher.end()}."
- }
- } else { // not found
- scanIndex = Math.max(scan - 1, 0)
- if (scanIndex > 0) {doHighlights()}
- swing.targetStatus.text = "No match."
- }
- } catch (PatternSyntaxException e) {
- swing.regexPane.highlighter.addHighlight(e.index, e.index + 2, red)
- swing.regexStatus.text = e.description
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/RegexCoachController.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/RegexCoachController.groovy b/src/examples/swing/RegexCoachController.groovy
deleted file mode 100644
index 7fa97fd..0000000
--- a/src/examples/swing/RegexCoachController.groovy
+++ /dev/null
@@ -1,105 +0,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.
- */
-import groovy.swing.SwingBuilder
-import java.awt.Color
-import java.awt.event.ActionEvent
-import java.awt.event.ActionListener
-import java.awt.event.KeyAdapter
-import java.awt.event.KeyEvent
-import java.util.regex.PatternSyntaxException
-import javax.swing.text.DefaultHighlighter.DefaultHighlightPainter
-
-// inspired by http://weitz.de/regex-coach/
-
-// define the view
-def swing = new SwingBuilder()
-
-def gui = swing.build(RegexCoachView)
-
-def highlighter = new RegexHighliter(swing: swing)
-swing.regexPane.addKeyListener(highlighter)
-swing.targetPane.addKeyListener(highlighter)
-swing.scanLeft.addActionListener(highlighter)
-swing.scanRight.addActionListener(highlighter)
-gui.show()
-
-class RegexHighliter extends KeyAdapter implements ActionListener {
- def swing // reference to the view
- int scanIndex // how many times to execute matcher.find()
- def orange = new DefaultHighlightPainter(Color.ORANGE)
- def yellow = new DefaultHighlightPainter(Color.YELLOW)
- def red = new DefaultHighlightPainter(Color.RED)
-
- // react to user actions
- public void actionPerformed(ActionEvent event) {
- if (event.actionCommand == '<<-') {scanIndex = Math.max(scanIndex - 1, 0)}
- if (event.actionCommand == '->>') {scanIndex++}
- doHighlights()
- }
- public void keyReleased(KeyEvent event) {
- scanIndex = 0
- doHighlights()
- }
-
- private resetView() {
- swing.regexPane.highlighter.removeAllHighlights()
- swing.targetPane.highlighter.removeAllHighlights()
- swing.regexStatus.text = ' '
- swing.targetStatus.text = ' '
- }
-
- // the main regex logic
- private doHighlights() {
- try {
- resetView()
- // note: get the text from the underlying document,
- // otherwise carriage return/line feeds different when using the JTextPane text
- def regex = swing.regexPane.document.getText(0, swing.regexPane.document.length)
- def target = swing.targetPane.document.getText(0, swing.targetPane.document.length)
-
- def matcher = (target =~ regex)
-
- // scan past the matches before the match we want
- int scan = 0
- while (scan < scanIndex) {
- matcher.find()
- scan++
- }
- if (matcher.find()) {
- // highlight any captured groups
- int i = 0
- while (i++ < matcher.groupCount()) {
- swing.targetPane.highlighter.addHighlight(matcher.start(i), matcher.end(i), orange)
- }
- // highlight whole match
- swing.targetPane.highlighter.addHighlight(matcher.start(), matcher.end(), yellow)
- if (regex.length() != 0) {
- swing.targetStatus.text = "Match #${scanIndex + 1} from ${matcher.start()} to ${matcher.end()}."
- }
- } else {// not found
- scanIndex = Math.max(scan - 1, 0)
- if (scanIndex > 0) {doHighlights()}
- swing.targetStatus.text = "No match."
- }
- } catch (PatternSyntaxException e) {
- swing.regexPane.highlighter.addHighlight(e.index, e.index + 2, red)
- swing.regexStatus.text = e.description
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/RegexCoachView.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/RegexCoachView.groovy b/src/examples/swing/RegexCoachView.groovy
deleted file mode 100644
index c4b4664..0000000
--- a/src/examples/swing/RegexCoachView.groovy
+++ /dev/null
@@ -1,53 +0,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.
- */
-import static java.awt.BorderLayout.*
-import static javax.swing.JSplitPane.VERTICAL_SPLIT
-import static javax.swing.WindowConstants.EXIT_ON_CLOSE
-
-frame(title: 'The Groovy Regex Coach', location: [20, 40], size: [600, 500], defaultCloseOperation: EXIT_ON_CLOSE) {
- panel {
- borderLayout()
- splitPane(orientation: VERTICAL_SPLIT, dividerLocation: 150) {
- panel {
- borderLayout()
- label(constraints: NORTH, text: 'Regular expression:')
- scrollPane(constraints: CENTER) {
- textPane(id: 'regexPane')
- }
- label(constraints: SOUTH, id: 'regexStatus', text: ' ')
- }
- panel {
- borderLayout()
- label(constraints: NORTH, text: 'Target string:')
- scrollPane(constraints: CENTER) {
- textPane(id: 'targetPane')
- }
- panel(constraints: SOUTH) {
- borderLayout()
- label(constraints: NORTH, id: 'targetStatus', text: ' ')
- panel(constraints: SOUTH) {
- flowLayout()
- button('<<-', id: 'scanLeft')
- button('->>', id: 'scanRight')
- }
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/Widgets.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/Widgets.groovy b/src/examples/swing/Widgets.groovy
deleted file mode 100644
index 29b7656..0000000
--- a/src/examples/swing/Widgets.groovy
+++ /dev/null
@@ -1,220 +0,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 groovy.swing
-
-import java.awt.Color
-import javax.swing.SwingConstants
-import javax.swing.WindowConstants
-import groovy.swing.SwingBuilder
-
-class Widgets {
-
- def swing = new SwingBuilder()
- def unownedDialog
- def ownedDialog
-
-
- static void main(args) {
- def demo = new Widgets()
- demo.run()
- }
-
- def showUnownedDialog(event) {
- unownedDialog.show();
- }
-
- def showOwnedDialog(event) {
- ownedDialog.show();
- }
-
- void run() {
- unownedDialog = swing.dialog(
- title:'unrooted dialog',
- location: [200, 200],
- pack:true,
- defaultCloseOperation:WindowConstants.DISPOSE_ON_CLOSE
- ) {
- label("I am unowned, but not unwanted");
- }
-
- def frame = swing.frame(
- title:'FrameTitle',
- location:[100,100],
- size:[800,400],
- defaultCloseOperation:WindowConstants.EXIT_ON_CLOSE) {
-
- menuBar {
- menu(text:'File') {
- menuItem() {
- action(name:'New', closure:{ println("clicked on the new menu item!") })
- }
- menuItem() {
- action(name:'Open', closure:{ println("clicked on the open menu item!") })
- }
- separator()
- menuItem() {
- action(name:'Save', enabled:false, closure:{ println("clicked on the Save menu item!") })
- }
- }
- menu(text:'Dialogs') {
- menuItem() {
- action(name:'Owned Dialog', closure: this.&showOwnedDialog)
- }
- menuItem() {
- action(name:'Unowned Dialog', closure: this.&showUnownedDialog)
- }
- def deeplyOwnedDialog = swing.dialog(
- title:'rooted dialog #2',
- location: [200, 200],
- pack:true,
- defaultCloseOperation:WindowConstants.DISPOSE_ON_CLOSE
- ) {
- label("ownership is deep");
- }
- menuItem() {
- action(name:'Deeply Owned Dialog', closure: {deeplyOwnedDialog.show()} )
- }
- }
- }
-
- tabbedPane() {
-
- //colorChooser(
- // name:"Color Chooser",
- // color: 0xfeed42)
-
- panel(name:"Formatted Text Fields") {
- gridLayout(columns: 2, rows: 0)
- label("Simple Constructor:")
- formattedTextField()
- label("Date Value")
- formattedTextField(value: new java.util.Date())
- label("Integer Value")
- formattedTextField(value: new java.lang.Integer(42))
- label("Date Format")
- formattedTextField(format: java.text.DateFormat.getDateInstance())
- label("Currency Format ")
- formattedTextField(format: new java.text.DecimalFormat("¤###.00;(¤###.00)"))
- }
-
- panel(name:"Sliders") {
- flowLayout()
- slider(minimum:-100,
- maximum:100,
- majorTickSpacing: 50,
- orientation: SwingConstants.VERTICAL,
- paintLabels:true)
- slider(minimum:-100,
- maximum:100,
- orientation: SwingConstants.VERTICAL,
- paintLabels:true,
- paintTicks:true,
- majorTickSpacing: 50,
- minorTickSpacing: 10,
- snapToTicks:true,
- paintTrack:true)
- }
-
- panel(name:"Spinners") {
- gridBagLayout()
- label(
- text:"Tempuature in London:",
- insets:[12, 12, 2, 2],
- anchor: EAST,
- gridx: 0)
- spinner(
- model:spinnerNumberModel(minimum:-10,
- maximum: 40,
- value:20,
- stepSize:5),
- insets:[12, 3, 2, 12],
- anchor: WEST,
- gridx: 1,
- fill: HORIZONTAL)
- label(
- text:"Baseball Leagues:",
- insets:[3, 12, 2, 2],
- anchor: EAST,
- gridx: 0)
- spinner(
- model:spinnerListModel(
- list: ["Major League", "AAA", "AA", "A", "Rookie", "Semi-Pro", "Rec A", "Rec B"],
- value: "AA"),
- insets:[3, 3, 2, 12],
- anchor: WEST,
- gridx: 1,
- fill: HORIZONTAL)
- label(
- text:"Today's Date:",
- insets:[3, 12, 2, 2],
- anchor: EAST,
- gridx: 0)
- spinner(
- model:spinnerDateModel(calendarField: Calendar.HOUR_OF_DAY),
- insets:[3, 3, 2, 12],
- anchor: WEST,
- gridx: 1,
- fill: HORIZONTAL)
- }
-
- panel(name:"Border Layout") {
- borderLayout()
- label(text:"Border Layout",
- constraints:NORTH,
- horizontalAlignment:SwingConstants.CENTER)
- label(text:"South",
- constraints:SOUTH,
- background:Color.YELLOW,
- opaque:true,
- horizontalAlignment:SwingConstants.CENTER,
- toolTipText:"Tooltip on south")
- label(text:"West",
- constraints:WEST,
- background:Color.ORANGE,
- opaque:true,
- horizontalAlignment:SwingConstants.CENTER,
- toolTipText:"Tooltip on west")
- label(text:"East",
- constraints:EAST,
- background:Color.GREEN,
- opaque:true,
- horizontalAlignment:SwingConstants.CENTER,
- toolTipText:"Tooltip on east")
- label(text:"Center",
- constraints:CENTER,
- background:Color.WHITE,
- opaque:true,
- horizontalAlignment:SwingConstants.CENTER,
- toolTipText:"<html>This is not the tooltip you are looking for.<br><i>*waves hand*</i>")
- }
- }
-
- ownedDialog = swing.dialog(
- title:'rooted dialog',
- location: [200, 200],
- pack:true,
- defaultCloseOperation:WindowConstants.DISPOSE_ON_CLOSE
- ) {
- label("j00 h4v3 b33n 0wn3xed");
- }
- }
- frame.show()
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/Caricature.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/Caricature.groovy b/src/examples/swing/binding/caricature/Caricature.groovy
deleted file mode 100644
index 4479c85..0000000
--- a/src/examples/swing/binding/caricature/Caricature.groovy
+++ /dev/null
@@ -1,79 +0,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 groovy.swing.binding.caricature
-
-import groovy.swing.SwingBuilder
-import java.awt.Color
-import javax.swing.border.TitledBorder
-
-SwingBuilder.build {
- frame(pack:true, show:true,
- defaultCloseOperation:javax.swing.JFrame.DISPOSE_ON_CLOSE)
- {
- borderLayout()
- panel(constraints:CENTER,) {
- // place in panel to insure square layout
- caricature = widget(new JCaricature(
- background:Color.WHITE, opaque:true))
- }
- hbox(constraints:SOUTH) {
- panel(border:new TitledBorder("Style")) {
- gridLayout(new java.awt.GridLayout(5, 2))
- label("Eyes") // font stuff
- eyeSlider = slider(minimum:0, maximum:4,
- value:bind(target:caricature,
- targetProperty:'eyeStyle',
- value:2))
- label("Face") // font stuff
- faceSlider = slider(minimum:0, maximum:4,
- value:bind(target:caricature,
- targetProperty:'faceStyle',
- value:2))
- label("Mouth") // font stuff
- mouthSlider = slider(minimum:0, maximum:4,
- value:bind(target:caricature,
- targetProperty:'mouthStyle',
- value:2))
- label("Hair") // font stuff
- hairSlider = slider(minimum:0, maximum:4,
- value:bind(target:caricature,
- targetProperty:'hairStyle',
- value:2))
- label("Nose") // font stuff
- noseSlider = slider(minimum:0, maximum:4,
- value:bind(target:caricature,
- targetProperty:'noseStyle',
- value:2))
- }
- panel(border:new TitledBorder("Effects")) {
- gridLayout(new java.awt.GridLayout(2, 5))
- label("Rotation") // font stuff
- rotationSlider = slider(maximum:360,
- value:bind(target:caricature,
- targetProperty:'rotation',
- value:0))
- label("Scale") // font stuff
- scaleSlider = slider(maximum: 150, minimum:50,
- value:bind(target:caricature,
- targetProperty:'scale',
- converter: {it / 100f}, value:100))
- }
- }
- }
-}
[2/4] groovy git commit: move examples to their own repo
Posted by pa...@apache.org.
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/JCaricature.java
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/JCaricature.java b/src/examples/swing/binding/caricature/JCaricature.java
deleted file mode 100644
index 5fdce3d..0000000
--- a/src/examples/swing/binding/caricature/JCaricature.java
+++ /dev/null
@@ -1,220 +0,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.
- */
-/*
- * Caricature.java
- *
- * Created on April 8, 2006, 4:09 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package groovy.swing.binding.caricature;
-
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import javax.swing.ImageIcon;
-import javax.swing.JPanel;
-
-/**
- *
- * @author sky
- */
-public class JCaricature extends JPanel {
- private Map/*<String,Image>*/ imageMap;
-
- private boolean empty;
- private int mouthStyle;
- private int faceStyle;
- private int hairStyle;
- private int eyeStyle;
- private int noseStyle;
- private int rotation;
- private float scale = 1.0f;
-
- public JCaricature() {
- if (imageMap == null) {
- imageMap = new HashMap/*<String,Image>*/(1);
- for (int i = 0; i < 5; i++) {
- getImage("face", i);
- getImage("hair", i);
- getImage("eyes", i);
- getImage("nose", i);
- getImage("mouth", i);
- }
- }
- }
-
- public void setEmpty(boolean empty) {
- if (this.empty != empty) {
- this.empty = empty;
- firePropertyChange("empty", !empty, empty);
- repaint();
- }
- }
-
- public boolean isEmpty() {
- return empty;
- }
-
- public void setRotation(int rotation) {
- int oldRotation = this.rotation;
- this.rotation = rotation;
- repaint();
- firePropertyChange("rotation", oldRotation, rotation);
- }
-
- public int getRotation() {
- return rotation;
- }
-
- public void setScale(float scale) {
- float oldScale = this.scale;
- this.scale = scale;
- repaint();
- firePropertyChange("scale", oldScale, scale);
- }
-
- public float getScale() {
- return scale;
- }
-
- public void setMouthStyle(int style) {
- int oldStyle = mouthStyle;
- mouthStyle = style;
- firePropertyChange("mouthStyle", oldStyle, style);
- repaint();
- }
-
- public int getMouthStyle() {
- return mouthStyle;
- }
-
- public void setFaceStyle(int style) {
- int oldStyle = faceStyle;
- faceStyle = style;
- firePropertyChange("faceStyle", oldStyle, style);
- repaint();
- }
-
- public int getFaceStyle() {
- return faceStyle;
- }
-
- public void setHairStyle(int style) {
- int oldStyle = hairStyle;
- hairStyle = style;
- firePropertyChange("hairStyle", oldStyle, style);
- repaint();
- }
-
- public int getHairStyle() {
- return hairStyle;
- }
-
- public void setEyeStyle(int style) {
- int oldStyle = eyeStyle;
- eyeStyle = style;
- firePropertyChange("eyeStyle", oldStyle, style);
- repaint();
- }
-
- public int getEyeStyle() {
- return eyeStyle;
- }
-
- public void setNoseStyle(int style) {
- int oldStyle = noseStyle;
- noseStyle = style;
- firePropertyChange("noseStyle", oldStyle, style);
- repaint();
- }
-
- public int getNoseStyle() {
- return noseStyle;
- }
-
- public Dimension getPreferredSize() {
- if (!isPreferredSizeSet()) {
- Image image = getImage("mouth", 0);
- return new Dimension(image.getWidth(null), image.getHeight(null));
- }
- return super.getPreferredSize();
- }
-
- public Dimension getMaximumSize() {
- if (!isMaximumSizeSet()) {
- return getPreferredSize();
- }
- return super.getMaximumSize();
- }
-
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- if (empty) {
- return;
- }
- Graphics2D g2 = (Graphics2D)g.create();
- Image image = getImage("face", getFaceStyle());
- int iw = image.getWidth(null);
- int ih = image.getHeight(null);
-// g2.translate(iw / 2, ih / 2);
- g2.translate(getWidth() / 2, getHeight() / 2);
- if (iw != getWidth()) {
- float forcedScale = (float)getWidth() / (float)iw;
- g2.scale(forcedScale, forcedScale);
- }
- float scale = getScale();
- if (scale != 1) {
- g2.scale((double)scale, (double)scale);
- }
- int rotation = getRotation();
- if (rotation != 0) {
- g2.rotate(Math.toRadians(rotation));
- }
- drawImage(g2, "face", getFaceStyle());
- drawImage(g2, "hair", getHairStyle());
- drawImage(g2, "eyes", getEyeStyle());
- drawImage(g2, "nose", getNoseStyle());
- drawImage(g2, "mouth", getMouthStyle());
- g2.dispose();
- }
-
- private void drawImage(Graphics g, String string, int i) {
- Image image = getImage(string, i);
- g.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);
- }
-
- private Image getImage(String key, int style) {
- String imageName = key + (style + 1) + ".gif";
- Image image = (Image) imageMap.get(imageName);
- if (image == null) {
- System.err.println("name=" + imageName);
- URL imageLoc = getClass().getResource("resources/" + imageName);
- image = new ImageIcon(imageLoc).getImage();
- imageMap.put(imageName, image);
- }
- return image;
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/eyes1.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/eyes1.gif b/src/examples/swing/binding/caricature/resources/eyes1.gif
deleted file mode 100644
index 54d0eb0..0000000
Binary files a/src/examples/swing/binding/caricature/resources/eyes1.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/eyes2.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/eyes2.gif b/src/examples/swing/binding/caricature/resources/eyes2.gif
deleted file mode 100644
index 4aa3091..0000000
Binary files a/src/examples/swing/binding/caricature/resources/eyes2.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/eyes3.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/eyes3.gif b/src/examples/swing/binding/caricature/resources/eyes3.gif
deleted file mode 100644
index bfbbdea..0000000
Binary files a/src/examples/swing/binding/caricature/resources/eyes3.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/eyes4.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/eyes4.gif b/src/examples/swing/binding/caricature/resources/eyes4.gif
deleted file mode 100644
index e25f652..0000000
Binary files a/src/examples/swing/binding/caricature/resources/eyes4.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/eyes5.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/eyes5.gif b/src/examples/swing/binding/caricature/resources/eyes5.gif
deleted file mode 100644
index e5b6d6b..0000000
Binary files a/src/examples/swing/binding/caricature/resources/eyes5.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/face1.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/face1.gif b/src/examples/swing/binding/caricature/resources/face1.gif
deleted file mode 100644
index 01a107f..0000000
Binary files a/src/examples/swing/binding/caricature/resources/face1.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/face2.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/face2.gif b/src/examples/swing/binding/caricature/resources/face2.gif
deleted file mode 100644
index 0a8ea44..0000000
Binary files a/src/examples/swing/binding/caricature/resources/face2.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/face3.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/face3.gif b/src/examples/swing/binding/caricature/resources/face3.gif
deleted file mode 100644
index e8c467b..0000000
Binary files a/src/examples/swing/binding/caricature/resources/face3.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/face4.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/face4.gif b/src/examples/swing/binding/caricature/resources/face4.gif
deleted file mode 100644
index 9364ab8..0000000
Binary files a/src/examples/swing/binding/caricature/resources/face4.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/face5.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/face5.gif b/src/examples/swing/binding/caricature/resources/face5.gif
deleted file mode 100644
index e5f5e7c..0000000
Binary files a/src/examples/swing/binding/caricature/resources/face5.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/glasses.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/glasses.gif b/src/examples/swing/binding/caricature/resources/glasses.gif
deleted file mode 100644
index ef46483..0000000
Binary files a/src/examples/swing/binding/caricature/resources/glasses.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/glassesWEyes.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/glassesWEyes.gif b/src/examples/swing/binding/caricature/resources/glassesWEyes.gif
deleted file mode 100644
index 93585b0..0000000
Binary files a/src/examples/swing/binding/caricature/resources/glassesWEyes.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/hair1.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/hair1.gif b/src/examples/swing/binding/caricature/resources/hair1.gif
deleted file mode 100644
index 0466d00..0000000
Binary files a/src/examples/swing/binding/caricature/resources/hair1.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/hair2.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/hair2.gif b/src/examples/swing/binding/caricature/resources/hair2.gif
deleted file mode 100644
index 47adf81..0000000
Binary files a/src/examples/swing/binding/caricature/resources/hair2.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/hair3.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/hair3.gif b/src/examples/swing/binding/caricature/resources/hair3.gif
deleted file mode 100644
index d93bd45..0000000
Binary files a/src/examples/swing/binding/caricature/resources/hair3.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/hair4.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/hair4.gif b/src/examples/swing/binding/caricature/resources/hair4.gif
deleted file mode 100644
index eca9d4b..0000000
Binary files a/src/examples/swing/binding/caricature/resources/hair4.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/hair5.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/hair5.gif b/src/examples/swing/binding/caricature/resources/hair5.gif
deleted file mode 100644
index 147057a..0000000
Binary files a/src/examples/swing/binding/caricature/resources/hair5.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/mouth1.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/mouth1.gif b/src/examples/swing/binding/caricature/resources/mouth1.gif
deleted file mode 100644
index a92e1d3..0000000
Binary files a/src/examples/swing/binding/caricature/resources/mouth1.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/mouth2.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/mouth2.gif b/src/examples/swing/binding/caricature/resources/mouth2.gif
deleted file mode 100644
index 1486022..0000000
Binary files a/src/examples/swing/binding/caricature/resources/mouth2.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/mouth3.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/mouth3.gif b/src/examples/swing/binding/caricature/resources/mouth3.gif
deleted file mode 100644
index b6f5348..0000000
Binary files a/src/examples/swing/binding/caricature/resources/mouth3.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/mouth4.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/mouth4.gif b/src/examples/swing/binding/caricature/resources/mouth4.gif
deleted file mode 100644
index 937b46d..0000000
Binary files a/src/examples/swing/binding/caricature/resources/mouth4.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/mouth5.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/mouth5.gif b/src/examples/swing/binding/caricature/resources/mouth5.gif
deleted file mode 100644
index f61a7a1..0000000
Binary files a/src/examples/swing/binding/caricature/resources/mouth5.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/nose1.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/nose1.gif b/src/examples/swing/binding/caricature/resources/nose1.gif
deleted file mode 100644
index 336ea9f..0000000
Binary files a/src/examples/swing/binding/caricature/resources/nose1.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/nose2.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/nose2.gif b/src/examples/swing/binding/caricature/resources/nose2.gif
deleted file mode 100644
index 5ab8609..0000000
Binary files a/src/examples/swing/binding/caricature/resources/nose2.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/nose3.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/nose3.gif b/src/examples/swing/binding/caricature/resources/nose3.gif
deleted file mode 100644
index ea3c643..0000000
Binary files a/src/examples/swing/binding/caricature/resources/nose3.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/nose4.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/nose4.gif b/src/examples/swing/binding/caricature/resources/nose4.gif
deleted file mode 100644
index 832628b..0000000
Binary files a/src/examples/swing/binding/caricature/resources/nose4.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/binding/caricature/resources/nose5.gif
----------------------------------------------------------------------
diff --git a/src/examples/swing/binding/caricature/resources/nose5.gif b/src/examples/swing/binding/caricature/resources/nose5.gif
deleted file mode 100644
index ec51067..0000000
Binary files a/src/examples/swing/binding/caricature/resources/nose5.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/greet/Greet.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/greet/Greet.groovy b/src/examples/swing/greet/Greet.groovy
deleted file mode 100644
index ca93900..0000000
--- a/src/examples/swing/greet/Greet.groovy
+++ /dev/null
@@ -1,153 +0,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.
- */
-/*
- * Created by IntelliJ IDEA.
- * User: Danno.Ferrin
- * Date: Apr 26, 2008
- * Time: 8:32:03 AM
- */
-package groovy.swing.greet
-
-import groovy.beans.Bindable
-import groovy.swing.SwingBuilder
-import javax.swing.JOptionPane
-
-class Greet {
-
- TwitterAPI api
- Binding view
-
- @Bindable boolean allowLogin = true
- @Bindable boolean allowSelection = true
- @Bindable boolean allowTweet = true
- @Bindable def focusedUser = ""
- @Bindable def friends = []
- @Bindable def tweets = []
- @Bindable def timeline = []
- @Bindable def statuses = []
-
- void startUp() {
- setAllowSelection(false)
- setAllowTweet(false)
- view.greetFrame.show()
- view.loginDialog.show()
- }
-
- void login(evt) {
- setAllowLogin(false)
- view.doOutside {
- try {
- if (api.login(view.twitterNameField.text, view.twitterPasswordField.password)) {
- setFriends(api.getFriends(api.authenticatedUser))
- friends.each {it.status.user = [screen_name:it.screen_name, profile_image_url:it.profile_image_url] }
- setStatuses(friends.collect {it.status})
- selectUser(api.authenticatedUser)
- view.greetFrame.show()
- view.loginDialog.dispose()
- } else {
- JOptionPane.showMessageDialog(view.loginDialog, "Login failed")
- }
- } catch (Exception e) {
- e.printStackTrace()
- } finally {
- view.edt {
- setAllowLogin(true)
- setAllowSelection(true)
- setAllowTweet(true)
- }
- }
- }
- }
-
- void filterTweets(evt = null) {
- setAllowSelection(false)
- setAllowTweet(false)
- view.doOutside {
- try {
- setStatuses(
- friends.collect {it.status}.findAll {it.text =~ view.searchField.text}
- )
- setTimeline(
- api.getFriendsTimeline(focusedUser).findAll {it.text =~ view.searchField.text}
- )
- setTweets(
- api.getTweets(focusedUser).findAll {it.text =~ view.searchField.text}
- )
- } catch (Exception e) {
- e.printStackTrace()
- } finally {
- view.edt {
- setAllowSelection(true)
- setAllowTweet(true)
- }
- }
- }
- }
-
- def userSelected(evt) {
- view.doOutside {
- selectUser(view.users.selectedItem)
- }
- }
-
- def selectUser(user) {
- setAllowSelection(false)
- setAllowTweet(false)
- try {
- setFocusedUser(api.getUser(user.screen_name as String))
- setTweets(api.getTweets(focusedUser).findAll {it.text =~ view.searchField.text})
- setTimeline(api.getFriendsTimeline(focusedUser).findAll {it.text =~ view.searchField.text})
- } finally {
- view.edt {
- setAllowSelection(true)
- setAllowTweet(true)
- }
- }
- }
-
- def tweet(evt = null) {
- setAllowTweet(false)
- view.doOutside {
- try {
- api.tweet(view.tweetBox.text)
- // true story: it froze w/o the EDT call here
- view.edt {tweetBox.text = ""}
- filterTweets()
- } finally {
- setAllowTweet(true)
- }
- }
- }
-
- public static void main(String[] args) {
- def model = new TwitterAPI()
- def controller = new Greet()
- def view = new SwingBuilder()
-
- controller.api = model
- controller.view = view
-
- view.controller = controller
-
- view.build(View)
- view.view = view
-
- controller.startUp()
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/swing/greet/TwitterAPI.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/greet/TwitterAPI.groovy b/src/examples/swing/greet/TwitterAPI.groovy
deleted file mode 100644
index 76d13f4..0000000
--- a/src/examples/swing/greet/TwitterAPI.groovy
+++ /dev/null
@@ -1,162 +0,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.
- */
-/**
- * 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/ed3814a0/src/examples/swing/greet/View.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/greet/View.groovy b/src/examples/swing/greet/View.groovy
deleted file mode 100644
index 3f8597c..0000000
--- a/src/examples/swing/greet/View.groovy
+++ /dev/null
@@ -1,175 +0,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.
- */
-/**
- * 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/ed3814a0/src/examples/swing/timelog/TimeLogMain.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/timelog/TimeLogMain.groovy b/src/examples/swing/timelog/TimeLogMain.groovy
deleted file mode 100644
index 31acefa..0000000
--- a/src/examples/swing/timelog/TimeLogMain.groovy
+++ /dev/null
@@ -1,46 +0,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 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/ed3814a0/src/examples/swing/timelog/TimeLogModel.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/timelog/TimeLogModel.groovy b/src/examples/swing/timelog/TimeLogModel.groovy
deleted file mode 100644
index bb93772..0000000
--- a/src/examples/swing/timelog/TimeLogModel.groovy
+++ /dev/null
@@ -1,62 +0,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 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/ed3814a0/src/examples/swing/timelog/TimeLogView.groovy
----------------------------------------------------------------------
diff --git a/src/examples/swing/timelog/TimeLogView.groovy b/src/examples/swing/timelog/TimeLogView.groovy
deleted file mode 100644
index 91f711d..0000000
--- a/src/examples/swing/timelog/TimeLogView.groovy
+++ /dev/null
@@ -1,67 +0,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 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/ed3814a0/src/examples/transforms/global/CompiledAtASTTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/CompiledAtASTTransformation.groovy b/src/examples/transforms/global/CompiledAtASTTransformation.groovy
deleted file mode 100755
index f94e444..0000000
--- a/src/examples/transforms/global/CompiledAtASTTransformation.groovy
+++ /dev/null
@@ -1,66 +0,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/ed3814a0/src/examples/transforms/global/CompiledAtExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/CompiledAtExample.groovy b/src/examples/transforms/global/CompiledAtExample.groovy
deleted file mode 100755
index dffbf4f..0000000
--- a/src/examples/transforms/global/CompiledAtExample.groovy
+++ /dev/null
@@ -1,33 +0,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
-
-/**
-* 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/ed3814a0/src/examples/transforms/global/CompiledAtIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/CompiledAtIntegrationTest.groovy b/src/examples/transforms/global/CompiledAtIntegrationTest.groovy
deleted file mode 100644
index 1f03f39..0000000
--- a/src/examples/transforms/global/CompiledAtIntegrationTest.groovy
+++ /dev/null
@@ -1,39 +0,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.
- */
-import transforms.global.CompiledAtASTTransformation
-import org.codehaus.groovy.ast.*
-import org.codehaus.groovy.transform.*
-import org.codehaus.groovy.control.*
-import org.codehaus.groovy.tools.ast.*
-
-/**
-* This shows how to use the TransformTestHelper to test
-* a global transformation. It is a little hard to invoke
-* because the CompiledAtASTTransformation must be on the
-* classpath but the JAR containing the transform must not
-* or the transform gets applied twice.
-*
-* @author Hamlet D'Arcy
-*/
-def transform = new CompiledAtASTTransformation()
-def phase = CompilePhase.CONVERSION
-def helper = new TransformTestHelper(transform, phase)
-def clazz = helper.parse(' class MyClass {} ' )
-assert clazz.getCompiledTime() != null
-println 'compiled at' + clazz.getCompiledTime()
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/transforms/global/LoggingASTTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/LoggingASTTransformation.groovy b/src/examples/transforms/global/LoggingASTTransformation.groovy
deleted file mode 100644
index c6a2903..0000000
--- a/src/examples/transforms/global/LoggingASTTransformation.groovy
+++ /dev/null
@@ -1,73 +0,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.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/ed3814a0/src/examples/transforms/global/LoggingExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/LoggingExample.groovy b/src/examples/transforms/global/LoggingExample.groovy
deleted file mode 100644
index 2d9f38e..0000000
--- a/src/examples/transforms/global/LoggingExample.groovy
+++ /dev/null
@@ -1,48 +0,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
-
-/**
-* 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/ed3814a0/src/examples/transforms/global/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/META-INF/services/org.codehaus.groovy.transform.ASTTransformation b/src/examples/transforms/global/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
deleted file mode 100644
index 2de1e18..0000000
--- a/src/examples/transforms/global/META-INF/services/org.codehaus.groovy.transform.ASTTransformation
+++ /dev/null
@@ -1,17 +0,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.
-
-transforms.global.LoggingASTTransformation
-transforms.global.CompiledAtASTTransformation
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/transforms/global/build.xml
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/build.xml b/src/examples/transforms/global/build.xml
deleted file mode 100644
index 66d16c3..0000000
--- a/src/examples/transforms/global/build.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?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">
-
- <!-- necessary groovy jars are 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/ed3814a0/src/examples/transforms/global/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/transforms/global/readme.txt b/src/examples/transforms/global/readme.txt
deleted file mode 100644
index e774984..0000000
--- a/src/examples/transforms/global/readme.txt
+++ /dev/null
@@ -1,48 +0,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.
-====
-
-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/ed3814a0/src/examples/transforms/local/LoggingASTTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/local/LoggingASTTransformation.groovy b/src/examples/transforms/local/LoggingASTTransformation.groovy
deleted file mode 100644
index bd19b95..0000000
--- a/src/examples/transforms/local/LoggingASTTransformation.groovy
+++ /dev/null
@@ -1,74 +0,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.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/ed3814a0/src/examples/transforms/local/LoggingExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/local/LoggingExample.groovy b/src/examples/transforms/local/LoggingExample.groovy
deleted file mode 100644
index 4d47a64..0000000
--- a/src/examples/transforms/local/LoggingExample.groovy
+++ /dev/null
@@ -1,64 +0,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.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/ed3814a0/src/examples/transforms/local/WithLogging.groovy
----------------------------------------------------------------------
diff --git a/src/examples/transforms/local/WithLogging.groovy b/src/examples/transforms/local/WithLogging.groovy
deleted file mode 100644
index 03611f2..0000000
--- a/src/examples/transforms/local/WithLogging.groovy
+++ /dev/null
@@ -1,37 +0,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.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/ed3814a0/src/examples/transforms/local/build.xml
----------------------------------------------------------------------
diff --git a/src/examples/transforms/local/build.xml b/src/examples/transforms/local/build.xml
deleted file mode 100644
index eef390a..0000000
--- a/src/examples/transforms/local/build.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?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">
-
- <!-- necessary groovy jars are 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/ed3814a0/src/examples/transforms/local/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/transforms/local/readme.txt b/src/examples/transforms/local/readme.txt
deleted file mode 100644
index 2daade2..0000000
--- a/src/examples/transforms/local/readme.txt
+++ /dev/null
@@ -1,40 +0,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.
-====
-
-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
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/WEB-INF/groovy/Animal.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/Animal.groovy b/src/examples/webapps/groovlet-examples/WEB-INF/groovy/Animal.groovy
deleted file mode 100644
index 49e13e9..0000000
--- a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/Animal.groovy
+++ /dev/null
@@ -1,23 +0,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.
- */
-interface Animal {
-
- String saySomething(String something);
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/Fish.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/Fish.groovy b/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/Fish.groovy
deleted file mode 100644
index 1c58730..0000000
--- a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/Fish.groovy
+++ /dev/null
@@ -1,27 +0,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 zoo
-
-abstract class Fish implements Animal {
-
- String saySomething(String something) {
- return "Blubb�: " + something + "..."
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Shark.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Shark.groovy b/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Shark.groovy
deleted file mode 100644
index 8f05925..0000000
--- a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Shark.groovy
+++ /dev/null
@@ -1,29 +0,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 zoo.fish
-
-import zoo.Fish
-
-class Shark extends Fish {
-
- String saySomething(String something) {
- return "Shark bites " + something + "...ROOOAR�!"
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Trout.groovy
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Trout.groovy b/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Trout.groovy
deleted file mode 100644
index 0b19518..0000000
--- a/src/examples/webapps/groovlet-examples/WEB-INF/groovy/zoo/fish/Trout.groovy
+++ /dev/null
@@ -1,27 +0,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 zoo.fish
-
-class Trout extends zoo.Fish {
-
- String saySomething(String something) {
- return "Trout says " + something + "...blubb�!"
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/webapps/groovlet-examples/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/examples/webapps/groovlet-examples/WEB-INF/web.xml b/src/examples/webapps/groovlet-examples/WEB-INF/web.xml
deleted file mode 100644
index cd22859..0000000
--- a/src/examples/webapps/groovlet-examples/WEB-INF/web.xml
+++ /dev/null
@@ -1,89 +0,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.
-
--->
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_3.xsd"
- version="2.3">
-
- <servlet>
- <servlet-name>Groovlet</servlet-name>
- <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
- <init-param>
- <param-name>verbose</param-name>
- <param-value>true</param-value>
- </init-param>
- <init-param>
- <param-name>resource.name.regex</param-name>
- <param-value>none</param-value>
- </init-param>
- <init-param>
- <param-name>resource.name.replacement</param-name>
- <param-value>none</param-value>
- </init-param>
- </servlet>
-
- <servlet>
- <servlet-name>Template|GSP</servlet-name>
- <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
- </servlet>
-
- <servlet>
- <servlet-name>Template|GString</servlet-name>
- <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
- <init-param>
- <param-name>template.engine</param-name>
- <param-value>groovy.text.GStringTemplateEngine</param-value>
- </init-param>
- </servlet>
-
- <servlet>
- <servlet-name>Template|XML</servlet-name>
- <servlet-class>groovy.servlet.TemplateServlet</servlet-class>
- <init-param>
- <param-name>template.engine</param-name>
- <param-value>groovy.text.XmlTemplateEngine</param-value>
- </init-param>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>Template|GSP</servlet-name>
- <url-pattern>*.html</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
- <servlet-name>Template|XML</servlet-name>
- <url-pattern>*.xhtml</url-pattern>
- </servlet-mapping>
-
- <servlet-mapping>
- <servlet-name>Groovlet</servlet-name>
- <url-pattern>*.groovy</url-pattern>
- </servlet-mapping>
-
- <welcome-file-list>
- <welcome-file>index.xhtml</welcome-file>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>index.jspx</welcome-file>
- <welcome-file>index.groovy</welcome-file>
- </welcome-file-list>
-
-</web-app>
[4/4] groovy git commit: move examples to their own repo
Posted by pa...@apache.org.
move examples to their own repo
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/ed3814a0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ed3814a0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ed3814a0
Branch: refs/heads/master
Commit: ed3814a053eee8a4480c85c23485e161fd74c16a
Parents: 87839a2
Author: Paul King <pa...@asert.com.au>
Authored: Sun Aug 12 16:07:08 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sun Aug 12 16:07:08 2018 +1000
----------------------------------------------------------------------
build.gradle | 45 +-
src/examples/astbuilder/Main.groovy | 38 --
src/examples/astbuilder/MainExample.groovy | 34 -
.../astbuilder/MainIntegrationTest.groovy | 44 --
.../astbuilder/MainTransformation.groovy | 80 ---
src/examples/astbuilder/build.xml | 43 --
src/examples/astbuilder/readme.txt | 42 --
src/examples/commandLineTools/AntMap.groovy | 84 ---
src/examples/commandLineTools/BigTests.groovy | 51 --
src/examples/commandLineTools/ListFiles.groovy | 43 --
.../commandLineTools/Reflections.groovy | 36 --
.../commandLineTools/SimpleWebServer.groovy | 92 ---
src/examples/console/MortgageCalculator.groovy | 95 ---
src/examples/console/knowYourTables.groovy | 34 -
src/examples/console/thinkOfANumber.groovy | 39 --
src/examples/groovy/j2ee/CreateData.groovy | 41 --
src/examples/groovy/j2ee/J2eeConsole.java | 78 ---
src/examples/groovy/model/MvcDemo.groovy | 61 --
src/examples/groovy/swing/Demo.java | 55 --
src/examples/groovy/swing/MyTableModel.java | 123 ----
src/examples/groovy/swing/SwingDemo.groovy | 127 ----
src/examples/groovy/swing/TableDemo.groovy | 72 ---
.../groovy/swing/TableLayoutDemo.groovy | 76 ---
src/examples/groovy2d/paintingByNumbers.groovy | 66 --
src/examples/groovyShell/ArithmeticShell.groovy | 157 -----
.../groovyShell/ArithmeticShellTest.groovy | 108 ----
.../groovyShell/BlacklistingShell.groovy | 96 ---
.../groovyShell/BlacklistingShellTest.groovy | 82 ---
.../DefaultGrailsDomainClassInjector.java | 264 --------
.../grails/compiler/injection/DomainClass.java | 38 --
src/examples/osgi/build.properties | 28 -
src/examples/osgi/build.xml | 140 -----
.../org/codehaus/groovy/osgi/Activator.groovy | 59 --
.../codehaus/groovy/osgi/GroovyGreeter.groovy | 30 -
.../groovy/osgi/GroovyGreeterImpl.groovy | 31 -
.../groovy/osgi/harness/HarnessActivator.groovy | 50 --
src/examples/osgi/readme.txt | 140 -----
src/examples/searchEngine/Indexer.groovy | 83 ---
src/examples/searchEngine/Searcher.groovy | 61 --
src/examples/swing/BindingExample.groovy | 62 --
src/examples/swing/BloglinesClient.groovy | 187 ------
src/examples/swing/ModelNodeExample.groovy | 87 ---
src/examples/swing/RegexCoach.groovy | 125 ----
src/examples/swing/RegexCoachController.groovy | 105 ----
src/examples/swing/RegexCoachView.groovy | 53 --
src/examples/swing/Widgets.groovy | 220 -------
.../swing/binding/caricature/Caricature.groovy | 79 ---
.../swing/binding/caricature/JCaricature.java | 220 -------
.../binding/caricature/resources/eyes1.gif | Bin 1789 -> 0 bytes
.../binding/caricature/resources/eyes2.gif | Bin 1925 -> 0 bytes
.../binding/caricature/resources/eyes3.gif | Bin 1969 -> 0 bytes
.../binding/caricature/resources/eyes4.gif | Bin 2355 -> 0 bytes
.../binding/caricature/resources/eyes5.gif | Bin 1829 -> 0 bytes
.../binding/caricature/resources/face1.gif | Bin 2548 -> 0 bytes
.../binding/caricature/resources/face2.gif | Bin 2395 -> 0 bytes
.../binding/caricature/resources/face3.gif | Bin 2707 -> 0 bytes
.../binding/caricature/resources/face4.gif | Bin 2324 -> 0 bytes
.../binding/caricature/resources/face5.gif | Bin 2445 -> 0 bytes
.../binding/caricature/resources/glasses.gif | Bin 2092 -> 0 bytes
.../caricature/resources/glassesWEyes.gif | Bin 2209 -> 0 bytes
.../binding/caricature/resources/hair1.gif | Bin 3449 -> 0 bytes
.../binding/caricature/resources/hair2.gif | Bin 2477 -> 0 bytes
.../binding/caricature/resources/hair3.gif | Bin 2409 -> 0 bytes
.../binding/caricature/resources/hair4.gif | Bin 2771 -> 0 bytes
.../binding/caricature/resources/hair5.gif | Bin 4387 -> 0 bytes
.../binding/caricature/resources/mouth1.gif | Bin 971 -> 0 bytes
.../binding/caricature/resources/mouth2.gif | Bin 1046 -> 0 bytes
.../binding/caricature/resources/mouth3.gif | Bin 1639 -> 0 bytes
.../binding/caricature/resources/mouth4.gif | Bin 1014 -> 0 bytes
.../binding/caricature/resources/mouth5.gif | Bin 1303 -> 0 bytes
.../binding/caricature/resources/nose1.gif | Bin 1230 -> 0 bytes
.../binding/caricature/resources/nose2.gif | Bin 1345 -> 0 bytes
.../binding/caricature/resources/nose3.gif | Bin 1366 -> 0 bytes
.../binding/caricature/resources/nose4.gif | Bin 1200 -> 0 bytes
.../binding/caricature/resources/nose5.gif | Bin 1399 -> 0 bytes
src/examples/swing/greet/Greet.groovy | 153 -----
src/examples/swing/greet/TwitterAPI.groovy | 162 -----
src/examples/swing/greet/View.groovy | 175 ------
src/examples/swing/timelog/TimeLogMain.groovy | 46 --
src/examples/swing/timelog/TimeLogModel.groovy | 62 --
src/examples/swing/timelog/TimeLogView.groovy | 67 --
.../global/CompiledAtASTTransformation.groovy | 66 --
.../transforms/global/CompiledAtExample.groovy | 33 -
.../global/CompiledAtIntegrationTest.groovy | 39 --
.../global/LoggingASTTransformation.groovy | 73 ---
.../transforms/global/LoggingExample.groovy | 48 --
....codehaus.groovy.transform.ASTTransformation | 17 -
src/examples/transforms/global/build.xml | 52 --
src/examples/transforms/global/readme.txt | 48 --
.../local/LoggingASTTransformation.groovy | 74 ---
.../transforms/local/LoggingExample.groovy | 64 --
.../transforms/local/WithLogging.groovy | 37 --
src/examples/transforms/local/build.xml | 44 --
src/examples/transforms/local/readme.txt | 40 --
.../WEB-INF/groovy/Animal.groovy | 23 -
.../WEB-INF/groovy/zoo/Fish.groovy | 27 -
.../WEB-INF/groovy/zoo/fish/Shark.groovy | 29 -
.../WEB-INF/groovy/zoo/fish/Trout.groovy | 27 -
.../webapps/groovlet-examples/WEB-INF/web.xml | 89 ---
.../groovlet-examples/codehaus-style.css | 626 -------------------
.../groovlet-examples/hello/hello.groovy | 51 --
.../webapps/groovlet-examples/images/code.gif | Bin 292 -> 0 bytes
.../groovlet-examples/images/execute.gif | Bin 1242 -> 0 bytes
.../webapps/groovlet-examples/images/groovy.png | Bin 12303 -> 0 bytes
.../webapps/groovlet-examples/images/return.gif | Bin 1231 -> 0 bytes
.../webapps/groovlet-examples/index.groovy | 107 ----
.../webapps/groovlet-examples/readme.txt | 32 -
.../webapps/groovlet-examples/xml/index.xhtml | 58 --
.../zoo/HommingbergerGepardenforelle.groovy | 27 -
.../webapps/groovlet-examples/zoo/visit.groovy | 37 --
.../webapps/groovlet-examples/zoo/zoo.groovy | 48 --
src/examples/webapps/gsp-examples/readme.txt | 20 -
.../template-examples/3.times.HelloWorld.html | 33 -
.../WEB-INF/lib/groovy-all-xyz.jar.placeholder | 18 -
.../webapps/template-examples/WEB-INF/web.xml | 46 --
.../template-examples/javasystemproperties.htm | 42 --
.../webapps/template-examples/readme.txt | 32 -
117 files changed, 1 insertion(+), 6675 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index e3db86e..8032f62 100644
--- a/build.gradle
+++ b/build.gradle
@@ -124,16 +124,13 @@ test.dependsOn(copyTestResources)
repositories {
// todo Some repos are needed only for some configs. Declare them just for the configuration once Gradle allows this.
- maven { url 'http://repository.jboss.org/nexus/content/groups/m2-release-proxy' } // examples, tools
+ maven { url 'http://repository.jboss.org/nexus/content/groups/m2-release-proxy' } // tools
maven { url 'http://repo.bodar.com' } // tools - jarjar
}
-// todo do we need compile and runtime scope for examples?
configurations {
compilerCompile
tools
- examplesCompile.extendsFrom compile
- examplesRuntime.extendsFrom examplesCompile
antlr2
spec
}
@@ -145,8 +142,6 @@ ext {
bridgerVersion = '1.5.Final'
coberturaVersion = '1.9.4.1'
commonsCliVersion = '1.4'
- commonsHttpClientVersion = '3.1'
- eclipseOsgiVersion = '3.9.1-v20140110-1610'
gparsVersion = '1.2.1'
ivyVersion = '2.5.0-rc1'
jansiVersion = '1.17.1'
@@ -156,9 +151,7 @@ ext {
logbackVersion = '1.1.7'
log4jVersion = '1.2.17'
log4j2Version = '2.8'
- luceneVersion = '4.7.2'
openbeansVersion = '1.0'
- openejbVersion = '1.0'
picocliVersion = '3.5.0'
qdoxVersion = '1.12.1'
slf4jVersion = '1.7.21'
@@ -218,27 +211,6 @@ dependencies {
tools "org.ow2.asm:asm:$asmVersion"
tools "com.thoughtworks.qdox:qdox:$qdoxVersion"
- examplesCompile project(':groovy-test')
- examplesCompile project(':groovy-swing')
-
- examplesCompile "org.apache.lucene:lucene-core:$luceneVersion"
- examplesCompile "org.apache.lucene:lucene-analyzers-common:$luceneVersion"
- examplesCompile "org.apache.lucene:lucene-queryparser:$luceneVersion"
- examplesCompile "org.eclipse:osgi:$eclipseOsgiVersion"
- examplesRuntime("commons-httpclient:commons-httpclient:$commonsHttpClientVersion") {
- exclude(module: 'junit')
- exclude(module: 'commons-logging')
- exclude(module: 'commons-codec')
- }
- examplesRuntime("openejb:openejb-loader:$openejbVersion") {
- exclude(module: 'log4j')
- exclude(module: 'openejb-core')
- exclude(module: 'geronimo-jta_1.0.1B_spec')
- exclude(module: 'geronimo-servlet_2.4_spec')
- exclude(module: 'geronimo-ejb_2.1_spec')
- exclude(module: 'geronimo-j2ee-connector_1.5_spec')
- }
-
antlr2 "org.apache.ant:ant-antlr:$antVersion"
testCompile project(':groovy-ant')
@@ -293,15 +265,6 @@ sourceSets {
compileClasspath = sourceSets.main.runtimeClasspath + configurations.tools
runtimeClasspath = output + compileClasspath
}
- examples {
- groovy {
- srcDirs = ['src/examples']
- }
- resources {
- srcDirs = ['src/examples']
- }
- compileClasspath = configurations.examplesRuntime + sourceSets.main.output + project(':groovy-xml').sourceSets.main.output
- }
}
task sourceJar(type: Jar) {
@@ -321,12 +284,6 @@ subprojects {
apply from: 'subprojects/parser-antlr4/build.gradle'
-// make sure examples can be compiled, even if we don't run them
-// todo: reorganize examples so that we can run them too
-check {
- dependsOn examplesClasses
-}
-
compileJava {
doLast {
ant.java(classname:'org.jboss.bridger.Bridger', classpath: rootProject.configurations.tools.asPath, outputproperty: 'stdout') {
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/Main.groovy
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/Main.groovy b/src/examples/astbuilder/Main.groovy
deleted file mode 100644
index 0fcb5ab..0000000
--- a/src/examples/astbuilder/Main.groovy
+++ /dev/null
@@ -1,38 +0,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 examples.astbuilder
-
-import org.codehaus.groovy.transform.GroovyASTTransformationClass
-import java.lang.annotation.ElementType
-import java.lang.annotation.Target
-import java.lang.annotation.RetentionPolicy
-import java.lang.annotation.Retention
-
-/**
- * Marker interface to mark a method as something that should be invokable
- * as a main() method. An AST transformation will later wire this together.
- *
- * @author Hamlet D'Arcy
- */
-
-@Retention (RetentionPolicy.SOURCE)
-@Target ([ElementType.METHOD])
-@GroovyASTTransformationClass (["examples.astbuilder.MainTransformation"])
-public @interface Main {
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/MainExample.groovy
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/MainExample.groovy b/src/examples/astbuilder/MainExample.groovy
deleted file mode 100644
index 2990d16..0000000
--- a/src/examples/astbuilder/MainExample.groovy
+++ /dev/null
@@ -1,34 +0,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 examples.astbuilder
-
-/**
- * Exists to test the @Main annotation. At compile time, there will be a main()
- * method added to this class that has the same body as the greet() method.
- * It can be invoked either by using either Java or Groovy to run the class.
- *
- * @author Hamlet D'Arcy
- */
-class MainExample {
-
- @Main
- public void greet() {
- println "Hello from the greet() method!"
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/MainIntegrationTest.groovy
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/MainIntegrationTest.groovy b/src/examples/astbuilder/MainIntegrationTest.groovy
deleted file mode 100644
index 3fb7dc9..0000000
--- a/src/examples/astbuilder/MainIntegrationTest.groovy
+++ /dev/null
@@ -1,44 +0,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 examples.astbuilder
-
-import org.codehaus.groovy.tools.ast.TransformTestHelper
-import org.codehaus.groovy.control.CompilePhase
-
-/**
- *
- * This TestCase shows how to invoke an AST Transformation from a unit test.
- * An IDE will let you step through the AST Transformation using this approach.
- *
- * @author Hamlet D'Arcy
- */
-
-class MainIntegrationTest extends GroovyTestCase {
-
- public void testInvokeUnitTest() {
- def invoker = new TransformTestHelper(new MainTransformation(), CompilePhase.CANONICALIZATION)
-
- def file = new File('./MainExample.groovy')
- assert file.exists()
-
- def clazz = invoker.parse(file)
- def tester = clazz.newInstance()
- tester.main(null) // main method added with AST transform
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/MainTransformation.groovy
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/MainTransformation.groovy b/src/examples/astbuilder/MainTransformation.groovy
deleted file mode 100644
index 4f66cf8..0000000
--- a/src/examples/astbuilder/MainTransformation.groovy
+++ /dev/null
@@ -1,80 +0,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 examples.astbuilder
-
-import org.codehaus.groovy.ast.*
-import org.codehaus.groovy.control.CompilePhase
-import org.codehaus.groovy.transform.GroovyASTTransformation
-import org.codehaus.groovy.transform.ASTTransformation
-import org.codehaus.groovy.control.SourceUnit
-import org.codehaus.groovy.ast.builder.AstBuilder
-
-/**
- * If there is a method in a class with the @Main annotation on it, then this
- * transformation adds a real main(String[]) method to the class with the same
- * method body as the annotated class.
- *
- * @author Hamlet D'Arcy
- */
-@GroovyASTTransformation(phase = CompilePhase.INSTRUCTION_SELECTION)
-public class MainTransformation implements ASTTransformation {
-
- // normally defined in org.objectweb.asm.Opcodes, but there duplicated
- // here to make the build script simpler.
- static int PUBLIC = 1
- static int STATIC = 8
-
- void visit(ASTNode[] astNodes, SourceUnit sourceUnit) {
-
- // use guard clauses as a form of defensive programming.
- if (!astNodes) return
- if (!astNodes[0]) return
- if (!astNodes[1]) return
- if (!(astNodes[0] instanceof AnnotationNode)) return
- if (astNodes[0].classNode?.name != Main.class.name) return
- if (!(astNodes[1] instanceof MethodNode)) return
-
- MethodNode annotatedMethod = astNodes[1]
- ClassNode declaringClass = annotatedMethod.declaringClass
- MethodNode mainMethod = makeMainMethod(annotatedMethod)
- declaringClass.addMethod(mainMethod)
- }
-
- /**
- * Uses the AstBuilder to synthesize a main method, and then sets the body of
- * the method to that of the source method. Notice how Void.TYPE is used as
- * a return value instead of Void.class. This is required so that resulting method
- * is void and not Void.
- */
- MethodNode makeMainMethod(MethodNode source) {
- def className = source.declaringClass.name
- def methodName = source.name
-
- def ast = new AstBuilder().buildFromString(CompilePhase.INSTRUCTION_SELECTION, false, """
- package $source.declaringClass.packageName
-
- class $source.declaringClass.nameWithoutPackage {
- public static void main(String[] args) {
- new $className().$methodName()
- }
- }
- """)
- ast[1].methods.find { it.name == 'main' }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/build.xml
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/build.xml b/src/examples/astbuilder/build.xml
deleted file mode 100644
index 3f31815..0000000
--- a/src/examples/astbuilder/build.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?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-astbuilder-usage-example" default="compile-transform">
-
- <!-- necessary groovy jars are 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="Main.groovy,MainTransformation.groovy"
- listfiles="true">
- </groovyc>
-
- <echo>You can now run "groovy MainExample.groovy", "groovyc MainExample.groovy", or "groovy MainIntegrationTest.groovy" to see that the transformation worked.</echo>
- </target>
-
-</project>
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/astbuilder/readme.txt
----------------------------------------------------------------------
diff --git a/src/examples/astbuilder/readme.txt b/src/examples/astbuilder/readme.txt
deleted file mode 100644
index 25f7f99..0000000
--- a/src/examples/astbuilder/readme.txt
+++ /dev/null
@@ -1,42 +0,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.
-====
-
-AstBuilder and AST Transformation Example
-
-This example shows how to use the AstBuilder to add a public static void main(String[])
-method to a class.
-
-The example requires ant in your path and the Groovy 1.7 (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 either of the following from the command lines:
- groovy MainExample.groovy
- groovyc MainExample.groovy (and then invoke with java or view with javap)
-
-The example should print:
- Hello from the greet() method!
-
-No exceptions should occur.
-
-The MainIntegrationTest.groovy file shows how to invoke an ASTTransformation
-from a unit test. An IDE should be able to debug this.
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/commandLineTools/AntMap.groovy
----------------------------------------------------------------------
diff --git a/src/examples/commandLineTools/AntMap.groovy b/src/examples/commandLineTools/AntMap.groovy
deleted file mode 100644
index 741c817..0000000
--- a/src/examples/commandLineTools/AntMap.groovy
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/env groovy
-/*
- * 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.
- */
-
-//
-// convert an ant build file into a format suitable for http://sf.net/projects/freemind
-//
-// by Jeremy Rayner - 2 Dec 2004
-// inspired by Sam Newman ( http://www.magpiebrain.com/archives/2004/12/02/antgui )
-//
-// usage: groovy AntMap > build.mm
-
-buildFileName = "build.xml" // default
-
-// handle command line params
-if (args.length > 0) {
- buildFileName = args[0]
-}
-
-// header
-println "<map version='0.7.1'>"
-project = new XmlParser().parse(buildFileName)
-name = project['@name']
-println "<node TEXT='${name}'>"
-level = 0
-
-printChildren(project,level)
-
-
-
-def void printChildren(node,level) {
- level++
- node.each {
- name = huntForName(it)
- if (name != null) {
- if (level > 1) {
- println "<node TEXT='${name}' POSITION='right'>"
- } else if (it.name() == 'property' || it.name() == 'path' ) {
- if (it.children().size() > 0) {
- println "<node TEXT='${name}' POSITION='left' FOLDED='true'>"
- } else {
- println "<node TEXT='${name}' POSITION='left'>"
- }
- } else if (it.children().size() > 0) {
- println "<node TEXT='${name}' POSITION='right' FOLDED='true'>"
- } else {
- println "<node TEXT='${name}' POSITION='right'>"
- }
- }
- if (it.children().size() > 0) printChildren(it,level)
- if (name!=null) println "</node>"
- }
-}
-
-// footer
-println "</node></map>"
-
-
-def String huntForName(node) {
- preferNodeNames = ["junitreport"]
- if (node == null) return null
- if (preferNodeNames.contains(node.name())) return node.name()
- if (node['@name'] != null) return node['@name']
- if (node['@todir'] != null) return node['@todir']
- if (node['@dir'] != null) return node['@dir']
- if (node['@refid'] != null) return node['@refid']
- return node.name()
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/commandLineTools/BigTests.groovy
----------------------------------------------------------------------
diff --git a/src/examples/commandLineTools/BigTests.groovy b/src/examples/commandLineTools/BigTests.groovy
deleted file mode 100644
index 85fa13b..0000000
--- a/src/examples/commandLineTools/BigTests.groovy
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/bin/env groovy
-/*
- * 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.
- */
-//
-// output tests in a junit xml report that took greater than specified time
-//
-// by Jeremy Rayner - 15 Dec 2004
-//
-// usage: groovy BigTests.groovy <TEST.xml> <time in secs>
-
-fileName = "" // default
-timeCutOff = new Float("1.0")
-
-if (args.length > 1) {
- fileName = args[0]
- timeCutOff = new Float(args[1])
-} else {
- println "usage: groovy BigTests.groovy <TEST.xml> <time in secs>"
-}
-
-testSuite = new XmlParser().parse(fileName)
-name = testSuite['@name']
-println "TestSuite: ${name}"
-bigTests = [:]
-testSuite.each {
- if ("testcase" == it.name()) {
- classname = it['@classname']
- name = it['@name']
- time = new Float(it['@time'])
- if (time > timeCutOff) {
- println " ${time} - ${classname}.${name}()"
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/commandLineTools/ListFiles.groovy
----------------------------------------------------------------------
diff --git a/src/examples/commandLineTools/ListFiles.groovy b/src/examples/commandLineTools/ListFiles.groovy
deleted file mode 100644
index e3d1f71..0000000
--- a/src/examples/commandLineTools/ListFiles.groovy
+++ /dev/null
@@ -1,43 +0,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.
- */
-public class ListFilesManualTest {
-
- static void main(args) {
- println("Called main with ${args}")
- listFiles(Arrays.asList(args))
- }
-
- static String getPath(file) {
- return file.absolutePath
- }
-
- static void listFiles(dirs) {
- println("called with ${dirs}")
-
- for(dir in dirs) {
- println("dir: ${dir}")
-
- def files = new java.io.File(dir).listFiles()
-
- for (f in files) {
- println(getPath(f))
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/commandLineTools/Reflections.groovy
----------------------------------------------------------------------
diff --git a/src/examples/commandLineTools/Reflections.groovy b/src/examples/commandLineTools/Reflections.groovy
deleted file mode 100644
index 4be7551..0000000
--- a/src/examples/commandLineTools/Reflections.groovy
+++ /dev/null
@@ -1,36 +0,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.
- */
-/**
- * Echoes back whatever is thrown at it (with a <br> at end for browsers) ...
- * @author <a href="mailto:jeremy.rayner@gmail.com">Jeremy Rayner</a>
- *
- * invoke using
- * groovy -l 80 Reflections.groovy
- *
- * (where 80 is the port to listen for requests upon)
- */
-
-// echo, echo, echo...
-println "${line} <br>"
-
-//assume no input means we've finished...
-if (line == "") {
- // clean up gracefully, closing sockets etc
- return "success"
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/commandLineTools/SimpleWebServer.groovy
----------------------------------------------------------------------
diff --git a/src/examples/commandLineTools/SimpleWebServer.groovy b/src/examples/commandLineTools/SimpleWebServer.groovy
deleted file mode 100644
index a8dd1ea..0000000
--- a/src/examples/commandLineTools/SimpleWebServer.groovy
+++ /dev/null
@@ -1,92 +0,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.
- */
-/**
- * Simple web server
- * @author <a href="mailto:jeremy.rayner@gmail.com">Jeremy Rayner</a>
- *
- * invoke using
- * groovy -l 80 SimpleWebServer.groovy
- *
- * (where 80 is the port to listen for requests upon)
- */
-import java.io.File
-
-if (init) {
- headers = [:]
- binaryTypes = ["gif","jpg","png"]
- mimeTypes = [
- "css" : "text/css",
- "gif" : "image/gif",
- "htm" : "text/html",
- "html": "text/html",
- "jpg" : "image/jpeg",
- "png" : "image/png"
- ]
-}
-
-// parse the request
-if (line.toLowerCase().startsWith("get")) {
- content = line.tokenize()[1]
-} else {
- h = line.tokenize(":")
- headers[h[0]] = h[1]
-}
-
-// all done, now process request
-if (line.size() == 0) {
- processRequest()
- return "success"
-}
-
-// ------------------------
-
-def processRequest() {
- if (content.indexOf("..") < 0) { //simplistic security
- // simple file browser rooted from current dir
- f = new File("." + content)
- if (f.isDirectory()) {
- printDirectoryListing(f)
- } else {
- extension = content.substring(content.lastIndexOf(".") + 1)
- printHeaders(mimeTypes.get(extension,"text/plain"))
-
- if (binaryTypes.contains(extension)) {
- socket.outputStream.write(f.readBytes())
- } else {
- println(f.text)
- }
- }
- }
-}
-
-def printDirectoryListing(f) {
- printHeaders("text/html")
- println "<html><head></head><body>"
- for (i in f.list().toList().sort()) {
- if ("/" == content) { content = "" } // special case for root document
- println "<a href='${content}/${i}'>${i}</a><br>"
- }
- println "</body></html>"
-}
-
-def printHeaders(mimeType) {
- println "HTTP/1.0 200 OK"
- println "Content-Type: ${mimeType}"
- println ""
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/console/MortgageCalculator.groovy
----------------------------------------------------------------------
diff --git a/src/examples/console/MortgageCalculator.groovy b/src/examples/console/MortgageCalculator.groovy
deleted file mode 100644
index 375e244..0000000
--- a/src/examples/console/MortgageCalculator.groovy
+++ /dev/null
@@ -1,95 +0,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.
- */
-/**
- * Mortgage Calculator
- * @author: Jeremy Rayner
- * based on algorithms by Jeff Louie, Dr W Carlini and Newton
- */
-
-println "__..::~~'''~~::..__"
-println "Mortgage Calculator"
-println "~~~~~~~~~~~~~~~~~~~"
-println "Please input 3 of the 4 values in your mortgage calculation"
-println "This program will then calculate the value you leave blank"
-println ""
-
-def variables = [
- "Amount of mortgage" : 0.0,
- "Annual interest rate (%)" : 0.0,
- "Loan duration (months)" : 0.0,
- "Monthly payments" : 0.0
-]
-
-for (entry in variables.entrySet()) {
- print("${entry.key}:")
- def userInput = System.in.readLine()
- if ("" == userInput) {
- valueToCalculate = entry.key
- } else {
- entry.value = userInput.toDouble()
- }
-}
-
-println "$valueToCalculate = ${calculateValueOf(valueToCalculate)}"
-
-
-
-
-
-def calculateValueOf(valueToCalculate) {
- def result = 0
- def principal = variables["Amount of mortgage"]
- def interest = variables["Annual interest rate (%)"] / 1200
- def months = variables["Loan duration (months)"]
- def payment = variables["Monthly payments"]
-
- switch (valueToCalculate) {
- case "Amount of mortgage":
- result = 1 + interest
- result = 1/Math.pow(result,months)
- result = ((1-result)/interest) * payment
- break
- case "Loan duration (months)":
- result = (1 - (principal * interest / payment))
- result = Math.log(result)
- result = - result / Math.log(1 + interest)
- break
- case "Monthly payments":
- result = 1 + interest
- result = 1 / Math.pow(result,months)
- result = (principal * interest) / (1 - result)
- break
- case "Annual interest rate (%)":
- result = payment / principal
- def diff = 100; def accuracy = 0.00001; def maxIterations = 1000
- def index = 0
- while ((diff > accuracy) && (index < maxIterations)) {
- def temp = result
- def numerator = (principal * temp / payment) + Math.pow((1 + temp), -months) - 1
- def denominator= (principal / payment) - months * Math.pow((1 + temp), (-months - 1))
- result = temp - (numerator / denominator)
- diff = result - temp
- diff = Math.abs(diff)
- index++
- }
- result *= 1200
- break
- }
- return result
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/console/knowYourTables.groovy
----------------------------------------------------------------------
diff --git a/src/examples/console/knowYourTables.groovy b/src/examples/console/knowYourTables.groovy
deleted file mode 100644
index 1343365..0000000
--- a/src/examples/console/knowYourTables.groovy
+++ /dev/null
@@ -1,34 +0,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.
- */
-/**
- * Simple mathematics quiz
- * @author: Jeremy Rayner
- * based on algorithms from INPUT/Marshall Cavendish/1984
- */
-while (true) {
- try {
- def n = (int)(Math.random() * 12) + 1
- println "What is $n times 9?"
- def a = System.in.readLine().toInteger()
- if (a == n * 9) println "Correct"
-
- } catch (Exception e) {
- println "The computer didn't understand your input"
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/console/thinkOfANumber.groovy
----------------------------------------------------------------------
diff --git a/src/examples/console/thinkOfANumber.groovy b/src/examples/console/thinkOfANumber.groovy
deleted file mode 100644
index 7a42cf9..0000000
--- a/src/examples/console/thinkOfANumber.groovy
+++ /dev/null
@@ -1,39 +0,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.
- */
-/**
- * Simple game
- * @author: Jeremy Rayner
- * based on algorithms from INPUT/Marshall Cavendish/1984
- */
-while (true) {
- try {
- int x = Math.random() * 6
- print "The computer has chosen a number between 0 and 5. Can you guess it?"
-
- def line = System.in.readLine()
- int g = line.toInteger()
- if (g == x) {
- println "Well done"
- } else {
- println "Tough luck - you're wrong"
- }
- } catch (NumberFormatException e) {
- println "The computer didn't understand '$line'"
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/j2ee/CreateData.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy/j2ee/CreateData.groovy b/src/examples/groovy/j2ee/CreateData.groovy
deleted file mode 100644
index a0bef2a..0000000
--- a/src/examples/groovy/j2ee/CreateData.groovy
+++ /dev/null
@@ -1,41 +0,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.
- */
-println("Called with context: " + context)
-
-db = context.lookup("/client/tools/DatabaseHome").create()
-
-println("About to do queries on: " + db)
-
-queries = [
- "CREATE TABLE account ( ssn CHAR(11) PRIMARY KEY, first_name CHAR(20), last_name CHAR(20), balance INT)",
- "CREATE TABLE entity ( id INT PRIMARY KEY AUTO INCREMENT, first_name CHAR(20), last_name CHAR(20) )"
-]
-
-for (sql in queries) {
- println("evaluating: " + sql)
- db.execute(sql)
-}
-
-println("creating entity bean")
-
-context.lookup("/client/tests/entity/bmp/BasicBmpHome").create("Groovy Dain")
-
-println("Done")
-
-"OK"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/j2ee/J2eeConsole.java
----------------------------------------------------------------------
diff --git a/src/examples/groovy/j2ee/J2eeConsole.java b/src/examples/groovy/j2ee/J2eeConsole.java
deleted file mode 100644
index 538ebf6..0000000
--- a/src/examples/groovy/j2ee/J2eeConsole.java
+++ /dev/null
@@ -1,78 +0,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 groovy.j2ee;
-
-import groovy.lang.GroovyObject;
-import groovy.lang.GroovyShell;
-import org.codehaus.groovy.runtime.InvokerHelper;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.util.Properties;
-
-/**
- * A J2EE console
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- */
-public class J2eeConsole {
-
- public static void main(String[] args) {
- if (args.length <= 0) {
- System.out.println("Usage: home [configuaration] [localcopy]");
- return;
- }
-
- String home = args[0];
-
- Properties p = new Properties();
- System.setProperty("openejb.home", home);
- p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
- p.put("openejb.loader", "embed");
- p.put("openejb.home", home);
-
- if (args.length > 1) {
- String conf = args[1];
- System.setProperty("openejb.configuration", conf);
- p.put("openejb.configuration", conf);
- }
- if (args.length > 2) {
- String copy = args[2];
- System.setProperty("openejb.localcopy", copy);
- p.put("openejb.localcopy", copy);
- }
- try {
- InitialContext ctx = new InitialContext(p);
-
- GroovyShell shell = new GroovyShell();
- shell.setVariable("context", ctx);
- //shell.evaluate("src/test/groovy/j2ee/CreateData.groovy");
-
- //shell.evaluate("src/main/groovy/ui/Console.groovy");
- GroovyObject console = (GroovyObject) InvokerHelper.invokeConstructorOf("groovy.ui.Console", null);
- console.setProperty("shell", shell);
- console.invokeMethod("run", null);
- /*
- */
- }
- catch (Exception e) {
- System.out.println("Caught: " + e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/model/MvcDemo.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy/model/MvcDemo.groovy b/src/examples/groovy/model/MvcDemo.groovy
deleted file mode 100644
index dc31126..0000000
--- a/src/examples/groovy/model/MvcDemo.groovy
+++ /dev/null
@@ -1,61 +0,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 groovy.model
-
-import groovy.swing.SwingBuilder
-/**
- *
- */
-class MvcDemo {
-
- def frame
- def swing
-
- void run() {
- swing = new SwingBuilder()
-
- def frame = swing.frame(title:'MVC Demo', location:[200,200], size:[300,200]) {
- menuBar {
- menu(text:'Help') {
- menuItem() {
- action(name:'About', closure:{ showAbout() })
- }
- }
- }
- panel {
- borderLayout()
- scrollPane(constraints:CENTER) {
- table() {
- tableModel(list:[ ['name':'James', 'location':'London'], ['name':'Bob', 'location':'Atlanta'] ]) {
- propertyColumn(header:'Name', propertyName:'name')
- propertyColumn(header:'Location', propertyName:'location')
- }
- }
- }
- }
- }
- frame.show()
- }
-
- void showAbout() {
- def pane = swing.optionPane(message:'This demo shows how you can create UI models from simple MVC models')
- def dialog = pane.createDialog(frame, 'About MVC Demo')
- dialog.show()
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/swing/Demo.java
----------------------------------------------------------------------
diff --git a/src/examples/groovy/swing/Demo.java b/src/examples/groovy/swing/Demo.java
deleted file mode 100644
index db997ca..0000000
--- a/src/examples/groovy/swing/Demo.java
+++ /dev/null
@@ -1,55 +0,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 groovy.swing;
-
-import groovy.lang.GroovyObject;
-import groovy.lang.GroovyCodeSource;
-import groovy.lang.GroovyClassLoader;
-import groovy.util.GroovyTestCase;
-
-import java.io.File;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- */
-public class Demo extends GroovyTestCase {
- ClassLoader parentLoader = getClass().getClassLoader();
- protected GroovyClassLoader loader =
- (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return new GroovyClassLoader(parentLoader);
- }
- });
-
- public static void main(String[] args) throws Exception {
- Demo demo = new Demo();
- GroovyObject object = demo.compile("src/examples/groovy/swing/SwingDemo.groovy");
- object.invokeMethod("run", null);
- }
-
- protected GroovyObject compile(String fileName) throws Exception {
- Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
- GroovyObject object = (GroovyObject) groovyClass.newInstance();
- assertTrue(object != null);
- return object;
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/swing/MyTableModel.java
----------------------------------------------------------------------
diff --git a/src/examples/groovy/swing/MyTableModel.java b/src/examples/groovy/swing/MyTableModel.java
deleted file mode 100644
index fa28bf5..0000000
--- a/src/examples/groovy/swing/MyTableModel.java
+++ /dev/null
@@ -1,123 +0,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 groovy.swing;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.swing.table.AbstractTableModel;
-
-/**
- * A sample table model
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- */
-public class MyTableModel extends AbstractTableModel {
-
- private static final Logger log = Logger.getLogger(MyTableModel.class.getName());
-
- public MyTableModel() {
- }
-
- final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" };
- final Object[][] data = { { "Mary", "Campione", "Snowboarding", Integer.valueOf(5), new Boolean(false)}, {
- "Alison", "Huml", "Rowing", Integer.valueOf(3), new Boolean(true)
- }, {
- "Kathy", "Walrath", "Chasing toddlers", Integer.valueOf(2), new Boolean(false)
- }, {
- "Mark", "Andrews", "Speed reading", Integer.valueOf(20), new Boolean(true)
- }, {
- "Angela", "Lih", "Teaching high school", Integer.valueOf(4), new Boolean(false)
- }
- };
-
- public int getColumnCount() {
- return columnNames.length;
- }
-
- public int getRowCount() {
- return data.length;
- }
-
- public String getColumnName(int col) {
- return columnNames[col];
- }
-
- public Object getValueAt(int row, int col) {
- return data[row][col];
- }
-
- /*
- * JTable uses this method to determine the default renderer/
- * editor for each cell. If we didn't implement this method,
- * then the last column would contain text ("true"/"false"),
- * rather than a check box.
- */
- public Class getColumnClass(int c) {
- return getValueAt(0, c).getClass();
- }
-
- /*
- * Don't need to implement this method unless your table's
- * editable.
- */
- public boolean isCellEditable(int row, int col) {
- //Note that the data/cell address is constant,
- //no matter where the cell appears onscreen.
- if (col < 2) {
- return false;
- }
- else {
- return true;
- }
- }
-
- /*
- * Don't need to implement this method unless your table's
- * data can change.
- */
- public void setValueAt(Object value, int row, int col) {
- if (log.isLoggable(Level.FINE)) {
- log.fine(
- "Setting value at " + row + "," + col + " to " + value + " (an instance of " + value.getClass() + ")");
- }
-
- if (data[0][col] instanceof Integer && !(value instanceof Integer)) {
- //With JFC/Swing 1.1 and JDK 1.2, we need to create
- //an Integer from the value; otherwise, the column
- //switches to contain Strings. Starting with v 1.3,
- //the table automatically converts value to an Integer,
- //so you only need the code in the 'else' part of this
- //'if' block.
- //XXX: See TableEditDemo.java for a better solution!!!
- try {
- data[row][col] = Integer.valueOf(value.toString());
- fireTableCellUpdated(row, col);
- }
- catch (NumberFormatException e) {
- log.log(Level.SEVERE, "The \"" + getColumnName(col) + "\" column accepts only integer values.");
- }
- }
- else {
- data[row][col] = value;
- fireTableCellUpdated(row, col);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/swing/SwingDemo.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy/swing/SwingDemo.groovy b/src/examples/groovy/swing/SwingDemo.groovy
deleted file mode 100644
index 6158032..0000000
--- a/src/examples/groovy/swing/SwingDemo.groovy
+++ /dev/null
@@ -1,127 +0,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 groovy.swing
-
-import java.awt.BorderLayout
-import javax.swing.BorderFactory
-import groovy.model.MvcDemo
-import groovy.swing.SwingBuilder
-
-class SwingDemo {
-
- def swing = new SwingBuilder()
- def frame
-
- static void main(args) {
- def demo = new SwingDemo()
- demo.run()
- }
-
- void run() {
- def frame = swing.frame(
- title:'This is a Frame',
- location:[100,100],
- size:[800,400],
- defaultCloseOperation:javax.swing.WindowConstants.EXIT_ON_CLOSE) {
-
- menuBar {
- menu(text:'File') {
- menuItem() {
- action(name:'New', closure:{ println("clicked on the new menu item!") })
- }
- menuItem() {
- action(name:'Open', closure:{ println("clicked on the open menu item!") })
- }
- separator()
- menuItem() {
- action(name:'Save', enabled:false, closure:{ println("clicked on the Save menu item!") })
- }
- }
- menu(text:'Demos') {
- menuItem() {
- action(name:'Simple TableModel Demo', closure:{ showGroovyTableDemo() })
- }
- menuItem() {
- action(name:'MVC Demo', closure:{ showMVCDemo() })
- }
- menuItem() {
- action(name:'TableLayout Demo', closure:{ showTableLayoutDemo() })
- }
- }
- menu(text:'Help') {
- menuItem() {
- action(name:'About', closure:{ showAbout() })
- }
- }
- }
- splitPane {
- panel(border:BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), 'titled border')) {
- borderLayout()
- vbox(constraints:NORTH) {
- panel {
- borderLayout()
- label(text:'Name', constraints:WEST, toolTipText:'This is the name field')
- textField(text:'James', constraints:CENTER, toolTipText:'Enter the name into this field')
- }
- panel {
- borderLayout()
- label(text:'Location', constraints:WEST, toolTipText:'This is the location field')
- comboBox(items:['Atlanta', 'London', 'New York'], constraints:CENTER, toolTipText:'Choose the location into this field')
- }
- button(text:'Click Me', actionPerformed:{event -> println("closure fired with event: " + event) })
- }
- scrollPane(constraints:CENTER, border:BorderFactory.createRaisedBevelBorder()) {
- textArea(text:'Some text goes here', toolTipText:'This is a large text area to type in text')
- }
- }
- scrollPane {
- table(model:new MyTableModel())
- }
- }
- }
- frame.show()
- }
-
- void showAbout() {
- // this version doesn't auto-size & position the dialog
- /*
- def dialog = swing.dialog(owner:frame, title:'About GroovySwing') {
- optionPane(message:'Welcome to the wonderful world of GroovySwing')
- }
- */
- def pane = swing.optionPane(message:'Welcome to the wonderful world of GroovySwing')
- def dialog = pane.createDialog(frame, 'About GroovySwing')
- dialog.show()
- }
-
- void showGroovyTableDemo() {
- def demo = new TableDemo()
- demo.run()
- }
-
- void showMVCDemo() {
- def demo = new MvcDemo()
- demo.run()
- }
-
- void showTableLayoutDemo() {
- def demo = new TableLayoutDemo()
- demo.run()
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/swing/TableDemo.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy/swing/TableDemo.groovy b/src/examples/groovy/swing/TableDemo.groovy
deleted file mode 100644
index abc2659..0000000
--- a/src/examples/groovy/swing/TableDemo.groovy
+++ /dev/null
@@ -1,72 +0,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 groovy.swing
-
-import java.awt.BorderLayout
-import javax.swing.BorderFactory
-import groovy.swing.SwingBuilder
-
-/**
- * Demonstrates the use of the Groovy TableModels for viewing tables of any List of objects
- */
-class TableDemo {
-
- // properties
- def frame
- def swing
-
- static void main(args) {
- def demo = new TableDemo()
- demo.run()
- }
-
- void run() {
- swing = new SwingBuilder()
-
- frame = swing.frame(title:'Groovy TableModel Demo', location:[200,200], size:[300,200]) {
- menuBar {
- menu(text:'Help') {
- menuItem() {
- action(name:'About', closure:{ showAbout() })
- }
- }
- }
- panel {
- borderLayout()
- scrollPane(constraints:CENTER) {
- table() {
- def model = [['name':'James', 'location':'London'], ['name':'Bob', 'location':'Atlanta'], ['name':'Geir', 'location':'New York']]
-
- tableModel(list:model) {
- closureColumn(header:'Name', read:{row -> return row.name})
- closureColumn(header:'Location', read:{row -> return row.location})
- }
- }
- }
- }
- }
- frame.show()
- }
-
- void showAbout() {
- def pane = swing.optionPane(message:'This demo shows how GroovySwing can use Groovy closures to create simple table models')
- def dialog = pane.createDialog(frame, 'About GroovySwing')
- dialog.show()
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy/swing/TableLayoutDemo.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy/swing/TableLayoutDemo.groovy b/src/examples/groovy/swing/TableLayoutDemo.groovy
deleted file mode 100644
index df2c223..0000000
--- a/src/examples/groovy/swing/TableLayoutDemo.groovy
+++ /dev/null
@@ -1,76 +0,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 groovy.swing
-
-import java.awt.BorderLayout
-import javax.swing.BorderFactory
-import groovy.swing.SwingBuilder
-
-/**
- * Demonstrates the use of the table layout
- */
-class TableLayoutDemo {
-
- def frame
- def swing
-
- void run() {
- swing = new SwingBuilder()
-
- frame = swing.frame(title:'TableLayout Demo', location:[200,200], size:[300,200]) {
- menuBar {
- menu(text:'Help') {
- menuItem() {
- action(name:'About', closure:{ showAbout() })
- }
- }
- }
- tableLayout {
- tr {
- td {
- label(text:'name')
- }
- td(colfill:true) {
- textField(text:'James')
- }
- }
- tr {
- td {
- label(text:'location')
- }
- td(colfill:true) {
- textField(text:'London')
- }
- }
- tr {
- td(colspan:2, align:'center') {
- button(text:'OK')
- }
- }
- }
- }
- frame.show()
- }
-
- void showAbout() {
- def pane = swing.optionPane(message:'This demo shows how you can use HTML style table layouts with Swing components')
- def dialog = pane.createDialog(frame, 'About TableLayout Demo')
- dialog.show()
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovy2d/paintingByNumbers.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovy2d/paintingByNumbers.groovy b/src/examples/groovy2d/paintingByNumbers.groovy
deleted file mode 100644
index 5a69baf..0000000
--- a/src/examples/groovy2d/paintingByNumbers.groovy
+++ /dev/null
@@ -1,66 +0,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.
- */
-/**
- * Simple patchwork graphics demo
- * @author: Jeremy Rayner, changes by Dierk Koenig
- */
-import javax.swing.WindowConstants as WC
-import groovy.swing.SwingBuilder
-
-def width = 500, height = 400, blockSize = 10
-def g = createGraphics(width, height)
-
-// main loop
-while (true) {
- drawBlock(width, height, blockSize, g)
-}
-
-// random integer
-def rnd(upperBound){
- (int)(Math.random() * upperBound)
-}
-
-// draw a random coloured square within bounds
-def drawBlock(w, h, b, g) {
- def row = rnd(h / b)
- def column = rnd(w / b)
- def colour = new java.awt.Color(rnd(255),rnd(255),rnd(255))
- g.color = colour
- g.fillRect(column * b, row * b, b, b)
-}
-
-// create a new frame and clear screen
-def createGraphics(w, h) {
- def frame = new SwingBuilder().frame(
- title:'Painting by numbers',
- location:[20,20],
- size:[w, h],
- defaultCloseOperation:WC.EXIT_ON_CLOSE
- )
- frame.show()
-
- // obtain graphics context
- def gfx = frame.graphics
-
- // clear screen
- gfx.color = java.awt.Color.BLACK
- gfx.fillRect(0, 0, w, h)
-
- return gfx
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovyShell/ArithmeticShell.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovyShell/ArithmeticShell.groovy b/src/examples/groovyShell/ArithmeticShell.groovy
deleted file mode 100644
index d1a5659..0000000
--- a/src/examples/groovyShell/ArithmeticShell.groovy
+++ /dev/null
@@ -1,157 +0,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.
- */
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.control.MultipleCompilationErrorsException
-import org.codehaus.groovy.control.customizers.ImportCustomizer
-import org.codehaus.groovy.control.customizers.SecureASTCustomizer
-import org.codehaus.groovy.control.messages.ExceptionMessage
-import static org.codehaus.groovy.syntax.Types.*
-import org.codehaus.groovy.ast.stmt.BlockStatement
-import org.codehaus.groovy.ast.stmt.ExpressionStatement
-import org.codehaus.groovy.ast.expr.BinaryExpression
-import org.codehaus.groovy.ast.expr.ConstantExpression
-import org.codehaus.groovy.ast.expr.MethodCallExpression
-import org.codehaus.groovy.ast.expr.StaticMethodCallExpression
-import org.codehaus.groovy.ast.expr.ArgumentListExpression
-import org.codehaus.groovy.ast.expr.PropertyExpression
-import org.codehaus.groovy.ast.expr.UnaryMinusExpression
-import org.codehaus.groovy.ast.expr.UnaryPlusExpression
-import org.codehaus.groovy.ast.expr.PrefixExpression
-import org.codehaus.groovy.ast.expr.PostfixExpression
-import org.codehaus.groovy.ast.expr.TernaryExpression
-import org.codehaus.groovy.ast.expr.ElvisOperatorExpression
-import org.codehaus.groovy.ast.expr.BooleanExpression
-import org.codehaus.groovy.ast.expr.ClassExpression
-
-/**
- * The arithmetic shell is similar to a GroovyShell in that it can evaluate text as
- * code and return a result. It is not a subclass of GroovyShell because it does not widen
- * the contract of GroovyShell, instead it narrows it. Using one of these shells like a
- * GroovyShell would result in many runtime errors.
- *
- * @author Hamlet D'Arcy (hamletdrc@gmail.com)
- * @author Guillaume Laforge
- */
-class ArithmeticShell {
-
- /**
- * Compiles the text into a Groovy object and then executes it, returning the result.
- * @param text
- * the script to evaluate typed as a string
- * @throws SecurityException
- * most likely the script is doing something other than arithmetic
- * @throws IllegalStateException
- * if the script returns something other than a number
- */
- Number evaluate(String text) {
- try {
- final ImportCustomizer imports = new ImportCustomizer().addStaticStars('java.lang.Math') // add static import of java.lang.Math
- final SecureASTCustomizer secure = new SecureASTCustomizer()
- secure.with {
- closuresAllowed = false
- methodDefinitionAllowed = false
-
- importsWhitelist = []
- staticImportsWhitelist = []
- staticStarImportsWhitelist = ['java.lang.Math'] // only java.lang.Math is allowed
-
- tokensWhitelist = [
- PLUS,
- MINUS,
- MULTIPLY,
- DIVIDE,
- MOD,
- POWER,
- PLUS_PLUS,
- MINUS_MINUS,
- COMPARE_EQUAL,
- COMPARE_NOT_EQUAL,
- COMPARE_LESS_THAN,
- COMPARE_LESS_THAN_EQUAL,
- COMPARE_GREATER_THAN,
- COMPARE_GREATER_THAN_EQUAL,
- ].asImmutable()
-
- constantTypesClassesWhiteList = [
- Integer,
- Float,
- Long,
- Double,
- BigDecimal,
- Integer.TYPE,
- Long.TYPE,
- Float.TYPE,
- Double.TYPE
- ].asImmutable()
-
- receiversClassesWhiteList = [
- Math,
- Integer,
- Float,
- Double,
- Long,
- BigDecimal
- ].asImmutable()
-
- statementsWhitelist = [
- BlockStatement,
- ExpressionStatement
- ].asImmutable()
-
- expressionsWhitelist = [
- BinaryExpression,
- ConstantExpression,
- MethodCallExpression,
- StaticMethodCallExpression,
- ArgumentListExpression,
- PropertyExpression,
- UnaryMinusExpression,
- UnaryPlusExpression,
- PrefixExpression,
- PostfixExpression,
- TernaryExpression,
- ElvisOperatorExpression,
- BooleanExpression,
- // ClassExpression needed for processing of MethodCallExpression, PropertyExpression
- // and StaticMethodCallExpression
- ClassExpression
- ].asImmutable()
-
- }
- CompilerConfiguration config = new CompilerConfiguration()
- config.addCompilationCustomizers(imports, secure)
- GroovyClassLoader loader = new GroovyClassLoader(this.class.classLoader, config)
- Class clazz = loader.parseClass(text)
- Script script = (Script) clazz.newInstance();
- Object result = script.run()
- if (!(result instanceof Number)) throw new IllegalStateException("Script returned a non-number: $result");
- return (Number) result
- } catch (SecurityException ex) {
- throw new SecurityException("Could not evaluate script: $text", ex)
- } catch (MultipleCompilationErrorsException mce) {
- //this allows compilation errors to be seen by the user
- mce.errorCollector.errors.each {
- if (it instanceof ExceptionMessage && it.cause instanceof SecurityException) {
- throw it.cause
- }
- }
- throw mce
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovyShell/ArithmeticShellTest.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovyShell/ArithmeticShellTest.groovy b/src/examples/groovyShell/ArithmeticShellTest.groovy
deleted file mode 100644
index 2c9e982..0000000
--- a/src/examples/groovyShell/ArithmeticShellTest.groovy
+++ /dev/null
@@ -1,108 +0,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.
- */
-/**
-* Unit test for ArithmeticShell.
-* Requires JUnit to be in path, just like any other GroovyTestCase.
-*
-* @author Hamlet D'Arcy
-*/
-class ArithmeticShellTest extends GroovyTestCase {
-
- private ArithmeticShell shell
-
- void setUp() {
- shell = new ArithmeticShell()
- }
-
- Number evaluate(String text) {
- shell.evaluate(text)
- }
-
- void testEvaluate_SuccessfulPaths() {
- assert 2.9073548971824276E135 == evaluate("((6L / 2f) - 1) ** 4.5e2")
- assert -6.816387600233341 == evaluate("10 * Math.sin(15/-20)")
- assert 1.0 == evaluate("Math.cos(2*Math.PI)")
- assert 74.17310622494026 == shell.evaluate("80*Math.E**(-(+(11++/40)**2))")
- assert 2147483646 == evaluate("Integer.MAX_VALUE - ++2%2")
- assert 6 == evaluate("++(5)")
- assert 0 == evaluate("5 < 4 ? 1 : 0")
- assert 0 == evaluate("5 != 4 ? 0 : 1")
- assert 0 == evaluate("5 < 4 ?: 0 ")
- }
-
- void testEvaluate_StaticImportOfMath() {
- assert 6.283185307179586 == evaluate("2*PI")
- assert 0.5403023058681398 == evaluate("cos(1)")
- assert 1.0 == evaluate("cos(2*PI)")
- }
-
- void testEvaluate_Failures() {
- shouldFail(SecurityException) {
- evaluate("Double.valueOf(\"5\")")
- }
-
- shouldFail(SecurityException) {
- evaluate("import java.text.DateFormat; 5")
- }
-
- shouldFail(SecurityException) {
- evaluate("import static java.lang.System.*; 6 * out")
- }
-
- shouldFail(SecurityException) {
- evaluate("def x = 5+3;x.toString()")
- }
-
- shouldFail(SecurityException) {
- evaluate("new File();Double.valueOf('5')")
- }
-
- shouldFail(SecurityException) {
- // without statement whitelist set, this causes the arithmetic shell to
- // enter an infinite loop
- evaluate("while (1);")
- }
-
- shouldFail(SecurityException) {
- // without statement whitelist set, security exception is still thrown as it should,
- // but with the error message that closures are not allowed, which may be confusing
- evaluate("for (;;);")
- }
-
- shouldFail(SecurityException) {
- // without statement whitelist set, no exception is thrown
- evaluate("if (1) 12 else 15")
- }
-
- shouldFail(SecurityException) {
- // without expression whitelist set, no exception is thrown
- evaluate("[1,2]; 1")
- }
-
- shouldFail(SecurityException) {
- // without expression whitelist set, no exception is thrown
- evaluate("[1:2]; 1")
- }
-
- shouldFail(SecurityException) {
- // without expression whitelist set, no exception is thrown
- evaluate("new Object(); 1")
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/ed3814a0/src/examples/groovyShell/BlacklistingShell.groovy
----------------------------------------------------------------------
diff --git a/src/examples/groovyShell/BlacklistingShell.groovy b/src/examples/groovyShell/BlacklistingShell.groovy
deleted file mode 100644
index becff49..0000000
--- a/src/examples/groovyShell/BlacklistingShell.groovy
+++ /dev/null
@@ -1,96 +0,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.
- */
-import org.codehaus.groovy.control.CompilerConfiguration
-import org.codehaus.groovy.control.MultipleCompilationErrorsException
-import org.codehaus.groovy.control.customizers.SecureASTCustomizer
-import org.codehaus.groovy.control.messages.ExceptionMessage
-import org.codehaus.groovy.ast.expr.MethodPointerExpression
-
-
-/**
- * The blacklisting shell is similar to a GroovyShell in that it can evaluate text as
- * code and return a result. It is intended as an example of using blacklisting to prevent
- * running methods on a class - in this case, java.lang.System. Please note that in creating
- * any secure environment, there is no substitution for using a SecurityManager.
- *
- * Amoung the many different calls this class prevents are:
- * System.exit(0)
- * Eval.me("System.exit(0)")
- * evaluate("System.exit(0)")
- * (new GroovyShell()).evaluate("System.exit(0)")
- * Class.forName("java.lang.System").exit(0)
- * System.&exit.call(0)
- * System.getMetaClass().invokeMethod("exit",0)
- * def s = System; s.exit(0)
- * Script t = this; t.evaluate("System.exit(0)")
- *
- * The restrictions required, however, also prevent the following code from working:
- * println "test"
- * def s = "test" ; s.count("t")
- *
- * @author Jim Driscoll (jamesgdriscoll@gmail.com)
- */
-class BlacklistingShell {
-
- /**
- * Compiles the text into a Groovy object and then executes it, returning the result.
- * Prevents calling any method on java.lang.System within the VM
- * @param text
- * the script to evaluate typed as a string
- * @throws SecurityException
- * most likely the script is doing something other than arithmetic
- * @throws IllegalStateException
- * if the script returns something other than a number
- */
- def evaluate(String text) {
- try {
- final SecureASTCustomizer secure = new SecureASTCustomizer()
- secure.with {
-
- receiversClassesBlackList = [
- Object,
- Script,
- GroovyShell,
- Eval,
- System,
- ].asImmutable()
-
- expressionsBlacklist = [MethodPointerExpression].asImmutable()
-
- }
- CompilerConfiguration config = new CompilerConfiguration()
- config.addCompilationCustomizers(secure)
- GroovyClassLoader loader = new GroovyClassLoader(this.class.classLoader, config)
- Class clazz = loader.parseClass(text)
- Script script = (Script) clazz.newInstance();
- Object result = script.run()
- return result
- } catch (SecurityException ex) {
- throw new SecurityException("Could not evaluate script: $text", ex)
- } catch (MultipleCompilationErrorsException mce) {
- //this allows compilation errors to be seen by the user
- mce.errorCollector.errors.each {
- if (it instanceof ExceptionMessage && it.cause instanceof SecurityException) {
- throw it.cause
- }
- }
- throw mce
- }
- }
-}
\ No newline at end of file