├── .gitignore ├── LICENSE ├── README.MD ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── samples ├── build.gradle ├── hello-world │ ├── README.MD │ ├── build.gradle │ ├── hello │ │ └── Main.pony │ └── test │ │ └── pony-test.pony ├── pony-basic │ ├── README.md │ ├── basic │ │ └── Main.pony │ ├── build.gradle │ ├── bundle.json │ └── test │ │ ├── main.pony │ │ └── message_test.pony ├── pony-configured │ ├── build.gradle │ ├── bundle.json │ └── pony-configured │ │ └── Main.pony ├── pony-multi-modules │ ├── build.gradle │ ├── bundle.json │ ├── local-deps │ │ ├── mod1 │ │ │ └── mod1 │ │ │ │ └── Mod1.pony │ │ └── not_used │ │ │ └── text.txt │ └── main │ │ └── Main.pony └── settings.gradle └── src ├── main ├── groovy │ └── com │ │ └── athaydes │ │ └── gradle │ │ └── pony │ │ ├── PonyConfig.groovy │ │ ├── PonyDependency.groovy │ │ ├── PonyPackageFileParser.groovy │ │ └── PonyPlugin.groovy └── resources │ └── META-INF │ └── gradle-plugins │ └── com.athaydes.pony.properties └── test └── groovy └── com └── athaydes └── gradle └── pony └── PonyPackageFileParserSpec.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea/ 3 | 4 | ## File-based project format: 5 | *.iws 6 | *.iml 7 | *.ipr 8 | 9 | ## Plugin-specific files: 10 | 11 | # IntelliJ 12 | /out/ 13 | 14 | # mpeltonen/sbt-idea plugin 15 | .idea_modules/ 16 | 17 | # JIRA plugin 18 | atlassian-ide-plugin.xml 19 | 20 | # Crashlytics plugin (for Android Studio and IntelliJ) 21 | com_crashlytics_export_strings.xml 22 | crashlytics.properties 23 | crashlytics-build.properties 24 | fabric.properties 25 | ### Gradle template 26 | .gradle 27 | build/ 28 | 29 | # Ignore Gradle GUI config 30 | gradle-app.setting 31 | 32 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 33 | !gradle-wrapper.jar 34 | 35 | # Cache of project 36 | .gradletasknamecache 37 | 38 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 39 | # gradle/wrapper/gradle-wrapper.properties 40 | 41 | ext-libs/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Pony Gradle Plugin 2 | 3 | 🐴 A Gradle Plugin to build [Pony](http://www.ponylang.org/) projects. 4 | 5 | ## Features 6 | 7 | * compile Pony sources. 8 | * resolve dependencies using `bundle.json` - compatible with [pony-stable](https://github.com/jemc/pony-stable). 9 | * resolve transitive dependencies (if the dependencies have a `bundle.json` file). 10 | 11 | ## Getting started 12 | 13 | Run the following commands to create a Pony project with Gradle support: 14 | 15 | * create and enter your new project directory. 16 | 17 | ``` 18 | mkdir my-project && cd my-project 19 | ``` 20 | 21 | * create the Gradle build file. 22 | 23 | ``` 24 | echo ' 25 | plugins { 26 | id "com.athaydes.pony" version "0.2.0" 27 | } 28 | ' > build.gradle 29 | ``` 30 | 31 | * create a Pony package with a `Main` actor. 32 | 33 | ``` 34 | mkdir main 35 | echo ' 36 | actor Main 37 | new create(env: Env) => 38 | env.out.print("Hello world!") 39 | ' > main/main.pony 40 | ``` 41 | 42 | * compile with Gradle. 43 | 44 | ``` 45 | gradle compile 46 | ``` 47 | 48 | * run the generated binary. 49 | 50 | ``` 51 | build/main 52 | ``` 53 | 54 | The following sections explain how this all works in detail. 55 | 56 | ## Build files 57 | 58 | To enable Gradle support, a basic `build.gradle` file must be supplied to apply this plugin. 59 | Dependencies are declared separately (to be compatible with `pony-stable`) in the `bundle.json` file. 60 | 61 | ### `build.gradle` - the Gradle build file. 62 | 63 | Simplest possible example without any configuration (see below for defaults): 64 | 65 | ```groovy 66 | plugins { 67 | id "com.athaydes.pony" version "0.2.0" 68 | } 69 | ``` 70 | 71 | The above is all you need, but you may configure the build using the `pony` block: 72 | 73 | ```groovy 74 | plugins { 75 | id "com.athaydes.pony" version "0.2.0" 76 | } 77 | 78 | pony { 79 | packageName = 'hello' 80 | docs = true 81 | } 82 | ``` 83 | 84 | ### Configuration options 85 | 86 | | Option | Type | Default | Description | 87 | |--------|------|---------|-------------| 88 | |packageName|String|`main`|name of the package to compile.| 89 | |testPackage|String|`test`|name of the test package to compile and run.| 90 | |docs|Boolean|false|whether to generate docs.| 91 | |debug|Boolean|false|Don't optimise the output.| 92 | |library|Boolean|false|Generate a C-API compatible static library.| 93 | |strip|Boolean|false|Strip debug info.| 94 | |runtimebc|Boolean|false|Compile with the LLVM bitcode file for the runtime.| 95 | |pic|Boolean|false|Compile using position independent code.| 96 | |compileOptions|List|`[]`|Extra compiler options to use when compiling.| 97 | |testOptions|List|`[]`|Extra compiler options to use when compiling and running tests.| 98 | 99 | To get started, see the [Hello World](samples/hello-world) sample. 100 | 101 | See the [pony-configured](samples/pony-configured) sample for a build file that uses all options. 102 | 103 | ### `bundle.json` - pony-stable dependencies file. 104 | 105 | Example: 106 | 107 | ```json 108 | { 109 | "name": "my-project", 110 | "version": "2.3.4", 111 | "deps": [ 112 | { "type": "github", "repo": "jemc/pony-inspect", "version": "1.0.1" }, 113 | { "type": "github", "repo": "other/dep" }, 114 | { "type": "local", "local-path": "../my-other-dep" } 115 | ] 116 | } 117 | ``` 118 | 119 | Everything in the json file is optional. Unrecognized fields are ignored. 120 | 121 | ## Dependency types 122 | 123 | The currently supported dependency types are the following: 124 | 125 | ### GitHub 126 | 127 | > GitHub dependencies are downloaded using the GitHub API, so other Git repositories are not 128 | currently supported. 129 | 130 | GitHub dependencies have the following fields: 131 | 132 | * `type` (mandatory): must be `github`. 133 | * `repo` (mandatory): `/`. 134 | * `version` (optional): tag/branch/commit 135 | 136 | If `version` is not given, the latest tag will be used, or if there's no tags, the main branch 137 | (usually `master`). 138 | 139 | See the [pony-basic](samples/pony-basic) sample for an example. 140 | 141 | ### Local 142 | 143 | Local dependencies are simple Pony projects that are located in the local file system. 144 | 145 | They are declared using the following fields: 146 | 147 | * `type` (mandatory): must be `local`. 148 | * `local-path` (mandatory): the path, relative to the root of this project, to the dependency project. 149 | 150 | See the [pony-multi-modules](samples/pony-multi-modules) sample for an example. 151 | 152 | ## Tasks 153 | 154 | The following tasks are added by this plugin: 155 | 156 | * `cleanPony`: deletes all artifacts created by previous builds. 157 | * `resolvePonyDependencies`: resolves the project dependencies. 158 | * `unpackPonyDependencies`: unpacks the dependencies archives. 159 | * `compilePony`: compiles Pony sources and dependencies. 160 | * `testPony`: compiles Pony sources and tests, then runs the test package. 161 | 162 | Normally, all you need to do to build your project is run `compilePony`, or just `compile`: 163 | 164 | ``` 165 | gradle compile 166 | ``` 167 | 168 | The other tasks will be run automatically if necessary. 169 | 170 | You can run only the task you want as well, for example: 171 | 172 | ``` 173 | gradle resolve 174 | ``` 175 | 176 | The above will resolve all dependencies. If any dependencies need to be downloaded, they will be, 177 | so that transitive dependencies can be also resolved. 178 | 179 | To compile both sources and test sources, then run tests, simply run the `test` task: 180 | 181 | ``` 182 | gradle test 183 | ``` 184 | 185 | ## Build layout 186 | 187 | Everything the Pony plugin creates goes into Gradle's `project.buildDir`, which is `build` by default. 188 | 189 | Sources should go into the `packageName` directory, as in any Pony project. 190 | 191 | For a project called `pony-basic`, the layout would look something like this **after** built: 192 | 193 | ``` 194 | ├── ext-libs # external libraries sources 195 | │   ├── unpacked # unpacked libraries 196 | │   │   ├── jemc-pony-inspect-03a65d4 197 | │   │   │   ... 198 | │   │   ├── jemc-pony-sodium-d293cdb 199 | │   │   │   ... 200 | │   │   └── jemc-pony-zmq-6e9157e 201 | │   │   ... 202 | │   └── zips # packaged libraries (not necessary to compile) 203 | │   ├── jemc-pony-inspect.zip 204 | │   ├── jemc-pony-sodium.zip 205 | │   └── jemc-pony-zmq.zip 206 | ├── build # generated by the Pony plugin 207 | │   ├── pony-basic # generated by ponyc 208 | │   └── pony-basic.dSYM 209 | │   └── Contents 210 | │   ├── Info.plist 211 | │   └── Resources 212 | │   └── DWARF 213 | │   └── pony-basic 214 | ├── build.gradle # Gradle build file 215 | ├── bundle.json # dependencies file 216 | └── pony-basic # source directory 217 | └── Main.pony 218 | 219 | 20 directories, 79 files 220 | ``` 221 | 222 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | maven { 5 | url "https://plugins.gradle.org/m2/" 6 | } 7 | } 8 | dependencies { 9 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6" 10 | classpath "com.gradle.publish:plugin-publish-plugin:0.9.1" 11 | } 12 | } 13 | 14 | apply plugin: "com.gradle.plugin-publish" 15 | apply plugin: 'groovy' 16 | apply plugin: 'idea' 17 | apply plugin: 'maven' 18 | apply plugin: 'maven-publish' 19 | 20 | group 'com.athaydes.pony.gradle' 21 | version '0.2.0' 22 | description 'A Gradle Plugin for the Pony programming language' 23 | 24 | repositories { 25 | jcenter() 26 | } 27 | 28 | sourceCompatibility = 1.8 29 | 30 | dependencies { 31 | compile gradleApi() 32 | compile localGroovy() 33 | 34 | testCompile "org.spockframework:spock-core:1.0-groovy-2.4", { 35 | transitive = false 36 | } 37 | } 38 | 39 | 40 | task sourcesJar(type: Jar, dependsOn: classes) { 41 | from sourceSets.main.allSource 42 | classifier "sources" 43 | extension "jar" 44 | } 45 | 46 | task javadocJar( type: Jar ) { 47 | classifier "javadoc" 48 | from javadoc 49 | } 50 | 51 | /* Publishing config */ 52 | 53 | artifacts { 54 | archives javadocJar, sourcesJar 55 | } 56 | 57 | // add all the info required by Maven Central to the pom 58 | configure( install.repositories.mavenInstaller ) { 59 | //repository(url: "file://$buildDir") 60 | pom.project { 61 | inceptionYear '2016' 62 | name project.name 63 | packaging 'jar' 64 | description project.description 65 | 66 | url 'https://github.com/renatoathaydes/pony-gradle-plugin' 67 | 68 | scm { 69 | connection 'git@github.com:renatoathaydes/pony-gradle-plugin.git' 70 | developerConnection 'git@github.com:renatoathaydes/pony-gradle-plugin.git' 71 | url 'https://github.com/renatoathaydes/pony-gradle-plugin' 72 | } 73 | 74 | licenses { 75 | license { 76 | name 'The Apache License, Version 2.0' 77 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 78 | } 79 | } 80 | 81 | developers { 82 | developer { 83 | id 'renatoathaydes' 84 | name 'Renato Athaydes' 85 | email 'renato@athaydes.com' 86 | } 87 | } 88 | } 89 | } 90 | 91 | pluginBundle { 92 | website = 'https://github.com/renatoathaydes/pony-gradle-plugin' 93 | vcsUrl = 'https://github.com/renatoathaydes/pony-gradle-plugin' 94 | 95 | //noinspection GroovyAssignabilityCheck 96 | plugins { 97 | ponyPlugin { 98 | id = 'com.athaydes.pony' 99 | displayName = 'Pony Gradle Plugin' 100 | description = project.description 101 | version = project.version 102 | tags = [ 'language', 'pony', 'gradle' ] 103 | } 104 | } 105 | } 106 | 107 | apply plugin: 'com.jfrog.bintray' 108 | 109 | bintray { 110 | user = project.hasProperty("bintrayUserName") ? bintrayUserName : null 111 | key = project.hasProperty("bintrayApiKey") ? bintrayApiKey : null 112 | configurations = [ 'archives' ] 113 | publish = true 114 | pkg { 115 | repo = 'maven' 116 | name = 'pony-gradle-plugin' 117 | licenses = ['Apache-2.0'] 118 | desc = project.description 119 | vcsUrl = 'https://github.com/renatoathaydes/pony-gradle-plugin.git' 120 | websiteUrl = 'https://github.com/renatoathaydes/pony-gradle-plugin' 121 | issueTrackerUrl = 'https://github.com/renatoathaydes/pony-gradle-plugin/issues' 122 | labels = [ 'language', 'pony', 'gradle' ] 123 | publicDownloadNumbers = true 124 | 125 | //noinspection GroovyAssignabilityCheck 126 | version { 127 | name = project.version 128 | vcsTag = project.version 129 | gpg { 130 | sign = true 131 | } 132 | mavenCentralSync { 133 | sync = true 134 | user = ossrhUsername 135 | password = ossrhPassword 136 | close = '1' // '0' to NOT close 137 | } 138 | } 139 | } 140 | 141 | } 142 | 143 | bintrayUpload.dependsOn build, sourcesJar 144 | publishPlugins.dependsOn build, sourcesJar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/renatoathaydes/pony-gradle-plugin/eb277bb65884e5b22264dd1c3b273fa5c66a95ea/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jun 11 21:45:27 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /samples/build.gradle: -------------------------------------------------------------------------------- 1 | subprojects { 2 | buildscript { 3 | repositories { 4 | flatDir { 5 | dirs rootProject.file( '../build/libs' ) 6 | } 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath "com.athaydes.gradle.pony:pony-gradle-plugin:0.2.0" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/hello-world/README.MD: -------------------------------------------------------------------------------- 1 | ## Hello World Sample 2 | 3 | This sample contains only three files: 4 | 5 | * build.gradle 6 | * hello/Main.pony 7 | * test/pony-test.pony 8 | 9 | ### Building 10 | 11 | ``` 12 | ../../gradlew compile 13 | ``` 14 | 15 | ### Running 16 | 17 | ``` 18 | build/hello 19 | ``` 20 | 21 | ### Testing 22 | 23 | ``` 24 | ../../gradlew test 25 | ``` 26 | 27 | ### Clean up 28 | 29 | Delete all built resources, but not downloaded dependencies in `ext-libs`. 30 | 31 | ``` 32 | ../../gradlew clean 33 | ``` 34 | -------------------------------------------------------------------------------- /samples/hello-world/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.athaydes.pony' 2 | 3 | pony { 4 | packageName = 'hello' 5 | } 6 | -------------------------------------------------------------------------------- /samples/hello-world/hello/Main.pony: -------------------------------------------------------------------------------- 1 | actor Main 2 | new create(env: Env) => 3 | env.out.print(Hello()) 4 | 5 | class Hello 6 | fun apply(): String => "Hello world" 7 | -------------------------------------------------------------------------------- /samples/hello-world/test/pony-test.pony: -------------------------------------------------------------------------------- 1 | use "ponytest" 2 | use "../hello" 3 | 4 | actor Main is TestList 5 | new create(env: Env) => 6 | PonyTest(env, this) 7 | 8 | new make() => 9 | None 10 | 11 | fun tag tests(test: PonyTest) => 12 | test(_TestHello) 13 | 14 | class iso _TestHello is UnitTest 15 | fun name(): String => "Hello world in Pony is great" 16 | 17 | fun apply(h: TestHelper) => 18 | h.assert_eq[String](Hello(), "Hello world") 19 | -------------------------------------------------------------------------------- /samples/pony-basic/README.md: -------------------------------------------------------------------------------- 1 | ## Pony Basic Sample 2 | 3 | This basic sample has a single dependency ("jemc/pony-zmq", see [bundle.json](bundle.json)), 4 | a simple package called `basic` and a test package called `test`. 5 | 6 | ### Building 7 | 8 | ``` 9 | ../../gradlew compile 10 | ``` 11 | 12 | ### Running 13 | 14 | ``` 15 | build/basic 16 | ``` 17 | 18 | ### Testing 19 | 20 | ``` 21 | ../../gradlew test 22 | ``` 23 | 24 | ### Clean up 25 | 26 | Delete all built resources, but not downloaded dependencies in `ext-libs`. 27 | 28 | ``` 29 | ../../gradlew clean 30 | ``` -------------------------------------------------------------------------------- /samples/pony-basic/basic/Main.pony: -------------------------------------------------------------------------------- 1 | use zmq = "zmq" 2 | 3 | actor Main 4 | new create(env: Env) => 5 | env.out.print("Creating ZMQ Message") 6 | let messenger = Messenger 7 | let msg = messenger.create_message("Message in a bottle") 8 | env.out.print("Ready to send... " + msg.string()) 9 | 10 | class Messenger 11 | fun create_message(msg: String): zmq.Message => 12 | recover zmq.Message.>push(msg) end -------------------------------------------------------------------------------- /samples/pony-basic/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.athaydes.pony' 2 | 3 | pony { 4 | packageName = 'basic' 5 | } 6 | -------------------------------------------------------------------------------- /samples/pony-basic/bundle.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": [ 3 | { "type": "github", "repo": "jemc/pony-zmq", "version": "1757f34" } 4 | ] 5 | } -------------------------------------------------------------------------------- /samples/pony-basic/test/main.pony: -------------------------------------------------------------------------------- 1 | use "ponytest" 2 | 3 | actor Main is TestList 4 | new create(env: Env) => PonyTest(env, this) 5 | new make() => None 6 | 7 | fun tag tests(test: PonyTest) => 8 | test(MessageTest) -------------------------------------------------------------------------------- /samples/pony-basic/test/message_test.pony: -------------------------------------------------------------------------------- 1 | use "ponytest" 2 | use zmq = "zmq" 3 | use "../basic" // our basic package 4 | 5 | class MessageTest is UnitTest 6 | new iso create() => None 7 | 8 | fun name(): String => "zmq.Message" 9 | 10 | fun apply(h: TestHelper) => 11 | let messenger = Messenger 12 | h.assert_eq[zmq.Message]( 13 | recover zmq.Message.>push("foo") end, 14 | messenger.create_message("foo") 15 | ) 16 | -------------------------------------------------------------------------------- /samples/pony-configured/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.athaydes.pony' 2 | 3 | pony { 4 | packageName = 'pony-configured' 5 | debug = true 6 | docs = true 7 | strip = true 8 | //runtimebc = true 9 | pic = true 10 | //compileOptions += ['--pass', 'asm'] 11 | } 12 | -------------------------------------------------------------------------------- /samples/pony-configured/bundle.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pony-configured", 3 | "version": "1.0.0", 4 | "deps": [ 5 | 6 | ] 7 | } -------------------------------------------------------------------------------- /samples/pony-configured/pony-configured/Main.pony: -------------------------------------------------------------------------------- 1 | actor Main 2 | "The main actor of pony-configured" 3 | 4 | new create(env: Env) => 5 | "Say hello" 6 | env.out.print("Hello, configured Pony!") 7 | -------------------------------------------------------------------------------- /samples/pony-multi-modules/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.athaydes.pony' 2 | -------------------------------------------------------------------------------- /samples/pony-multi-modules/bundle.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": [ 3 | { "type": "local", "local-path": "local-deps/mod1" } 4 | ] 5 | } -------------------------------------------------------------------------------- /samples/pony-multi-modules/local-deps/mod1/mod1/Mod1.pony: -------------------------------------------------------------------------------- 1 | class Mod1 2 | let name: String 3 | 4 | new create(name': String) => 5 | name = "-- " + name' + " --" 6 | -------------------------------------------------------------------------------- /samples/pony-multi-modules/local-deps/not_used/text.txt: -------------------------------------------------------------------------------- 1 | Not used, here to verify this is not copied into a zip file. -------------------------------------------------------------------------------- /samples/pony-multi-modules/main/Main.pony: -------------------------------------------------------------------------------- 1 | use "mod1" 2 | 3 | actor Main 4 | new create(env: Env) => 5 | let mod1Name = Mod1("module 1").name 6 | env.out.print("Hello, " + mod1Name) 7 | 8 | -------------------------------------------------------------------------------- /samples/settings.gradle: -------------------------------------------------------------------------------- 1 | include 'hello-world', 'pony-basic', 'pony-configured', 'pony-multi-modules' -------------------------------------------------------------------------------- /src/main/groovy/com/athaydes/gradle/pony/PonyConfig.groovy: -------------------------------------------------------------------------------- 1 | package com.athaydes.gradle.pony 2 | 3 | /** 4 | * The pony configuration block. 5 | */ 6 | class PonyConfig { 7 | 8 | String packageName = 'main' 9 | String testPackage = 'test' 10 | boolean debug = false 11 | boolean docs = false 12 | boolean library = false 13 | boolean strip = false 14 | boolean runtimebc = false 15 | boolean pic = false 16 | List compileOptions = [ ] 17 | List testOptions = [ ] 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/groovy/com/athaydes/gradle/pony/PonyDependency.groovy: -------------------------------------------------------------------------------- 1 | package com.athaydes.gradle.pony 2 | 3 | import groovy.json.JsonSlurper 4 | import groovy.transform.CompileStatic 5 | import groovy.transform.Immutable 6 | import org.gradle.api.GradleException 7 | import org.gradle.api.Nullable 8 | import org.gradle.api.Project 9 | import org.gradle.api.logging.Logger 10 | import org.gradle.api.logging.Logging 11 | 12 | import java.nio.file.Path 13 | 14 | @CompileStatic 15 | interface PonyDependency { 16 | Path resolvedPath() 17 | } 18 | 19 | @Immutable( knownImmutableClasses = [ Project ] ) 20 | class GitHubPonyDependency implements PonyDependency { 21 | 22 | static final Logger logger = Logging.getLogger( GitHubPonyDependency ) 23 | 24 | Project project 25 | String repo 26 | @Nullable 27 | String version 28 | 29 | static final gitHubHost = "https://api.github.com" 30 | 31 | @Override 32 | Path resolvedPath() { 33 | def tags = new JsonSlurper().parseText( 34 | URI.create( "$gitHubHost/repos/$repo/tags" ) 35 | .toURL().text ) as List 36 | 37 | URL zipBallUrl = resolveZipUrl( tags ) 38 | 39 | def repoZip = new File( ResolveDependenciesTask.outputDir( project ), zipName( repo ) ) 40 | 41 | // ensure the repository does not exist 42 | project.delete( repoZip ) 43 | 44 | zipBallUrl.withInputStream { InputStream ins -> 45 | repoZip.withOutputStream { out -> 46 | out.write( ins.bytes ) 47 | } 48 | } 49 | 50 | logger.info( "Downloaded ${repoZip.length()} bytes to ${repoZip.name}" ) 51 | 52 | return repoZip.toPath() 53 | } 54 | 55 | private URL resolveZipUrl( List tags ) { 56 | def actualTags = tags.findAll { it instanceof Map } 57 | 58 | logger.info( "GitHub repo $repo has ${tags.size()} tags." ) 59 | 60 | if ( actualTags.empty && !version ) { 61 | logger.info "Downloading main branch of $repo because no version was specified and no tags exist." 62 | return URI.create( "$gitHubHost/repos/$repo/zipball" ).toURL() 63 | } 64 | 65 | def actualVersion = version ? actualTags.find { Map tag -> tag.name == version } : null 66 | 67 | if ( actualVersion ) { 68 | logger.info "Downloading tag for $repo matching required version: $version" 69 | } else if ( !version && !actualTags.empty ) { 70 | logger.info "Downloading repository latest tag ${actualTags.first()} (no version was specified)" 71 | } else { // here, there must be a version specified 72 | logger.info "Trying to download branch $version of $repo (no tag matching the required version exists)" 73 | return URI.create( "$gitHubHost/repos/$repo/zipball/$version" ).toURL() 74 | } 75 | 76 | def tag = actualVersion ?: actualTags.first() 77 | 78 | return URI.create( tag[ "zipball_url" ].toString() ).toURL() 79 | } 80 | 81 | static String zipName( String repo ) { 82 | repo.replace( '/', '-' ).replace( '\\', '-' ) + '.zip' 83 | } 84 | 85 | } 86 | 87 | @Immutable( knownImmutableClasses = [ Project ] ) 88 | class LocalDependency implements PonyDependency { 89 | 90 | static final Logger logger = Logging.getLogger( LocalDependency ) 91 | 92 | Project project 93 | String dependencyPath 94 | 95 | @Override 96 | Path resolvedPath() { 97 | logger.debug( "Resolving local dependency: {}", dependencyPath ) 98 | 99 | def dep = project.file( dependencyPath ) 100 | if ( !dep.directory ) { 101 | throw new GradleException( "Cannot resolve local dependency: $dependencyPath (not a directory)" ) 102 | } 103 | 104 | def destinationZip = new File( ResolveDependenciesTask.outputDir( project ), dep.name + '.zip' ) 105 | 106 | logger.info( "Zipping local dependency to {}", destinationZip ) 107 | 108 | project.ant.zip( destfile: destinationZip.absolutePath ) { 109 | zipfileset( dir: dep.absolutePath, prefix: "local-${dep.name}" ) 110 | } 111 | 112 | return destinationZip.toPath() 113 | } 114 | } -------------------------------------------------------------------------------- /src/main/groovy/com/athaydes/gradle/pony/PonyPackageFileParser.groovy: -------------------------------------------------------------------------------- 1 | package com.athaydes.gradle.pony 2 | 3 | import groovy.json.JsonSlurper 4 | import groovy.transform.CompileStatic 5 | import org.gradle.api.GradleException 6 | import org.gradle.api.Project 7 | import org.gradle.api.logging.Logger 8 | import org.gradle.api.logging.Logging 9 | 10 | @CompileStatic 11 | class PonyPackageFileParser { 12 | 13 | static final Logger logger = Logging.getLogger( PonyPackageFileParser ) 14 | 15 | final Project project 16 | 17 | PonyPackageFileParser( Project project ) { 18 | this.project = project 19 | } 20 | 21 | PonyPackage parse( String packageFile ) { 22 | def json = new JsonSlurper().parseText( packageFile ) 23 | 24 | String name = json[ "name" ] ?: '' 25 | String version = json[ "version" ] ?: '0' 26 | def deps = ( json[ "deps" ] ?: [ ] ) as List 27 | 28 | logger.info( "Parsing ${deps.size()} dependencies of package $name - $version" ) 29 | 30 | List dependencies = [ ] 31 | 32 | try { 33 | dependencies = deps.collect { parseAnyDep( it ) } 34 | } catch ( ClassCastException e ) { 35 | throw new GradleException( "Dependencies of package $name are invalid - " + 36 | "${e.message ?: ''}", e ) 37 | } 38 | 39 | return new PonyPackage( name, version, dependencies ) 40 | } 41 | 42 | PonyDependency parseAnyDep( any ) { 43 | switch ( any ) { 44 | case ( Map ): return parseMapDep( any as Map ) 45 | default: 46 | throw new GradleException( "Invalid type for dependency (expected Map): $any" ) 47 | } 48 | } 49 | 50 | PonyDependency parseMapDep( Map map ) { 51 | def type = map[ "type" ] 52 | 53 | // TODO add other types of dependencies 54 | switch ( type ) { 55 | case "github": return parseGitHubDep( map ) 56 | case "local": return parseLocalDep( map ) 57 | case null: throw new GradleException( "Must provide dependency type for '$map'" ) 58 | default: 59 | throw new GradleException( "Unrecognized dependency type: $type" ) 60 | } 61 | } 62 | 63 | PonyDependency parseGitHubDep( Map map ) { 64 | def repo = map[ "repo" ] as String 65 | def version = map[ "version" ] as String 66 | 67 | return new GitHubPonyDependency( project, repo, version ) 68 | } 69 | 70 | PonyDependency parseLocalDep( Map map ) { 71 | def path = map[ "local-path" ] as String 72 | 73 | return new LocalDependency( project, path ) 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/groovy/com/athaydes/gradle/pony/PonyPlugin.groovy: -------------------------------------------------------------------------------- 1 | package com.athaydes.gradle.pony 2 | 3 | import groovy.transform.CompileDynamic 4 | import groovy.transform.CompileStatic 5 | import groovy.transform.Immutable 6 | import org.gradle.api.DefaultTask 7 | import org.gradle.api.GradleException 8 | import org.gradle.api.Nullable 9 | import org.gradle.api.Plugin 10 | import org.gradle.api.Project 11 | import org.gradle.api.tasks.Delete 12 | import org.gradle.api.tasks.InputDirectory 13 | import org.gradle.api.tasks.InputFile 14 | import org.gradle.api.tasks.Optional 15 | import org.gradle.api.tasks.OutputDirectory 16 | import org.gradle.api.tasks.TaskAction 17 | 18 | import java.nio.file.Path 19 | import java.nio.file.Paths 20 | import java.util.zip.ZipEntry 21 | import java.util.zip.ZipFile 22 | 23 | /** 24 | * Pony Gradle plugin. 25 | */ 26 | @CompileStatic 27 | class PonyPlugin implements Plugin { 28 | 29 | @Override 30 | void apply( Project project ) { 31 | project.extensions.create( 'pony', PonyConfig ) 32 | project.tasks.create( ResolveDependenciesTask.NAME, ResolveDependenciesTask ) 33 | project.tasks.create( UnpackArchivesTask.NAME, UnpackArchivesTask ) 34 | project.tasks.create( CleanTask.NAME, CleanTask ) 35 | project.tasks.create( CompilePonyTask.NAME, CompilePonyTask ) 36 | project.tasks.create( PonyTestTask.NAME, PonyTestTask ) 37 | } 38 | 39 | } 40 | 41 | @Immutable 42 | class PonyPackage { 43 | String name 44 | String version 45 | List dependencies = [ ] 46 | } 47 | 48 | @CompileStatic 49 | class CleanTask extends Delete { 50 | 51 | static final String NAME = 'cleanPony' 52 | 53 | CleanTask() { 54 | description = 'deletes all artifacts created by previous builds' 55 | group = 'build' 56 | 57 | delete( project.buildDir ) 58 | } 59 | } 60 | 61 | @CompileStatic 62 | class ResolveDependenciesTask extends DefaultTask { 63 | 64 | static final String NAME = "resolvePonyDependencies" 65 | 66 | final PonyPackageFileParser packageParser = new PonyPackageFileParser( project ) 67 | 68 | ResolveDependenciesTask() { 69 | description = 'resolves the project dependencies' 70 | group = 'build' 71 | } 72 | 73 | @Optional 74 | @InputFile 75 | File getBundleFile() { 76 | def bundle = project.file( "bundle.json" ) 77 | if ( bundle.file ) { 78 | return bundle 79 | } else { 80 | return null 81 | } 82 | } 83 | 84 | @OutputDirectory 85 | File getOutputDir() { 86 | outputDir( project ) 87 | } 88 | 89 | static File outputDir( Project project ) { 90 | Paths.get( project.projectDir.absolutePath, "ext-libs/zips" ).toFile() 91 | } 92 | 93 | @TaskAction 94 | def run() { 95 | if ( !bundleFile?.file ) { 96 | logger.info( "bundle.json file does not exist. No dependencies to resolve." ) 97 | return 98 | } 99 | 100 | outputDir.mkdirs() 101 | 102 | PonyPackage ponyPackage = packageParser.parse( bundleFile.text ) 103 | 104 | logger.debug( ponyPackage.toString() ) 105 | 106 | resolveDependencies( ponyPackage.dependencies ) 107 | } 108 | 109 | private void resolveDependencies( List dependencies ) { 110 | logger.debug( "Resolving ${dependencies.size()} dependencies" ) 111 | dependencies.parallelStream().each { PonyDependency it -> 112 | Path depPath = it.resolvedPath() 113 | logger.debug( "Resolved dependency: {}", depPath ) 114 | def depBundle = bundleFromZip( depPath ) 115 | if ( depBundle ) { 116 | logger.info( "Resolving transitive dependencies of $depPath" ) 117 | resolveDependencies( packageParser.parse( depBundle ).dependencies ) 118 | } else { 119 | logger.info( "No transitive dependencies found for $depPath" ) 120 | } 121 | } 122 | } 123 | 124 | @Nullable 125 | private String bundleFromZip( Path zipPath ) { 126 | def zip = new ZipFile( zipPath.toFile() ) 127 | try { 128 | def bundle = zip.entries().find { ZipEntry entry -> 129 | entry.name.endsWith( '/bundle.json' ) 130 | } as ZipEntry 131 | if ( bundle ) { 132 | return zip.getInputStream( bundle ).text 133 | } 134 | } catch ( e ) { 135 | logger.error( "Problem parsing bundle.json for $zipPath", e ) 136 | } finally { 137 | zip.close() 138 | } 139 | 140 | return null 141 | } 142 | 143 | } 144 | 145 | @CompileStatic 146 | class UnpackArchivesTask extends DefaultTask { 147 | 148 | static final String NAME = "unpackPonyDependencies" 149 | 150 | UnpackArchivesTask() { 151 | description = 'unpacks the dependencies archives' 152 | group = 'build' 153 | 154 | dependsOn project.tasks.getByName( ResolveDependenciesTask.NAME ) 155 | } 156 | 157 | static File outputDir( Project project ) { 158 | Paths.get( project.projectDir.absolutePath, "ext-libs/unpacked" ).toFile() 159 | } 160 | 161 | @Optional 162 | @InputDirectory 163 | File getInputDir() { 164 | def input = ResolveDependenciesTask.outputDir( project ) 165 | if ( input.directory ) { 166 | return input 167 | } else { 168 | return null 169 | } 170 | } 171 | 172 | @OutputDirectory 173 | File getOutputDir() { 174 | outputDir( project ) 175 | } 176 | 177 | @CompileDynamic 178 | @TaskAction 179 | def run() { 180 | def zipsDir = ResolveDependenciesTask.outputDir( project ) 181 | if ( zipsDir.directory ) { 182 | def output = outputDir( project ) 183 | output.mkdirs() 184 | 185 | zipsDir.listFiles( { File f, String name -> 186 | name.endsWith( '.zip' ) 187 | } as FilenameFilter ).each { File file -> 188 | logger.debug "Unzipping $file" 189 | try { 190 | ant.unzip( src: file, 191 | dest: output, 192 | overwrite: true ) 193 | } catch ( e ) { 194 | logger.error( "Failed to unzip file {} due to {}", file, e ) 195 | } 196 | } 197 | } 198 | } 199 | 200 | } 201 | 202 | @CompileStatic 203 | class CompilePonyTask extends BaseCompileTask { 204 | 205 | static final String NAME = 'compilePony' 206 | 207 | CompilePonyTask() { 208 | description = 'compiles Pony sources and dependencies' 209 | group = 'build' 210 | } 211 | 212 | @Override 213 | String packageName( PonyConfig config ) { 214 | config.packageName 215 | } 216 | 217 | @Override 218 | List getAllOptions( PonyConfig config ) { 219 | super.getAllOptions( config ) + config.compileOptions 220 | } 221 | 222 | } 223 | 224 | @CompileStatic 225 | class PonyTestTask extends BaseCompileTask { 226 | 227 | static final String NAME = 'testPony' 228 | 229 | PonyTestTask() { 230 | description = 'compiles Pony sources, dependencies and the test package, then runs the tests' 231 | group = 'verification' 232 | } 233 | 234 | @InputDirectory 235 | File getMainPackageDir() { 236 | def config = project.extensions.getByName( 'pony' ) as PonyConfig 237 | 238 | // besides the package of the test itself, the package of the application must be added 239 | project.file( config.packageName ) 240 | } 241 | 242 | @Override 243 | String packageName( PonyConfig config ) { 244 | config.testPackage 245 | } 246 | 247 | @Override 248 | List getAllOptions( PonyConfig config ) { 249 | super.getAllOptions( config ) + config.testOptions 250 | } 251 | 252 | @TaskAction 253 | @Override 254 | void run() { 255 | super.run() // compile 256 | 257 | def config = project.extensions.getByName( 'pony' ) as PonyConfig 258 | 259 | def executable = new File( project.buildDir, packageName( config ) ) 260 | 261 | logger.info( "Running Pony test executable: $executable" ) 262 | 263 | def process = executable.absolutePath.execute( null as List, project.projectDir ) 264 | 265 | process.consumeProcessOutput( System.out as OutputStream, System.err ) 266 | def status = process.waitFor() 267 | process.waitForProcessOutput() 268 | 269 | if ( status != 0 ) { 270 | throw new GradleException( "Pony tests failed, see output for details. Exit code: $status" ) 271 | } 272 | } 273 | 274 | } 275 | 276 | @CompileStatic 277 | abstract class BaseCompileTask extends DefaultTask { 278 | 279 | BaseCompileTask() { 280 | dependsOn project.tasks.getByName( UnpackArchivesTask.NAME ) 281 | } 282 | 283 | @Optional 284 | @InputDirectory 285 | File getDepsDir() { 286 | def dir = UnpackArchivesTask.outputDir( project ) 287 | if ( dir.directory ) { 288 | return dir 289 | } else { 290 | return null 291 | } 292 | } 293 | 294 | @InputDirectory 295 | File getPackageDir() { 296 | def config = project.extensions.getByName( 'pony' ) as PonyConfig 297 | project.file( packageName( config ) ) 298 | } 299 | 300 | @OutputDirectory 301 | File getOutputDir() { 302 | project.buildDir 303 | } 304 | 305 | protected List getAllOptions( PonyConfig config ) { 306 | pathOption() + outputOption() + 307 | docsOption( config ) + debugOption( config ) + libraryOption( config ) + 308 | stripDebugOption( config ) + runtimeBcOption( config ) + usePicOption( config ) 309 | } 310 | 311 | @TaskAction 312 | void run() { 313 | def config = project.extensions.getByName( 'pony' ) as PonyConfig 314 | def options = getAllOptions( config ) 315 | 316 | def command = [ 'ponyc' ] + ( options.flatten() as List ) + [ packageName( config ) ] 317 | 318 | logger.info( "Running ponyc command: {}", command.join( ' ' ) ) 319 | 320 | def process = command.execute( null as List, project.projectDir ) 321 | 322 | process.consumeProcessOutput( System.out as OutputStream, System.err ) 323 | def status = process.waitFor() 324 | process.waitForProcessOutput() 325 | 326 | if ( status != 0 ) { 327 | throw new GradleException( "Ponyc failed, see output for details. Exit code: $status" ) 328 | } 329 | } 330 | 331 | abstract String packageName( PonyConfig config ) 332 | 333 | private List pathOption() { 334 | def dirs = otherPackages() 335 | if ( dirs ) { 336 | return [ '--path', dirs.join( ':' ) ] 337 | } else { 338 | return [ ] 339 | } 340 | } 341 | 342 | private List otherPackages() { 343 | UnpackArchivesTask.outputDir( project ) 344 | .listFiles( { File f -> f.directory } as FileFilter ) 345 | .collect { File f -> f.absolutePath } 346 | } 347 | 348 | private List outputOption() { 349 | [ '--output', outputDir.absolutePath ] 350 | } 351 | 352 | private static List debugOption( PonyConfig config ) { 353 | config.debug ? [ '--debug' ] : [ ] 354 | } 355 | 356 | private static List docsOption( PonyConfig config ) { 357 | config.docs ? [ '--docs' ] : [ ] 358 | } 359 | 360 | private static List libraryOption( PonyConfig config ) { 361 | config.library ? [ '--library' ] : [ ] 362 | } 363 | 364 | private static List stripDebugOption( PonyConfig config ) { 365 | config.strip ? [ '--strip' ] : [ ] 366 | } 367 | 368 | private static List runtimeBcOption( PonyConfig config ) { 369 | config.runtimebc ? [ '--runtimebc' ] : [ ] 370 | } 371 | 372 | private static List usePicOption( PonyConfig config ) { 373 | config.pic ? [ '--pic' ] : [ ] 374 | } 375 | 376 | } 377 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/com.athaydes.pony.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.athaydes.gradle.pony.PonyPlugin -------------------------------------------------------------------------------- /src/test/groovy/com/athaydes/gradle/pony/PonyPackageFileParserSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.athaydes.gradle.pony 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.testfixtures.ProjectBuilder 5 | import spock.lang.Shared 6 | import spock.lang.Specification 7 | import spock.lang.Subject 8 | 9 | class PonyPackageFileParserSpec extends Specification { 10 | 11 | @Shared 12 | def testProject = Stub( Project ) { 13 | getName() >> 'test-project' 14 | getVersion() >> '0' 15 | } 16 | 17 | @Shared 18 | def parsedSimplePackage = new PonyPackage( 'test-project', '0', 19 | [ new GitHubPonyDependency( testProject, 'jemc/pony-inspect', null ) ] ) 20 | 21 | static final simplePackage = ''' 22 | { 23 | "name": "test-project", 24 | "deps": [ 25 | { "type": "github", "repo": "jemc/pony-inspect" } 26 | ] 27 | }''' 28 | 29 | @Shared 30 | def parsedVersionedPackage = new PonyPackage( 'versioned-project', '2.3.4', 31 | [ new GitHubPonyDependency( testProject, 'jemc/pony-inspect', '1.0.1' ), 32 | new GitHubPonyDependency( testProject, 'other/dep', null ), 33 | new LocalDependency( testProject, '..' ) ] ) 34 | 35 | static final versionedPackage = ''' 36 | { 37 | "name": "versioned-project", 38 | "version": "2.3.4", 39 | "deps": [ 40 | { "type": "github", "repo": "jemc/pony-inspect", "version": "1.0.1" }, 41 | { "type": "github", "repo": "other/dep" }, 42 | { "type": "local", "local-path": ".." } 43 | ] 44 | }''' 45 | 46 | 47 | @Subject 48 | final parser = new PonyPackageFileParser( testProject ) 49 | 50 | 51 | def "Pony Plugin can understand Pony package files as defined by pony-stable"() { 52 | when: 'an example, valid Pony package file is parsed' 53 | def result = parser.parse( ponyPackageFileContents ) 54 | 55 | then: 'A Map is returned containing all the correct information' 56 | result == expectedResult 57 | 58 | where: 59 | ponyPackageFileContents | expectedResult 60 | simplePackage | parsedSimplePackage 61 | versionedPackage | parsedVersionedPackage 62 | } 63 | 64 | def "Can resolve a simple package"() { 65 | given: 'A real project' 66 | Project project = ProjectBuilder.builder() 67 | .withName( 'test1' ).build() 68 | project.buildDir = new File( 'build' ) 69 | 70 | when: 'the com.athaydes.pony plugin is applied to the project' 71 | project.pluginManager.apply( 'com.athaydes.pony' ) 72 | 73 | then: 'no errors should occur' 74 | true 75 | 76 | and: 'the tasks should be added' 77 | project.tasks.getByName( ResolveDependenciesTask.NAME ) 78 | project.tasks.getByName( UnpackArchivesTask.NAME ) 79 | project.tasks.getByName( CleanTask.NAME ) 80 | project.tasks.getByName( CompilePonyTask.NAME ) 81 | project.tasks.getByName( PonyTestTask.NAME ) 82 | 83 | and: 'the extensions should be added' 84 | project.extensions.getByName( 'pony' ) 85 | } 86 | 87 | } 88 | --------------------------------------------------------------------------------