├── .asf.yaml ├── .github ├── ISSUE_TEMPLATE │ ├── BUG.yml │ ├── FEATURE.yml │ └── config.yml ├── dependabot.yml ├── pull_request_template.md ├── release-drafter.yml └── workflows │ ├── maven-verify.yml │ ├── pr-automation.yml │ ├── release-drafter.yml │ └── stale.yml ├── .gitignore ├── Jenkinsfile ├── README.md ├── pom.xml └── src ├── main └── java │ └── org │ └── apache │ └── maven │ └── shared │ └── scriptinterpreter │ ├── BeanShellScriptInterpreter.java │ ├── ExecutionLogger.java │ ├── FileLogger.java │ ├── FileLoggerMirrorHandler.java │ ├── GroovyScriptInterpreter.java │ ├── ScriptEvaluationException.java │ ├── ScriptException.java │ ├── ScriptInterpreter.java │ ├── ScriptReturnException.java │ └── ScriptRunner.java ├── site ├── apt │ └── index.apt.vm ├── resources │ └── download.cgi ├── site.xml └── xdoc │ └── download.xml.vm ├── test-class-path └── class-path.txt └── test ├── java └── org │ └── apache │ └── maven │ └── shared │ └── scriptinterpreter │ ├── BeanShellScriptInterpreterTest.java │ ├── FileLoggerTest.java │ ├── GroovyScriptInterpreterTest.java │ ├── ScriptRunnerTest.java │ └── TestMirrorHandler.java └── resources ├── bsh-test ├── class-path1.bsh ├── class-path2.bsh ├── failed.bsh ├── return-not-true.bsh ├── return-null.bsh └── verify.bsh ├── class-path.txt └── groovy-test ├── class-path1.groovy ├── class-path2.groovy ├── failed.groovy ├── return-false.groovy ├── return-null.groovy └── verify.groovy /.asf.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. 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 | # see https://s.apache.org/asfyaml 18 | github: 19 | description: "Apache Maven Script Interpreter" 20 | homepage: https://maven.apache.org/shared/maven-script-interpreter/ 21 | labels: 22 | - java 23 | - build-management 24 | - maven-shared 25 | - maven 26 | - hacktoberfest 27 | enabled_merge_buttons: 28 | squash: true 29 | merge: false 30 | rebase: true 31 | autolink_jira: 32 | - MSHARED 33 | del_branch_on_merge: true 34 | features: 35 | issues: true 36 | notifications: 37 | commits: commits@maven.apache.org 38 | issues: issues@maven.apache.org 39 | pullrequests: issues@maven.apache.org 40 | jira_options: link label comment 41 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. 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 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema 19 | 20 | name: Bug Report 21 | description: File a bug report 22 | labels: ["bug"] 23 | 24 | body: 25 | - type: markdown 26 | attributes: 27 | value: | 28 | Thanks for taking the time to fill out this bug report. 29 | 30 | Simple fixes in single PRs do not require issues. 31 | 32 | **Do you use the latest project version?** 33 | 34 | - type: input 35 | id: version 36 | attributes: 37 | label: Affected version 38 | validations: 39 | required: true 40 | 41 | - type: textarea 42 | id: message 43 | attributes: 44 | label: Bug description 45 | validations: 46 | required: true 47 | 48 | 49 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. 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 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema 19 | 20 | name: Feature request 21 | description: File a proposal for new feature, improvement 22 | labels: ["enhancement"] 23 | 24 | body: 25 | - type: markdown 26 | attributes: 27 | value: | 28 | Thanks for taking the time to fill out this new feature, improvement proposal. 29 | 30 | - type: textarea 31 | id: message 32 | attributes: 33 | label: New feature, improvement proposal 34 | validations: 35 | required: true 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. 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 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser 19 | 20 | blank_issues_enabled: false 21 | 22 | contact_links: 23 | 24 | - name: Project Mailing Lists 25 | url: https://maven.apache.org/mailing-lists.html 26 | about: Please ask a question or discuss here 27 | 28 | - name: Old JIRA Issues 29 | url: https://issues.apache.org/jira/browse/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-script-interpreter 30 | about: Please search old JIRA issues 31 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. 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 | # Please see the documentation for all configuration options: 18 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 19 | # 20 | version: 2 21 | updates: 22 | - package-ecosystem: "maven" 23 | directory: "/" 24 | schedule: 25 | interval: "daily" 26 | - package-ecosystem: "github-actions" 27 | directory: "/" 28 | schedule: 29 | interval: "daily" 30 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Following this checklist to help us incorporate your 2 | contribution quickly and easily: 3 | 4 | - [ ] Your pull request should address just one issue, without pulling in other changes. 5 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 6 | - [ ] Each commit in the pull request should have a meaningful subject line and body. 7 | Note that commits might be squashed by a maintainer on merge. 8 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. 9 | This may not always be possible but is a best-practice. 10 | - [ ] Run `mvn verify` to make sure basic checks pass. 11 | A more thorough check will be performed on your pull request automatically. 12 | - [ ] You have run the integration tests successfully (`mvn -Prun-its verify`). 13 | 14 | If your pull request is about ~20 lines of code you don't need to sign an 15 | [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure 16 | please ask on the developers list. 17 | 18 | To make clear that you license your contribution under 19 | the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0) 20 | you have to acknowledge this by using the following check-box. 21 | 22 | - [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0) 23 | - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). 24 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | _extends: maven-gh-actions-shared 19 | # Template is individual, because only major and minor version are used 20 | tag-template: maven-script-interpreter-$NEXT_MINOR_VERSION 21 | -------------------------------------------------------------------------------- /.github/workflows/maven-verify.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: Verify 19 | 20 | on: 21 | push: 22 | pull_request: 23 | 24 | jobs: 25 | build: 26 | name: Verify 27 | uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4 28 | -------------------------------------------------------------------------------- /.github/workflows/pr-automation.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: PR Automation 19 | on: 20 | pull_request_target: 21 | types: 22 | - closed 23 | 24 | jobs: 25 | pr-automation: 26 | name: PR Automation 27 | uses: apache/maven-gh-actions-shared/.github/workflows/pr-automation.yml@v4 28 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: Release Drafter 19 | on: 20 | push: 21 | branches: 22 | - master 23 | workflow_dispatch: 24 | 25 | jobs: 26 | update_release_draft: 27 | uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v4 28 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. 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, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: Stale 19 | 20 | on: 21 | schedule: 22 | - cron: '38 1 * * *' 23 | issue_comment: 24 | types: [ 'created' ] 25 | 26 | jobs: 27 | stale: 28 | uses: 'apache/maven-gh-actions-shared/.github/workflows/stale.yml@v4' 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .project 3 | .classpath 4 | .settings/ 5 | .svn/ 6 | bin/ 7 | # Intellij 8 | *.ipr 9 | *.iml 10 | .idea 11 | out/ 12 | .DS_Store 13 | /bootstrap 14 | /dependencies.xml 15 | .java-version 16 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | asfMavenTlpStdBuild() 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 17 | Contributing to [Apache Maven Script Interpreter](https://maven.apache.org/shared/maven-script-interpreter/) 18 | ====================== 19 | 20 | [![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven.svg?label=License)][license] 21 | [![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven.shared/maven-script-interpreter.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.maven.shared/maven-script-interpreter) 22 | [![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/apache/maven/shared/maven-script-interpreter/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-script-interpreter/README.md) 23 | [![Jenkins Status](https://img.shields.io/jenkins/s/https/ci-maven.apache.org/job/Maven/job/maven-box/job/maven-script-interpreter/job/master.svg)][build] 24 | [![Jenkins tests](https://img.shields.io/jenkins/t/https/ci-maven.apache.org/job/Maven/job/maven-box/job/maven-script-interpreter/job/master.svg)][test-results] 25 | 26 | 27 | You have found a bug, or you have an idea for a cool new feature? Contributing 28 | code is a great way to give something back to the open source community. Before 29 | you dig right into the code, there are a few guidelines that we need 30 | contributors to follow so that we can have a chance of keeping on top of 31 | things. 32 | 33 | Getting Started 34 | --------------- 35 | 36 | + Make sure you have a [GitHub account](https://github.com/signup/free). 37 | + If you're planning to implement a new feature, it makes sense to discuss your changes 38 | on the [dev list][ml-list] first. 39 | This way you can make sure you're not wasting your time on something that isn't 40 | considered to be in Apache Maven's scope. 41 | + Submit a ticket for your issue, assuming one does not already exist. 42 | + Clearly describe the issue, including steps to reproduce when it is a bug. 43 | + Make sure you fill in the earliest version that you know has the issue. 44 | + Fork the repository on GitHub. 45 | 46 | Making and Submitting Changes 47 | -------------- 48 | 49 | We accept Pull Requests via GitHub. The [developer mailing list][ml-list] is the 50 | main channel of communication for contributors. 51 | There are some guidelines which will make applying PRs easier for us: 52 | + Create a topic branch from where you want to base your work (this is usually the master branch). 53 | Push your changes to a topic branch in your fork of the repository. 54 | + Make commits of logical units. 55 | + Respect the original code style: by using the same [codestyle][code-style], 56 | patches should only highlight the actual difference, not being disturbed by any formatting issues: 57 | + Only use spaces for indentation. 58 | + Create minimal diffs - disable on save actions like reformat source code or organize imports. 59 | If you feel the source code should be reformatted, create a separate PR for this change. 60 | + Check for unnecessary whitespace with `git diff --check` before committing. 61 | + Make sure you have added the necessary tests (JUnit/IT) for your changes. 62 | + Run all the tests with `mvn -Prun-its verify` to assure nothing else was accidentally broken. 63 | + Submit a pull request to the repository in the Apache organization. 64 | 65 | If you plan to contribute on a regular basis, please consider filing a [contributor license agreement][cla]. 66 | 67 | Additional Resources 68 | -------------------- 69 | 70 | + [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch) 71 | + [Contributor License Agreement][cla] 72 | + [General GitHub documentation](https://help.github.com/) 73 | + [GitHub pull request documentation](https://help.github.com/send-pull-requests/) 74 | + [Apache Maven X Account](https://x.com/ASFMavenProject) 75 | + [Apache Maven Bluesky Account](https://bsky.app/profile/maven.apache.org) 76 | + [Apache Maven Mastodon Account](https://mastodon.social/deck/@ASFMavenProject@fosstodon.org) 77 | 78 | [license]: https://www.apache.org/licenses/LICENSE-2.0 79 | [ml-list]: https://maven.apache.org/mailing-lists.html 80 | [code-style]: https://maven.apache.org/developers/conventions/code.html 81 | [cla]: https://www.apache.org/licenses/#clas 82 | [maven-wiki]: https://cwiki.apache.org/confluence/display/MAVEN/Index 83 | [test-results]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-script-interpreter/job/master/lastCompletedBuild/testReport/ 84 | [build]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-script-interpreter/job/master/ 85 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 4.0.0 22 | 23 | org.apache.maven.shared 24 | maven-shared-components 25 | 42 26 | 27 | 28 | 29 | maven-script-interpreter 30 | 1.7-SNAPSHOT 31 | 32 | Apache Maven Script Interpreter 33 | This component provides some utilities to interpret/execute some scripts for various implementations: 34 | groovy or beanshell. 35 | 36 | 37 | scm:git:https://gitbox.apache.org/repos/asf/maven-script-interpreter.git 38 | scm:git:https://gitbox.apache.org/repos/asf/maven-script-interpreter.git 39 | HEAD 40 | https://github.com/apache/maven-script-interpreter/tree/${project.scm.tag} 41 | 42 | 43 | GitHub Issues 44 | https://github.com/apache/maven-script-interpreter/issues 45 | 46 | 47 | Jenkins 48 | https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-script-interpreter/ 49 | 50 | 51 | 52 | apache.website 53 | scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path} 54 | 55 | 56 | 57 | 58 | 2024-04-29T21:40:28Z 59 | 1.7.36 60 | 61 | 62 | 63 | 64 | commons-io 65 | commons-io 66 | 2.16.1 67 | 68 | 69 | 70 | org.apache.groovy 71 | groovy 72 | 4.0.21 73 | 74 | 75 | 76 | org.apache-extras.beanshell 77 | bsh 78 | 2.0b6 79 | 80 | 81 | 82 | org.slf4j 83 | slf4j-api 84 | ${slf4j.version} 85 | 86 | 87 | 88 | org.slf4j 89 | slf4j-simple 90 | ${slf4j.version} 91 | test 92 | 93 | 94 | 95 | org.junit.jupiter 96 | junit-jupiter-api 97 | test 98 | 99 | 100 | org.junit.jupiter 101 | junit-jupiter-params 102 | test 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | org.apache.maven.plugins 111 | maven-dependency-plugin 112 | 113 | 114 | 115 | copy 116 | 117 | generate-test-resources 118 | 119 | true 120 | 121 | 122 | com.github.tomakehurst 123 | wiremock-jre8-standalone 124 | 2.35.2 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.io.PrintStream; 24 | import java.io.UncheckedIOException; 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | import java.net.URLClassLoader; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | import bsh.Capabilities; 32 | import bsh.EvalError; 33 | import bsh.Interpreter; 34 | import bsh.TargetError; 35 | 36 | /** 37 | * Provides a facade to evaluate BeanShell scripts. 38 | * 39 | * @author Benjamin Bentmann 40 | */ 41 | class BeanShellScriptInterpreter implements ScriptInterpreter { 42 | 43 | private static class ChildFirstURLClassLoader extends URLClassLoader { 44 | ChildFirstURLClassLoader() { 45 | super(new URL[] {}, Thread.currentThread().getContextClassLoader()); 46 | } 47 | 48 | @Override 49 | public void addURL(URL url) { 50 | super.addURL(url); 51 | } 52 | 53 | @Override 54 | protected synchronized Class loadClass(final String name, final boolean resolve) 55 | throws ClassNotFoundException { 56 | 57 | Class c = findLoadedClass(name); 58 | if (c != null) { 59 | return c; 60 | } 61 | 62 | try { 63 | c = super.findClass(name); 64 | } catch (ClassNotFoundException e) { 65 | // ignore 66 | } 67 | 68 | if (c == null) { 69 | c = super.loadClass(name, resolve); 70 | } 71 | 72 | if (resolve) { 73 | resolveClass(c); 74 | } 75 | 76 | return c; 77 | } 78 | 79 | @Override 80 | public URL getResource(final String name) { 81 | URL url = findResource(name); 82 | return url != null ? url : super.getResource(name); 83 | } 84 | } 85 | 86 | private final ChildFirstURLClassLoader classLoader = new ChildFirstURLClassLoader(); 87 | 88 | @Override 89 | public void setClassPath(List classPath) { 90 | if (classPath == null || classPath.isEmpty()) { 91 | return; 92 | } 93 | 94 | classPath.stream().map(this::toUrl).forEach(classLoader::addURL); 95 | } 96 | 97 | private URL toUrl(String path) { 98 | try { 99 | return new File(path).toURI().toURL(); 100 | } catch (MalformedURLException e) { 101 | throw new UncheckedIOException(e); 102 | } 103 | } 104 | 105 | @Override 106 | public Object evaluateScript(String script, Map globalVariables, PrintStream scriptOutput) 107 | throws ScriptEvaluationException { 108 | PrintStream origOut = System.out; 109 | PrintStream origErr = System.err; 110 | 111 | try { 112 | Interpreter engine = new Interpreter(); 113 | 114 | if (scriptOutput != null) { 115 | System.setErr(scriptOutput); 116 | System.setOut(scriptOutput); 117 | engine.setErr(scriptOutput); 118 | engine.setOut(scriptOutput); 119 | } 120 | 121 | if (!Capabilities.haveAccessibility()) { 122 | try { 123 | Capabilities.setAccessibility(true); 124 | } catch (Exception e) { 125 | if (scriptOutput != null) { 126 | e.printStackTrace(scriptOutput); 127 | } 128 | } 129 | } 130 | 131 | engine.setClassLoader(classLoader); 132 | 133 | if (globalVariables != null) { 134 | for (Map.Entry entry : globalVariables.entrySet()) { 135 | try { 136 | engine.set(entry.getKey(), entry.getValue()); 137 | } catch (EvalError e) { 138 | throw new RuntimeException(e); 139 | } 140 | } 141 | } 142 | ClassLoader curentClassLoader = Thread.currentThread().getContextClassLoader(); 143 | try { 144 | Thread.currentThread().setContextClassLoader(classLoader); 145 | return engine.eval(script); 146 | } catch (TargetError e) { 147 | throw new ScriptEvaluationException(e.getTarget()); 148 | } catch (ThreadDeath e) { 149 | throw e; 150 | } catch (Throwable e) { 151 | throw new ScriptEvaluationException(e); 152 | } finally { 153 | Thread.currentThread().setContextClassLoader(curentClassLoader); 154 | } 155 | } finally { 156 | System.setErr(origErr); 157 | System.setOut(origOut); 158 | } 159 | } 160 | 161 | @Override 162 | public void close() throws IOException { 163 | classLoader.close(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ExecutionLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.PrintStream; 22 | 23 | /** 24 | *

