├── .github
├── dco.yml
├── workflows
│ └── continuous-integration-build.yml
└── dependabot.yml
├── initial
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── .mvn
│ └── wrapper
│ │ └── maven-wrapper.properties
├── src
│ └── main
│ │ ├── resources
│ │ └── templates
│ │ │ ├── hello.html
│ │ │ └── home.html
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── securingweb
│ │ ├── SecuringWebApplication.java
│ │ └── MvcConfig.java
├── build.gradle
├── pom.xml
├── gradlew.bat
├── mvnw.cmd
├── gradlew
└── mvnw
├── initial-kotlin
├── settings.gradle.kts
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── src
│ └── main
│ │ ├── resources
│ │ └── templates
│ │ │ ├── hello.html
│ │ │ └── home.html
│ │ └── kotlin
│ │ └── com
│ │ └── example
│ │ └── securingweb
│ │ ├── SecuringWebApplication.kt
│ │ └── MvcConfig.kt
├── build.gradle.kts
├── gradlew.bat
└── gradlew
├── complete
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── .mvn
│ └── wrapper
│ │ └── maven-wrapper.properties
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── templates
│ │ │ │ ├── home.html
│ │ │ │ ├── hello.html
│ │ │ │ └── login.html
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── securingweb
│ │ │ ├── SecuringWebApplication.java
│ │ │ ├── MvcConfig.java
│ │ │ └── WebSecurityConfig.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── securingweb
│ │ └── SecuringWebApplicationTests.java
├── build.gradle
├── pom.xml
├── gradlew.bat
├── mvnw.cmd
├── gradlew
└── mvnw
├── complete-kotlin
├── settings.gradle.kts
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── src
│ ├── main
│ │ ├── kotlin
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── securingweb
│ │ │ │ ├── SecuringWebApplication.kt
│ │ │ │ ├── MvcConfig.kt
│ │ │ │ └── WebSecurityConfig.kt
│ │ └── resources
│ │ │ └── templates
│ │ │ ├── home.html
│ │ │ ├── hello.html
│ │ │ └── login.html
│ └── test
│ │ └── kotlin
│ │ └── com
│ │ └── example
│ │ └── securingweb
│ │ └── SecuringWebApplicationTests.kt
├── build.gradle.kts
├── gradlew.bat
└── gradlew
├── images
├── home.png
├── login.png
└── greeting.png
├── LICENSE.writing.txt
├── .gitignore
├── CONTRIBUTING.adoc
├── test
└── run.sh
├── LICENSE.txt
└── README.adoc
/.github/dco.yml:
--------------------------------------------------------------------------------
1 | require:
2 | members: false
3 |
--------------------------------------------------------------------------------
/initial/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'securing-web'
2 |
--------------------------------------------------------------------------------
/initial-kotlin/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "securing-web"
--------------------------------------------------------------------------------
/complete/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'securing-web-complete'
2 |
--------------------------------------------------------------------------------
/complete-kotlin/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "securing-web-complete"
--------------------------------------------------------------------------------
/images/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/images/home.png
--------------------------------------------------------------------------------
/images/login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/images/login.png
--------------------------------------------------------------------------------
/images/greeting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/images/greeting.png
--------------------------------------------------------------------------------
/initial/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .gradle/
3 | .project
4 | .settings/
5 | bin/
6 | build/
7 | target/
8 | work/
9 |
--------------------------------------------------------------------------------
/initial-kotlin/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .gradle/
3 | .project
4 | .settings/
5 | bin/
6 | build/
7 | target/
8 | work/
9 |
--------------------------------------------------------------------------------
/complete-kotlin/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .gradle/
3 | .project
4 | .settings/
5 | bin/
6 | build/
7 | target/
8 | work/
9 |
--------------------------------------------------------------------------------
/LICENSE.writing.txt:
--------------------------------------------------------------------------------
1 | Except where otherwise noted, this work is licensed under https://creativecommons.org/licenses/by-nd/3.0/
2 |
--------------------------------------------------------------------------------
/initial/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/initial/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/complete/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/complete/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/complete-kotlin/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/complete-kotlin/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/initial-kotlin/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-guides/gs-securing-web/HEAD/initial-kotlin/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/complete/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionType=only-script
2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
3 |
--------------------------------------------------------------------------------
/initial/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionType=only-script
2 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | *.sw?
3 | .#*
4 | *#
5 | *~
6 | .classpath
7 | .project
8 | .settings
9 | bin
10 | build
11 | target
12 | dependency-reduced-pom.xml
13 | *.sublime-*
14 | /scratch
15 | .gradle
16 | .idea
17 | *.iml
18 | README.html
19 |
--------------------------------------------------------------------------------
/initial/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello World!
5 |
6 |
7 | Hello world!
8 |
9 |
--------------------------------------------------------------------------------
/initial-kotlin/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello World!
5 |
6 |
7 | Hello world!
8 |
9 |
--------------------------------------------------------------------------------
/initial/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/complete/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/complete-kotlin/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/initial-kotlin/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/.github/workflows/continuous-integration-build.yml:
--------------------------------------------------------------------------------
1 | name: CI Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 | branches:
9 | - main
10 |
11 | jobs:
12 | build:
13 | uses: spring-guides/getting-started-macros/.github/workflows/build_initial_complete_maven_gradle.yml@main
14 |
--------------------------------------------------------------------------------
/initial/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | Click here to see a greeting.
10 |
11 |
--------------------------------------------------------------------------------
/CONTRIBUTING.adoc:
--------------------------------------------------------------------------------
1 | All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
2 | For additional details, please refer to the blog post https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring[Hello DCO, Goodbye CLA: Simplifying Contributions to Spring].
3 |
--------------------------------------------------------------------------------
/initial-kotlin/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | Click here to see a greeting.
10 |
11 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/kotlin/com/example/securingweb/SecuringWebApplication.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.springframework.boot.autoconfigure.SpringBootApplication
4 | import org.springframework.boot.runApplication
5 |
6 | @SpringBootApplication
7 | class SecuringWebApplication
8 |
9 | fun main(args: Array) {
10 | runApplication(*args)
11 | }
12 |
--------------------------------------------------------------------------------
/initial-kotlin/src/main/kotlin/com/example/securingweb/SecuringWebApplication.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.springframework.boot.autoconfigure.SpringBootApplication
4 | import org.springframework.boot.runApplication
5 |
6 | @SpringBootApplication
7 | class SecuringWebApplication
8 |
9 | fun main(args: Array) {
10 | runApplication(*args)
11 | }
12 |
--------------------------------------------------------------------------------
/test/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | cd "$(dirname "$0")"
5 |
6 | cd ../initial
7 | ./mvnw clean compile
8 | rm -rf target
9 |
10 | ./gradlew compileJava
11 | rm -rf build
12 |
13 | cd ../initial-kotlin
14 | ./gradlew compileKotlin
15 | rm -rf build
16 |
17 | cd ../complete
18 | ./mvnw clean package
19 | rm -rf target
20 |
21 | ./gradlew build
22 | rm -rf build
23 |
24 | cd ../complete-kotlin
25 | ./gradlew build
26 | rm -rf build
--------------------------------------------------------------------------------
/complete/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | Click here to see a greeting.
10 |
11 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 | Welcome!
8 |
9 | Click here to see a greeting.
10 |
11 |
--------------------------------------------------------------------------------
/complete/src/main/java/com/example/securingweb/SecuringWebApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecuringWebApplication {
8 |
9 | public static void main(String[] args) throws Throwable {
10 | SpringApplication.run(SecuringWebApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/initial/src/main/java/com/example/securingweb/SecuringWebApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecuringWebApplication {
8 |
9 | public static void main(String[] args) throws Throwable {
10 | SpringApplication.run(SecuringWebApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/complete/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | Hello World!
6 |
7 |
8 | Hello thymeleaf!
9 |
12 |
13 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | Hello World!
6 |
7 |
8 | Hello thymeleaf!
9 |
12 |
13 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/kotlin/com/example/securingweb/MvcConfig.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.springframework.context.annotation.Configuration
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
6 |
7 | @Configuration
8 | class MvcConfig : WebMvcConfigurer {
9 |
10 | override fun addViewControllers(registry: ViewControllerRegistry) = with(registry) {
11 | addViewController("/home").setViewName("home")
12 | addViewController("/").setViewName("home")
13 | addViewController("/hello").setViewName("hello")
14 | addViewController("/login").setViewName("login")
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/initial/src/main/java/com/example/securingweb/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6 |
7 | @Configuration
8 | public class MvcConfig implements WebMvcConfigurer {
9 |
10 | public void addViewControllers(ViewControllerRegistry registry) {
11 | registry.addViewController("/home").setViewName("home");
12 | registry.addViewController("/").setViewName("home");
13 | registry.addViewController("/hello").setViewName("hello");
14 | registry.addViewController("/login").setViewName("login");
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/initial-kotlin/src/main/kotlin/com/example/securingweb/MvcConfig.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.springframework.context.annotation.Configuration
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
6 |
7 | @Configuration
8 | class MvcConfig : WebMvcConfigurer {
9 | override fun addViewControllers(registry: ViewControllerRegistry) {
10 | registry.addViewController("/home").setViewName("home")
11 | registry.addViewController("/").setViewName("home")
12 | registry.addViewController("/hello").setViewName("hello")
13 | registry.addViewController("/login").setViewName("login")
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/complete/src/main/java/com/example/securingweb/MvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6 |
7 | @Configuration
8 | public class MvcConfig implements WebMvcConfigurer {
9 |
10 | @Override
11 | public void addViewControllers(ViewControllerRegistry registry) {
12 | registry.addViewController("/home").setViewName("home");
13 | registry.addViewController("/").setViewName("home");
14 | registry.addViewController("/hello").setViewName("hello");
15 | registry.addViewController("/login").setViewName("login");
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/initial/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '4.0.0'
4 | id 'io.spring.dependency-management' version '1.1.7'
5 | }
6 |
7 | group = 'com.example'
8 | version = '0.0.1-SNAPSHOT'
9 |
10 | java {
11 | toolchain {
12 | languageVersion = JavaLanguageVersion.of(17)
13 | }
14 | }
15 |
16 | repositories {
17 | mavenCentral()
18 | }
19 |
20 | dependencies {
21 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
22 | implementation 'org.springframework.boot:spring-boot-starter-webmvc'
23 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
24 | testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
25 | }
26 |
27 | test {
28 | useJUnitPlatform()
29 | }
30 |
--------------------------------------------------------------------------------
/complete/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 |
8 | Invalid username and password.
9 |
10 |
11 | You have been logged out.
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Spring Security Example
5 |
6 |
7 |
8 | Invalid username and password.
9 |
10 |
11 | You have been logged out.
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 |
4 | - package-ecosystem: "maven"
5 | directories:
6 | - "/initial"
7 | - "/complete"
8 | ignore:
9 | - dependency-name: "*"
10 | update-types: ["version-update:semver-patch"]
11 | schedule:
12 | interval: "monthly"
13 | target-branch: "main"
14 | groups:
15 | guide-dependencies-maven:
16 | patterns:
17 | - "*"
18 |
19 | - package-ecosystem: "gradle"
20 | directories:
21 | - "/initial"
22 | - "/complete"
23 | ignore:
24 | - dependency-name: "*"
25 | update-types: ["version-update:semver-patch"]
26 | schedule:
27 | interval: "monthly"
28 | target-branch: "main"
29 | groups:
30 | guide-dependencies-gradle:
31 | patterns:
32 | - "*"
33 |
--------------------------------------------------------------------------------
/initial-kotlin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.springframework.boot") version "4.0.0"
3 | id("io.spring.dependency-management") version "1.1.7"
4 | kotlin("jvm") version "2.2.21"
5 | kotlin("plugin.spring") version "2.2.21"
6 | }
7 |
8 | group = "com.example"
9 | version = "0.0.1-SNAPSHOT"
10 |
11 | java {
12 | toolchain {
13 | languageVersion = JavaLanguageVersion.of(17)
14 | }
15 | }
16 |
17 | repositories {
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
23 | implementation("org.springframework.boot:spring-boot-starter-webmvc")
24 | implementation("org.jetbrains.kotlin:kotlin-reflect")
25 | testImplementation("org.springframework.boot:spring-boot-starter-test")
26 | testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
27 | }
28 |
29 | kotlin {
30 | compilerOptions {
31 | freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property")
32 | }
33 | }
34 |
35 | tasks.withType {
36 | useJUnitPlatform()
37 | }
--------------------------------------------------------------------------------
/complete/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '4.0.0'
4 | id 'io.spring.dependency-management' version '1.1.7'
5 | }
6 |
7 | group = 'com.example'
8 | version = '0.0.1-SNAPSHOT'
9 |
10 | java {
11 | toolchain {
12 | languageVersion = JavaLanguageVersion.of(17)
13 | }
14 | }
15 |
16 | repositories {
17 | mavenCentral()
18 | }
19 |
20 | dependencies {
21 | implementation 'org.springframework.boot:spring-boot-starter-webmvc'
22 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
23 | // tag::security-dependencies[]
24 | implementation 'org.springframework.boot:spring-boot-starter-security'
25 | implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
26 | testImplementation 'org.springframework.security:spring-security-test'
27 | // end::security-dependencies[]
28 | testImplementation 'org.springframework.boot:spring-boot-starter-test'
29 | testImplementation 'org.springframework.boot:spring-boot-starter-security-test'
30 | testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
31 | }
32 |
33 | test {
34 | useJUnitPlatform()
35 | }
36 |
--------------------------------------------------------------------------------
/complete-kotlin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.springframework.boot") version "4.0.0"
3 | id("io.spring.dependency-management") version "1.1.7"
4 | kotlin("jvm") version "2.2.21"
5 | kotlin("plugin.spring") version "2.2.21"
6 | }
7 |
8 | group = "com.example"
9 | version = "0.0.1-SNAPSHOT"
10 |
11 | java {
12 | toolchain {
13 | languageVersion = JavaLanguageVersion.of(17)
14 | }
15 | }
16 |
17 | repositories {
18 | mavenCentral()
19 | }
20 |
21 | dependencies {
22 | implementation("org.springframework.boot:spring-boot-starter-webmvc")
23 | implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
24 | implementation("org.jetbrains.kotlin:kotlin-reflect")
25 | // tag::security-dependencies[]
26 | implementation("org.springframework.boot:spring-boot-starter-security")
27 | implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6")
28 | testImplementation("org.springframework.boot:spring-boot-starter-security-test")
29 | // end::security-dependencies[]
30 | testImplementation("org.springframework.boot:spring-boot-starter-test")
31 | testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
32 | }
33 |
34 | kotlin {
35 | compilerOptions {
36 | freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property")
37 | }
38 | }
39 |
40 | tasks.withType {
41 | useJUnitPlatform()
42 | }
--------------------------------------------------------------------------------
/initial/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 4.0.0
9 |
10 |
11 | com.example
12 | securing-web-initial
13 | 0.0.1-SNAPSHOT
14 | securing-web-initial
15 | Demo project for Spring Boot
16 |
17 |
18 | 17
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-thymeleaf
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-webmvc
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-test
34 | test
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-webmvc-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/complete/src/main/java/com/example/securingweb/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7 | import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
8 | import org.springframework.security.core.userdetails.User;
9 | import org.springframework.security.core.userdetails.UserDetails;
10 | import org.springframework.security.core.userdetails.UserDetailsService;
11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12 | import org.springframework.security.crypto.password.PasswordEncoder;
13 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
14 | import org.springframework.security.web.SecurityFilterChain;
15 |
16 | @Configuration
17 | @EnableWebSecurity
18 | public class WebSecurityConfig {
19 |
20 | @Bean
21 | public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
22 | http
23 | .authorizeHttpRequests((requests) -> requests
24 | .requestMatchers("/", "/home").permitAll()
25 | .anyRequest().authenticated()
26 | )
27 | .formLogin((form) -> form
28 | .loginPage("/login")
29 | .permitAll()
30 | )
31 | .logout(LogoutConfigurer::permitAll);
32 |
33 | return http.build();
34 | }
35 |
36 | @Bean
37 | public PasswordEncoder passwordEncoder() {
38 | return new BCryptPasswordEncoder();
39 | }
40 |
41 | @Bean
42 | public UserDetailsService userDetailsService() {
43 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
44 | UserDetails user =
45 | User.builder()
46 | .username("user")
47 | .password(encoder.encode("password"))
48 | .roles("USER")
49 | .build();
50 |
51 | return new InMemoryUserDetailsManager(user);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/complete/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 4.0.0
9 |
10 |
11 | com.example
12 | securing-web-complete
13 | 0.0.1-SNAPSHOT
14 |
15 |
16 | 17
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-thymeleaf
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-webmvc
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-security
32 |
33 |
34 | org.thymeleaf.extras
35 | thymeleaf-extras-springsecurity6
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-security-test
40 | test
41 |
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-test
47 | test
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-webmvc-test
52 | test
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/complete-kotlin/src/main/kotlin/com/example/securingweb/WebSecurityConfig.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.springframework.context.annotation.Bean
4 | import org.springframework.context.annotation.Configuration
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity
6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
7 | import org.springframework.security.config.annotation.web.invoke
8 | import org.springframework.security.core.userdetails.User
9 | import org.springframework.security.core.userdetails.UserDetailsService
10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
11 | import org.springframework.security.crypto.password.PasswordEncoder
12 | import org.springframework.security.provisioning.InMemoryUserDetailsManager
13 | import org.springframework.security.web.SecurityFilterChain
14 |
15 | @Configuration
16 | @EnableWebSecurity
17 | class WebSecurityConfig {
18 |
19 | @Bean
20 | fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
21 | http {
22 | // Kotlin security extensions allow concise DSL instead of builder-style lambdas
23 | authorizeHttpRequests {
24 | authorize("/", permitAll)
25 | authorize("/home", permitAll)
26 | authorize(anyRequest, authenticated)
27 | }
28 | formLogin {
29 | loginPage = "/login"
30 | permitAll()
31 | }
32 | logout {
33 | permitAll()
34 | }
35 | }
36 |
37 | return http.build()
38 | }
39 |
40 | @Bean
41 | fun passwordEncoder(): PasswordEncoder {
42 | return BCryptPasswordEncoder()
43 | }
44 |
45 | @Bean
46 | fun userDetailsService(): UserDetailsService {
47 | val encoder = BCryptPasswordEncoder()
48 | val user = User.builder()
49 | .username("user")
50 | .password(encoder.encode("password"))
51 | .roles("USER")
52 | .build()
53 |
54 | return InMemoryUserDetailsManager(user)
55 | }
56 | }
--------------------------------------------------------------------------------
/complete-kotlin/src/test/kotlin/com/example/securingweb/SecuringWebApplicationTests.kt:
--------------------------------------------------------------------------------
1 | package com.example.securingweb
2 |
3 | import org.assertj.core.api.Assertions
4 | import org.junit.jupiter.api.Test
5 | import org.springframework.beans.factory.annotation.Autowired
6 | import org.springframework.boot.test.context.SpringBootTest
7 | import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc
8 | import org.springframework.security.test.context.support.WithMockUser
9 | import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders
10 | import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers
11 | import org.springframework.test.web.servlet.MockMvc
12 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
13 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl
14 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
15 |
16 | @SpringBootTest
17 | @AutoConfigureMockMvc
18 | class SecuringWebApplicationTests @Autowired constructor(private val mockMvc: MockMvc) {
19 |
20 | @Test
21 | fun loginWithValidUserThenAuthenticated() {
22 | val login = SecurityMockMvcRequestBuilders.formLogin()
23 | .user("user")
24 | .password("password")
25 |
26 | mockMvc.perform(login)
27 | .andExpect(SecurityMockMvcResultMatchers.authenticated().withUsername("user"))
28 | }
29 |
30 | @Test
31 | fun loginWithInvalidUserThenUnauthenticated() {
32 | val login = SecurityMockMvcRequestBuilders.formLogin()
33 | .user("invalid")
34 | .password("invalidpassword")
35 |
36 | mockMvc.perform(login)
37 | .andExpect(SecurityMockMvcResultMatchers.unauthenticated())
38 | }
39 |
40 | @Test
41 | fun accessUnsecuredResourceThenOk() {
42 | mockMvc.perform(get("/"))
43 | .andExpect(status().isOk())
44 | }
45 |
46 | @Test
47 | fun accessSecuredResourceUnauthenticatedThenRedirectsToLogin() {
48 | mockMvc.perform(get("/hello"))
49 | .andExpect(status().is3xxRedirection())
50 | .andExpect(redirectedUrl("/login"))
51 | }
52 |
53 | @Test
54 | @WithMockUser
55 | fun accessSecuredResourceAuthenticatedThenOk() {
56 | val mvcResult = mockMvc.perform(get("/hello"))
57 | .andExpect(status().isOk())
58 | .andReturn()
59 |
60 | Assertions.assertThat(mvcResult.response.contentAsString).contains("Hello user!")
61 | }
62 | }
--------------------------------------------------------------------------------
/complete/src/test/java/com/example/securingweb/SecuringWebApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.securingweb;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
8 | import org.springframework.security.test.context.support.WithMockUser;
9 | import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.FormLoginRequestBuilder;
10 | import org.springframework.test.web.servlet.MockMvc;
11 | import org.springframework.test.web.servlet.MvcResult;
12 |
13 | import static org.assertj.core.api.Assertions.assertThat;
14 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
15 | import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated;
16 | import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated;
17 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
19 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
20 |
21 | @SpringBootTest
22 | @AutoConfigureMockMvc
23 | public class SecuringWebApplicationTests {
24 |
25 | @Autowired
26 | private MockMvc mockMvc;
27 |
28 | @Test
29 | public void loginWithValidUserThenAuthenticated() throws Exception {
30 | FormLoginRequestBuilder login = formLogin()
31 | .user("user")
32 | .password("password");
33 |
34 | mockMvc.perform(login)
35 | .andExpect(authenticated().withUsername("user"));
36 | }
37 |
38 | @Test
39 | public void loginWithInvalidUserThenUnauthenticated() throws Exception {
40 | FormLoginRequestBuilder login = formLogin()
41 | .user("invalid")
42 | .password("invalidpassword");
43 |
44 | mockMvc.perform(login)
45 | .andExpect(unauthenticated());
46 | }
47 |
48 | @Test
49 | public void accessUnsecuredResourceThenOk() throws Exception {
50 | mockMvc.perform(get("/"))
51 | .andExpect(status().isOk());
52 | }
53 |
54 | @Test
55 | public void accessSecuredResourceUnauthenticatedThenRedirectsToLogin() throws Exception {
56 | mockMvc.perform(get("/hello"))
57 | .andExpect(status().is3xxRedirection())
58 | .andExpect(redirectedUrl("/login"));
59 | }
60 |
61 | @Test
62 | @WithMockUser
63 | public void accessSecuredResourceAuthenticatedThenOk() throws Exception {
64 | MvcResult mvcResult = mockMvc.perform(get("/hello"))
65 | .andExpect(status().isOk())
66 | .andReturn();
67 |
68 | assertThat(mvcResult.getResponse().getContentAsString()).contains("Hello user!");
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/complete/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/initial/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/complete-kotlin/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/initial-kotlin/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/initial/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.3.3
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 -eq $False) { "/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 |
82 | $MAVEN_M2_PATH = "$HOME/.m2"
83 | if ($env:MAVEN_USER_HOME) {
84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
85 | }
86 |
87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
89 | }
90 |
91 | $MAVEN_WRAPPER_DISTS = $null
92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
94 | } else {
95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
96 | }
97 |
98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
101 |
102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
105 | exit $?
106 | }
107 |
108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
110 | }
111 |
112 | # prepare tmp dir
113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
116 | trap {
117 | if ($TMP_DOWNLOAD_DIR.Exists) {
118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
120 | }
121 | }
122 |
123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
124 |
125 | # Download and Install Apache Maven
126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
127 | Write-Verbose "Downloading from: $distributionUrl"
128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
129 |
130 | $webclient = New-Object System.Net.WebClient
131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
133 | }
134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
136 |
137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
139 | if ($distributionSha256Sum) {
140 | if ($USE_MVND) {
141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
142 | }
143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
145 | 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."
146 | }
147 | }
148 |
149 | # unzip and move
150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
151 |
152 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
153 | $actualDistributionDir = ""
154 |
155 | # First try the expected directory name (for regular distributions)
156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
159 | $actualDistributionDir = $distributionUrlNameMain
160 | }
161 |
162 | # If not found, search for any directory with the Maven executable (for snapshots)
163 | if (!$actualDistributionDir) {
164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD"
166 | if (Test-Path -Path $testPath -PathType Leaf) {
167 | $actualDistributionDir = $_.Name
168 | }
169 | }
170 | }
171 |
172 | if (!$actualDistributionDir) {
173 | Write-Error "Could not find Maven distribution directory in extracted archive"
174 | }
175 |
176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
178 | try {
179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
180 | } catch {
181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
182 | Write-Error "fail to move MAVEN_HOME"
183 | }
184 | } finally {
185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
187 | }
188 |
189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
190 |
--------------------------------------------------------------------------------
/complete/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.3.3
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 -eq $False) { "/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 |
82 | $MAVEN_M2_PATH = "$HOME/.m2"
83 | if ($env:MAVEN_USER_HOME) {
84 | $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
85 | }
86 |
87 | if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
88 | New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
89 | }
90 |
91 | $MAVEN_WRAPPER_DISTS = $null
92 | if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
93 | $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
94 | } else {
95 | $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
96 | }
97 |
98 | $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
99 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
100 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
101 |
102 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
103 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
104 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
105 | exit $?
106 | }
107 |
108 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
109 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
110 | }
111 |
112 | # prepare tmp dir
113 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
114 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
115 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
116 | trap {
117 | if ($TMP_DOWNLOAD_DIR.Exists) {
118 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
119 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
120 | }
121 | }
122 |
123 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
124 |
125 | # Download and Install Apache Maven
126 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
127 | Write-Verbose "Downloading from: $distributionUrl"
128 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
129 |
130 | $webclient = New-Object System.Net.WebClient
131 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
132 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
133 | }
134 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
135 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
136 |
137 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
138 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
139 | if ($distributionSha256Sum) {
140 | if ($USE_MVND) {
141 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
142 | }
143 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
144 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
145 | 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."
146 | }
147 | }
148 |
149 | # unzip and move
150 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
151 |
152 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
153 | $actualDistributionDir = ""
154 |
155 | # First try the expected directory name (for regular distributions)
156 | $expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
157 | $expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
158 | if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
159 | $actualDistributionDir = $distributionUrlNameMain
160 | }
161 |
162 | # If not found, search for any directory with the Maven executable (for snapshots)
163 | if (!$actualDistributionDir) {
164 | Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
165 | $testPath = Join-Path $_.FullName "bin/$MVN_CMD"
166 | if (Test-Path -Path $testPath -PathType Leaf) {
167 | $actualDistributionDir = $_.Name
168 | }
169 | }
170 | }
171 |
172 | if (!$actualDistributionDir) {
173 | Write-Error "Could not find Maven distribution directory in extracted archive"
174 | }
175 |
176 | Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
177 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null
178 | try {
179 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
180 | } catch {
181 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
182 | Write-Error "fail to move MAVEN_HOME"
183 | }
184 | } finally {
185 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
186 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
187 | }
188 |
189 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
190 |
--------------------------------------------------------------------------------
/initial/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/complete/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/complete-kotlin/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/initial-kotlin/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | https://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "{}"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright {yyyy} {name of copyright owner}
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | https://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | :spring_boot_version: current
2 | :SpringBootSecurity: http://docs.spring.io/spring-boot/docs/{spring_boot_version}/reference/htmlsingle/#boot-features-security
3 | :images: https://raw.githubusercontent.com/spring-guides/gs-securing-web/main/images
4 | :toc:
5 | :icons: font
6 | :source-highlighter: prettify
7 | :project_id: gs-securing-web
8 |
9 | This guide walks you through the process of creating a simple web application with
10 | resources that are protected by Spring Security.
11 |
12 | == What You Will Build
13 |
14 | You will build a Spring MVC application that secures the page with a login form that is
15 | backed by a fixed list of users.
16 |
17 | == What You Need
18 |
19 | :java_version: 17
20 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/prereq_editor_jdk_buildtools.adoc[]
21 |
22 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/how_to_complete_this_guide.adoc[]
23 |
24 | [[scratch]]
25 | == Starting with Spring Initializr
26 |
27 | You can use this https://start.spring.io/#!type=gradle-project&packaging=jar&language=java&jvmVersion=17&groupId=com.example&artifactId=securing-web&packageName=com.example.securingweb&dependencies=web,thymeleaf[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
28 |
29 | To manually initialize the project:
30 |
31 | . Navigate to https://start.spring.io.
32 | This service pulls in all the dependencies you need for an application and does most of the setup for you.
33 | . Choose either Gradle or Maven and the language you want to use.
34 | . Click *Dependencies* and select *Spring Web* and *Thymeleaf*.
35 | . Click *Generate*.
36 | . Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.
37 |
38 | NOTE: If your IDE has the Spring Initializr integration, you can complete this process from your IDE.
39 |
40 | NOTE: You can also fork the project from GitHub and open it in your IDE or other editor.
41 |
42 | [[initial]]
43 | == Create an Unsecured Web Application
44 |
45 | Before you can apply security to a web application, you need a web application to secure.
46 | This section walks you through creating a simple web application. Then you will secure it
47 | with Spring Security in the next section.
48 |
49 | The web application includes two simple views: a home page and a "`Hello, World`" page.
50 | The home page is defined in the following Thymeleaf template (from
51 | `src/main/resources/templates/home.html`):
52 |
53 | ====
54 | [source,html]
55 | ----
56 | include::initial/src/main/resources/templates/home.html[]
57 | ----
58 | ====
59 |
60 | This simple view includes a link to the `/hello` page, which is defined in the following
61 | Thymeleaf template (from `src/main/resources/templates/hello.html`):
62 |
63 | ====
64 | [source,html]
65 | ----
66 | include::initial/src/main/resources/templates/hello.html[]
67 | ----
68 | ====
69 |
70 | The web application is based on Spring MVC. As a result, you need to configure Spring MVC
71 | and set up view controllers to expose these templates. The following listing shows a class that configures
72 | Spring MVC in the application:
73 |
74 | ====
75 | [source,java,indent=0,subs="verbatim,quotes",role="primary"]
76 | .Java
77 | ----
78 | include::initial/src/main/java/com/example/securingweb/MvcConfig.java[]
79 | ----
80 | [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
81 | .Kotlin
82 | ----
83 | include::initial-kotlin/src/main/kotlin/com/example/securingweb/MvcConfig.kt[]
84 | ----
85 | ====
86 |
87 | The `addViewControllers()` method (which overrides the method of the same name in
88 | `WebMvcConfigurer`) adds four view controllers. Two of the view controllers reference
89 | the view whose name is `home` (defined in `home.html`), and another references the view
90 | named `hello` (defined in `hello.html`). The fourth view controller references another
91 | view named `login`. You will create that view in the next section.
92 |
93 | At this point, you could jump ahead to "`<>`" and run the application without
94 | having to log in to anything.
95 |
96 | Now that you have an unsecured web application, you can add security to it.
97 |
98 | [[initial]]
99 | == Set up Spring Security
100 |
101 | Suppose that you want to prevent unauthorized users from viewing the greeting page at
102 | `/hello`. As it is now, if visitors click the link on the home page, they see the greeting
103 | with no barriers to stop them. You need to add a barrier that forces the visitor to sign
104 | in before they can see that page.
105 |
106 | You do that by configuring Spring Security in the application. If Spring Security is on
107 | the classpath, Spring Boot {SpringBootSecurity}[automatically secures all HTTP endpoints]
108 | with "`basic`" authentication. However, you can further customize the security settings.
109 | The first thing you need to do is add Spring Security to the classpath.
110 |
111 | With Gradle, you need to add three lines (one for the application, one for Thymeleaf & Spring Security integration, and one for testing) in
112 | the `dependencies` section of your `build.gradle(.kts)` file, as the following listing shows:
113 |
114 | ====
115 | [source,groovy,indent=0,subs="verbatim,quotes",role="primary"]
116 | .Groovy (build.gradle)
117 | ----
118 | include::complete/build.gradle[tags=security-dependencies,indent=0]
119 | ----
120 | [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
121 | .Kotlin (build.gradle.kts)
122 | ----
123 | include::complete-kotlin/build.gradle.kts[tags=security-dependencies,indent=0]
124 | ----
125 | ====
126 |
127 | The following listing shows the finished `build.gradle(.kts)` file:
128 |
129 | ====
130 | [source,groovy,indent=0,subs="verbatim,quotes",role="primary"]
131 | .Groovy (build.gradle)
132 | ----
133 | include::complete/build.gradle[tags=**]
134 | ----
135 | [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
136 | .Kotlin (build.gradle.kts)
137 | ----
138 | include::complete-kotlin/build.gradle.kts[tags=**]
139 | ----
140 | ====
141 |
142 | With Maven, you need to add two extra entries (one for the application and one for
143 | testing) to the `` element in `pom.xml`, as the following listing shows:
144 |
145 | ====
146 | [source,xml]
147 | ----
148 | include::complete/pom.xml[tags=security-dependencies,indent=0]
149 | ----
150 | ====
151 |
152 | The following listing shows the finished `pom.xml` file:
153 |
154 | ====
155 | [source,text]
156 | ----
157 | include::complete/pom.xml[tags=**]
158 | ----
159 | ====
160 |
161 | The following security configuration ensures that only authenticated users can see the secret greeting:
162 |
163 | ====
164 | [source,java,indent=0,subs="verbatim,quotes",role="primary"]
165 | .Java
166 | ----
167 | include::complete/src/main/java/com/example/securingweb/WebSecurityConfig.java[]
168 | ----
169 | [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
170 | .Kotlin
171 | ----
172 | include::complete-kotlin/src/main/kotlin/com/example/securingweb/WebSecurityConfig.kt[]
173 | ----
174 | ====
175 |
176 | The `WebSecurityConfig` class is annotated with `@EnableWebSecurity` to enable Spring
177 | Security's web security support and provide the Spring MVC integration. It also exposes
178 | two beans to set some specifics for the web security configuration:
179 |
180 | The `SecurityFilterChain` bean defines which URL paths should be secured and which
181 | should not. Specifically, the `/` and `/home` paths are configured to not require any
182 | authentication. All other paths must be authenticated.
183 |
184 | When a user successfully logs in, they are redirected to the previously requested page
185 | that required authentication. There is a custom `/login` page (which is specified by
186 | `loginPage()`), and everyone is allowed to view it.
187 |
188 | The `UserDetailsService` bean sets up an in-memory user store with a single user. That
189 | user is given a user name of `user`, a password of `password`, and a role of `USER`.
190 |
191 | Now you need to create the login page. There is already a view controller for the `login`
192 | view, so you need only to create the login view itself, as the following listing (from
193 | `src/main/resources/templates/login.html`) shows:
194 |
195 | ====
196 | [source,html]
197 | ----
198 | include::complete/src/main/resources/templates/login.html[]
199 | ----
200 | ====
201 |
202 | This Thymeleaf template presents a form that captures a username and password and posts
203 | them to `/login`. As configured, Spring Security provides a filter that intercepts that
204 | request and authenticates the user. If the user fails to authenticate, the page is
205 | redirected to `/login?error`, and your page displays the appropriate error message. Upon
206 | successfully signing out, your application is sent to `/login?logout`, and your page
207 | displays the appropriate success message.
208 |
209 | Last, you need to provide the visitor a way to display the current user name and sign out.
210 | To do so, update the `hello.html` to say hello to the current user and contain a
211 | `Sign Out` form, as the following listing (from `src/main/resources/templates/hello.html`)
212 | shows:
213 |
214 | ====
215 |
216 | [source,html]
217 | ----
218 | include::complete/src/main/resources/templates/hello.html[]
219 | ----
220 | ====
221 |
222 | We display the username by using Thymeleaf's integration with Spring Security. The "`Sign Out`" form submits a POST to `/logout`.
223 | Upon successfully logging out, it redirects the user to `/login?logout`.
224 |
225 | [[run_the_app]]
226 | == Run the Application
227 |
228 | The Spring Initializr creates an application class for you. In this case, you need not
229 | modify the class. The following listing shows the application class:
230 |
231 | ====
232 | [source,java,indent=0,subs="verbatim,quotes",role="primary"]
233 | .Java
234 | ----
235 | include::complete/src/main/java/com/example/securingweb/SecuringWebApplication.java[]
236 | ----
237 | [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
238 | .Kotlin
239 | ----
240 | include::complete-kotlin/src/main/kotlin/com/example/securingweb/SecuringWebApplication.kt[]
241 | ----
242 | ====
243 |
244 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/build_an_executable_jar_subhead.adoc[]
245 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/build_an_executable_jar_with_both.adoc[]
246 |
247 |
248 | Once the application starts up, point your browser to `http://localhost:8080`. You should
249 | see the home page, as the following image shows:
250 |
251 | image::{images}/home.png[The application's home page]
252 |
253 | When you click on the link, it attempts to take you to the greeting page at `/hello`.
254 | However, because that page is secured and you have not yet logged in, it takes you to the
255 | login page, as the following image shows:
256 |
257 | image::{images}/login.png[The login page]
258 |
259 | NOTE: If you jumped down here with the unsecured version, you do not see the login page.
260 | You should back up and write the rest of the security-based code.
261 |
262 | At the login page, sign in as the test user by entering `user` and `password` for the
263 | username and password fields, respectively. Once you submit the login form, you are
264 | authenticated and then taken to the greeting page, as the following image shows:
265 |
266 | image::{images}/greeting.png[The secured greeting page]
267 |
268 | If you click on the *Sign Out* button, your authentication is revoked, and you are
269 | returned to the login page with a message indicating that you are logged out.
270 |
271 |
272 | == Summary
273 | Congratulations! You have developed a simple web application that is secured with Spring
274 | Security.
275 |
276 | == See Also
277 |
278 | The following guides may also be helpful:
279 |
280 | * https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot]
281 | * https://spring.io/guides/gs/serving-web-content/[Serving Web Content with Spring MVC]
282 | * https://spring.io/guides/tutorials/spring-security-and-angular-js/[Spring Security and Angular JS] (Tutorial)
283 |
284 | include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/main/footer.adoc[]
285 |
--------------------------------------------------------------------------------
/complete/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.3.3
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*)
39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
40 | native_path() { cygpath --path --windows "$1"; }
41 | ;;
42 | esac
43 |
44 | # set JAVACMD and JAVACCMD
45 | set_java_home() {
46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
47 | if [ -n "${JAVA_HOME-}" ]; then
48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then
49 | # IBM's JDK on AIX uses strange locations for the executables
50 | JAVACMD="$JAVA_HOME/jre/sh/java"
51 | JAVACCMD="$JAVA_HOME/jre/sh/javac"
52 | else
53 | JAVACMD="$JAVA_HOME/bin/java"
54 | JAVACCMD="$JAVA_HOME/bin/javac"
55 |
56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
59 | return 1
60 | fi
61 | fi
62 | else
63 | JAVACMD="$(
64 | 'set' +e
65 | 'unset' -f command 2>/dev/null
66 | 'command' -v java
67 | )" || :
68 | JAVACCMD="$(
69 | 'set' +e
70 | 'unset' -f command 2>/dev/null
71 | 'command' -v javac
72 | )" || :
73 |
74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
76 | return 1
77 | fi
78 | fi
79 | }
80 |
81 | # hash string like Java String::hashCode
82 | hash_string() {
83 | str="${1:-}" h=0
84 | while [ -n "$str" ]; do
85 | char="${str%"${str#?}"}"
86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
87 | str="${str#?}"
88 | done
89 | printf %x\\n $h
90 | }
91 |
92 | verbose() { :; }
93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
94 |
95 | die() {
96 | printf %s\\n "$1" >&2
97 | exit 1
98 | }
99 |
100 | trim() {
101 | # MWRAPPER-139:
102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
103 | # Needed for removing poorly interpreted newline sequences when running in more
104 | # exotic environments such as mingw bash on Windows.
105 | printf "%s" "${1}" | tr -d '[:space:]'
106 | }
107 |
108 | scriptDir="$(dirname "$0")"
109 | scriptName="$(basename "$0")"
110 |
111 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
112 | while IFS="=" read -r key value; do
113 | case "${key-}" in
114 | distributionUrl) distributionUrl=$(trim "${value-}") ;;
115 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
116 | esac
117 | done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
118 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
119 |
120 | case "${distributionUrl##*/}" in
121 | maven-mvnd-*bin.*)
122 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
123 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
124 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
125 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
126 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
127 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
128 | *)
129 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
130 | distributionPlatform=linux-amd64
131 | ;;
132 | esac
133 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
134 | ;;
135 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
136 | *) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
137 | esac
138 |
139 | # apply MVNW_REPOURL and calculate MAVEN_HOME
140 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
141 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
142 | distributionUrlName="${distributionUrl##*/}"
143 | distributionUrlNameMain="${distributionUrlName%.*}"
144 | distributionUrlNameMain="${distributionUrlNameMain%-bin}"
145 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
146 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
147 |
148 | exec_maven() {
149 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
150 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
151 | }
152 |
153 | if [ -d "$MAVEN_HOME" ]; then
154 | verbose "found existing MAVEN_HOME at $MAVEN_HOME"
155 | exec_maven "$@"
156 | fi
157 |
158 | case "${distributionUrl-}" in
159 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
160 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
161 | esac
162 |
163 | # prepare tmp dir
164 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
165 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
166 | trap clean HUP INT TERM EXIT
167 | else
168 | die "cannot create temp dir"
169 | fi
170 |
171 | mkdir -p -- "${MAVEN_HOME%/*}"
172 |
173 | # Download and Install Apache Maven
174 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
175 | verbose "Downloading from: $distributionUrl"
176 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
177 |
178 | # select .zip or .tar.gz
179 | if ! command -v unzip >/dev/null; then
180 | distributionUrl="${distributionUrl%.zip}.tar.gz"
181 | distributionUrlName="${distributionUrl##*/}"
182 | fi
183 |
184 | # verbose opt
185 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
186 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
187 |
188 | # normalize http auth
189 | case "${MVNW_PASSWORD:+has-password}" in
190 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
191 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
192 | esac
193 |
194 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
195 | verbose "Found wget ... using wget"
196 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
197 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
198 | verbose "Found curl ... using curl"
199 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
200 | elif set_java_home; then
201 | verbose "Falling back to use Java to download"
202 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
203 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
204 | cat >"$javaSource" <<-END
205 | public class Downloader extends java.net.Authenticator
206 | {
207 | protected java.net.PasswordAuthentication getPasswordAuthentication()
208 | {
209 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
210 | }
211 | public static void main( String[] args ) throws Exception
212 | {
213 | setDefault( new Downloader() );
214 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
215 | }
216 | }
217 | END
218 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java
219 | verbose " - Compiling Downloader.java ..."
220 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
221 | verbose " - Running Downloader.java ..."
222 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
223 | fi
224 |
225 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
226 | if [ -n "${distributionSha256Sum-}" ]; then
227 | distributionSha256Result=false
228 | if [ "$MVN_CMD" = mvnd.sh ]; then
229 | echo "Checksum validation is not supported for maven-mvnd." >&2
230 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
231 | exit 1
232 | elif command -v sha256sum >/dev/null; then
233 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
234 | distributionSha256Result=true
235 | fi
236 | elif command -v shasum >/dev/null; then
237 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
238 | distributionSha256Result=true
239 | fi
240 | else
241 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
242 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
243 | exit 1
244 | fi
245 | if [ $distributionSha256Result = false ]; then
246 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
247 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
248 | exit 1
249 | fi
250 | fi
251 |
252 | # unzip and move
253 | if command -v unzip >/dev/null; then
254 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
255 | else
256 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
257 | fi
258 |
259 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
260 | actualDistributionDir=""
261 |
262 | # First try the expected directory name (for regular distributions)
263 | if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
264 | if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
265 | actualDistributionDir="$distributionUrlNameMain"
266 | fi
267 | fi
268 |
269 | # If not found, search for any directory with the Maven executable (for snapshots)
270 | if [ -z "$actualDistributionDir" ]; then
271 | # enable globbing to iterate over items
272 | set +f
273 | for dir in "$TMP_DOWNLOAD_DIR"/*; do
274 | if [ -d "$dir" ]; then
275 | if [ -f "$dir/bin/$MVN_CMD" ]; then
276 | actualDistributionDir="$(basename "$dir")"
277 | break
278 | fi
279 | fi
280 | done
281 | set -f
282 | fi
283 |
284 | if [ -z "$actualDistributionDir" ]; then
285 | verbose "Contents of $TMP_DOWNLOAD_DIR:"
286 | verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
287 | die "Could not find Maven distribution directory in extracted archive"
288 | fi
289 |
290 | verbose "Found extracted Maven distribution directory: $actualDistributionDir"
291 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
292 | mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
293 |
294 | clean || :
295 | exec_maven "$@"
296 |
--------------------------------------------------------------------------------
/initial/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.3.3
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*)
39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
40 | native_path() { cygpath --path --windows "$1"; }
41 | ;;
42 | esac
43 |
44 | # set JAVACMD and JAVACCMD
45 | set_java_home() {
46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
47 | if [ -n "${JAVA_HOME-}" ]; then
48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then
49 | # IBM's JDK on AIX uses strange locations for the executables
50 | JAVACMD="$JAVA_HOME/jre/sh/java"
51 | JAVACCMD="$JAVA_HOME/jre/sh/javac"
52 | else
53 | JAVACMD="$JAVA_HOME/bin/java"
54 | JAVACCMD="$JAVA_HOME/bin/javac"
55 |
56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
59 | return 1
60 | fi
61 | fi
62 | else
63 | JAVACMD="$(
64 | 'set' +e
65 | 'unset' -f command 2>/dev/null
66 | 'command' -v java
67 | )" || :
68 | JAVACCMD="$(
69 | 'set' +e
70 | 'unset' -f command 2>/dev/null
71 | 'command' -v javac
72 | )" || :
73 |
74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
76 | return 1
77 | fi
78 | fi
79 | }
80 |
81 | # hash string like Java String::hashCode
82 | hash_string() {
83 | str="${1:-}" h=0
84 | while [ -n "$str" ]; do
85 | char="${str%"${str#?}"}"
86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
87 | str="${str#?}"
88 | done
89 | printf %x\\n $h
90 | }
91 |
92 | verbose() { :; }
93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
94 |
95 | die() {
96 | printf %s\\n "$1" >&2
97 | exit 1
98 | }
99 |
100 | trim() {
101 | # MWRAPPER-139:
102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
103 | # Needed for removing poorly interpreted newline sequences when running in more
104 | # exotic environments such as mingw bash on Windows.
105 | printf "%s" "${1}" | tr -d '[:space:]'
106 | }
107 |
108 | scriptDir="$(dirname "$0")"
109 | scriptName="$(basename "$0")"
110 |
111 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
112 | while IFS="=" read -r key value; do
113 | case "${key-}" in
114 | distributionUrl) distributionUrl=$(trim "${value-}") ;;
115 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
116 | esac
117 | done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
118 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
119 |
120 | case "${distributionUrl##*/}" in
121 | maven-mvnd-*bin.*)
122 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
123 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
124 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
125 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
126 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
127 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;;
128 | *)
129 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
130 | distributionPlatform=linux-amd64
131 | ;;
132 | esac
133 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
134 | ;;
135 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
136 | *) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
137 | esac
138 |
139 | # apply MVNW_REPOURL and calculate MAVEN_HOME
140 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
141 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
142 | distributionUrlName="${distributionUrl##*/}"
143 | distributionUrlNameMain="${distributionUrlName%.*}"
144 | distributionUrlNameMain="${distributionUrlNameMain%-bin}"
145 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
146 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
147 |
148 | exec_maven() {
149 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
150 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
151 | }
152 |
153 | if [ -d "$MAVEN_HOME" ]; then
154 | verbose "found existing MAVEN_HOME at $MAVEN_HOME"
155 | exec_maven "$@"
156 | fi
157 |
158 | case "${distributionUrl-}" in
159 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
160 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
161 | esac
162 |
163 | # prepare tmp dir
164 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
165 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
166 | trap clean HUP INT TERM EXIT
167 | else
168 | die "cannot create temp dir"
169 | fi
170 |
171 | mkdir -p -- "${MAVEN_HOME%/*}"
172 |
173 | # Download and Install Apache Maven
174 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
175 | verbose "Downloading from: $distributionUrl"
176 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
177 |
178 | # select .zip or .tar.gz
179 | if ! command -v unzip >/dev/null; then
180 | distributionUrl="${distributionUrl%.zip}.tar.gz"
181 | distributionUrlName="${distributionUrl##*/}"
182 | fi
183 |
184 | # verbose opt
185 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
186 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
187 |
188 | # normalize http auth
189 | case "${MVNW_PASSWORD:+has-password}" in
190 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
191 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
192 | esac
193 |
194 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
195 | verbose "Found wget ... using wget"
196 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
197 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
198 | verbose "Found curl ... using curl"
199 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
200 | elif set_java_home; then
201 | verbose "Falling back to use Java to download"
202 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
203 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
204 | cat >"$javaSource" <<-END
205 | public class Downloader extends java.net.Authenticator
206 | {
207 | protected java.net.PasswordAuthentication getPasswordAuthentication()
208 | {
209 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
210 | }
211 | public static void main( String[] args ) throws Exception
212 | {
213 | setDefault( new Downloader() );
214 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
215 | }
216 | }
217 | END
218 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java
219 | verbose " - Compiling Downloader.java ..."
220 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
221 | verbose " - Running Downloader.java ..."
222 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
223 | fi
224 |
225 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
226 | if [ -n "${distributionSha256Sum-}" ]; then
227 | distributionSha256Result=false
228 | if [ "$MVN_CMD" = mvnd.sh ]; then
229 | echo "Checksum validation is not supported for maven-mvnd." >&2
230 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
231 | exit 1
232 | elif command -v sha256sum >/dev/null; then
233 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then
234 | distributionSha256Result=true
235 | fi
236 | elif command -v shasum >/dev/null; then
237 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
238 | distributionSha256Result=true
239 | fi
240 | else
241 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
242 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
243 | exit 1
244 | fi
245 | if [ $distributionSha256Result = false ]; then
246 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
247 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
248 | exit 1
249 | fi
250 | fi
251 |
252 | # unzip and move
253 | if command -v unzip >/dev/null; then
254 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
255 | else
256 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
257 | fi
258 |
259 | # Find the actual extracted directory name (handles snapshots where filename != directory name)
260 | actualDistributionDir=""
261 |
262 | # First try the expected directory name (for regular distributions)
263 | if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
264 | if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
265 | actualDistributionDir="$distributionUrlNameMain"
266 | fi
267 | fi
268 |
269 | # If not found, search for any directory with the Maven executable (for snapshots)
270 | if [ -z "$actualDistributionDir" ]; then
271 | # enable globbing to iterate over items
272 | set +f
273 | for dir in "$TMP_DOWNLOAD_DIR"/*; do
274 | if [ -d "$dir" ]; then
275 | if [ -f "$dir/bin/$MVN_CMD" ]; then
276 | actualDistributionDir="$(basename "$dir")"
277 | break
278 | fi
279 | fi
280 | done
281 | set -f
282 | fi
283 |
284 | if [ -z "$actualDistributionDir" ]; then
285 | verbose "Contents of $TMP_DOWNLOAD_DIR:"
286 | verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
287 | die "Could not find Maven distribution directory in extracted archive"
288 | fi
289 |
290 | verbose "Found extracted Maven distribution directory: $actualDistributionDir"
291 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
292 | mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
293 |
294 | clean || :
295 | exec_maven "$@"
296 |
--------------------------------------------------------------------------------