Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>As of Groovy-Eclipse 2.5.2, there is now command line support for testing DSLD descriptors. Because DSLD support us intertwined with Eclipse API, it is not possible to simply run unit tests against them. Rather, it is necessary to load up the Eclipse workbench and process the DSLD files from within the workbench in order to evaluate them.</p> <h3>Setting up</h3> <p>You can only evaluate DSLDs against an existing Eclipse project. So, you need to create an eclipse project inside an existing workspace.</p> <ol> <li>Start Eclipse</li> <li>Create a groovy project</li> <li>Create some Groovy classes</li> <li>You can add your DSLDs directly to this project, or you can add them later when you perform the type checking.</li> <li>Add some type annotations to assert the static types of certain expressions. Eg- <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> def name = "myName" name // TYPE:java.lang.String [name] // TYPE:java.util.List<java.lang.String> [name:1] // TYPE:java.util.Map<java.lang.String,java.lang.Integer> </pre></td></tr></table></li> </ol> <p>Shut down Eclipse and you are ready to run static type checking.</p> <h3>Running static type checking</h3> <p>The command looks like this:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> eclipse -application org.codehause.groovy.eclipse.staticCheck [-data /path/to/eclipse/workspace] \ [--help] [-h] [--extra_dslds <FILES>] [--assertions_only] [--excludes <PATH>] \ [--includes <PATH>] <PROJECT_NAME> </pre></td></tr></table> <p>Here is a description of the arguments:</p> <table class="confluenceTable"><tbody> <tr> <td class="confluenceTd"><p>--help OR -h</p></td> <td class="confluenceTd"><p> Prints a help message and exits.</p></td> </tr> <tr> <td class="confluenceTd"><p>--extra_dslds</p></td> <td class="confluenceTd"><p> list of extra dsld files to be included in this check. Use '|' as a file separator.</p></td> </tr> <tr> <td class="confluenceTd"><p>--assertions_only</p></td> <td class="confluenceTd"><p> Don't report unknown types. Only look for type assertions</p></td> </tr> <tr> <td class="confluenceTd"><p>--excludes</p></td> <td class="confluenceTd"><p> Project-relative exclusion filters.</p></td> </tr> <tr> <td class="confluenceTd"><p>--includes</p></td> <td class="confluenceTd"><p> Project-relative inclusion filters.</p></td> </tr> <tr> <td class="confluenceTd"><p><PROJECT_NAME></p></td> <td class="confluenceTd"><p> Name of a project to type check. Must be already in the workspace.</p></td> </tr> </tbody></table> <p>The exclusion and inclusion filters use the syntax from <a href="http://ant.apache.org/manual/Types/fileset.html">ant filesets</a>. Individual filters can be concatenated using '|'.</p> <p>For example:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>--includes "**" --excludes "src/test/java/**/*Test.groovy|src/test/groovy/**/*Test.groovy"</pre></td></tr></table> <p>includes all files, but excludes all <code>*Test.groovy</code> files in <code>test/java</code> and <code>test/groovy</code>.</p> <h3>The results</h3> <p>Let's assume that there is a Groovy project in an Eclipse workspace with a single file:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=/MyProj/src/MyScript.groovy" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9L015UHJvai9zcmMvTXlTY3JpcHQuZ3Jvb3Z5fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> happiness // TYPE:java.lang.Integer happiness // TYPE:java.lang.String somethingUndefined </pre></td></tr></table> <p>And this DSLD file exists outside of the workspace:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="title=/tmp/myapp.dsld" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9L3RtcC9teWFwcC5kc2xkfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> currentType().accept { property name:"happiness", type:Integer } </pre></td></tr></table> <p>Then executing this command:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> eclipse -application org.codehause.groovy.eclipse.staticCheck --extra_dslds /tmp/myapp.dsld MyProj </pre></td></tr></table> <p>Will produce the following output:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> Adding file:/tmp/other.dsld Checking: /MyProj/src/MyScript.groovy Line 2: Invalid inferred type. happiness Expected: java.lang.String Actual: java.lang.Integer Line 3: unknown type: somethingUndefined Removing file:/tmp/other.dsld </pre></td></tr></table> <p>If you want to suppress all of the <code>unknown type</code> warnings, then include the <code>--assertions_only</code> parameter on the command line.</p> <p>You may also see some error messages sent to syserr, like this:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.jdt.internal.ui.InitializeAfterLoadJob </pre></td></tr></table> <p>These messages can be safely ignored. These messages occur since Eclipse is being shut down early enough before all initialization jobs are complete. We'll be fixing this in future versions.</p> <h3>More to come</h3> <p>This is just a first pass at static checking. We are looking for feedback as to the best way to display failed assertions, or if there is anything else that can be improved. If there is significant interest, we can do the work to make it easy to create JUnit (or Spock!) tests for DSLDs, but we need to hear the feedback first.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced