wad-lab 1.0.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +13 -5
- package/package.json +1 -1
- package/templates/servlet-session-tracking/WEB-INF/LoginServlet.java +46 -0
- package/templates/servlet-session-tracking/WEB-INF/LogoutServlet.java +39 -0
- package/templates/servlet-session-tracking/WEB-INF/ProfileServlet.java +83 -0
- package/templates/servlet-session-tracking/WEB-INF/classes/LoginServlet.class +0 -0
- package/templates/servlet-session-tracking/WEB-INF/classes/LogoutServlet.class +0 -0
- package/templates/servlet-session-tracking/WEB-INF/classes/ProfileServlet.class +0 -0
- package/templates/servlet-session-tracking/WEB-INF/web.xml +38 -0
- package/templates/servlet-session-tracking/index.html +36 -0
- package/templates/springboot-hospital-api/.mvn/wrapper/maven-wrapper.properties +3 -0
- package/templates/springboot-hospital-api/mvnw +295 -0
- package/templates/springboot-hospital-api/mvnw.cmd +189 -0
- package/templates/springboot-hospital-api/pom.xml +41 -0
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/HospitalApplication.java +12 -0
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +50 -0
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/model/Appointment.java +95 -0
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/repository/AppointmentRepository.java +15 -0
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +54 -0
- package/templates/springboot-hospital-api/src/main/resources/application.properties +3 -0
- package/templates/springboot-hospital-api/src/test/java/com/example/hospital/HospitalApplicationTests.java +12 -0
- package/templates/springboot-library-api/.mvn/wrapper/maven-wrapper.properties +3 -0
- package/templates/springboot-library-api/mvnw +295 -0
- package/templates/springboot-library-api/mvnw.cmd +189 -0
- package/templates/springboot-library-api/pom.xml +42 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/LibraryApplication.java +12 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +51 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/model/Book.java +76 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/model/CategoryAnalytics.java +41 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/repository/BookRepository.java +13 -0
- package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +60 -0
- package/templates/springboot-library-api/src/main/resources/application.properties +3 -0
- package/templates/vue-game-rps/index.html +12 -0
- package/templates/vue-game-rps/package.json +19 -0
- package/templates/vue-game-rps/src/App.vue +125 -0
- package/templates/vue-game-rps/src/main.js +5 -0
- package/templates/vue-game-rps/src/stores/rpsStore.js +43 -0
- package/templates/vue-game-rps/vite.config.js +6 -0
- package/templates/vue-game-tictactoe/index.html +12 -0
- package/templates/vue-game-tictactoe/package.json +19 -0
- package/templates/vue-game-tictactoe/src/App.vue +105 -0
- package/templates/vue-game-tictactoe/src/main.js +5 -0
- package/templates/vue-game-tictactoe/src/stores/tictactoeStore.js +61 -0
- package/templates/vue-game-tictactoe/vite.config.js +6 -0
- package/templates/vue-game-whackamole/index.html +12 -0
- package/templates/vue-game-whackamole/package.json +19 -0
- package/templates/vue-game-whackamole/src/App.vue +104 -0
- package/templates/vue-game-whackamole/src/main.js +7 -0
- package/templates/vue-game-whackamole/src/stores/moleStore.js +71 -0
- package/templates/vue-game-whackamole/vite.config.js +6 -0
- package/templates/vue-hospital-portal/index.html +12 -0
- package/templates/vue-hospital-portal/package.json +20 -0
- package/templates/vue-hospital-portal/src/App.vue +107 -0
- package/templates/vue-hospital-portal/src/main.js +9 -0
- package/templates/vue-hospital-portal/src/router/index.js +17 -0
- package/templates/vue-hospital-portal/src/stores/hospitalStore.js +91 -0
- package/templates/vue-hospital-portal/src/views/HospitalBillingView.vue +271 -0
- package/templates/vue-hospital-portal/src/views/OPDRegistrationView.vue +453 -0
- package/templates/vue-hospital-portal/src/views/PatientListView.vue +315 -0
- package/templates/vue-hospital-portal/vite.config.js +6 -0
- package/templates/vue-library-system/index.html +12 -0
- package/templates/vue-library-system/package.json +20 -0
- package/templates/vue-library-system/src/App.vue +91 -0
- package/templates/vue-library-system/src/main.js +9 -0
- package/templates/vue-library-system/src/router/index.js +29 -0
- package/templates/vue-library-system/src/stores/libraryStore.js +87 -0
- package/templates/vue-library-system/src/views/BookCatalogView.vue +432 -0
- package/templates/vue-library-system/src/views/LoanManagerView.vue +296 -0
- package/templates/vue-library-system/src/views/MembershipView.vue +269 -0
- package/templates/vue-library-system/vite.config.js +6 -0
package/bin/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function copyDirRecursive(src, dest) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const templates = [
|
|
31
|
-
{ name: 'all (Unpack All
|
|
31
|
+
{ name: 'all (Unpack All 41 Templates)', value: 'all' },
|
|
32
32
|
{ name: 'vue-basics (ref, reactive, computed, v-model)', value: 'vue-basics' },
|
|
33
33
|
{ name: 'vue-props-emits (Parent/Child Component Communication)', value: 'vue-props-emits' },
|
|
34
34
|
{ name: 'vue-router (Parent Layout & Nested Children)', value: 'vue-router' },
|
|
@@ -44,6 +44,7 @@ const templates = [
|
|
|
44
44
|
{ name: 'servlet-basic (Tomcat GET + POST)', value: 'servlet-basic' },
|
|
45
45
|
{ name: 'servlet-jdbc (Tomcat + MySQL JDBC)', value: 'servlet-jdbc' },
|
|
46
46
|
{ name: 'servlet-flow (HelloServlet with GET/POST)', value: 'servlet-flow' },
|
|
47
|
+
{ name: 'servlet-session-tracking (HttpSession, Cookies, Redirect, URL Rewriting)', value: 'servlet-session-tracking' },
|
|
47
48
|
{ name: 'springboot-mongo-crud (4-Layer REST API)', value: 'springboot-mongo-crud' },
|
|
48
49
|
{ name: 'springboot-mongo-aggregation ($group, $sum, $avg, $sort)', value: 'springboot-mongo-aggregation' },
|
|
49
50
|
{ name: 'springboot-mockmvc (Controller Tests)', value: 'springboot-mockmvc' },
|
|
@@ -52,16 +53,23 @@ const templates = [
|
|
|
52
53
|
{ name: 'game-tic-tac-toe (3x3 Turn Grid with Win Check)', value: 'game-tic-tac-toe' },
|
|
53
54
|
{ name: 'game-whack-a-mole (3x3 Mole Whack with Timer)', value: 'game-whack-a-mole' },
|
|
54
55
|
{ name: 'game-memory-cards (3x4 Flashcard Matching Game)', value: 'game-memory-cards' },
|
|
56
|
+
{ name: 'game-bingo (Exercise 3 — JavaScript Bingo Game)', value: 'game-bingo' },
|
|
57
|
+
{ name: 'vue-game-rps (Vue 3 + Pinia Rock Paper Scissors)', value: 'vue-game-rps' },
|
|
58
|
+
{ name: 'vue-game-tictactoe (Vue 3 + Pinia Tic Tac Toe)', value: 'vue-game-tictactoe' },
|
|
59
|
+
{ name: 'vue-game-whackamole (Vue 3 + Pinia Whack A Mole)', value: 'vue-game-whackamole' },
|
|
55
60
|
{ name: 'vue-memory-game (Vue 3 + Pinia Flashcard Matching)', value: 'vue-memory-game' },
|
|
56
61
|
{ name: 'vue-springboot-mongo-crud (Fullstack CRUD)', value: 'vue-springboot-mongo-crud' },
|
|
57
62
|
{ name: 'vue-springboot-mongo-aggregation (Fullstack Dashboard)', value: 'vue-springboot-mongo-aggregation' },
|
|
58
63
|
{ name: 'vue-router-pinia-springboot (Fullstack Enterprise)', value: 'vue-router-pinia-springboot' },
|
|
59
|
-
{ name: 'game-bingo (Exercise 3 — JavaScript Bingo Game)', value: 'game-bingo' },
|
|
60
64
|
{ name: 'vue-food-ordering (Exercise 7 — Online Food Ordering App)', value: 'vue-food-ordering' },
|
|
61
|
-
{ name: 'vue-banking-app (Banking Portal & Ledger Variant)', value: 'vue-banking-app' },
|
|
62
|
-
{ name: 'vue-employee-system (Employee HR & Payroll Variant)', value: 'vue-employee-system' },
|
|
63
65
|
{ name: 'vue-symposium-system (Exercise 6 — College Symposium Management)', value: 'vue-symposium-system' },
|
|
64
|
-
{ name: '
|
|
66
|
+
{ name: 'vue-banking-app (Variant 2 — Banking Portal & Ledger)', value: 'vue-banking-app' },
|
|
67
|
+
{ name: 'vue-employee-system (Variant 1 — Employee HR & Payroll)', value: 'vue-employee-system' },
|
|
68
|
+
{ name: 'vue-hospital-portal (Variant 3 — Hospital OPD & Vitals Portal)', value: 'vue-hospital-portal' },
|
|
69
|
+
{ name: 'vue-library-system (Variant 4 — Library Book Loans & Members)', value: 'vue-library-system' },
|
|
70
|
+
{ name: 'springboot-course-registration (Exercise 5 — Course Registration REST API)', value: 'springboot-course-registration' },
|
|
71
|
+
{ name: 'springboot-hospital-api (Variant 3 — Hospital Appointments API)', value: 'springboot-hospital-api' },
|
|
72
|
+
{ name: 'springboot-library-api (Variant 4 — Library Catalog & Analytics API)', value: 'springboot-library-api' }
|
|
65
73
|
];
|
|
66
74
|
|
|
67
75
|
let selectedIndex = 0;
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import java.io.PrintWriter;
|
|
3
|
+
import javax.servlet.ServletException;
|
|
4
|
+
import javax.servlet.http.Cookie;
|
|
5
|
+
import javax.servlet.http.HttpServlet;
|
|
6
|
+
import javax.servlet.http.HttpServletRequest;
|
|
7
|
+
import javax.servlet.http.HttpServletResponse;
|
|
8
|
+
import javax.servlet.http.HttpSession;
|
|
9
|
+
|
|
10
|
+
public class LoginServlet extends HttpServlet {
|
|
11
|
+
|
|
12
|
+
@Override
|
|
13
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
14
|
+
throws ServletException, IOException {
|
|
15
|
+
response.setContentType("text/html");
|
|
16
|
+
PrintWriter out = response.getWriter();
|
|
17
|
+
out.println("<html><body>");
|
|
18
|
+
out.println("<h2>Please submit the login form from <a href='index.html'>index.html</a></h2>");
|
|
19
|
+
out.println("</body></html>");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
24
|
+
throws ServletException, IOException {
|
|
25
|
+
|
|
26
|
+
String username = request.getParameter("username");
|
|
27
|
+
String role = request.getParameter("role");
|
|
28
|
+
|
|
29
|
+
if (username == null || username.trim().isEmpty()) {
|
|
30
|
+
response.sendRedirect("index.html");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
HttpSession session = request.getSession(true);
|
|
35
|
+
session.setAttribute("currentUser", username.trim());
|
|
36
|
+
session.setAttribute("userRole", role != null ? role.trim() : "Student");
|
|
37
|
+
session.setMaxInactiveInterval(1800);
|
|
38
|
+
|
|
39
|
+
Cookie userCookie = new Cookie("lastUser", username.trim());
|
|
40
|
+
userCookie.setMaxAge(60 * 60 * 24);
|
|
41
|
+
response.addCookie(userCookie);
|
|
42
|
+
|
|
43
|
+
String encodedRedirectURL = response.encodeRedirectURL("session-profile");
|
|
44
|
+
response.sendRedirect(encodedRedirectURL);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import java.io.PrintWriter;
|
|
3
|
+
import javax.servlet.ServletException;
|
|
4
|
+
import javax.servlet.http.Cookie;
|
|
5
|
+
import javax.servlet.http.HttpServlet;
|
|
6
|
+
import javax.servlet.http.HttpServletRequest;
|
|
7
|
+
import javax.servlet.http.HttpServletResponse;
|
|
8
|
+
import javax.servlet.http.HttpSession;
|
|
9
|
+
|
|
10
|
+
public class LogoutServlet extends HttpServlet {
|
|
11
|
+
|
|
12
|
+
@Override
|
|
13
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
14
|
+
throws ServletException, IOException {
|
|
15
|
+
|
|
16
|
+
HttpSession session = request.getSession(false);
|
|
17
|
+
if (session != null) {
|
|
18
|
+
session.invalidate();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Cookie clearCookie = new Cookie("lastUser", "");
|
|
22
|
+
clearCookie.setMaxAge(0);
|
|
23
|
+
response.addCookie(clearCookie);
|
|
24
|
+
|
|
25
|
+
response.setContentType("text/html");
|
|
26
|
+
PrintWriter out = response.getWriter();
|
|
27
|
+
out.println("<html><head><title>Logged Out</title></head><body>");
|
|
28
|
+
out.println("<h2>You have been successfully logged out!</h2>");
|
|
29
|
+
out.println("<p>HttpSession invalidated and client cookies expired.</p>");
|
|
30
|
+
out.println("<p><a href='index.html'>Click here to Login Again</a></p>");
|
|
31
|
+
out.println("</body></html>");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
36
|
+
throws ServletException, IOException {
|
|
37
|
+
doGet(request, response);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import java.io.PrintWriter;
|
|
3
|
+
import java.util.Date;
|
|
4
|
+
import javax.servlet.ServletException;
|
|
5
|
+
import javax.servlet.http.Cookie;
|
|
6
|
+
import javax.servlet.http.HttpServlet;
|
|
7
|
+
import javax.servlet.http.HttpServletRequest;
|
|
8
|
+
import javax.servlet.http.HttpServletResponse;
|
|
9
|
+
import javax.servlet.http.HttpSession;
|
|
10
|
+
|
|
11
|
+
public class ProfileServlet extends HttpServlet {
|
|
12
|
+
|
|
13
|
+
@Override
|
|
14
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
15
|
+
throws ServletException, IOException {
|
|
16
|
+
|
|
17
|
+
response.setContentType("text/html");
|
|
18
|
+
PrintWriter out = response.getWriter();
|
|
19
|
+
|
|
20
|
+
HttpSession session = request.getSession(false);
|
|
21
|
+
|
|
22
|
+
if (session == null || session.getAttribute("currentUser") == null) {
|
|
23
|
+
out.println("<html><body>");
|
|
24
|
+
out.println("<h3 style='color:red;'>Access Denied. No active session found.</h3>");
|
|
25
|
+
out.println("<a href='index.html'>Click here to Login</a>");
|
|
26
|
+
out.println("</body></html>");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
String username = (String) session.getAttribute("currentUser");
|
|
31
|
+
String role = (String) session.getAttribute("userRole");
|
|
32
|
+
String sessionId = session.getId();
|
|
33
|
+
Date creationTime = new Date(session.getCreationTime());
|
|
34
|
+
Date lastAccessed = new Date(session.getLastAccessedTime());
|
|
35
|
+
|
|
36
|
+
String lastUserCookieVal = "None";
|
|
37
|
+
Cookie[] cookies = request.getCookies();
|
|
38
|
+
if (cookies != null) {
|
|
39
|
+
for (Cookie c : cookies) {
|
|
40
|
+
if ("lastUser".equals(c.getName())) {
|
|
41
|
+
lastUserCookieVal = c.getValue();
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
String logoutURLWithRewriting = response.encodeURL("session-logout");
|
|
48
|
+
|
|
49
|
+
out.println("<html><head><title>User Profile</title></head><body>");
|
|
50
|
+
out.println("<h2>Welcome, " + username + "!</h2>");
|
|
51
|
+
out.println("<fieldset>");
|
|
52
|
+
out.println("<legend>HttpSession Details</legend>");
|
|
53
|
+
out.println("<p><strong>Username:</strong> " + username + "</p>");
|
|
54
|
+
out.println("<p><strong>Assigned Role:</strong> " + role + "</p>");
|
|
55
|
+
out.println("<p><strong>Session ID:</strong> " + sessionId + "</p>");
|
|
56
|
+
out.println("<p><strong>Session Creation Time:</strong> " + creationTime + "</p>");
|
|
57
|
+
out.println("<p><strong>Last Accessed Time:</strong> " + lastAccessed + "</p>");
|
|
58
|
+
out.println("</fieldset>");
|
|
59
|
+
|
|
60
|
+
out.println("<br>");
|
|
61
|
+
|
|
62
|
+
out.println("<fieldset>");
|
|
63
|
+
out.println("<legend>Cookie Details</legend>");
|
|
64
|
+
out.println("<p><strong>Cookie 'lastUser':</strong> " + lastUserCookieVal + "</p>");
|
|
65
|
+
out.println("</fieldset>");
|
|
66
|
+
|
|
67
|
+
out.println("<br>");
|
|
68
|
+
|
|
69
|
+
out.println("<fieldset>");
|
|
70
|
+
out.println("<legend>URL Rewriting & Navigation</legend>");
|
|
71
|
+
out.println("<p><a href='" + logoutURLWithRewriting + "'>Logout (via URL Rewritten Link)</a></p>");
|
|
72
|
+
out.println("<p><a href='index.html'>Return to Home Form</a></p>");
|
|
73
|
+
out.println("</fieldset>");
|
|
74
|
+
|
|
75
|
+
out.println("</body></html>");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Override
|
|
79
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
80
|
+
throws ServletException, IOException {
|
|
81
|
+
doGet(request, response);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
4
|
+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
|
5
|
+
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
|
6
|
+
version="3.1">
|
|
7
|
+
|
|
8
|
+
<servlet>
|
|
9
|
+
<servlet-name>LoginServlet</servlet-name>
|
|
10
|
+
<servlet-class>LoginServlet</servlet-class>
|
|
11
|
+
</servlet>
|
|
12
|
+
<servlet-mapping>
|
|
13
|
+
<servlet-name>LoginServlet</servlet-name>
|
|
14
|
+
<url-pattern>/session-login</url-pattern>
|
|
15
|
+
</servlet-mapping>
|
|
16
|
+
|
|
17
|
+
<servlet>
|
|
18
|
+
<servlet-name>ProfileServlet</servlet-name>
|
|
19
|
+
<servlet-class>ProfileServlet</servlet-class>
|
|
20
|
+
</servlet>
|
|
21
|
+
<servlet-mapping>
|
|
22
|
+
<servlet-name>ProfileServlet</servlet-name>
|
|
23
|
+
<url-pattern>/session-profile</url-pattern>
|
|
24
|
+
</servlet-mapping>
|
|
25
|
+
|
|
26
|
+
<servlet>
|
|
27
|
+
<servlet-name>LogoutServlet</servlet-name>
|
|
28
|
+
<servlet-class>LogoutServlet</servlet-class>
|
|
29
|
+
</servlet>
|
|
30
|
+
<servlet-mapping>
|
|
31
|
+
<servlet-name>LogoutServlet</servlet-name>
|
|
32
|
+
<url-pattern>/session-logout</url-pattern>
|
|
33
|
+
</servlet-mapping>
|
|
34
|
+
|
|
35
|
+
<welcome-file-list>
|
|
36
|
+
<welcome-file>index.html</welcome-file>
|
|
37
|
+
</welcome-file-list>
|
|
38
|
+
</web-app>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Servlet Session & State Tracking</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h2>Session Tracking & Redirect Demo</h2>
|
|
8
|
+
|
|
9
|
+
<fieldset>
|
|
10
|
+
<legend>1. Login & Establish HttpSession & Cookies</legend>
|
|
11
|
+
<form action="session-login" method="post">
|
|
12
|
+
<label>Username:</label><br>
|
|
13
|
+
<input type="text" name="username" required><br><br>
|
|
14
|
+
|
|
15
|
+
<label>Role:</label><br>
|
|
16
|
+
<input type="text" name="role" value="Student" required><br><br>
|
|
17
|
+
|
|
18
|
+
<button type="submit">Login (Stores Session & Sets Cookie & Redirects)</button>
|
|
19
|
+
</form>
|
|
20
|
+
</fieldset>
|
|
21
|
+
|
|
22
|
+
<br>
|
|
23
|
+
|
|
24
|
+
<fieldset>
|
|
25
|
+
<legend>2. Access Protected Profile</legend>
|
|
26
|
+
<a href="session-profile">View Profile (Reads HttpSession & Cookies)</a>
|
|
27
|
+
</fieldset>
|
|
28
|
+
|
|
29
|
+
<br>
|
|
30
|
+
|
|
31
|
+
<fieldset>
|
|
32
|
+
<legend>3. Logout & Invalidate Session</legend>
|
|
33
|
+
<a href="session-logout">Logout (Invalidates Session & Clears Cookies)</a>
|
|
34
|
+
</fieldset>
|
|
35
|
+
</body>
|
|
36
|
+
</html>
|
|
@@ -0,0 +1,295 @@
|
|
|
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.4
|
|
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-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
|
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 "$@"
|