ExecutionLogger interface.

25 | * 26 | * @author Olivier Lamy 27 | */ 28 | public interface ExecutionLogger { 29 | /** 30 | * The stream which will catch the output of the {@link org.apache.maven.shared.scriptinterpreter.ScriptRunner}. 31 | * 32 | * @return the output stream 33 | */ 34 | PrintStream getPrintStream(); 35 | 36 | /** 37 | * Consume logging from this component. 38 | * 39 | * @param line the line to consume 40 | */ 41 | void consumeLine(String line); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/FileLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | import java.io.PrintStream; 25 | import java.nio.file.Files; 26 | 27 | /** 28 | *

FileLogger class.

29 | */ 30 | public class FileLogger implements ExecutionLogger, AutoCloseable { 31 | 32 | /** 33 | * The path to the log file. 34 | */ 35 | private File file; 36 | 37 | /** 38 | * The underlying file stream this logger writes to. 39 | */ 40 | private PrintStream stream; 41 | 42 | /** 43 | * Creates a new logger that writes to the specified file. 44 | * 45 | * @param outputFile The path to the output file, if null all message will be discarded. 46 | * @throws java.io.IOException If the output file could not be created. 47 | */ 48 | public FileLogger(File outputFile) throws IOException { 49 | this(outputFile, null); 50 | } 51 | 52 | /** 53 | * Creates a new logger that writes to the specified file and optionally mirrors messages. 54 | * 55 | * @param outputFile The path to the output file, if null all message will be discarded. 56 | * @param mirrorHandler The class which handle mirrored message, can be null. 57 | * @throws java.io.IOException If the output file could not be created. 58 | */ 59 | public FileLogger(File outputFile, FileLoggerMirrorHandler mirrorHandler) throws IOException { 60 | this.file = outputFile; 61 | 62 | OutputStream outputStream; 63 | 64 | if (outputFile != null) { 65 | outputFile.getParentFile().mkdirs(); 66 | outputStream = Files.newOutputStream(outputFile.toPath()); 67 | } else { 68 | outputStream = new NullOutputStream(); 69 | } 70 | 71 | if (mirrorHandler != null) { 72 | stream = new PrintStream(new MirrorStreamWrapper(outputStream, mirrorHandler)); 73 | } else { 74 | stream = new PrintStream(outputStream); 75 | } 76 | } 77 | 78 | /** 79 | * Gets the path to the output file. 80 | * 81 | * @return The path to the output file, never null. 82 | */ 83 | public File getOutputFile() { 84 | return file; 85 | } 86 | 87 | /** 88 | * Gets the underlying stream used to write message to the log file. 89 | * 90 | * @return The underlying stream used to write message to the log file, never null. 91 | */ 92 | @Override 93 | public PrintStream getPrintStream() { 94 | return stream; 95 | } 96 | 97 | /** 98 | * Writes the specified line to the log file 99 | * and invoke {@link FileLoggerMirrorHandler#consumeOutput(String)} if is given. 100 | * 101 | * @param line The message to log. 102 | */ 103 | @Override 104 | public void consumeLine(String line) { 105 | stream.println(line); 106 | stream.flush(); 107 | } 108 | 109 | /** 110 | * Closes the underlying file stream. 111 | */ 112 | public void close() { 113 | if (stream != null) { 114 | stream.flush(); 115 | stream.close(); 116 | stream = null; 117 | } 118 | } 119 | 120 | private static class MirrorStreamWrapper extends OutputStream { 121 | private OutputStream out; 122 | 123 | private final FileLoggerMirrorHandler mirrorHandler; 124 | 125 | private StringBuilder lineBuffer; 126 | 127 | MirrorStreamWrapper(OutputStream outputStream, FileLoggerMirrorHandler mirrorHandler) { 128 | this.out = outputStream; 129 | this.mirrorHandler = mirrorHandler; 130 | this.lineBuffer = new StringBuilder(); 131 | } 132 | 133 | @Override 134 | public void write(int b) throws IOException { 135 | out.write(b); 136 | lineBuffer.append((char) (b)); 137 | } 138 | 139 | @Override 140 | public void write(byte[] b, int off, int len) throws IOException { 141 | out.write(b, off, len); 142 | lineBuffer.append(new String(b, off, len)); 143 | } 144 | 145 | @Override 146 | public void flush() throws IOException { 147 | out.flush(); 148 | 149 | int len = lineBuffer.length(); 150 | if (len == 0) { 151 | // nothing to log 152 | return; 153 | } 154 | 155 | // remove line end for log 156 | while (len > 0 && (lineBuffer.charAt(len - 1) == '\n' || lineBuffer.charAt(len - 1) == '\r')) { 157 | len--; 158 | } 159 | lineBuffer.setLength(len); 160 | 161 | mirrorHandler.consumeOutput(lineBuffer.toString()); 162 | 163 | // clear buffer 164 | lineBuffer = new StringBuilder(); 165 | } 166 | 167 | @Override 168 | public void close() throws IOException { 169 | flush(); 170 | if (out != null) { 171 | out.close(); 172 | out = null; 173 | } 174 | } 175 | } 176 | 177 | private static class NullOutputStream extends OutputStream { 178 | @Override 179 | public void write(int b) { 180 | // do nothing 181 | } 182 | 183 | @Override 184 | public void write(byte[] b, int off, int len) { 185 | // do nothing 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/FileLoggerMirrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | /** 22 | * Handle output form interpreter. 23 | * 24 | * @since 1.3 25 | */ 26 | public interface FileLoggerMirrorHandler { 27 | /** 28 | * Handle output message generated by script interpreter. 29 | * This method is invoked when flush occurs on the underlying stream. 30 | * 31 | * @param message last message 32 | */ 33 | void consumeOutput(String message); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/GroovyScriptInterpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.io.PrintStream; 24 | import java.io.UncheckedIOException; 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | import groovy.lang.Binding; 31 | import groovy.lang.GroovyShell; 32 | import org.codehaus.groovy.control.CompilerConfiguration; 33 | import org.codehaus.groovy.tools.RootLoader; 34 | 35 | /** 36 | * Provides a facade to evaluate Groovy scripts. 37 | * 38 | * @author Benjamin Bentmann 39 | */ 40 | class GroovyScriptInterpreter implements ScriptInterpreter { 41 | 42 | private final RootLoader childFirstLoader = 43 | new RootLoader(new URL[] {}, Thread.currentThread().getContextClassLoader()); 44 | 45 | @Override 46 | public void setClassPath(List classPath) { 47 | if (classPath == null || classPath.isEmpty()) { 48 | return; 49 | } 50 | 51 | classPath.stream().map(this::toUrl).forEach(childFirstLoader::addURL); 52 | } 53 | 54 | private URL toUrl(String path) { 55 | try { 56 | return new File(path).toURI().toURL(); 57 | } catch (MalformedURLException e) { 58 | throw new UncheckedIOException(e); 59 | } 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | public Object evaluateScript(String script, Map globalVariables, PrintStream scriptOutput) 67 | throws ScriptEvaluationException { 68 | PrintStream origOut = System.out; 69 | PrintStream origErr = System.err; 70 | 71 | ClassLoader curentClassLoader = Thread.currentThread().getContextClassLoader(); 72 | try { 73 | 74 | if (scriptOutput != null) { 75 | System.setErr(scriptOutput); 76 | System.setOut(scriptOutput); 77 | } 78 | 79 | GroovyShell interpreter = new GroovyShell( 80 | childFirstLoader, 81 | new Binding(globalVariables), 82 | new CompilerConfiguration(CompilerConfiguration.DEFAULT)); 83 | 84 | Thread.currentThread().setContextClassLoader(childFirstLoader); 85 | return interpreter.evaluate(script); 86 | } catch (Throwable e) { 87 | throw new ScriptEvaluationException(e); 88 | } finally { 89 | Thread.currentThread().setContextClassLoader(curentClassLoader); 90 | System.setErr(origErr); 91 | System.setOut(origOut); 92 | } 93 | } 94 | 95 | @Override 96 | public void close() throws IOException { 97 | childFirstLoader.close(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptEvaluationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | /** 22 | * Signals an error during parsing/evaluation of a script. This can either be a syntax error in the script itself or an 23 | * exception triggered by the methods it invoked. 24 | * 25 | * @author Benjamin Bentmann 26 | */ 27 | public class ScriptEvaluationException extends ScriptException { 28 | 29 | /** 30 | * The serial version identifier for this class. 31 | */ 32 | private static final long serialVersionUID = 199336743291078393L; 33 | 34 | /** 35 | * Creates a new exception with the specified cause. 36 | * 37 | * @param cause The cause, may be null. 38 | */ 39 | ScriptEvaluationException(Throwable cause) { 40 | super(cause); 41 | } 42 | 43 | /** 44 | * Creates a new exception with the specified message and cause. 45 | * 46 | * @param message The message, may be null. 47 | * @param cause The cause, may be null. 48 | * @since 1.3 49 | */ 50 | public ScriptEvaluationException(String message, Throwable cause) { 51 | super(message, cause); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | /** 22 | * Common errors during script running. 23 | * 24 | * @author Slawomir Jaranowski 25 | * @since 1.3 26 | */ 27 | public class ScriptException extends Exception { 28 | private static final long serialVersionUID = 4553276474852776472L; 29 | 30 | /** 31 | * Creates a new exception with the specified message and cause. 32 | * 33 | * @param message The message, may be null. 34 | * @param cause The cause, may be null. 35 | */ 36 | public ScriptException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | ScriptException(String message) { 41 | super(message); 42 | } 43 | 44 | ScriptException(Throwable cause) { 45 | super(cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptInterpreter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.Closeable; 22 | import java.io.PrintStream; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * Defines a simple abstraction used to plug-in several script interpreters for the pre-/post-build-hooks. Each 28 | * interpreter implementation should be stateless and support reuse. 29 | * 30 | * @author Benjamin Bentmann 31 | */ 32 | public interface ScriptInterpreter extends Closeable { 33 | 34 | /** 35 | * Set class path used by interpreted. 36 | * 37 | * @param classPath The additional class path for the script interpreter, may be null or empty if only 38 | * the plugin realm should be used for the script evaluation. If specified, this class path will 39 | * precede 40 | * the artifacts from the plugin class path. 41 | */ 42 | void setClassPath(List classPath); 43 | 44 | /** 45 | * Evaluates the specified script. 46 | * 47 | * @param script The script contents to evaluate, must not be null. 48 | * @param globalVariables The global variables (as a mapping from variable name to value) to define for the script, 49 | * may be null if not used. 50 | * @param scriptOutput A print stream to redirect any output from the script to, may be null to use 51 | * stdout/stderr. 52 | * @return The return value from the script, can be null 53 | * @throws ScriptEvaluationException If the script evaluation produced an error. 54 | */ 55 | Object evaluateScript(String script, Map globalVariables, PrintStream scriptOutput) 56 | throws ScriptEvaluationException; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptReturnException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | /** 22 | * Signals an invalid value returned from script execution. 23 | * 24 | * @author Slawomir Jaranowski 25 | * @since 1.3 26 | */ 27 | public class ScriptReturnException extends ScriptException { 28 | 29 | private static final long serialVersionUID = -4705573157701206786L; 30 | /** 31 | * Result 32 | */ 33 | private final Object result; 34 | 35 | /** 36 | * Creates a new exception with the specified message and result. 37 | * 38 | * @param message The message, may be null. 39 | * @param result The cause, may be null. 40 | */ 41 | ScriptReturnException(String message, Object result) { 42 | super(message); 43 | this.result = result; 44 | } 45 | 46 | /** 47 | * Retrieve result returned by script. 48 | * 49 | * @return script result. 50 | */ 51 | public Object getResult() { 52 | return result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/apache/maven/shared/scriptinterpreter/ScriptRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.Closeable; 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.io.PrintStream; 25 | import java.nio.file.Files; 26 | import java.util.HashMap; 27 | import java.util.LinkedHashMap; 28 | import java.util.List; 29 | import java.util.Locale; 30 | import java.util.Map; 31 | 32 | import org.apache.commons.io.FilenameUtils; 33 | import org.slf4j.Logger; 34 | import org.slf4j.LoggerFactory; 35 | 36 | /** 37 | * Runs pre-/post-build hook scripts. 38 | * 39 | * @author Benjamin Bentmann 40 | */ 41 | public class ScriptRunner implements Closeable { 42 | 43 | private static final Object LOCK = new Object(); 44 | 45 | private static final Logger LOG = LoggerFactory.getLogger(ScriptRunner.class); 46 | 47 | /** 48 | * The supported script interpreters, indexed by the lower-case file extension of their associated script files, 49 | * never null. 50 | */ 51 | private Map scriptInterpreters; 52 | 53 | /** 54 | * The common set of global variables to pass into the script interpreter, never null. 55 | */ 56 | private Map globalVariables; 57 | 58 | /** 59 | * The file encoding of the hook scripts or null to use platform encoding. 60 | */ 61 | private String encoding; 62 | 63 | /** 64 | * Creates a new script runner with BSH and Groovy interpreters. 65 | */ 66 | public ScriptRunner() { 67 | scriptInterpreters = new LinkedHashMap<>(); 68 | scriptInterpreters.put("bsh", new BeanShellScriptInterpreter()); 69 | scriptInterpreters.put("groovy", new GroovyScriptInterpreter()); 70 | globalVariables = new HashMap<>(); 71 | } 72 | 73 | /** 74 | * Add new script Interpreter 75 | * 76 | * @param id The Id of interpreter 77 | * @param scriptInterpreter the Script Interpreter implementation 78 | */ 79 | public void addScriptInterpreter(String id, ScriptInterpreter scriptInterpreter) { 80 | scriptInterpreters.put(id, scriptInterpreter); 81 | } 82 | 83 | /** 84 | * Sets a global variable for the script interpreter. 85 | * 86 | * @param name The name of the variable, must not be null. 87 | * @param value The value of the variable, may be null. 88 | */ 89 | public void setGlobalVariable(String name, Object value) { 90 | this.globalVariables.put(name, value); 91 | } 92 | 93 | /** 94 | * Sets the additional class path for the hook scripts. Note that the provided list is copied, so any later changes 95 | * will not affect the scripts. 96 | * 97 | * @param classPath The additional class path for the script interpreter, may be null or empty if only 98 | * the plugin realm should be used for the script evaluation. If specified, this class path will precede the 99 | * artifacts from the plugin class path. 100 | */ 101 | public void setClassPath(List classPath) { 102 | if (classPath != null && !classPath.isEmpty()) { 103 | scriptInterpreters.values().forEach(scriptInterpreter -> scriptInterpreter.setClassPath(classPath)); 104 | } 105 | } 106 | 107 | /** 108 | * Sets the file encoding of the hook scripts. 109 | * 110 | * @param encoding The file encoding of the hook scripts, may be null or empty to use the platform's 111 | * default encoding. 112 | */ 113 | public void setScriptEncoding(String encoding) { 114 | this.encoding = encoding != null && !encoding.isEmpty() ? encoding : null; 115 | } 116 | 117 | /** 118 | * Runs the specified hook script (after resolution). 119 | * 120 | * @param scriptDescription The description of the script to use for logging, must not be null. 121 | * @param basedir The base directory of the project, must not be null. 122 | * @param relativeScriptPath The path to the script relative to the project base directory, may be null 123 | * to skip the script execution and may not have extensions (resolution will search). 124 | * @param context The key-value storage used to share information between hook scripts, may be null. 125 | * @param logger The logger to redirect the script output to, may be null to use stdout/stderr. 126 | * @throws IOException If an I/O error occurred while reading the script file. 127 | * @throws ScriptException If the script did not return true of threw an exception. 128 | */ 129 | public void run( 130 | final String scriptDescription, 131 | final File basedir, 132 | final String relativeScriptPath, 133 | final Map context, 134 | final ExecutionLogger logger) 135 | throws IOException, ScriptException { 136 | if (relativeScriptPath == null) { 137 | LOG.debug("{}: relativeScriptPath is null, not executing script", scriptDescription); 138 | return; 139 | } 140 | 141 | final File scriptFile = resolveScript(new File(basedir, relativeScriptPath)); 142 | 143 | if (!scriptFile.exists()) { 144 | LOG.debug( 145 | "{} : no script '{}' found in directory {}", 146 | scriptDescription, 147 | relativeScriptPath, 148 | basedir.getAbsolutePath()); 149 | return; 150 | } 151 | 152 | LOG.info( 153 | "run {} {}.{}", 154 | scriptDescription, 155 | relativeScriptPath, 156 | FilenameUtils.getExtension(scriptFile.getAbsolutePath())); 157 | 158 | executeRun(scriptDescription, scriptFile, context, logger); 159 | } 160 | 161 | /** 162 | * Runs the specified hook script. 163 | * 164 | * @param scriptDescription The description of the script to use for logging, must not be null. 165 | * @param scriptFile The path to the script, may be null to skip the script execution. 166 | * @param context The key-value storage used to share information between hook scripts, may be null. 167 | * @param logger The logger to redirect the script output to, may be null to use stdout/stderr. 168 | * @throws IOException If an I/O error occurred while reading the script file. 169 | * @throws ScriptException If the script did not return true of threw an exception. 170 | */ 171 | public void run( 172 | final String scriptDescription, File scriptFile, final Map context, final ExecutionLogger logger) 173 | throws IOException, ScriptException { 174 | 175 | if (!scriptFile.exists()) { 176 | LOG.debug("{} : script file not found in directory {}", scriptDescription, scriptFile.getAbsolutePath()); 177 | return; 178 | } 179 | 180 | LOG.info("run {} {}", scriptDescription, scriptFile.getAbsolutePath()); 181 | 182 | executeRun(scriptDescription, scriptFile, context, logger); 183 | } 184 | 185 | private void executeRun( 186 | final String scriptDescription, File scriptFile, final Map context, final ExecutionLogger logger) 187 | throws IOException, ScriptException { 188 | ScriptInterpreter interpreter = getInterpreter(scriptFile); 189 | if (LOG.isDebugEnabled()) { 190 | String name = interpreter.getClass().getName(); 191 | name = name.substring(name.lastIndexOf('.') + 1); 192 | LOG.debug("Running script with {} :{}", name, scriptFile); 193 | } 194 | 195 | String script; 196 | try { 197 | byte[] bytes = Files.readAllBytes(scriptFile.toPath()); 198 | if (encoding != null) { 199 | script = new String(bytes, encoding); 200 | } else { 201 | script = new String(bytes); 202 | } 203 | } catch (IOException e) { 204 | String errorMessage = 205 | "error reading " + scriptDescription + " " + scriptFile.getPath() + ", " + e.getMessage(); 206 | throw new IOException(errorMessage, e); 207 | } 208 | 209 | Object result; 210 | try { 211 | if (logger != null) { 212 | logger.consumeLine("Running " + scriptDescription + ": " + scriptFile); 213 | } 214 | 215 | PrintStream out = (logger != null) ? logger.getPrintStream() : null; 216 | 217 | Map scriptVariables = new HashMap<>(this.globalVariables); 218 | scriptVariables.put("basedir", scriptFile.getParentFile()); 219 | scriptVariables.put("context", context); 220 | 221 | synchronized (LOCK) { 222 | result = interpreter.evaluateScript(script, scriptVariables, out); 223 | } 224 | if (logger != null) { 225 | logger.consumeLine("Finished " + scriptDescription + ": " + scriptFile); 226 | } 227 | } catch (ScriptEvaluationException e) { 228 | Throwable t = (e.getCause() != null) ? e.getCause() : e; 229 | if (logger != null) { 230 | t.printStackTrace(logger.getPrintStream()); 231 | } 232 | throw e; 233 | } 234 | 235 | if (!(result == null || Boolean.parseBoolean(String.valueOf(result)))) { 236 | throw new ScriptReturnException("The " + scriptDescription + " returned " + result + ".", result); 237 | } 238 | } 239 | 240 | /** 241 | * Gets the effective path to the specified script. For convenience, we allow to specify a script path as "verify" 242 | * and have the plugin auto-append the file extension to search for "verify.bsh" and "verify.groovy". 243 | * 244 | * @param scriptFile The script file to resolve, may be null. 245 | * @return The effective path to the script file or null if the input was null. 246 | */ 247 | private File resolveScript(File scriptFile) { 248 | if (scriptFile != null && !scriptFile.exists()) { 249 | for (String ext : this.scriptInterpreters.keySet()) { 250 | File candidateFile = new File(scriptFile.getPath() + '.' + ext); 251 | if (candidateFile.exists()) { 252 | scriptFile = candidateFile; 253 | break; 254 | } 255 | } 256 | } 257 | return scriptFile; 258 | } 259 | 260 | /** 261 | * Determines the script interpreter for the specified script file by looking at its file extension. In this 262 | * context, file extensions are considered case-insensitive. For backward compatibility with plugin versions 1.2-, 263 | * the BeanShell interpreter will be used for any unrecognized extension. 264 | * 265 | * @param scriptFile The script file for which to determine an interpreter, must not be null. 266 | * @return The script interpreter for the file, never null. 267 | */ 268 | private ScriptInterpreter getInterpreter(File scriptFile) { 269 | String ext = FilenameUtils.getExtension(scriptFile.getName()).toLowerCase(Locale.ENGLISH); 270 | ScriptInterpreter interpreter = scriptInterpreters.get(ext); 271 | if (interpreter == null) { 272 | interpreter = scriptInterpreters.get("bsh"); 273 | } 274 | return interpreter; 275 | } 276 | 277 | /** 278 | * Closes this script interpreter and releases any system resources associated with it. 279 | * 280 | * @throws IOException if an I/O error occurs. 281 | */ 282 | @Override 283 | public void close() throws IOException { 284 | for (ScriptInterpreter scriptInterpreter : scriptInterpreters.values()) { 285 | scriptInterpreter.close(); 286 | } 287 | scriptInterpreters.clear(); 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /src/site/apt/index.apt.vm: -------------------------------------------------------------------------------- 1 | ------ 2 | Introduction 3 | ------ 4 | Olivier Lamy 5 | ------ 6 | 2013-07-24 7 | ------ 8 | 9 | ~~ Licensed to the Apache Software Foundation (ASF) under one 10 | ~~ or more contributor license agreements. See the NOTICE file 11 | ~~ distributed with this work for additional information 12 | ~~ regarding copyright ownership. The ASF licenses this file 13 | ~~ to you under the Apache License, Version 2.0 (the 14 | ~~ "License"); you may not use this file except in compliance 15 | ~~ with the License. You may obtain a copy of the License at 16 | ~~ 17 | ~~ http://www.apache.org/licenses/LICENSE-2.0 18 | ~~ 19 | ~~ Unless required by applicable law or agreed to in writing, 20 | ~~ software distributed under the License is distributed on an 21 | ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 22 | ~~ KIND, either express or implied. See the License for the 23 | ~~ specific language governing permissions and limitations 24 | ~~ under the License. 25 | 26 | ~~ NOTE: For help with the syntax of this file, see: 27 | ~~ http://maven.apache.org/doxia/references/apt-format.html 28 | 29 | ${project.name} 30 | 31 | This component provides some utilities to interpret/execute some scripts for various implementations: groovy or beanshell. 32 | 33 | * Dependency declaration 34 | 35 | +--------- 36 | 37 | org.apache.maven.shared 38 | maven-script-interpreter 39 | ${project.version} 40 | 41 | +--------- 42 | 43 | <<>> has dependency only to core interpreters library, 44 | all specific extensions should be added in your project. 45 | 46 | For example, if you want to use {{{https://docs.groovy-lang.org/latest/html/documentation/grape.html}<>}} 47 | in a <> script, you must add a dependency to Ivy in your project or in the plugin that will invoke the script: 48 | 49 | +--------- 50 | 51 | org.apache.ivy 52 | ivy 53 | ... 54 | 55 | +--------- 56 | 57 | * Using ScriptRunner 58 | 59 | <<>> class will detect the script file to run based on supported extensions (<<<.bsh>>>, <<<.groovy>>>). 60 | 61 | This class will search in the provided directory the script with the provided fileName and the supported extensions. 62 | 63 | See {{{./apidocs/org/apache/maven/shared/scriptinterpreter/ScriptRunner.html}javadoc}} for <<>> methods. 64 | 65 | +--------- 66 | try (ScriptRunner scriptRunner = new ScriptRunner()) { 67 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "verify", buildContext(), 68 | new FileLogger(logFile)); 69 | } 70 | +--------- 71 | 72 | * Mirror output from script interpreter 73 | 74 | In order to do something more with script output, eg. log by your application you must implement <<>> 75 | 76 | +--------- 77 | class MyMirrorHandler implements FileLoggerMirrorHandler { 78 | void consumeOutput(String message) { 79 | // this method is invoked every time when flush occurs on the underlying stream. 80 | } 81 | } 82 | +--------- 83 | 84 | Now use it: 85 | 86 | +--------- 87 | try (ScriptRunner scriptRunner = new ScriptRunner()) { 88 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "verify", buildContext(), 89 | new FileLogger(logFile, new MyMirrorHandler())); 90 | } 91 | +--------- 92 | 93 | ** Global variables 94 | 95 | Your scripts will have by default two global variables: 96 | 97 | * <<>>: the base directory of your script 98 | 99 | * <<>>: the build context (see below) 100 | 101 | [] 102 | 103 | You can add more global variables as it. 104 | 105 | +--------- 106 | try (ScriptRunner scriptRunner = new ScriptRunner()) { 107 | scriptRunner.setGlobalVariable( name, value ); 108 | ... 109 | } 110 | +--------- 111 | 112 | ** Build context 113 | 114 | You can pass some values to your script using an execution context which have the type << context>>>: 115 | 116 | +--------- 117 | private Map buildContext() { 118 | Map context = new HashMap(); 119 | context.put("foo", "bar"); 120 | return context; 121 | } 122 | +--------- 123 | 124 | Then values are available in scripts context: 125 | 126 | +--------- 127 | // in your bsh script 128 | String value = context.get( "foo" ); 129 | +--------- 130 | 131 | value will be "bar" 132 | 133 | +--------- 134 | // in your Groovy script 135 | context.get("foo") 136 | +--------- 137 | 138 | ** Additional classpath entries 139 | 140 | You can add some additional classpath entries for your script execution 141 | 142 | +--------- 143 | List classpathEntries = list of jar paths 144 | 145 | try (ScriptRunner scriptRunner = new ScriptRunner()) { 146 | scriptRunner.setClassPath( classpathEntries ); 147 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "verify", buildContext(), 148 | new FileLogger(logFile)); 149 | } 150 | +--------- 151 | -------------------------------------------------------------------------------- /src/site/resources/download.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | # Just call the standard mirrors.cgi script. It will use download.html 21 | # as the input template. 22 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/site/xdoc/download.xml.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | Download ${project.name} Source 25 | 26 | 27 | 28 |
29 | 30 |

${project.name} ${project.version} is distributed in source format.

31 | 32 |

Use a source archive if you intend to build ${project.name} yourself.

33 | 34 |

Otherwise, simply use the ready-made binary artifacts from central repository.

35 | 36 |

${project.name} is distributed under the Apache License, version 2.0.

37 | 38 | 39 | 40 |

This is the current stable version of ${project.name}.

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
LinkChecksumSignature
${project.name} ${project.version} (Source zip)${project.artifactId}-${project.version}-source-release.zip${project.artifactId}-${project.version}-source-release.zip.sha512${project.artifactId}-${project.version}-source-release.zip.asc
60 | 61 |

It is essential that you verify the integrity of the downloaded file 62 | using the checksum (.sha512 file) 63 | or using the signature (.asc file) against the public KEYS used by the Apache Maven developers. 64 |

65 | 66 |
67 | 68 | 69 |

It is strongly recommended to use the latest release version of ${project.name} to take advantage of the newest features and bug fixes.

70 |

Older non-recommended releases can be found on our archive site.

71 |
72 |
73 | 74 |
75 | 76 | -------------------------------------------------------------------------------- /src/test-class-path/class-path.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | -------------------------------------------------------------------------------- /src/test/java/org/apache/maven/shared/scriptinterpreter/BeanShellScriptInterpreterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.PrintStream; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | import org.junit.jupiter.api.Test; 27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals; 29 | 30 | /** 31 | * Tests the BeanShell interpreter facade. 32 | * 33 | * @author Benjamin Bentmann 34 | */ 35 | class BeanShellScriptInterpreterTest { 36 | @Test 37 | void testEvaluateScript() throws Exception { 38 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 39 | try (ScriptInterpreter interpreter = new BeanShellScriptInterpreter()) { 40 | assertEquals( 41 | Boolean.TRUE, 42 | interpreter.evaluateScript("System.out.print(\"Test\"); return true;", null, new PrintStream(out))); 43 | } 44 | assertEquals("Test", out.toString()); 45 | } 46 | 47 | @Test 48 | void testEvaluateScriptVars() throws Exception { 49 | Map vars = new HashMap<>(); 50 | vars.put("testVar", "data"); 51 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 52 | try (ScriptInterpreter interpreter = new BeanShellScriptInterpreter()) { 53 | assertEquals( 54 | Boolean.TRUE, 55 | interpreter.evaluateScript("System.out.print(testVar); return true;", vars, new PrintStream(out))); 56 | } 57 | assertEquals("data", out.toString()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/org/apache/maven/shared/scriptinterpreter/FileLoggerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.nio.file.Files; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals; 28 | import static org.junit.jupiter.api.Assertions.assertNull; 29 | import static org.junit.jupiter.api.Assertions.assertTrue; 30 | 31 | /** 32 | * FileLoggerTest 33 | */ 34 | public class FileLoggerTest { 35 | 36 | public static final String EXPECTED_LOG = "Test1" + System.lineSeparator() + "Test2" + System.lineSeparator(); 37 | 38 | @Test 39 | public void nullOutputFileNoMirror() throws IOException { 40 | try (FileLogger fileLogger = new FileLogger(null)) { 41 | fileLogger.consumeLine("Test1"); 42 | fileLogger.getPrintStream().println("Test2"); 43 | fileLogger.getPrintStream().flush(); 44 | 45 | assertNull(fileLogger.getOutputFile()); 46 | } 47 | } 48 | 49 | @Test 50 | public void nullOutputFileWithMirror() throws IOException { 51 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 52 | 53 | try (FileLogger fileLogger = new FileLogger(null, mirrorHandler)) { 54 | fileLogger.consumeLine("Test1"); 55 | fileLogger.getPrintStream().println("Test2"); 56 | fileLogger.getPrintStream().flush(); 57 | 58 | assertNull(fileLogger.getOutputFile()); 59 | } 60 | 61 | assertEquals(EXPECTED_LOG, mirrorHandler.getLoggedMessage()); 62 | } 63 | 64 | @Test 65 | public void nullOutputFileWithMirrorWriteByte() throws IOException { 66 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 67 | 68 | try (FileLogger fileLogger = new FileLogger(null, mirrorHandler)) { 69 | fileLogger.getPrintStream().write('A'); 70 | fileLogger.getPrintStream().flush(); 71 | 72 | assertNull(fileLogger.getOutputFile()); 73 | } 74 | 75 | assertEquals("A" + System.lineSeparator(), mirrorHandler.getLoggedMessage()); 76 | } 77 | 78 | @Test 79 | public void outputFileNoMirror() throws IOException { 80 | File outputFile = new File("target/test.log"); 81 | if (outputFile.exists()) { 82 | outputFile.delete(); 83 | } 84 | 85 | try (FileLogger fileLogger = new FileLogger(outputFile)) { 86 | fileLogger.consumeLine("Test1"); 87 | fileLogger.getPrintStream().println("Test2"); 88 | fileLogger.getPrintStream().flush(); 89 | 90 | assertEquals(outputFile, fileLogger.getOutputFile()); 91 | } 92 | 93 | assertTrue(outputFile.exists()); 94 | assertEquals(EXPECTED_LOG, new String(Files.readAllBytes(outputFile.toPath()))); 95 | } 96 | 97 | @Test 98 | public void outputFileWithMirror() throws IOException { 99 | File outputFile = new File("target/test.log"); 100 | if (outputFile.exists()) { 101 | outputFile.delete(); 102 | } 103 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 104 | 105 | try (FileLogger fileLogger = new FileLogger(outputFile, mirrorHandler)) { 106 | fileLogger.consumeLine("Test1"); 107 | fileLogger.getPrintStream().println("Test2"); 108 | fileLogger.getPrintStream().flush(); 109 | 110 | assertEquals(outputFile, fileLogger.getOutputFile()); 111 | } 112 | 113 | assertEquals(EXPECTED_LOG, mirrorHandler.getLoggedMessage()); 114 | 115 | assertTrue(outputFile.exists()); 116 | assertEquals(EXPECTED_LOG, new String(Files.readAllBytes(outputFile.toPath()))); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/test/java/org/apache/maven/shared/scriptinterpreter/GroovyScriptInterpreterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.ByteArrayOutputStream; 22 | import java.io.File; 23 | import java.io.PrintStream; 24 | import java.util.Collections; 25 | import java.util.HashMap; 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | import org.junit.jupiter.api.Test; 30 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; 32 | 33 | /** 34 | * Tests the Groovy interpreter facade. 35 | * 36 | * @author Benjamin Bentmann 37 | */ 38 | class GroovyScriptInterpreterTest { 39 | @Test 40 | void testEvaluateScript() throws Exception { 41 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 42 | try (ScriptInterpreter interpreter = new GroovyScriptInterpreter()) { 43 | assertEquals( 44 | Boolean.TRUE, 45 | interpreter.evaluateScript("print \"Test\"\nreturn true", null, new PrintStream(out))); 46 | } 47 | assertEquals("Test", out.toString()); 48 | } 49 | 50 | @Test 51 | void testEvaluateScriptWithDefaultClassPath() throws Exception { 52 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 53 | try (ScriptInterpreter interpreter = new GroovyScriptInterpreter()) { 54 | assertEquals( 55 | Boolean.TRUE, 56 | interpreter.evaluateScript( 57 | "print getClass().getResource( \"/class-path.txt\" ).getPath().toURI().getPath()\nreturn true", 58 | null, 59 | new PrintStream(out))); 60 | } 61 | 62 | String testClassPath = 63 | new File("target/test-classes/class-path.txt").toURI().getPath(); 64 | assertEquals(testClassPath, out.toString()); 65 | } 66 | 67 | @Test 68 | void testEvaluateScriptWithCustomClassPath() throws Exception { 69 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 70 | try (ScriptInterpreter interpreter = new GroovyScriptInterpreter()) { 71 | 72 | List classPath = Collections.singletonList(new File("src/test-class-path").getAbsolutePath()); 73 | interpreter.setClassPath(classPath); 74 | 75 | assertEquals( 76 | Boolean.TRUE, 77 | interpreter.evaluateScript( 78 | "print getClass().getResource( \"/class-path.txt\" ).getPath().toURI().getPath()\nreturn true", 79 | null, 80 | new PrintStream(out))); 81 | } 82 | 83 | String testClassPath = 84 | new File("src/test-class-path/class-path.txt").toURI().getPath(); 85 | assertEquals(testClassPath, out.toString()); 86 | } 87 | 88 | @Test 89 | void testEvaluateScriptVars() throws Exception { 90 | Map vars = new HashMap<>(); 91 | vars.put("testVar", "data"); 92 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 93 | try (ScriptInterpreter interpreter = new GroovyScriptInterpreter()) { 94 | assertEquals( 95 | Boolean.TRUE, interpreter.evaluateScript("print testVar\nreturn true", vars, new PrintStream(out))); 96 | } 97 | assertEquals("data", out.toString()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/org/apache/maven/shared/scriptinterpreter/ScriptRunnerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | import java.io.File; 22 | import java.nio.file.Files; 23 | import java.util.Collections; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | import org.junit.jupiter.api.Test; 28 | import org.junit.jupiter.api.io.TempDir; 29 | import org.junit.jupiter.params.ParameterizedTest; 30 | import org.junit.jupiter.params.provider.ValueSource; 31 | 32 | import static org.junit.jupiter.api.Assertions.assertEquals; 33 | import static org.junit.jupiter.api.Assertions.assertNotNull; 34 | import static org.junit.jupiter.api.Assertions.assertTrue; 35 | 36 | /** 37 | * @author Olivier Lamy 38 | */ 39 | public class ScriptRunnerTest { 40 | 41 | @TempDir 42 | private File tempDir; 43 | 44 | @Test 45 | public void testBeanshell() throws Exception { 46 | File logFile = new File(tempDir, "build.log"); 47 | 48 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 49 | 50 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 51 | ScriptRunner scriptRunner = new ScriptRunner()) { 52 | scriptRunner.setGlobalVariable("globalVar", "Yeah baby it's rocks"); 53 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "verify", buildContext(), fileLogger); 54 | } 55 | 56 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 57 | assertTrue(logContent.contains(new File("src/test/resources/bsh-test/verify.bsh").getPath())); 58 | assertTrue(logContent.contains("foo=bar")); 59 | assertTrue(logContent.contains("globalVar=Yeah baby it's rocks")); 60 | 61 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 62 | } 63 | 64 | @Test 65 | public void beanshellReturnedNullShouldBeOk() throws Exception { 66 | File logFile = new File(tempDir, "build.log"); 67 | 68 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 69 | 70 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 71 | ScriptRunner scriptRunner = new ScriptRunner()) { 72 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "return-null", null, fileLogger); 73 | } 74 | 75 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 76 | assertTrue(logContent.contains(new File("src/test/resources/bsh-test/return-null.bsh").getPath())); 77 | assertTrue(logContent.contains("ok with null result")); 78 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 79 | } 80 | 81 | @Test 82 | public void failedBeanshellShouldCreateProperLogsMessage() throws Exception { 83 | File logFile = new File(tempDir, "build.log"); 84 | 85 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 86 | 87 | Exception catchedException = null; 88 | 89 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 90 | ScriptRunner scriptRunner = new ScriptRunner()) { 91 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "failed", buildContext(), fileLogger); 92 | } catch (ScriptEvaluationException e) { 93 | catchedException = e; 94 | } 95 | 96 | assertNotNull(catchedException); 97 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 98 | assertTrue(logContent.contains(new File("src/test/resources/bsh-test/failed.bsh").getPath())); 99 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 100 | } 101 | 102 | @Test 103 | public void beanshellReturnedNotTrueShouldThrowException() throws Exception { 104 | File logFile = new File(tempDir, "build.log"); 105 | 106 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 107 | 108 | ScriptReturnException catchedException = null; 109 | 110 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 111 | ScriptRunner scriptRunner = new ScriptRunner()) { 112 | scriptRunner.run("test", new File("src/test/resources/bsh-test"), "return-not-true", null, fileLogger); 113 | } catch (ScriptReturnException e) { 114 | catchedException = e; 115 | } 116 | 117 | assertEquals("Not true value", catchedException.getResult()); 118 | assertEquals("The test returned Not true value.", catchedException.getMessage()); 119 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 120 | assertTrue(logContent.contains(new File("src/test/resources/bsh-test/return-not-true.bsh").getPath())); 121 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 122 | } 123 | 124 | @Test 125 | public void testBeanshellWithFile() throws Exception { 126 | File logFile = new File(tempDir, "build.log"); 127 | 128 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 129 | 130 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 131 | ScriptRunner scriptRunner = new ScriptRunner()) { 132 | scriptRunner.setGlobalVariable("globalVar", "Yeah baby it's rocks"); 133 | scriptRunner.run("test", new File("src/test/resources/bsh-test/verify.bsh"), buildContext(), fileLogger); 134 | } 135 | 136 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 137 | assertTrue(logContent.contains(new File("src/test/resources/bsh-test/verify.bsh").getPath())); 138 | assertTrue(logContent.contains("foo=bar")); 139 | 140 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 141 | } 142 | 143 | @Test 144 | public void testGroovy() throws Exception { 145 | File logFile = new File(tempDir, "build.log"); 146 | 147 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 148 | 149 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 150 | ScriptRunner scriptRunner = new ScriptRunner()) { 151 | scriptRunner.setGlobalVariable("globalVar", "Yeah baby it's rocks"); 152 | scriptRunner.run("test", new File("src/test/resources/groovy-test"), "verify", buildContext(), fileLogger); 153 | } 154 | 155 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 156 | assertTrue(logContent.contains(new File("src/test/resources/groovy-test/verify.groovy").getPath())); 157 | assertTrue(logContent.contains("foo=bar")); 158 | assertTrue(logContent.contains("globalVar=Yeah baby it's rocks")); 159 | 160 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 161 | } 162 | 163 | @Test 164 | public void groovyReturnedNullShouldBeOk() throws Exception { 165 | File logFile = new File(tempDir, "build.log"); 166 | 167 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 168 | 169 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 170 | ScriptRunner scriptRunner = new ScriptRunner()) { 171 | scriptRunner.setGlobalVariable("globalVar", "Yeah baby it's rocks"); 172 | scriptRunner.run("test", new File("src/test/resources/groovy-test"), "return-null", null, fileLogger); 173 | } 174 | 175 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 176 | assertTrue(logContent.contains(new File("src/test/resources/groovy-test/return-null.groovy").getPath())); 177 | assertTrue(logContent.contains("ok with null result")); 178 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 179 | } 180 | 181 | @Test 182 | public void failedGroovyShouldCreateProperLogsMessage() throws Exception { 183 | File logFile = new File(tempDir, "build.log"); 184 | 185 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 186 | 187 | Exception catchedException = null; 188 | 189 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 190 | ScriptRunner scriptRunner = new ScriptRunner()) { 191 | scriptRunner.run("test", new File("src/test/resources/groovy-test"), "failed", buildContext(), fileLogger); 192 | } catch (ScriptEvaluationException e) { 193 | catchedException = e; 194 | } 195 | 196 | assertNotNull(catchedException); 197 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 198 | assertTrue(logContent.contains(new File("src/test/resources/groovy-test/failed.groovy").getPath())); 199 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 200 | } 201 | 202 | @Test 203 | public void groovyReturnedFalseShouldThrowException() throws Exception { 204 | File logFile = new File(tempDir, "build.log"); 205 | 206 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 207 | 208 | ScriptReturnException catchedException = null; 209 | 210 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 211 | ScriptRunner scriptRunner = new ScriptRunner()) { 212 | scriptRunner.run( 213 | "test", new File("src/test/resources/groovy-test"), "return-false", buildContext(), fileLogger); 214 | } catch (ScriptReturnException e) { 215 | catchedException = e; 216 | } 217 | 218 | assertEquals(false, catchedException.getResult()); 219 | assertEquals("The test returned false.", catchedException.getMessage()); 220 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 221 | assertTrue(logContent.contains(new File("src/test/resources/groovy-test/return-false.groovy").getPath())); 222 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 223 | } 224 | 225 | @Test 226 | public void testGroovyWithFile() throws Exception { 227 | File logFile = new File(tempDir, "build.log"); 228 | 229 | TestMirrorHandler mirrorHandler = new TestMirrorHandler(); 230 | 231 | try (FileLogger fileLogger = new FileLogger(logFile, mirrorHandler); 232 | ScriptRunner scriptRunner = new ScriptRunner()) { 233 | scriptRunner.run( 234 | "test", new File("src/test/resources/groovy-test/verify.groovy"), buildContext(), fileLogger); 235 | } 236 | 237 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 238 | assertTrue(logContent.contains(new File("src/test/resources/groovy-test/verify.groovy").getPath())); 239 | assertTrue(logContent.contains("foo=bar")); 240 | 241 | assertEquals(logContent, mirrorHandler.getLoggedMessage()); 242 | } 243 | 244 | @ValueSource(strings = {"bsh", "groovy"}) 245 | @ParameterizedTest 246 | void theSameClassloaderShouldBeUsed(String scriptType) throws Exception { 247 | 248 | Map context = buildContext(); 249 | File logFile = new File(tempDir, "build.log"); 250 | File basedir = new File(String.format("target/test-classes/%s-test", scriptType)); 251 | 252 | try (FileLogger logger = new FileLogger(logFile); 253 | ScriptRunner scriptRunner = new ScriptRunner()) { 254 | scriptRunner.setClassPath(Collections.singletonList("target/dependency/wiremock-jre8-standalone.jar")); 255 | 256 | scriptRunner.run("test classpath 1", basedir, "class-path1", context, logger); 257 | assertNotNull(context.get("wireMockServer")); 258 | 259 | scriptRunner.run("test classpath 2", basedir, "class-path2", context, logger); 260 | } 261 | 262 | String logContent = new String(Files.readAllBytes(logFile.toPath())); 263 | assertTrue(logContent.contains("wireMockServer started with port=")); 264 | assertTrue(logContent.contains("wireMockServer stopped")); 265 | } 266 | 267 | private Map buildContext() { 268 | Map context = new HashMap<>(); 269 | context.put("foo", "bar"); 270 | return context; 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /src/test/java/org/apache/maven/shared/scriptinterpreter/TestMirrorHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.maven.shared.scriptinterpreter; 20 | 21 | /** 22 | * Implementing {@link FileLoggerMirrorHandler} for testing 23 | */ 24 | class TestMirrorHandler implements FileLoggerMirrorHandler { 25 | 26 | private StringBuilder loggedMessage; 27 | 28 | public TestMirrorHandler() { 29 | loggedMessage = new StringBuilder(); 30 | } 31 | 32 | public String getLoggedMessage() { 33 | return loggedMessage.toString(); 34 | } 35 | 36 | @Override 37 | public void consumeOutput(String message) { 38 | loggedMessage.append(message); 39 | loggedMessage.append(System.lineSeparator()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/class-path1.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import com.github.tomakehurst.wiremock.WireMockServer; 21 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 22 | 23 | 24 | WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort().dynamicHttpsPort()); 25 | wireMockServer.start(); 26 | 27 | System.out.println("wireMockServer started with port=" + wireMockServer.port()); 28 | 29 | context.put("wireMockServer", wireMockServer); 30 | 31 | return true; 32 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/class-path2.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import com.github.tomakehurst.wiremock.WireMockServer; 21 | 22 | WireMockServer wireMockServer = context.get("wireMockServer"); 23 | wireMockServer.stop(); 24 | 25 | System.out.println("wireMockServer stopped"); 26 | 27 | return true; 28 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/failed.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | throw new Exception( "test exception" ) 21 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/return-not-true.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | return "Not true value" 21 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/return-null.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | System.out.print("ok with null result"); 21 | -------------------------------------------------------------------------------- /src/test/resources/bsh-test/verify.bsh: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import java.io.*; 21 | 22 | if ( !( basedir instanceof File ) ) 23 | { 24 | System.out.println( "Global script variable not defined: basedir or not a File" ); 25 | throw new RuntimeException("Global script variable not defined: basedir or not a File"); 26 | } 27 | 28 | if ( !( context instanceof Map ) ) 29 | { 30 | System.out.println( "Global script variable not defined: context or not a Map" ); 31 | throw new RuntimeException("Global script variable not defined: context or not a Map"); 32 | } 33 | 34 | File file = new File( basedir, "verify.bsh"); 35 | if ( !file.exists()) 36 | { 37 | throw new FileNotFoundException("verify.bsh not found in " + basedir); 38 | } 39 | 40 | String value = context.get( "foo" ); 41 | System.out.println("foo="+value); 42 | 43 | System.out.println("globalVar="+globalVar); 44 | 45 | System.out.print("Test"); 46 | return true; 47 | -------------------------------------------------------------------------------- /src/test/resources/class-path.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/class-path1.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import com.github.tomakehurst.wiremock.WireMockServer 21 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration 22 | 23 | WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort().dynamicHttpsPort()) 24 | wireMockServer.start() 25 | 26 | println("wireMockServer started with port=" + wireMockServer.port()) 27 | 28 | context.put("wireMockServer", wireMockServer) 29 | 30 | return true 31 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/class-path2.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import com.github.tomakehurst.wiremock.WireMockServer; 21 | 22 | WireMockServer wireMockServer = context.get("wireMockServer") 23 | wireMockServer.stop() 24 | 25 | println("wireMockServer stopped") 26 | 27 | return true 28 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/failed.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | def message = 'no Te Message' 22 | 23 | assert message.contains('Test Message') 24 | 25 | return true 26 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/return-false.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | return false 22 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/return-null.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | println 'ok with null result' 21 | -------------------------------------------------------------------------------- /src/test/resources/groovy-test/verify.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | if ( !( basedir instanceof File ) ) 21 | { 22 | println "Global script variable not defined: basedir or not a File" 23 | throw new RuntimeException("Global script variable not defined: basedir or not a File"); 24 | } 25 | def verify = new File( basedir, "verify.groovy" ) 26 | assert (verify.exists()) 27 | 28 | if ( !( context instanceof Map ) ) 29 | { 30 | println "Global script variable not defined: context or not a Map" 31 | throw new RuntimeException("Global script variable not defined: context or not a Map"); 32 | } 33 | 34 | System.out.println("foo="+context.get("foo")); 35 | 36 | if (binding.variables.containsKey("globalVar")) System.out.println("globalVar="+globalVar); 37 | 38 | return true 39 | --------------------------------------------------------------------------------