├── docs
├── modules
│ └── ROOT
│ │ ├── nav.adoc
│ │ └── partials
│ │ └── nav.adoc
├── antora.yml
└── readme2index.java
├── src
├── it
│ ├── script
│ │ ├── hello.java
│ │ ├── verify.groovy
│ │ └── pom.xml
│ ├── skip
│ │ ├── hello.java
│ │ ├── verify.groovy
│ │ └── pom.xml
│ ├── script-with-args
│ │ ├── hello.java
│ │ ├── verify.groovy
│ │ └── pom.xml
│ ├── script-with-jbang-args
│ │ ├── hello.java
│ │ ├── verify.groovy
│ │ └── pom.xml
│ ├── script-with-trust
│ │ ├── verify.groovy
│ │ └── pom.xml
│ └── settings.xml
└── main
│ ├── resources
│ └── META-INF
│ │ └── m2e
│ │ └── lifecycle-mapping-metadata.xml
│ └── java
│ └── dev
│ └── jbang
│ └── RunMojo.java
├── .gitignore
├── RELEASE.md
├── .mvn
└── wrapper
│ └── maven-wrapper.properties
├── LICENSE
├── .github
└── workflows
│ └── ci.yml
├── README.adoc
├── README.md
├── mvnw.cmd
├── pom.xml
└── mvnw
/docs/modules/ROOT/nav.adoc:
--------------------------------------------------------------------------------
1 | include::partial$nav.adoc[]
2 |
--------------------------------------------------------------------------------
/docs/modules/ROOT/partials/nav.adoc:
--------------------------------------------------------------------------------
1 | * xref:jbang-maven-plugin:ROOT:index.adoc[]
2 |
--------------------------------------------------------------------------------
/src/it/script/hello.java:
--------------------------------------------------------------------------------
1 | class hello {
2 |
3 | public static void main(String... args) throws Exception {
4 | System.out.println("HELLO WORLD!");
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/src/it/skip/hello.java:
--------------------------------------------------------------------------------
1 | class hello {
2 |
3 | public static void main(String... args) throws Exception {
4 | System.out.println("HELLO WORLD!");
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/src/it/script-with-args/hello.java:
--------------------------------------------------------------------------------
1 | class hello {
2 |
3 | public static void main(String... args) throws Exception {
4 | System.out.println("HELLO WORLD! " + java.util.Arrays.asList(args));
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .vscode
4 | .settings
5 | target
6 | .idea
7 | *.iml
8 | build
9 | .gradle
10 | .factorypath
11 | bin
12 | homebrew-tap
13 | RESULTS
14 | *.db
15 | jbang-action
16 | out
17 | modules/ROOT/pages/index.adoc
18 |
--------------------------------------------------------------------------------
/src/it/script/verify.groovy:
--------------------------------------------------------------------------------
1 | import java.nio.file.Files
2 | import java.nio.file.Path
3 | import java.nio.file.Paths
4 |
5 | Path path = Paths.get(basedir.toString(), "build.log" );
6 | assert new String(Files.readAllBytes(path)).contains("HELLO WORLD")
7 |
--------------------------------------------------------------------------------
/src/it/script-with-args/verify.groovy:
--------------------------------------------------------------------------------
1 | import java.nio.file.Files
2 | import java.nio.file.Path
3 | import java.nio.file.Paths
4 |
5 | Path path = Paths.get(basedir.toString(), "build.log" );
6 | assert new String(Files.readAllBytes(path)).contains("--option1=foo")
7 |
--------------------------------------------------------------------------------
/src/it/skip/verify.groovy:
--------------------------------------------------------------------------------
1 | import java.nio.file.Files
2 | import java.nio.file.Path
3 | import java.nio.file.Paths
4 |
5 | Path path = Paths.get(basedir.toString(), "build.log" );
6 | assert new String(Files.readAllBytes(path)).contains("Skipping plugin execution")
7 |
--------------------------------------------------------------------------------
/src/it/script-with-jbang-args/hello.java:
--------------------------------------------------------------------------------
1 | class hello {
2 |
3 | public static void main(String... args) throws Exception {
4 | System.out.println("HELLO WORLD! " + java.util.Arrays.asList(args));
5 | System.out.println("foo => " + System.getProperty("foo"));
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/it/script-with-jbang-args/verify.groovy:
--------------------------------------------------------------------------------
1 | import java.nio.file.Files
2 | import java.nio.file.Path
3 | import java.nio.file.Paths
4 |
5 | Path path = Paths.get(basedir.toString(), "build.log" );
6 | def logs = new String(Files.readAllBytes(path))
7 | assert logs.contains("--option1=foo")
8 | assert logs.contains("foo => bar")
--------------------------------------------------------------------------------
/docs/antora.yml:
--------------------------------------------------------------------------------
1 | name: jbang-maven-plugin
2 | title: JBang Maven Plugin
3 | version: latest
4 | nav:
5 | - modules/ROOT/nav.adoc
6 | ext:
7 | collector:
8 | - run: jbang docs/readme2index.java
9 | - scan:
10 | dir: build/content/pages
11 | files: index.adoc
12 | into: modules/ROOT/pages
13 |
14 |
--------------------------------------------------------------------------------
/RELEASE.md:
--------------------------------------------------------------------------------
1 | ## How to release
2 |
3 | This should get automated in github actions but until then:
4 |
5 | ```
6 | mvn versions:set -DnewVersion=0.0.x
7 | git commit -m 'release 0.0.x' -a
8 | git tag v0.0.x
9 | mvn clean verify
10 | mvn -Drelease deploy
11 | mvn versions:set -DnewVersion=0.0.x+1-SNAPSHOT
12 | git commit -m '0.0.x+1-SNAPSHOT'
13 | ```
14 |
--------------------------------------------------------------------------------
/src/it/script-with-trust/verify.groovy:
--------------------------------------------------------------------------------
1 | import java.nio.charset.Charset
2 | import java.nio.file.Files
3 | import java.nio.file.Path
4 | import java.nio.file.Paths
5 |
6 | Path path = Paths.get(basedir.toString(), "build.log" );
7 | assert new String(Files.readAllBytes(path)).contains(Locale.getDefault().getLanguage() + "." + Charset.defaultCharset().displayName())
8 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | run
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/readme2index.java:
--------------------------------------------------------------------------------
1 | ///usr/bin/env jbang "$0" "$@" ; exit $?
2 |
3 | import static java.nio.file.Files.copy;
4 | import static java.nio.file.Files.createDirectories;
5 | import java.nio.file.StandardCopyOption;
6 | import java.nio.file.Paths;
7 |
8 | import static java.lang.System.*;
9 |
10 | public class readme2index {
11 |
12 | public static void main(String... args) throws Exception {
13 | var target = Paths.get("build/content/pages/index.adoc");
14 | createDirectories(target.getParent());
15 | copy(Paths.get("README.adoc"),target,StandardCopyOption.REPLACE_EXISTING);
16 | out.println("README.adoc copied to " + target);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/it/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | it-repo
8 |
9 | true
10 |
11 |
12 |
13 | local.central
14 | @localRepositoryUrl@
15 |
16 | true
17 |
18 |
19 | true
20 |
21 |
22 |
23 |
24 |
25 | local.central
26 | @localRepositoryUrl@
27 |
28 | true
29 |
30 |
31 | true
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
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 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
18 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Max Rydahl Andersen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/it/script/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | dev.jbang.it
7 | simple-it
8 | 1.0-SNAPSHOT
9 |
10 | A simple IT verifying the basic use case.
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 |
18 |
19 | @project.groupId@
20 | @project.artifactId@
21 | @project.version@
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/it/skip/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | dev.jbang.it
7 | simple-it
8 | 1.0-SNAPSHOT
9 |
10 | A simple IT verifying the basic use case.
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 |
18 |
19 | @project.groupId@
20 | @project.artifactId@
21 | @project.version@
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 | true
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/it/script-with-args/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | dev.jbang.it
7 | simple-it
8 | 1.0-SNAPSHOT
9 |
10 | A simple IT verifying the basic use case.
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 |
18 |
19 | @project.groupId@
20 | @project.artifactId@
21 | @project.version@
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 |
32 | --option1=foo
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/it/script-with-trust/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | dev.jbang.it
7 | simple-it
8 | 1.0-SNAPSHOT
9 |
10 | A simple IT verifying the basic use case.
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 |
18 |
19 | @project.groupId@
20 | @project.artifactId@
21 | @project.version@
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 |
32 | https://github.com
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: JBang CI
5 |
6 | on:
7 | push:
8 | branches: [ main ]
9 | pull_request:
10 | branches: [ main ]
11 |
12 | jobs:
13 | build:
14 | strategy:
15 | fail-fast: true
16 | matrix:
17 | java: [ 8, 11 ]
18 | os: [ ubuntu-latest, windows-latest ]
19 | runs-on: ${{ matrix.os }}
20 |
21 | steps:
22 | - uses: actions/checkout@v4
23 |
24 | - name: Cache local Maven repository
25 | uses: actions/cache@v4
26 | with:
27 | path: ~/.m2/repository
28 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
29 | restore-keys: |
30 | ${{ runner.os }}-maven-
31 | - name: Set up JDK ${{ matrix.java }}
32 | uses: joschi/setup-jdk@v2
33 | with:
34 | java-version: ${{ matrix.java }}
35 |
36 | - name: Build with Maven
37 | run: ./mvnw --no-transfer-progress verify
38 |
39 |
40 | deploy:
41 | needs: build
42 | runs-on: ubuntu-latest
43 | steps:
44 |
45 | - uses: actions/checkout@v4
46 | - name: Set up Java/Maven
47 | uses: actions/setup-java@v1
48 | with:
49 | java-version: 1.8
50 | server-id: ossrh
51 | server-username: MAVEN_USERNAME
52 | server-password: MAVEN_PASSWORD
53 |
54 | - name: Publish
55 | if: github.ref == 'refs/heads/main'
56 | run: ./mvnw -B -Pgpg-sign deploy
57 | env:
58 | MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
59 | MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
60 |
--------------------------------------------------------------------------------
/src/it/script-with-jbang-args/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | dev.jbang.it
7 | simple-it
8 | 1.0-SNAPSHOT
9 |
10 | A simple IT verifying the basic use case.
11 |
12 |
13 | UTF-8
14 |
15 |
16 |
17 |
18 |
19 | @project.groupId@
20 | @project.artifactId@
21 | @project.version@
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 | -Dfoo=bar
32 |
33 |
34 |
35 | --option1=foo
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = JBang Maven Plugin
2 |
3 | image:https://img.shields.io/github/actions/workflow/status/jbangdev/jbang-maven-plugin/ci.yml?style=for-the-badge[GitHub Workflow Status]
4 | image:https://img.shields.io/maven-central/v/dev.jbang/jbang-maven-plugin.svg?label=Maven-Central&style=for-the-badge[Maven Central,link=https://search.maven.org/search?q=g:%22dev.jbang%22%20AND%20a:%22jbang-maven-plugin%22]
5 |
6 | The JBang Maven plugin allows JBang scripts to be executed during a Maven build, or through `mvn` command-line (without pom file).
7 |
8 | The plugin attempts to use an existing JBang installation. If no JBang installation is found, the plugin will install JBang by downloading and caching the latest version binaries (by default in your Maven project directory) for subsequent runs.
9 |
10 | == Arguments
11 |
12 | * `script`: The script to be executed by JBang
13 |
14 | === Example
15 |
16 | From inside a Maven buid:
17 | [source,xml]
18 | ----
19 |
20 | dev.jbang
21 | jbang-maven-plugin
22 | 0.0.7
23 |
24 |
25 | run
26 | process-resources
27 |
28 | run
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | ----
37 |
38 | Or with command-line `$ mvn dev.jbang:jbang-maven-plugin:0.0.8:run -Djbang.script="helloworld/helloworld.java"`.
39 |
40 | * `args`: The arguments to be used in the JBang script (if any)
41 |
42 | === Example
43 |
44 | [source,xml]
45 | ----
46 |
47 | dev.jbang
48 | jbang-maven-plugin
49 | 0.0.7
50 |
51 |
52 | run
53 | process-resources
54 |
55 | run
56 |
57 |
58 |
59 |
60 | --option1=foo
61 |
62 |
63 |
64 |
65 |
66 | ----
67 |
68 | * `trusts`: If the script resides in a remote location, this parameter specifies what URLs should be trusted. See link:https://github.com/jbangdev/jbang#urls-from-trusted-sources[URLs from Trusted Sources] for more information
69 |
70 | === Example
71 |
72 | [source,xml]
73 | ----
74 |
75 | dev.jbang
76 | jbang-maven-plugin
77 | 0.0.7
78 |
79 |
80 | run
81 | process-resources
82 |
83 | run
84 |
85 |
86 |
87 |
88 | https://github.com
89 |
90 |
91 |
92 |
93 |
94 | ----
95 |
96 | * `jbangargs`: Arguments for `jbang` (not the script)
97 |
98 | === Example
99 |
100 | [source,xml]
101 | ----
102 |
103 | dev.jbang
104 | jbang-maven-plugin
105 | 0.0.7
106 |
107 |
108 | run
109 | process-resources
110 |
111 | run
112 |
113 |
114 |
115 | --quiet
116 |
117 |
118 |
119 |
120 |
121 |
122 | ----
123 |
124 | * `jbangVersion`: If your envronment lacks the JBang binaries in the PATH, you can specify the JBang version to be installed. If not specified, the plugin will resolve to the latest JBang release available
125 |
126 | === Example
127 |
128 | [source,xml]
129 | ----
130 |
131 | dev.jbang
132 | jbang-maven-plugin
133 | 0.0.7
134 |
135 |
136 | run
137 | process-resources
138 |
139 | run
140 |
141 |
142 |
143 | 0.47.1
144 |
145 |
146 |
147 |
148 | ----
149 |
150 | * `jbangInstallDir`: Alternative location of JBang installation. The default value is `${project.basedir}`
151 |
152 | === Example
153 |
154 | [source,xml]
155 | ----
156 |
157 | dev.jbang
158 | jbang-maven-plugin
159 | 0.0.7
160 |
161 |
162 | run
163 | process-resources
164 |
165 | run
166 |
167 |
168 |
169 | ${project.build.directory}
170 |
171 |
172 |
173 |
174 | ----
175 |
176 | == Reporting bugs/issues/features
177 |
178 | Please use https://github.com/jbangdev/jbang for reporting bugs/issues/features.
179 |
180 | == Releasing
181 |
182 | To release a new version of the plugin, run the following command:
183 |
184 | [source,shell]
185 | ----
186 | mvn versions:set -DnewVersion=0.0.Z
187 | git commit -a -m "release 0.0.Z"
188 | git tag -a 0.0.Z -m "release 0.0.Z"
189 | git push
190 | ----
191 |
192 | When completed correctly, the new version will be available in Maven Central within some time (usually less than 30 minutes).
193 |
194 | To prepare for the next development iteration, run the following command:
195 |
196 | [source,shell]
197 | ----
198 | mvn versions:set -DnewVersion=0.0.Z+1-SNAPSHOT
199 | git commit -a -m "prepare for next development iteration"
200 | git push
201 | ----
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## JBang Maven Plugin
2 |
3 | 
4 | [](https://search.maven.org/search?q=g:%22dev.jbang%22%20AND%20a:%22jbang-maven-plugin%22)
5 |
6 | The JBang Maven plugin allows JBang scripts to be executed during a Maven build, or through `mvn` command-line (without pom file).
7 |
8 | The plugin attempts to use an existing JBang installation. If no JBang installation is found, the plugin will install JBang by downloading and caching the latest version binaries (by default in your Maven project directory) for subsequent runs.
9 |
10 | ### Arguments
11 |
12 | - `script`: The script to be executed by JBang
13 |
14 | #### Example
15 |
16 | From inside a Maven buid:
17 | ```xml
18 |
19 | dev.jbang
20 | jbang-maven-plugin
21 | 0.0.7
22 |
23 |
24 | run
25 | process-resources
26 |
27 | run
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
36 |
37 | Or with command-line `$ mvn dev.jbang:jbang-maven-plugin:0.0.8:run -Djbang.script="helloworld/helloworld.java"`.
38 |
39 | - `args` : The arguments to be used in the JBang script (if any)
40 |
41 | #### Example
42 |
43 | ```xml
44 |
45 | dev.jbang
46 | jbang-maven-plugin
47 | 0.0.7
48 |
49 |
50 | run
51 | process-resources
52 |
53 | run
54 |
55 |
56 |
57 |
58 | --option1=foo
59 |
60 |
61 |
62 |
63 |
64 | ```
65 |
66 | - `trusts`: If the script resides in a remote location, this parameter specifies what URLs should be trusted. See [URLs from Trusted Sources](https://github.com/jbangdev/jbang#urls-from-trusted-sources) for more information
67 |
68 |
69 | #### Example
70 |
71 | ```xml
72 |
73 | dev.jbang
74 | jbang-maven-plugin
75 | 0.0.7
76 |
77 |
78 | run
79 | process-resources
80 |
81 | run
82 |
83 |
84 |
85 |
86 | https://github.com
87 |
88 |
89 |
90 |
91 |
92 | ```
93 |
94 | - `jbangargs`: Arguments for `jbang` (not the script)
95 |
96 | #### Example
97 |
98 | ```xml
99 |
100 | dev.jbang
101 | jbang-maven-plugin
102 | 0.0.7
103 |
104 |
105 | run
106 | process-resources
107 |
108 | run
109 |
110 |
111 |
112 | --quiet
113 |
114 |
115 |
116 |
117 |
118 |
119 | ```
120 |
121 | - `jbangVersion`: If your envronment lacks the JBang binaries in the PATH, you can specify the JBang version to be installed. If not specified, the plugin will resolve to the latest JBang release available
122 |
123 |
124 | #### Example
125 |
126 | ```xml
127 |
128 | dev.jbang
129 | jbang-maven-plugin
130 | 0.0.7
131 |
132 |
133 | run
134 | process-resources
135 |
136 | run
137 |
138 |
139 |
140 | 0.47.1
141 |
142 |
143 |
144 |
145 | ```
146 |
147 | - `jbangInstallDir`: Alternative location of JBang installation. The default value is `${project.basedir}`
148 |
149 |
150 | #### Example
151 |
152 | ```xml
153 |
154 | dev.jbang
155 | jbang-maven-plugin
156 | 0.0.7
157 |
158 |
159 | run
160 | process-resources
161 |
162 | run
163 |
164 |
165 |
166 | ${project.build.directory}
167 |
168 |
169 |
170 |
171 | ```
172 |
173 | ### Reporting bugs/issues/features
174 |
175 | Please use https://github.com/jbangdev/jbang for reporting bugs/issues/features.
176 |
177 | ### Releasing
178 |
179 | To release a new version of the plugin, run the following command:
180 |
181 | ```shell
182 | mvn versions:set -DnewVersion=0.0.Z
183 | git commit -a -m "release 0.0.Z"
184 | git tag -a 0.0.Z -m "release 0.0.Z"
185 | git push
186 | ```
187 |
188 | When completed correctly, the new version will be available in Maven Central within some time (usually less than 30 minutes).
189 |
190 | To prepare for the next development iteration, run the following command:
191 |
192 | ```shell```
193 | mvn versions:set -DnewVersion=0.0.Z+1-SNAPSHOT
194 | git commit -a -m "prepare for next development iteration"
195 | git push
196 | ```
197 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | <# : batch portion
2 | @REM ----------------------------------------------------------------------------
3 | @REM Licensed to the Apache Software Foundation (ASF) under one
4 | @REM or more contributor license agreements. See the NOTICE file
5 | @REM distributed with this work for additional information
6 | @REM regarding copyright ownership. The ASF licenses this file
7 | @REM to you under the Apache License, Version 2.0 (the
8 | @REM "License"); you may not use this file except in compliance
9 | @REM with the License. You may obtain a copy of the License at
10 | @REM
11 | @REM http://www.apache.org/licenses/LICENSE-2.0
12 | @REM
13 | @REM Unless required by applicable law or agreed to in writing,
14 | @REM software distributed under the License is distributed on an
15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | @REM KIND, either express or implied. See the License for the
17 | @REM specific language governing permissions and limitations
18 | @REM under the License.
19 | @REM ----------------------------------------------------------------------------
20 |
21 | @REM ----------------------------------------------------------------------------
22 | @REM Apache Maven Wrapper startup batch script, version 3.2.0
23 | @REM
24 | @REM Optional ENV vars
25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution
26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
28 | @REM ----------------------------------------------------------------------------
29 |
30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31 | @SET __MVNW_CMD__=
32 | @SET __MVNW_ERROR__=
33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34 | @SET PSModulePath=
35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
37 | )
38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39 | @SET __MVNW_PSMODULEP_SAVE=
40 | @SET __MVNW_ARG0_NAME__=
41 | @SET MVNW_USERNAME=
42 | @SET MVNW_PASSWORD=
43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
44 | @echo Cannot start maven from wrapper >&2 && exit /b 1
45 | @GOTO :EOF
46 | : end batch / begin powershell #>
47 |
48 | $ErrorActionPreference = "Stop"
49 | if ($env:MVNW_VERBOSE -eq "true") {
50 | $VerbosePreference = "Continue"
51 | }
52 |
53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55 | if (!$distributionUrl) {
56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57 | }
58 |
59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60 | "maven-mvnd-*" {
61 | $USE_MVND = $true
62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63 | $MVN_CMD = "mvnd.cmd"
64 | break
65 | }
66 | default {
67 | $USE_MVND = $false
68 | $MVN_CMD = $script -replace '^mvnw','mvn'
69 | break
70 | }
71 | }
72 |
73 | # apply MVNW_REPOURL and calculate MAVEN_HOME
74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
83 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
84 |
85 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
86 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
87 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
88 | exit $?
89 | }
90 |
91 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
92 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
93 | }
94 |
95 | # prepare tmp dir
96 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
97 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
98 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
99 | trap {
100 | if ($TMP_DOWNLOAD_DIR.Exists) {
101 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
102 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
103 | }
104 | }
105 |
106 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
107 |
108 | # Download and Install Apache Maven
109 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
110 | Write-Verbose "Downloading from: $distributionUrl"
111 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
112 |
113 | $webclient = New-Object System.Net.WebClient
114 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
115 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
116 | }
117 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
118 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
119 |
120 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
121 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
122 | if ($distributionSha256Sum) {
123 | if ($USE_MVND) {
124 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
125 | }
126 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
127 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
128 | }
129 | }
130 |
131 | # unzip and move
132 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
133 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
134 | try {
135 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
136 | } catch {
137 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
138 | Write-Error "fail to move MAVEN_HOME"
139 | }
140 | } finally {
141 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
142 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
143 | }
144 |
145 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
146 |
--------------------------------------------------------------------------------
/src/main/java/dev/jbang/RunMojo.java:
--------------------------------------------------------------------------------
1 | package dev.jbang;
2 |
3 |
4 | import java.io.File;
5 | import java.nio.file.Path;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Locale;
9 |
10 | import org.apache.maven.artifact.Artifact;
11 | import org.apache.maven.execution.MavenSession;
12 | import org.apache.maven.plugin.AbstractMojo;
13 | import org.apache.maven.plugin.BuildPluginManager;
14 | import org.apache.maven.plugin.MojoExecutionException;
15 | import org.apache.maven.plugins.annotations.Component;
16 | import org.apache.maven.plugins.annotations.LifecyclePhase;
17 | import org.apache.maven.plugins.annotations.Mojo;
18 | import org.apache.maven.plugins.annotations.Parameter;
19 | import org.apache.maven.project.MavenProject;
20 | import org.zeroturnaround.exec.ProcessExecutor;
21 | import org.zeroturnaround.exec.ProcessResult;
22 | import org.zeroturnaround.exec.stream.slf4j.Slf4jStream;
23 |
24 | import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
25 | import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
26 | import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
27 | import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
28 | import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
29 | import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
30 |
31 | /**
32 | * Run JBang with the specified parameters
33 | *
34 | * @author George Gastaldi
35 | */
36 | @Mojo(name = "run", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, requiresProject = false)
37 | public class RunMojo extends AbstractMojo {
38 |
39 | private static final boolean IS_OS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows");
40 |
41 | private static final int OK_EXIT_CODE = 0;
42 |
43 | /**
44 | * The arguments to be used for JBang itself
45 | */
46 | @Parameter(property = "jbang.jbangargs")
47 | private String[] jbangargs;
48 |
49 | /**
50 | * Location of the JBang script to use
51 | */
52 | @Parameter(property = "jbang.script", required = true)
53 | private String script;
54 |
55 | /**
56 | * The arguments to be used in the JBang script
57 | */
58 | @Parameter(property = "jbang.args")
59 | private String[] args;
60 |
61 | /**
62 | * If the script is in a remote location, what URLs should be trusted
63 | *
64 | * See https://github.com/jbangdev/jbang#urls-from-trusted-sources for more information
65 | */
66 | @Parameter(property = "jbang.trusts")
67 | private String[] trusts;
68 |
69 | /**
70 | * JBang Version to use. This version is only used to download the JBang binaries if nothing is found in the PATH
71 | */
72 | @Parameter(property = "jbang.version", defaultValue = Artifact.LATEST_VERSION)
73 | private String jbangVersion;
74 |
75 | /**
76 | * JBang installation directory. Default location is ${project.basedir}
77 | */
78 | @Parameter(property = "jbang.install.dir", defaultValue = "${project.basedir}")
79 | private File jbangInstallDir;
80 |
81 | /**
82 | * Skip this execution
83 | */
84 | @Parameter(property = "jbang.skip")
85 | private boolean skip;
86 |
87 | // Used in MojoExecutor. See RunMojo#download
88 | @Parameter(defaultValue = "${project}", readonly = true, required = true)
89 | protected MavenProject project;
90 |
91 | @Parameter(defaultValue = "${session}")
92 | private MavenSession session;
93 |
94 | @Component
95 | private BuildPluginManager pluginManager;
96 |
97 | private Path jbangHome;
98 |
99 | @Override
100 | public void execute() throws MojoExecutionException {
101 | if (skip) {
102 | getLog().info("Skipping plugin execution");
103 | return;
104 | }
105 | detectJBang();
106 | executeTrust();
107 | executeJBang();
108 | }
109 |
110 | private void detectJBang() throws MojoExecutionException {
111 | ProcessResult result = version();
112 | if (result.getExitValue() == OK_EXIT_CODE) {
113 | getLog().info("Found JBang v." + result.outputString().trim());
114 | } else {
115 | getLog().warn("JBang not found. Downloading " + (isLatestVersion() ? "the latest version" :
116 | "version " + jbangVersion));
117 | download();
118 | result = version();
119 | if (result.getExitValue() == OK_EXIT_CODE) {
120 | getLog().info("Using JBang v." + result.outputString().trim());
121 | }
122 | }
123 | }
124 |
125 | private void download() throws MojoExecutionException {
126 | String uri;
127 | String homePath;
128 | if (isLatestVersion()) {
129 | uri = "https://www.jbang.dev/releases/latest/download/jbang.zip";
130 | homePath = "jbang";
131 | } else {
132 | uri = String.format("https://github.com/jbangdev/jbang/releases/download/v%s/jbang-%s.zip",
133 | jbangVersion, jbangVersion);
134 | homePath = "jbang-" + jbangVersion;
135 | }
136 | Path installDir = jbangInstallDir.toPath().resolve(".jbang").toAbsolutePath();
137 | getLog().debug("Downloading JBang from " + uri + " and installing in " + installDir);
138 | executeMojo(
139 | plugin("com.googlecode.maven-download-plugin",
140 | "download-maven-plugin",
141 | "1.6.2"),
142 | goal("wget"),
143 | configuration(
144 | element("uri", uri),
145 | element("followRedirects", "true"),
146 | element("unpack", "true"),
147 | element("outputDirectory", installDir.toString())
148 | ),
149 | executionEnvironment(
150 | project,
151 | session,
152 | pluginManager));
153 | jbangHome = installDir.resolve(homePath);
154 | }
155 |
156 | private boolean isLatestVersion() {
157 | return Artifact.LATEST_VERSION.equals(jbangVersion);
158 | }
159 |
160 | private ProcessResult version() throws MojoExecutionException {
161 | List command = command();
162 | command.add(findJBangExecutable() + " version");
163 | ProcessResult result = null;
164 | try {
165 | result = new ProcessExecutor()
166 | .command(command)
167 | .readOutput(true)
168 | .destroyOnExit()
169 | .execute();
170 | } catch (Exception e) {
171 | throw new MojoExecutionException("Error while fetching the JBang version", e);
172 | }
173 | return result;
174 | }
175 |
176 |
177 | /**
178 | * Execute "jbang trust add URL..."
179 | *
180 | * @throws MojoExecutionException if the exit value is different from
181 | * 0: success
182 | * 1: Already trusted source(s)
183 | */
184 | private void executeTrust() throws MojoExecutionException {
185 | if (trusts == null || trusts.length == 0) {
186 | // No trust required
187 | return;
188 | }
189 | List command = command();
190 | command.add(findJBangExecutable() + " trust add " + String.join(" ", trusts));
191 | ProcessResult result = execute(command);
192 | int exitValue = result.getExitValue();
193 | if (exitValue != 0 && exitValue != 1) {
194 | throw new MojoExecutionException("Error while trusting JBang URLs. Exit code: " + result.getExitValue());
195 | }
196 | }
197 |
198 | /**
199 | * Execute jbang run script arguments
200 | *
201 | * @throws MojoExecutionException if exit value != 0
202 | */
203 | private void executeJBang() throws MojoExecutionException {
204 | List command = command();
205 | StringBuilder executable = new StringBuilder(findJBangExecutable());
206 | executable.append(" run ");
207 | if (jbangargs != null) {
208 | executable.append(" ").append(String.join(" ", jbangargs)).append(" ");
209 | }
210 | executable.append(script);
211 | if (args != null) {
212 | executable.append(" ").append(String.join(" ", args));
213 | }
214 | command.add(executable.toString());
215 | ProcessResult result = execute(command);
216 | if (result.getExitValue() != 0) {
217 | throw new MojoExecutionException("Error while executing JBang. Exit code: " + result.getExitValue());
218 | }
219 | }
220 |
221 | private ProcessResult execute(List command) throws MojoExecutionException {
222 | try {
223 | return new ProcessExecutor()
224 | .command(command)
225 | .redirectOutput(Slf4jStream.ofCaller().asInfo())
226 | .destroyOnExit()
227 | .execute();
228 | } catch (Exception e) {
229 | throw new MojoExecutionException("Error while executing JBang", e);
230 | }
231 | }
232 |
233 | /**
234 | * @return the command containing the supported shell per OS
235 | */
236 | private List command() {
237 | List command = new ArrayList<>();
238 | if (IS_OS_WINDOWS) {
239 | command.add("cmd.exe");
240 | command.add("/c");
241 | } else {
242 | command.add("sh");
243 | command.add("-c");
244 | }
245 | return command;
246 | }
247 |
248 | private String findJBangExecutable() {
249 | if (jbangHome != null) {
250 | if (IS_OS_WINDOWS) {
251 | return jbangHome.resolve("bin/jbang.cmd").toString();
252 | } else {
253 | return jbangHome.resolve("bin/jbang").toString();
254 | }
255 | } else {
256 | if (IS_OS_WINDOWS) {
257 | return "jbang.cmd";
258 | } else {
259 | return "jbang";
260 | }
261 | }
262 | }
263 | }
264 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.jboss
7 | jboss-parent
8 | 39
9 |
10 | dev.jbang
11 | jbang-maven-plugin
12 | 0.0.9-SNAPSHOT
13 | maven-plugin
14 |
15 | JBang Maven Plugin
16 |
17 | https://jbang.dev
18 |
19 |
20 | ${mavenMinRuntime.version}
21 |
22 |
23 |
24 |
25 | MIT License
26 | http://www.opensource.org/licenses/mit-license.php
27 |
28 |
29 |
30 |
31 |
32 | gastaldi
33 | George Gastaldi
34 |
35 |
36 | maxandersen
37 | Max Rydahl Andersen
38 |
39 |
40 |
41 |
42 | UTF-8
43 |
44 | 1.8
45 | 1.8
46 | 3.6.0
47 | 3.9.6
48 | 3.10.2
49 |
50 |
51 |
52 |
53 | org.zeroturnaround
54 | zt-exec
55 | 1.12
56 |
57 |
58 | org.twdata.maven
59 | mojo-executor
60 | 2.4.0
61 |
62 |
63 |
64 |
65 | org.codehaus.plexus
66 | plexus-utils
67 | 3.5.1
68 |
69 |
70 |
71 | org.apache.maven
72 | maven-plugin-api
73 | ${maven.version}
74 | provided
75 |
76 |
77 | org.apache.maven
78 | maven-core
79 | ${maven.version}
80 | provided
81 |
82 |
83 | org.apache.maven.plugin-tools
84 | maven-plugin-annotations
85 | ${mavenPluginTools.version}
86 | provided
87 |
88 |
89 |
90 |
91 |
92 |
93 | org.apache.maven.plugins
94 | maven-plugin-plugin
95 | ${mavenPluginTools.version}
96 |
97 | true
98 |
99 |
100 |
101 | mojo-descriptor
102 |
103 | descriptor
104 |
105 |
106 |
107 | help-goal
108 |
109 | helpmojo
110 |
111 |
112 |
113 |
114 |
115 | org.sonatype.plugins
116 | nexus-staging-maven-plugin
117 | 1.6.7
118 | true
119 |
120 | ossrh
121 | https://oss.sonatype.org/
122 | true
123 |
124 |
125 |
126 |
127 |
128 | scm:git:https://github.com/jbangdev/jbang-maven-plugin
129 | scm:git:https://github.com/jbangdev/jbang-maven-plugin
130 | https://github.com/jbangdev/jbang-maven-plugin
131 | HEAD
132 |
133 |
134 |
135 | ossrh
136 | https://oss.sonatype.org/content/repositories/snapshots
137 |
138 |
139 | ossrh
140 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
141 |
142 |
143 |
144 |
145 | it
146 |
147 |
148 | skipTests
149 | !true
150 |
151 |
152 |
153 |
154 |
155 | org.codehaus.mojo
156 | mrm-maven-plugin
157 | 1.5.0
158 |
159 |
160 |
161 | start
162 | stop
163 |
164 |
165 |
166 |
167 | repository.proxy.url
168 |
169 |
170 |
171 | org.apache.maven.plugins
172 | maven-invoker-plugin
173 | 3.6.0
174 |
175 | false
176 | ${project.build.directory}/it
177 |
178 | */pom.xml
179 |
180 | verify
181 | ${project.build.directory}/local-repo
182 | src/it/settings.xml
183 | true
184 |
185 | ${repository.proxy.url}
186 |
187 |
188 |
189 |
190 | org.apache.groovy
191 | groovy-all
192 | 4.0.16
193 | pom
194 |
195 |
196 |
197 |
198 | integration-test
199 |
200 | install
201 | integration-test
202 | verify
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 | release-sign-artifacts
213 |
214 |
215 | release
216 | true
217 |
218 |
219 |
220 |
221 |
222 | org.apache.maven.plugins
223 | maven-gpg-plugin
224 |
225 |
226 | --pinentry-mode
227 | loopback
228 |
229 |
230 |
231 |
232 | sign-artifacts
233 | verify
234 |
235 | sign
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
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 |
21 | # ----------------------------------------------------------------------------
22 | # Apache Maven Wrapper startup batch script, version 3.2.0
23 | #
24 | # Optional ENV vars
25 | # -----------------
26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source
27 | # MVNW_REPOURL - repo url base for downloading maven distribution
28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
30 | # ----------------------------------------------------------------------------
31 |
32 | set -euf
33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x
34 |
35 | # OS specific support.
36 | native_path() { printf %s\\n "$1"; }
37 | case "$(uname)" in
38 | (CYGWIN*|MINGW*) [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
39 | native_path() { cygpath --path --windows "$1"; } ;;
40 | esac
41 |
42 | # set JAVACMD and JAVACCMD
43 | set_java_home() {
44 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
45 | if [ -n "${JAVA_HOME-}" ] ; then
46 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
47 | # IBM's JDK on AIX uses strange locations for the executables
48 | JAVACMD="$JAVA_HOME/jre/sh/java"
49 | JAVACCMD="$JAVA_HOME/jre/sh/javac"
50 | else
51 | JAVACMD="$JAVA_HOME/bin/java"
52 | JAVACCMD="$JAVA_HOME/bin/javac"
53 |
54 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ] ; then
55 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
56 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
57 | return 1
58 | fi
59 | fi
60 | else
61 | JAVACMD="$('set' +e; 'unset' -f command 2>/dev/null; 'command' -v java)" || :
62 | JAVACCMD="$('set' +e; 'unset' -f command 2>/dev/null; 'command' -v javac)" || :
63 |
64 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ] ; then
65 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
66 | return 1
67 | fi
68 | fi
69 | }
70 |
71 | # hash string like Java String::hashCode
72 | hash_string() {
73 | str="${1:-}" h=0
74 | while [ -n "$str" ]; do
75 | h=$(( ( h * 31 + $(LC_CTYPE=C printf %d "'$str") ) % 4294967296 ))
76 | str="${str#?}"
77 | done
78 | printf %x\\n $h
79 | }
80 |
81 | verbose() { :; }
82 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
83 |
84 | die() {
85 | printf %s\\n "$1" >&2
86 | exit 1
87 | }
88 |
89 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
90 | while IFS="=" read -r key value; do
91 | case "${key-}" in
92 | distributionUrl) distributionUrl="${value-}" ;;
93 | distributionSha256Sum) distributionSha256Sum="${value-}" ;;
94 | esac
95 | done < "${0%/*}/.mvn/wrapper/maven-wrapper.properties"
96 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
97 |
98 |
99 | case "${distributionUrl##*/}" in
100 | (maven-mvnd-*bin.*)
101 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
102 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
103 | (*AMD64:CYGWIN*|*AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
104 | (:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
105 | (:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
106 | (:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
107 | (*) echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
108 | distributionPlatform=linux-amd64
109 | ;;
110 | esac
111 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
112 | ;;
113 | (maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
114 | (*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
115 | esac
116 |
117 | # apply MVNW_REPOURL and calculate MAVEN_HOME
118 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
119 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
120 | distributionUrlName="${distributionUrl##*/}"
121 | distributionUrlNameMain="${distributionUrlName%.*}"
122 | distributionUrlNameMain="${distributionUrlNameMain%-bin}"
123 | MAVEN_HOME="$HOME/.m2/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
124 |
125 | exec_maven() {
126 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
127 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
128 | }
129 |
130 | if [ -d "$MAVEN_HOME" ]; then
131 | verbose "found existing MAVEN_HOME at $MAVEN_HOME"
132 | exec_maven "$@"
133 | fi
134 |
135 | case "${distributionUrl-}" in
136 | (*?-bin.zip|*?maven-mvnd-?*-?*.zip) ;;
137 | (*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
138 | esac
139 |
140 | # prepare tmp dir
141 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
142 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
143 | trap clean HUP INT TERM EXIT
144 | else
145 | die "cannot create temp dir"
146 | fi
147 |
148 | mkdir -p -- "${MAVEN_HOME%/*}"
149 |
150 | # Download and Install Apache Maven
151 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
152 | verbose "Downloading from: $distributionUrl"
153 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
154 |
155 | # select .zip or .tar.gz
156 | if ! command -v unzip >/dev/null; then
157 | distributionUrl="${distributionUrl%.zip}.tar.gz"
158 | distributionUrlName="${distributionUrl##*/}"
159 | fi
160 |
161 | # verbose opt
162 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
163 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
164 |
165 | # normalize http auth
166 | case "${MVNW_PASSWORD:+has-password}" in
167 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
168 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
169 | esac
170 |
171 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget > /dev/null; then
172 | verbose "Found wget ... using wget"
173 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName"
174 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl > /dev/null; then
175 | verbose "Found curl ... using curl"
176 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl"
177 | elif set_java_home; then
178 | verbose "Falling back to use Java to download"
179 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
180 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
181 | cat > "$javaSource" <<-END
182 | public class Downloader extends java.net.Authenticator
183 | {
184 | protected java.net.PasswordAuthentication getPasswordAuthentication()
185 | {
186 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
187 | }
188 | public static void main( String[] args ) throws Exception
189 | {
190 | setDefault( new Downloader() );
191 | java.nio.file.Files.copy( new java.net.URL( args[0] ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
192 | }
193 | }
194 | END
195 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java
196 | verbose " - Compiling Downloader.java ..."
197 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")"
198 | verbose " - Running Downloader.java ..."
199 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
200 | fi
201 |
202 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
203 | if [ -n "${distributionSha256Sum-}" ]; then
204 | distributionSha256Result=false
205 | if [ "$MVN_CMD" = mvnd.sh ]; then
206 | echo "Checksum validation is not supported for maven-mvnd." >&2
207 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
208 | exit 1
209 | elif command -v sha256sum > /dev/null; then
210 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c > /dev/null 2>&1; then
211 | distributionSha256Result=true
212 | fi
213 | elif command -v shasum > /dev/null; then
214 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c > /dev/null 2>&1; then
215 | distributionSha256Result=true
216 | fi
217 | else
218 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
219 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
220 | exit 1
221 | fi
222 | if [ $distributionSha256Result = false ]; then
223 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
224 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
225 | exit 1
226 | fi
227 | fi
228 |
229 | # unzip and move
230 | if command -v unzip > /dev/null; then
231 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR"
232 | else
233 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR"
234 | fi
235 | printf %s\\n "$distributionUrl" > "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
236 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
237 |
238 | clean || :
239 | exec_maven "$@"
240 |
--------------------------------------------------------------------------------