├── .github └── workflows │ └── build.yml ├── .gitignore ├── COPYING ├── Makefile ├── README.md ├── buildSrc ├── build.gradle └── src │ └── main │ └── groovy │ ├── io.nextflow.groovy-application-conventions.gradle │ ├── io.nextflow.groovy-common-conventions.gradle │ └── io.nextflow.groovy-library-conventions.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── launch.sh ├── nextflow.config ├── plugins ├── build.gradle └── nf-hello │ ├── build.gradle │ └── src │ ├── main │ └── nextflow │ │ └── hello │ │ ├── HelloConfig.groovy │ │ ├── HelloExtension.groovy │ │ ├── HelloFactory.groovy │ │ ├── HelloObserver.groovy │ │ └── HelloPlugin.groovy │ ├── resources │ └── META-INF │ │ ├── MANIFEST.MF │ │ └── extensions.idx │ └── test │ └── nextflow │ └── hello │ ├── HelloDslTest.groovy │ ├── HelloFactoryTest.groovy │ ├── MockHelpers.groovy │ └── TestHelper.groovy └── settings.gradle /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: nf-hello CI 2 | on: 3 | push: 4 | branches: 5 | - '*' 6 | tags-ignore: 7 | - '*' 8 | pull_request: 9 | branches: 10 | - '*' 11 | jobs: 12 | build: 13 | name: Build nf-hello 14 | if: "!contains(github.event.head_commit.message, '[ci skip]')" 15 | runs-on: ubuntu-latest 16 | timeout-minutes: 10 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | java_version: [17, 21] 21 | 22 | steps: 23 | - name: Environment 24 | run: env | sort 25 | 26 | - name: Checkout 27 | uses: actions/checkout@v3 28 | with: 29 | fetch-depth: 1 30 | submodules: true 31 | 32 | - name: Setup Java ${{ matrix.java_version }} 33 | uses: actions/setup-java@v3 34 | with: 35 | java-version: ${{matrix.java_version}} 36 | architecture: x64 37 | distribution: 'temurin' 38 | 39 | - name: Compile 40 | run: ./gradlew assemble 41 | 42 | - name: Tests 43 | run: ./gradlew check 44 | env: 45 | GRADLE_OPTS: '-Dorg.gradle.daemon=false' 46 | 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | .idea 4 | .nextflow* 5 | 6 | # Ignore Gradle build output directory 7 | build 8 | work 9 | out 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | config ?= compileClasspath 3 | 4 | ifdef module 5 | mm = :${module}: 6 | else 7 | mm = 8 | endif 9 | 10 | clean: 11 | rm -rf .nextflow* 12 | rm -rf work 13 | rm -rf build 14 | rm -rf plugins/*/build 15 | ./gradlew clean 16 | 17 | compile: 18 | ./gradlew :nextflow:exportClasspath compileGroovy 19 | @echo "DONE `date`" 20 | 21 | 22 | check: 23 | ./gradlew check 24 | 25 | 26 | # 27 | # Show dependencies try `make deps config=runtime`, `make deps config=google` 28 | # 29 | deps: 30 | ./gradlew -q ${mm}dependencies --configuration ${config} 31 | 32 | deps-all: 33 | ./gradlew -q dependencyInsight --configuration ${config} --dependency ${module} 34 | 35 | # 36 | # Refresh SNAPSHOTs dependencies 37 | # 38 | refresh: 39 | ./gradlew --refresh-dependencies 40 | 41 | # 42 | # Run all tests or selected ones 43 | # 44 | test: 45 | ifndef class 46 | ./gradlew ${mm}test 47 | else 48 | ./gradlew ${mm}test --tests ${class} 49 | endif 50 | 51 | assemble: 52 | ./gradlew assemble 53 | 54 | # 55 | # generate build zips under build/plugins 56 | # you can install the plugin copying manually these files to $HOME/.nextflow/plugins 57 | # 58 | buildPlugins: 59 | ./gradlew copyPluginZip 60 | 61 | # 62 | # Upload JAR artifacts to Maven Central 63 | # 64 | upload: 65 | ./gradlew upload 66 | 67 | 68 | upload-plugins: 69 | ./gradlew plugins:upload 70 | 71 | publish-index: 72 | ./gradlew plugins:publishIndex 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nf-hello plugin 2 | 3 | This project contains a simple Nextflow plugin called `nf-hello` which provides examples of different plugin extensions: 4 | 5 | - A custom trace observer that prints a message when the workflow starts and when the workflow completes 6 | - A custom channel factory called `reverse` 7 | - A custom operator called `goodbye` 8 | - A custom function called `randomString` 9 | 10 | NOTE: If you want to use this project as a starting point for a custom plugin, you must rename the `plugins/nf-hello` folder and update `settings.gradle` with your plugin name. 11 | 12 | See the [Nextflow documentation](https://nextflow.io/docs/latest/plugins.html) for more information about developing plugins. 13 | 14 | ## Plugin structure 15 | 16 | - `settings.gradle` 17 | 18 | Gradle project settings. 19 | 20 | - `plugins/nf-hello` 21 | 22 | The plugin implementation base directory. 23 | 24 | - `plugins/nf-hello/build.gradle` 25 | 26 | Plugin Gradle build file. Project dependencies should be added here. 27 | 28 | - `plugins/nf-hello/src/resources/META-INF/MANIFEST.MF` 29 | 30 | Manifest file defining the plugin attributes e.g. name, version, etc. The attribute `Plugin-Class` declares the plugin main class. This class should extend the base class `nextflow.plugin.BasePlugin` e.g. `nextflow.hello.HelloPlugin`. 31 | 32 | - `plugins/nf-hello/src/resources/META-INF/extensions.idx` 33 | 34 | This file declares one or more extension classes provided by the plugin. Each line should contain the fully qualified name of a Java class that implements the `org.pf4j.ExtensionPoint` interface (or a sub-interface). 35 | 36 | - `plugins/nf-hello/src/main` 37 | 38 | The plugin implementation sources. 39 | 40 | - `plugins/nf-hello/src/test` 41 | 42 | The plugin unit tests. 43 | 44 | ## Plugin classes 45 | 46 | - `HelloConfig`: shows how to handle options from the Nextflow configuration 47 | 48 | - `HelloExtension`: shows how to create custom channel factories, operators, and fuctions that can be included into pipeline scripts 49 | 50 | - `HelloFactory` and `HelloObserver`: shows how to react to workflow events with custom behavior 51 | 52 | - `HelloPlugin`: the plugin entry point 53 | 54 | ## Unit testing 55 | 56 | To run your unit tests, run the following command in the project root directory (ie. where the file `settings.gradle` is located): 57 | 58 | ```bash 59 | ./gradlew check 60 | ``` 61 | 62 | ## Testing and debugging 63 | 64 | To build and test the plugin during development, configure a local Nextflow build with the following steps: 65 | 66 | 1. Clone the Nextflow repository in your computer into a sibling directory: 67 | ```bash 68 | git clone --depth 1 https://github.com/nextflow-io/nextflow ../nextflow 69 | ``` 70 | 71 | 2. Configure the plugin build to use the local Nextflow code: 72 | ```bash 73 | echo "includeBuild('../nextflow')" >> settings.gradle 74 | ``` 75 | 76 | (Make sure to not add it more than once!) 77 | 78 | 3. Compile the plugin alongside the Nextflow code: 79 | ```bash 80 | make assemble 81 | ``` 82 | 83 | 4. Run Nextflow with the plugin, using `./launch.sh` as a drop-in replacement for the `nextflow` command, and adding the option `-plugins nf-hello` to load the plugin: 84 | ```bash 85 | ./launch.sh run nextflow-io/hello -plugins nf-hello 86 | ``` 87 | 88 | ## Testing without Nextflow build 89 | 90 | The plugin can be tested without using a local Nextflow build using the following steps: 91 | 92 | 1. Build the plugin: `make buildPlugins` 93 | 2. Copy `build/plugins/` to `$HOME/.nextflow/plugins` 94 | 3. Create a pipeline that uses your plugin and run it: `nextflow run ./my-pipeline-script.nf` 95 | 96 | ## Package, upload, and publish 97 | 98 | The project should be hosted in a GitHub repository whose name matches the name of the plugin, that is the name of the directory in the `plugins` folder (e.g. `nf-hello`). 99 | 100 | Follow these steps to package, upload and publish the plugin: 101 | 102 | 1. Create a file named `gradle.properties` in the project root containing the following attributes (this file should not be committed to Git): 103 | 104 | * `github_organization`: the GitHub organisation where the plugin repository is hosted. 105 | * `github_username`: The GitHub username granting access to the plugin repository. 106 | * `github_access_token`: The GitHub access token required to upload and commit changes to the plugin repository. 107 | * `github_commit_email`: The email address associated with your GitHub account. 108 | 109 | 2. Use the following command to package and create a release for your plugin on GitHub: 110 | ```bash 111 | ./gradlew :plugins:nf-hello:upload 112 | ``` 113 | 114 | 3. Create a pull request against [nextflow-io/plugins](https://github.com/nextflow-io/plugins/blob/main/plugins.json) to make the plugin accessible to Nextflow. 115 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | plugins { 6 | // Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build. 7 | id 'groovy-gradle-plugin' 8 | } 9 | 10 | repositories { 11 | // Use the plugin portal to apply community plugins in convention plugins. 12 | gradlePluginPortal() 13 | } 14 | 15 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.nextflow.groovy-application-conventions.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | plugins { 6 | // Apply the common convention plugin for shared build configuration between library and application projects. 7 | id 'io.nextflow.groovy-common-conventions' 8 | 9 | // Apply the application plugin to add support for building a CLI application in Java. 10 | id 'application' 11 | } 12 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.nextflow.groovy-common-conventions.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | plugins { 6 | // Apply the groovy Plugin to add support for Groovy. 7 | id 'groovy' 8 | } 9 | 10 | repositories { 11 | // Use Maven Central for resolving dependencies. 12 | mavenCentral() 13 | } 14 | 15 | java { 16 | // these settings apply to all jvm tooling, including groovy 17 | toolchain { 18 | languageVersion = JavaLanguageVersion.of(21) 19 | } 20 | sourceCompatibility = 17 21 | targetCompatibility = 17 22 | } 23 | 24 | tasks.withType(Test) { 25 | jvmArgs ([ 26 | '--add-opens=java.base/java.lang=ALL-UNNAMED', 27 | '--add-opens=java.base/java.io=ALL-UNNAMED', 28 | '--add-opens=java.base/java.nio=ALL-UNNAMED', 29 | '--add-opens=java.base/java.nio.file.spi=ALL-UNNAMED', 30 | '--add-opens=java.base/java.net=ALL-UNNAMED', 31 | '--add-opens=java.base/java.util=ALL-UNNAMED', 32 | '--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED', 33 | '--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED', 34 | '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED', 35 | '--add-opens=java.base/sun.nio.fs=ALL-UNNAMED', 36 | '--add-opens=java.base/sun.net.www.protocol.http=ALL-UNNAMED', 37 | '--add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED', 38 | '--add-opens=java.base/sun.net.www.protocol.ftp=ALL-UNNAMED', 39 | '--add-opens=java.base/sun.net.www.protocol.file=ALL-UNNAMED', 40 | '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED', 41 | ]) 42 | } 43 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/io.nextflow.groovy-library-conventions.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | */ 4 | 5 | plugins { 6 | // Apply the common convention plugin for shared build configuration between library and application projects. 7 | id 'io.nextflow.groovy-common-conventions' 8 | // Apply the java-library plugin for API and implementation separation. 9 | id 'java-library' 10 | } 11 | 12 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nextflow-io/nf-hello/ee8371fb7c46b82d9e705a1b3281736aeaea3ad1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /launch.sh: -------------------------------------------------------------------------------- 1 | export NXF_PLUGINS_DEV=$PWD/plugins 2 | ../nextflow/launch.sh "$@" 3 | -------------------------------------------------------------------------------- /nextflow.config: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'nf-hello' 3 | } -------------------------------------------------------------------------------- /plugins/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | id "java" 19 | id "io.nextflow.nf-build-plugin" version "1.0.1" 20 | } 21 | 22 | ext.github_organization = 'nextflow-io' 23 | ext.github_username = project.findProperty('github_username') ?: 'pditommaso' 24 | ext.github_access_token = project.findProperty('github_access_token') ?: System.getenv('GITHUB_TOKEN') 25 | ext.github_commit_email = project.findProperty('github_commit_email') ?: 'paolo.ditommaso@gmail.com' 26 | 27 | jar.enabled = false 28 | 29 | String computeSha512(File file) { 30 | if( !file.exists() ) 31 | throw new GradleException("Missing file: $file -- cannot compute SHA-512") 32 | return org.apache.commons.codec.digest.DigestUtils.sha512Hex(file.bytes) 33 | } 34 | 35 | String now() { 36 | "${java.time.OffsetDateTime.now().format(java.time.format.DateTimeFormatter.ISO_DATE_TIME)}" 37 | } 38 | 39 | List allPlugins() { 40 | def plugins = [] 41 | new File(rootProject.rootDir, 'plugins') .eachDir { if(it.name.startsWith('nf-')) plugins.add(it.name) } 42 | return plugins 43 | } 44 | 45 | String metaFromManifest(String meta, File file) { 46 | def str = file.text 47 | def regex = ~/(?m)^$meta:\s*([\w-\.<>=]+)$/ 48 | def m = regex.matcher(str) 49 | if( m.find() ) { 50 | def ver = m.group(1) 51 | //println "Set plugin '${file.parentFile.parentFile.parentFile.parentFile.name}' version=${ver}" 52 | return ver 53 | } 54 | throw new GradleException("Cannot find '$meta' for plugin: $file") 55 | } 56 | 57 | def timestamp = now() 58 | 59 | subprojects { 60 | apply plugin: 'java' 61 | apply plugin: 'groovy' 62 | apply plugin: 'io.nextflow.nf-build-plugin' 63 | 64 | repositories { 65 | mavenLocal() 66 | mavenCentral() 67 | } 68 | 69 | version = metaFromManifest('Plugin-Version',file('src/resources/META-INF/MANIFEST.MF')) 70 | 71 | tasks.withType(Jar) { 72 | duplicatesStrategy = DuplicatesStrategy.INCLUDE 73 | } 74 | 75 | /* 76 | * Creates plugin zip and json meta file in plugin `build/libs` directory 77 | */ 78 | task makeZip(type: Jar) { 79 | into('classes') { with jar } 80 | into('lib') { from configurations.runtimeClasspath } 81 | manifest.from file('src/resources/META-INF/MANIFEST.MF') 82 | archiveExtension = 'zip' 83 | preserveFileTimestamps = false 84 | reproducibleFileOrder = true 85 | 86 | doLast { 87 | // create the meta file 88 | final zip = new File("$buildDir/libs/${project.name}-${project.version}.zip") 89 | final json = new File("$buildDir/libs/${project.name}-${project.version}-meta.json") 90 | json.text = """\ 91 | { 92 | "version": "${project.version}", 93 | "date": "${timestamp}", 94 | "url": "https://github.com/${github_organization}/${project.name}/releases/download/${project.version}/${project.name}-${project.version}.zip", 95 | "requires": "${metaFromManifest('Plugin-Requires',file('src/resources/META-INF/MANIFEST.MF'))}", 96 | "sha512sum": "${computeSha512(zip)}" 97 | } 98 | """.stripIndent() 99 | // cleanup tmp dir 100 | file("$buildDir/tmp/makeZip").deleteDir() 101 | } 102 | outputs.file("$buildDir/libs/${project.name}-${project.version}.zip") 103 | } 104 | 105 | /* 106 | * Copy the plugin dependencies in the subproject `build/target/libs` directory 107 | */ 108 | task copyPluginLibs(type: Sync) { 109 | from configurations.runtimeClasspath 110 | into 'build/target/libs' 111 | } 112 | 113 | /* 114 | * Copy the plugin in the project root build/plugins directory 115 | */ 116 | task copyPluginZip(type: Copy, dependsOn: project.tasks.findByName('makeZip')) { 117 | from makeZip 118 | into "$rootProject.buildDir/plugins" 119 | outputs.file("$rootProject.buildDir/plugins/${project.name}-${project.version}.zip") 120 | doLast { 121 | ant.unzip( 122 | src: "$rootProject.buildDir/plugins/${project.name}-${project.version}.zip", 123 | dest: "$rootProject.buildDir/plugins/${project.name}-${project.version}" 124 | ) 125 | } 126 | } 127 | 128 | /* 129 | * "install" the plugin the project root build/plugins directory 130 | */ 131 | project.parent.tasks.getByName("assemble").dependsOn << copyPluginZip 132 | 133 | task uploadPlugin(type: io.nextflow.gradle.tasks.GithubUploader, dependsOn: makeZip) { 134 | assets = providers.provider {["$buildDir/libs/${project.name}-${project.version}.zip", 135 | "$buildDir/libs/${project.name}-${project.version}-meta.json" ]} 136 | release = providers.provider { project.version } 137 | repo = providers.provider { project.name } 138 | owner = github_organization 139 | userName = github_username 140 | authToken = github_access_token 141 | skipExisting = true 142 | } 143 | 144 | jar { 145 | from sourceSets.main.allSource 146 | doLast { 147 | file("$buildDir/tmp/jar").deleteDir() 148 | } 149 | } 150 | 151 | tasks.withType(GenerateModuleMetadata) { 152 | enabled = false 153 | } 154 | 155 | task upload(dependsOn: [uploadPlugin] ) { } 156 | } 157 | 158 | /* 159 | * Upload all plugins to the corresponding GitHub repos 160 | */ 161 | task upload(dependsOn: [subprojects.uploadPlugin]) { } 162 | 163 | /* 164 | * Copies the plugins required dependencies in the corresponding lib directory 165 | */ 166 | classes.dependsOn subprojects.copyPluginLibs 167 | 168 | /* 169 | * Merge and publish the plugins index file 170 | */ 171 | task publishIndex( type: io.nextflow.gradle.tasks.GithubRepositoryPublisher ) { 172 | indexUrl = 'https://github.com/nextflow-io/plugins/main/plugins.json' 173 | repos = allPlugins() 174 | owner = github_organization 175 | githubUser = github_username 176 | githubEmail = github_commit_email 177 | githubToken = github_access_token 178 | } 179 | -------------------------------------------------------------------------------- /plugins/nf-hello/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2022, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | // Apply the groovy plugin to add support for Groovy 19 | id 'io.nextflow.groovy-library-conventions' 20 | id 'idea' 21 | } 22 | 23 | group = 'io.nextflow' 24 | // DO NOT SET THE VERSION HERE 25 | // THE VERSION FOR PLUGINS IS DEFINED IN THE `/resources/META-INF/MANIFEST.NF` file 26 | 27 | idea { 28 | module.inheritOutputDirs = true 29 | } 30 | 31 | repositories { 32 | mavenCentral() 33 | maven { url = 'https://jitpack.io' } 34 | maven { url = 'https://s3-eu-west-1.amazonaws.com/maven.seqera.io/releases' } 35 | maven { url = 'https://s3-eu-west-1.amazonaws.com/maven.seqera.io/snapshots' } 36 | } 37 | 38 | configurations { 39 | // see https://docs.gradle.org/4.1/userguide/dependency_management.html#sub:exclude_transitive_dependencies 40 | runtimeClasspath.exclude group: 'org.slf4j', module: 'slf4j-api' 41 | } 42 | 43 | sourceSets { 44 | main.java.srcDirs = [] 45 | main.groovy.srcDirs = ['src/main'] 46 | main.resources.srcDirs = ['src/resources'] 47 | test.groovy.srcDirs = ['src/test'] 48 | test.java.srcDirs = [] 49 | test.resources.srcDirs = ['src/testResources'] 50 | } 51 | 52 | ext{ 53 | nextflowVersion = '25.01.0-edge' 54 | } 55 | 56 | dependencies { 57 | // This dependency is exported to consumers, that is to say found on their compile classpath. 58 | compileOnly "io.nextflow:nextflow:$nextflowVersion" 59 | compileOnly 'org.slf4j:slf4j-api:2.0.16' 60 | compileOnly 'org.pf4j:pf4j:3.12.0' 61 | 62 | // test configuration 63 | testImplementation "org.apache.groovy:groovy:4.0.26" 64 | testImplementation "org.apache.groovy:groovy-nio:4.0.26" 65 | testImplementation "io.nextflow:nextflow:$nextflowVersion" 66 | testImplementation ("org.apache.groovy:groovy-test:4.0.26") { exclude group: 'org.apache.groovy' } 67 | testImplementation ("cglib:cglib-nodep:3.3.0") 68 | testImplementation ("org.objenesis:objenesis:3.1") 69 | testImplementation ("org.spockframework:spock-core:2.3-groovy-4.0") { exclude group: 'org.apache.groovy'; exclude group: 'net.bytebuddy' } 70 | testImplementation ('org.spockframework:spock-junit4:2.3-groovy-4.0') { exclude group: 'org.apache.groovy'; exclude group: 'net.bytebuddy' } 71 | testImplementation ('com.google.jimfs:jimfs:1.1') 72 | 73 | testImplementation(testFixtures("io.nextflow:nextflow:$nextflowVersion")) 74 | testImplementation(testFixtures("io.nextflow:nf-commons:$nextflowVersion")) 75 | 76 | // see https://docs.gradle.org/4.1/userguide/dependency_management.html#sec:module_replacement 77 | modules { 78 | module("commons-logging:commons-logging") { replacedBy("org.slf4j:jcl-over-slf4j") } 79 | } 80 | } 81 | 82 | // use JUnit 5 platform 83 | test { 84 | useJUnitPlatform() 85 | } 86 | 87 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/main/nextflow/hello/HelloConfig.groovy: -------------------------------------------------------------------------------- 1 | package nextflow.hello 2 | 3 | import groovy.transform.PackageScope 4 | 5 | 6 | /** 7 | * This class allows model an specific configuration, extracting values from a map and converting 8 | * 9 | * In this plugin, the user can configure how the messages are prefixed with a String, i.e. 10 | * due a nextflow.config 11 | * 12 | * hello { 13 | * prefix = '>>' 14 | * } 15 | * 16 | * when the plugin reverse a String it will append '>>' at the beginning instead the default 'Mr.' 17 | * 18 | * We anotate this class as @PackageScope to restrict the access of their methods only to class in the 19 | * same package 20 | * 21 | * @author : jorge 22 | * 23 | */ 24 | @PackageScope 25 | class HelloConfig { 26 | 27 | final private String prefix 28 | 29 | HelloConfig(Map map){ 30 | def config = map ?: Collections.emptyMap() 31 | prefix = config.prefix ?: 'Mr.' 32 | } 33 | 34 | String getPrefix() { prefix } 35 | } 36 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/main/nextflow/hello/HelloExtension.groovy: -------------------------------------------------------------------------------- 1 | package nextflow.hello 2 | 3 | 4 | import groovy.transform.CompileStatic 5 | import groovy.util.logging.Slf4j 6 | import groovyx.gpars.dataflow.DataflowReadChannel 7 | import groovyx.gpars.dataflow.DataflowWriteChannel 8 | import nextflow.Channel 9 | import nextflow.Session 10 | import nextflow.extension.CH 11 | import nextflow.extension.DataflowHelper 12 | import nextflow.plugin.extension.Factory 13 | import nextflow.plugin.extension.Function 14 | import nextflow.plugin.extension.Operator 15 | import nextflow.plugin.extension.PluginExtensionPoint 16 | 17 | /** 18 | * Example plugin extension showing how to implement a basic 19 | * channel factory method, a channel operator and a custom function. 20 | * 21 | * @author : jorge 22 | * 23 | */ 24 | @Slf4j 25 | @CompileStatic 26 | class HelloExtension extends PluginExtensionPoint { 27 | 28 | /* 29 | * A session hold information about current execution of the script 30 | */ 31 | private Session session 32 | 33 | /* 34 | * A Custom config extracted from nextflow.config under hello tag 35 | * nextflow.config 36 | * --------------- 37 | * docker{ 38 | * enabled = true 39 | * } 40 | * ... 41 | * hello{ 42 | * prefix = 'Mrs' 43 | * } 44 | */ 45 | private HelloConfig config 46 | 47 | /* 48 | * nf-core initializes the plugin once loaded and session is ready 49 | * @param session 50 | */ 51 | @Override 52 | protected void init(Session session) { 53 | this.session = session 54 | this.config = new HelloConfig(session.config.navigate('hello') as Map) 55 | } 56 | 57 | /* 58 | * {@code reverse} is a `producer` method and will be available to the script because: 59 | * 60 | * - it's public 61 | * - it returns a DataflowWriteChannel 62 | * - it's marked with the @Factory annotation 63 | * 64 | * The method can require arguments but it's not mandatory, it depends of the business logic of the method. 65 | * 66 | */ 67 | @Factory 68 | DataflowWriteChannel reverse(String message) { 69 | final channel = CH.create() 70 | session.addIgniter((action) -> reverseImpl(channel, message)) 71 | return channel 72 | } 73 | 74 | private void reverseImpl(DataflowWriteChannel channel, String message) { 75 | channel.bind(message.reverse()); 76 | channel.bind(Channel.STOP) 77 | } 78 | 79 | /* 80 | * {@code goodbye} is a *consumer* method as it receives values from a channel to perform some logic. 81 | * 82 | * Consumer methods are introspected by nextflow-core and include into the DSL if the method: 83 | * 84 | * - it's public 85 | * - it returns a DataflowWriteChannel 86 | * - it has only one arguments of DataflowReadChannel class 87 | * - it's marked with the @Operator annotation 88 | * 89 | * a consumer method needs to proportionate 2 closures: 90 | * - a closure to consume items (one by one) 91 | * - a finalizer closure 92 | * 93 | * in this case `goodbye` will consume a message and will store it as an upper case 94 | */ 95 | @Operator 96 | DataflowWriteChannel goodbye(DataflowReadChannel source) { 97 | final target = CH.createBy(source) 98 | final next = { target.bind("Goodbye $it".toString()) } 99 | final done = { target.bind(Channel.STOP) } 100 | DataflowHelper.subscribeImpl(source, [onNext: next, onComplete: done]) 101 | return target 102 | } 103 | 104 | /* 105 | * Generate a random string 106 | * 107 | * Using @Function annotation we allow this function can be imported from the pipeline script 108 | */ 109 | @Function 110 | String randomString(int length=9){ 111 | new Random().with {(1..length).collect {(('a'..'z')).join(null)[ nextInt((('a'..'z')).join(null).length())]}.join(null)} 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/main/nextflow/hello/HelloFactory.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nextflow.hello 18 | 19 | import groovy.transform.CompileStatic 20 | import nextflow.Session 21 | import nextflow.trace.TraceObserver 22 | import nextflow.trace.TraceObserverFactory 23 | /** 24 | * Implements the validation observer factory 25 | * 26 | * @author Paolo Di Tommaso 27 | */ 28 | @CompileStatic 29 | class HelloFactory implements TraceObserverFactory { 30 | 31 | @Override 32 | Collection create(Session session) { 33 | final result = new ArrayList() 34 | result.add( new HelloObserver() ) 35 | return result 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/main/nextflow/hello/HelloObserver.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nextflow.hello 18 | 19 | import groovy.transform.CompileStatic 20 | import groovy.util.logging.Slf4j 21 | import nextflow.Session 22 | import nextflow.trace.TraceObserver 23 | 24 | /** 25 | * Example workflow events observer 26 | * 27 | * @author Paolo Di Tommaso 28 | */ 29 | @Slf4j 30 | @CompileStatic 31 | class HelloObserver implements TraceObserver { 32 | 33 | @Override 34 | void onFlowCreate(Session session) { 35 | log.info "Pipeline is starting! 🚀" 36 | } 37 | 38 | @Override 39 | void onFlowComplete() { 40 | log.info "Pipeline complete! 👋" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/main/nextflow/hello/HelloPlugin.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nextflow.hello 18 | 19 | import groovy.transform.CompileStatic 20 | import nextflow.plugin.BasePlugin 21 | import nextflow.plugin.Scoped 22 | import org.pf4j.PluginWrapper 23 | 24 | /** 25 | * Implements the Hello plugins entry point 26 | * 27 | * @author Paolo Di Tommaso 28 | */ 29 | @CompileStatic 30 | class HelloPlugin extends BasePlugin { 31 | 32 | HelloPlugin(PluginWrapper wrapper) { 33 | super(wrapper) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Plugin-Id: nf-hello 3 | Plugin-Version: 0.7.0 4 | Plugin-Class: nextflow.hello.HelloPlugin 5 | Plugin-Provider: nextflow 6 | Plugin-Requires: >=25.01.0-edge 7 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/resources/META-INF/extensions.idx: -------------------------------------------------------------------------------- 1 | nextflow.hello.HelloFactory 2 | nextflow.hello.HelloExtension -------------------------------------------------------------------------------- /plugins/nf-hello/src/test/nextflow/hello/HelloDslTest.groovy: -------------------------------------------------------------------------------- 1 | package nextflow.hello 2 | 3 | import java.nio.file.Files 4 | import java.util.jar.Manifest 5 | 6 | import nextflow.Channel 7 | import nextflow.plugin.Plugins 8 | import nextflow.plugin.TestPluginDescriptorFinder 9 | import nextflow.plugin.TestPluginManager 10 | import nextflow.plugin.extension.PluginExtensionProvider 11 | import org.pf4j.PluginDescriptorFinder 12 | import spock.lang.Shared 13 | import spock.lang.Timeout 14 | import test.Dsl2Spec 15 | 16 | import java.nio.file.Path 17 | 18 | 19 | /** 20 | * Unit test for Hello DSL 21 | * 22 | * @author : jorge 23 | */ 24 | @Timeout(10) 25 | class HelloDslTest extends Dsl2Spec{ 26 | 27 | @Shared String pluginsMode 28 | 29 | def setup() { 30 | // reset previous instances 31 | PluginExtensionProvider.reset() 32 | // this need to be set *before* the plugin manager class is created 33 | pluginsMode = System.getProperty('pf4j.mode') 34 | System.setProperty('pf4j.mode', 'dev') 35 | // the plugin root should 36 | def root = Path.of('.').toAbsolutePath().normalize() 37 | def manager = new TestPluginManager(root){ 38 | @Override 39 | protected PluginDescriptorFinder createPluginDescriptorFinder() { 40 | return new TestPluginDescriptorFinder(){ 41 | 42 | @Override 43 | protected Manifest readManifestFromDirectory(Path pluginPath) { 44 | if( !Files.isDirectory(pluginPath) ) 45 | return null 46 | 47 | final manifestPath = pluginPath.resolve('build/resources/main/META-INF/MANIFEST.MF') 48 | if( !Files.exists(manifestPath) ) 49 | return null 50 | 51 | final input = Files.newInputStream(manifestPath) 52 | return new Manifest(input) 53 | } 54 | } 55 | } 56 | } 57 | Plugins.init(root, 'dev', manager) 58 | } 59 | 60 | def cleanup() { 61 | Plugins.stop() 62 | PluginExtensionProvider.reset() 63 | pluginsMode ? System.setProperty('pf4j.mode',pluginsMode) : System.clearProperty('pf4j.mode') 64 | } 65 | 66 | def 'should perform a hi and create a channel' () { 67 | when: 68 | def SCRIPT = ''' 69 | include {reverse} from 'plugin/nf-hello' 70 | channel.reverse('hi!') 71 | ''' 72 | and: 73 | def result = new MockScriptRunner([hello:[prefix:'>>']]).setScript(SCRIPT).execute() 74 | then: 75 | result.val == 'hi!'.reverse() 76 | result.val == Channel.STOP 77 | } 78 | 79 | def 'should store a goodbye' () { 80 | when: 81 | def SCRIPT = ''' 82 | include {goodbye} from 'plugin/nf-hello' 83 | channel 84 | .of('folks') 85 | .goodbye() 86 | ''' 87 | and: 88 | def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() 89 | then: 90 | result.val == 'Goodbye folks' 91 | result.val == Channel.STOP 92 | 93 | } 94 | 95 | def 'can use an imported function' () { 96 | when: 97 | def SCRIPT = ''' 98 | include {randomString} from 'plugin/nf-hello' 99 | channel 100 | .of( randomString(20) ) 101 | ''' 102 | and: 103 | def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() 104 | then: 105 | result.val.size() == 20 106 | result.val == Channel.STOP 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/test/nextflow/hello/HelloFactoryTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package nextflow.hello 18 | 19 | import nextflow.Session 20 | import spock.lang.Specification 21 | 22 | /** 23 | * 24 | * @author Paolo Di Tommaso 25 | */ 26 | class HelloFactoryTest extends Specification { 27 | 28 | def 'should return observer' () { 29 | when: 30 | def result = new HelloFactory().create(Mock(Session)) 31 | then: 32 | result.size()==1 33 | result[0] instanceof HelloObserver 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/test/nextflow/hello/MockHelpers.groovy: -------------------------------------------------------------------------------- 1 | package nextflow.hello 2 | 3 | import groovy.util.logging.Slf4j 4 | import groovyx.gpars.dataflow.DataflowBroadcast 5 | import nextflow.Session 6 | import nextflow.executor.Executor 7 | import nextflow.executor.ExecutorFactory 8 | import nextflow.processor.TaskHandler 9 | import nextflow.processor.TaskMonitor 10 | import nextflow.processor.TaskRun 11 | import nextflow.processor.TaskStatus 12 | import nextflow.script.BaseScript 13 | import nextflow.script.ChannelOut 14 | import nextflow.script.ScriptRunner 15 | import nextflow.script.ScriptType 16 | 17 | import java.nio.file.Paths 18 | 19 | class MockScriptRunner extends ScriptRunner { 20 | 21 | MockScriptRunner() { 22 | super(new MockSession()) 23 | } 24 | 25 | MockScriptRunner(Map config) { 26 | super(new MockSession(config)) 27 | } 28 | 29 | MockScriptRunner setScript(String str) { 30 | def script = TestHelper.createInMemTempFile('main.nf', str) 31 | setScript(script) 32 | return this 33 | } 34 | 35 | MockScriptRunner invoke() { 36 | execute() 37 | return this 38 | } 39 | 40 | BaseScript getScript() { getScriptObj() } 41 | 42 | @Override 43 | def normalizeOutput(output) { 44 | if( output instanceof ChannelOut ) { 45 | def list = new ArrayList(output.size()) 46 | for( int i=0; i(output.size()) 54 | for( def item : output ) { 55 | ((List)result).add(read0(item)) 56 | } 57 | return result 58 | } 59 | 60 | else { 61 | return read0(output) 62 | } 63 | } 64 | 65 | 66 | private read0( obj ) { 67 | if( obj instanceof DataflowBroadcast ) 68 | return obj.createReadChannel() 69 | return obj 70 | } 71 | 72 | } 73 | 74 | class MockSession extends Session { 75 | 76 | @Override 77 | Session start() { 78 | this.executorFactory = new MockExecutorFactory() 79 | return super.start() 80 | } 81 | 82 | MockSession() { 83 | super() 84 | } 85 | 86 | MockSession(Map config) { 87 | super(config) 88 | } 89 | } 90 | 91 | class MockExecutorFactory extends ExecutorFactory { 92 | @Override 93 | protected Class getExecutorClass(String executorName) { 94 | return MockExecutor 95 | } 96 | 97 | @Override 98 | protected boolean isTypeSupported(ScriptType type, Object executor) { 99 | true 100 | } 101 | } 102 | 103 | /** 104 | * 105 | * @author Paolo Di Tommaso 106 | */ 107 | class MockExecutor extends Executor { 108 | 109 | @Override 110 | void signal() { } 111 | 112 | protected TaskMonitor createTaskMonitor() { 113 | new MockMonitor() 114 | } 115 | 116 | @Override 117 | TaskHandler createTaskHandler(TaskRun task) { 118 | return new MockTaskHandler(task) 119 | } 120 | } 121 | 122 | class MockMonitor implements TaskMonitor { 123 | 124 | void schedule(TaskHandler handler) { 125 | handler.submit() 126 | } 127 | 128 | /** 129 | * Remove the {@code TaskHandler} instance from the queue of tasks to be processed 130 | * 131 | * @param handler A not null {@code TaskHandler} instance 132 | */ 133 | boolean evict(TaskHandler handler) { } 134 | 135 | /** 136 | * Start the monitoring activity for the queued tasks 137 | * @return The instance itself, useful to chain methods invocation 138 | */ 139 | TaskMonitor start() { } 140 | 141 | /** 142 | * Notify when a task terminates 143 | */ 144 | void signal() { } 145 | } 146 | 147 | @Slf4j 148 | class MockTaskHandler extends TaskHandler { 149 | 150 | protected MockTaskHandler(TaskRun task) { 151 | super(task) 152 | } 153 | 154 | @Override 155 | void submit() { 156 | log.info ">> launching mock task: ${task}" 157 | if( task.type == ScriptType.SCRIPTLET ) { 158 | task.workDir = Paths.get('.').complete() 159 | task.stdout = task.script 160 | task.exitStatus = 0 161 | } 162 | else { 163 | task.code.call() 164 | } 165 | status = TaskStatus.COMPLETED 166 | task.processor.finalizeTask(task) 167 | } 168 | 169 | @Override 170 | boolean checkIfRunning() { 171 | return false 172 | } 173 | 174 | @Override 175 | boolean checkIfCompleted() { 176 | true 177 | } 178 | 179 | @Override 180 | protected void killTask() { } 181 | 182 | } 183 | -------------------------------------------------------------------------------- /plugins/nf-hello/src/test/nextflow/hello/TestHelper.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022, Seqera Labs 3 | * Copyright 2013-2019, Centre for Genomic Regulation (CRG) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package nextflow.hello 19 | 20 | import com.google.common.jimfs.Configuration 21 | import com.google.common.jimfs.Jimfs 22 | import groovy.transform.Memoized 23 | 24 | import java.nio.file.Files 25 | import java.nio.file.Path 26 | import java.util.zip.GZIPInputStream 27 | 28 | /** 29 | * 30 | * @author Paolo Di Tommaso 31 | */ 32 | class TestHelper { 33 | 34 | static private fs = Jimfs.newFileSystem(Configuration.unix()); 35 | 36 | static Path createInMemTempFile(String name='temp.file', String content=null) { 37 | Path tmp = fs.getPath("/tmp"); 38 | tmp.mkdir() 39 | def result = Files.createTempDirectory(tmp, 'test').resolve(name) 40 | if( content ) 41 | result.text = content 42 | return result 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021, Seqera Labs 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | // required to download the toolchain (jdk) from a remote repository 19 | // https://github.com/gradle/foojay-toolchains 20 | // https://docs.gradle.org/current/userguide/toolchains.html#sub:download_repositories 21 | id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" 22 | } 23 | 24 | rootProject.name = 'nf-hello' 25 | include('plugins') 26 | include('plugins:nf-hello') 27 | --------------------------------------------------------------------------------