wad-lab 1.1.8 → 1.2.0

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.
Files changed (18) hide show
  1. package/bin/index.js +3 -1
  2. package/package.json +2 -2
  3. package/templates/html-css-styles/index.html +109 -0
  4. package/templates/html-css-styles/style.css +139 -0
  5. package/templates/springboot-mongo-aggregation-join/.mvn/wrapper/maven-wrapper.properties +3 -0
  6. package/templates/springboot-mongo-aggregation-join/mvnw +295 -0
  7. package/templates/springboot-mongo-aggregation-join/mvnw.cmd +189 -0
  8. package/templates/springboot-mongo-aggregation-join/pom.xml +91 -0
  9. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/JoinAggApplication.java +36 -0
  10. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/controller/JoinController.java +33 -0
  11. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/model/Customer.java +14 -0
  12. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/model/CustomerTotal.java +11 -0
  13. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/model/Order.java +16 -0
  14. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/model/OrderWithCustomer.java +14 -0
  15. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/repository/CustomerRepository.java +9 -0
  16. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/repository/OrderRepository.java +73 -0
  17. package/templates/springboot-mongo-aggregation-join/src/main/java/com/example/joinagg/service/JoinService.java +58 -0
  18. package/templates/springboot-mongo-aggregation-join/src/main/resources/application.properties +4 -0
package/bin/index.js CHANGED
@@ -42,7 +42,7 @@ const frontendOptions = [
42
42
  ];
43
43
 
44
44
  const templates = [
45
- { name: 'all (Unpack All 54 Templates)', value: 'all' },
45
+ { name: 'all (Unpack All 56 Templates)', value: 'all' },
46
46
  { name: 'servlet-voter-eligibility (Name & Age Voting Eligibility Check)', value: 'servlet-voter-eligibility' },
47
47
  { name: 'fullstack-springboot-vue (Spring Boot: 2 Models, 2 Repos, 1 Service, 1 Controller + Selectable Vue 3 Axios Frontend)', value: 'fullstack-springboot-vue' },
48
48
  { name: 'springboot-2model-1controller-api (Spring Boot 1 Service, 1 Controller, 2 Models, 2 Repos)', value: 'springboot-2model-1controller-api' },
@@ -68,12 +68,14 @@ const templates = [
68
68
  { name: 'vue-todo-router (Router Multi-View Tasks)', value: 'vue-todo-router' },
69
69
  { name: 'vue-cart-router-pinia (Router + Pinia Shopping Cart)', value: 'vue-cart-router-pinia' },
70
70
  { name: 'html-css-js (Form Validation & DOM)', value: 'html-css-js' },
71
+ { name: 'html-css-styles (50 CSS properties showcase)', value: 'html-css-styles' },
71
72
  { name: 'servlet-basic (Tomcat GET + POST)', value: 'servlet-basic' },
72
73
  { name: 'servlet-jdbc (Tomcat + MySQL JDBC)', value: 'servlet-jdbc' },
73
74
  { name: 'servlet-flow (HelloServlet with GET/POST)', value: 'servlet-flow' },
74
75
  { name: 'servlet-session-tracking (HttpSession, Cookies, Redirect, URL Rewriting)', value: 'servlet-session-tracking' },
75
76
  { name: 'springboot-mongo-crud (4-Layer REST API)', value: 'springboot-mongo-crud' },
76
77
  { name: 'springboot-mongo-aggregation ($group, $sum, $avg, $sort)', value: 'springboot-mongo-aggregation' },
78
+ { name: 'springboot-mongo-aggregation-join ($lookup JOIN, @Query, @Aggregation)', value: 'springboot-mongo-aggregation-join' },
77
79
  { name: 'springboot-mockmvc (Controller Tests)', value: 'springboot-mockmvc' },
78
80
  { name: 'springboot-mongo-aggregation-mockmvc (Full Tests)', value: 'springboot-mongo-aggregation-mockmvc' },
79
81
  { name: 'game-rock-paper-scissors (Player vs Computer RPS)', value: 'game-rock-paper-scissors' },
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "wad-lab",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "Interactive CLI for WAD Lab starter templates compatible with Node 12+",
5
5
  "bin": {
6
- "wad-lab": "./bin/index.js"
6
+ "wad-lab": "bin/index.js"
7
7
  },
8
8
  "engines": {
9
9
  "node": ">=12.0.0"
@@ -0,0 +1,109 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>CSS Styles Showcase</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ </head>
9
+ <body>
10
+ <header class="site-header">
11
+ <h1 class="gradient-text">CSS Styles Showcase</h1>
12
+ <nav class="nav">
13
+ <a href="#box">Box</a><a href="#text">Text</a><a href="#layout">Layout</a>
14
+ <a href="#effects">Effects</a><a href="#anim">Animation</a><a href="#form">Form</a>
15
+ </nav>
16
+ </header>
17
+
18
+ <main class="container">
19
+
20
+ <section id="box">
21
+ <h2>1. Box model &amp; borders</h2>
22
+ <div class="grid">
23
+ <div class="card shadow">box-shadow</div>
24
+ <div class="card shadow-inset">inset box-shadow</div>
25
+ <div class="card shadow-multi">multiple shadows</div>
26
+ <div class="card rounded">border-radius</div>
27
+ <div class="card circle">circle</div>
28
+ <div class="card dashed">dashed border</div>
29
+ <div class="card outlined">outline + offset</div>
30
+ <div class="card padded">padding / margin</div>
31
+ </div>
32
+ </section>
33
+
34
+ <section id="text">
35
+ <h2>2. Typography</h2>
36
+ <p class="t-spacing">letter-spacing, word-spacing, line-height</p>
37
+ <p class="t-shadow">text-shadow</p>
38
+ <p class="t-upper">text-transform uppercase</p>
39
+ <p class="t-deco">text-decoration</p>
40
+ <p class="t-clamp">text-overflow ellipsis: this long line is cut off with three dots because of overflow hidden and white-space nowrap.</p>
41
+ <p class="t-indent">text-indent and text-align justify. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
42
+ <p class="t-weight">font-weight / font-style / font-variant</p>
43
+ <p class="gradient-text big">background-clip: text</p>
44
+ </section>
45
+
46
+ <section id="layout">
47
+ <h2>3. Layout</h2>
48
+ <h3>Flexbox (display, justify-content, align-items, gap, flex-wrap)</h3>
49
+ <div class="flex-demo"><div>1</div><div>2</div><div>3</div></div>
50
+ <h3>Grid (grid-template-columns, gap)</h3>
51
+ <div class="grid-demo"><div>A</div><div>B</div><div>C</div><div>D</div></div>
52
+ <h3>Position (relative / absolute / sticky) + z-index</h3>
53
+ <div class="pos-parent">relative parent<span class="badge">absolute</span></div>
54
+ <h3>Float</h3>
55
+ <div class="clearfix"><div class="float-box">float</div><p>Text wraps around the floated box. Use clearfix to contain floats.</p></div>
56
+ <h3>overflow</h3>
57
+ <div class="scroll-box"><p>overflow: auto gives a scrollbar when content is taller than the box. Keep adding lines so it overflows. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore.</p></div>
58
+ </section>
59
+
60
+ <section id="effects">
61
+ <h2>4. Colours, backgrounds &amp; effects</h2>
62
+ <div class="grid">
63
+ <div class="card bg-linear">linear-gradient</div>
64
+ <div class="card bg-radial">radial-gradient</div>
65
+ <div class="card bg-conic">conic-gradient</div>
66
+ <div class="card opacity">opacity</div>
67
+ <div class="card blur-glass">backdrop-filter (glass)</div>
68
+ <div class="card filter-fx">filter: grayscale + blur</div>
69
+ <div class="card transform-fx">transform: rotate/scale</div>
70
+ <div class="card clip">clip-path</div>
71
+ <div class="card cursor-demo">cursor: pointer</div>
72
+ <div class="card hover-lift">:hover lift</div>
73
+ <div class="card blend">mix-blend-mode</div>
74
+ <div class="card var-demo">CSS variables</div>
75
+ </div>
76
+ </section>
77
+
78
+ <section id="anim">
79
+ <h2>5. Transitions &amp; animations</h2>
80
+ <button class="btn">transition on hover</button>
81
+ <div class="spinner" title="@keyframes + animation"></div>
82
+ <div class="pulse">pulse</div>
83
+ <div class="bounce">bounce</div>
84
+ </section>
85
+
86
+ <section id="form">
87
+ <h2>6. Form &amp; table styling</h2>
88
+ <form class="form" onsubmit="return false">
89
+ <input type="text" placeholder="Focus me (outline, transition)">
90
+ <select><option>Select</option><option>Option 2</option></select>
91
+ <textarea rows="2" placeholder="resize: vertical"></textarea>
92
+ <label><input type="checkbox" checked> accent-color checkbox</label>
93
+ <button class="btn">Submit</button>
94
+ </form>
95
+ <table class="table">
96
+ <thead><tr><th>ID</th><th>Name</th><th>Score</th></tr></thead>
97
+ <tbody>
98
+ <tr><td>1</td><td>Asha</td><td>92</td></tr>
99
+ <tr><td>2</td><td>Ravi</td><td>85</td></tr>
100
+ <tr><td>3</td><td>Meena</td><td>78</td></tr>
101
+ </tbody>
102
+ </table>
103
+ <ul class="list"><li>list-style custom marker</li><li>::before / ::after pseudo-elements</li><li>:nth-child</li></ul>
104
+ </section>
105
+
106
+ </main>
107
+ <footer class="site-footer">position: sticky header &middot; media query: resize the window</footer>
108
+ </body>
109
+ </html>
@@ -0,0 +1,139 @@
1
+ /* ===== CSS Styles Showcase: ~50 commonly asked properties, each tagged in a comment ===== */
2
+
3
+ /* 1. CSS variables (custom properties) */
4
+ :root {
5
+ --primary: #4f46e5;
6
+ --accent: #ec4899;
7
+ --bg: #f5f7fb;
8
+ --text: #1f2937;
9
+ --radius: 12px;
10
+ }
11
+
12
+ /* 2. universal reset + box-sizing */
13
+ * { margin: 0; padding: 0; box-sizing: border-box; }
14
+
15
+ html { scroll-behavior: smooth; } /* 3. scroll-behavior */
16
+
17
+ body {
18
+ font-family: 'Segoe UI', Arial, sans-serif; /* 4. font-family */
19
+ font-size: 16px; /* 5. font-size */
20
+ line-height: 1.6; /* 6. line-height */
21
+ color: var(--text); /* 7. color */
22
+ background: var(--bg); /* 8. background */
23
+ }
24
+
25
+ .container { max-width: 1000px; margin: 0 auto; padding: 20px; } /* 9. max-width, margin auto */
26
+ section { margin-bottom: 40px; }
27
+ h2 { margin-bottom: 14px; border-bottom: 3px solid var(--primary); display: inline-block; }
28
+ h3 { margin: 14px 0 6px; font-size: 1rem; color: #555; }
29
+
30
+ /* ---------- Header / nav (position: sticky, z-index) ---------- */
31
+ .site-header {
32
+ position: sticky; top: 0; z-index: 100; /* 10. position sticky, 11. z-index */
33
+ display: flex; justify-content: space-between; align-items: center;
34
+ padding: 12px 24px; background: white;
35
+ box-shadow: 0 2px 10px rgba(0,0,0,.15); /* 12. box-shadow */
36
+ }
37
+ .nav a {
38
+ text-decoration: none; color: var(--text); /* 13. text-decoration */
39
+ margin-left: 16px; padding: 6px 10px; border-radius: 6px;
40
+ transition: background .3s, color .3s; /* 14. transition */
41
+ }
42
+ .nav a:hover { background: var(--primary); color: #fff; } /* 15. :hover */
43
+
44
+ /* ---------- Cards / box model ---------- */
45
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; } /* 16. grid */
46
+ .card {
47
+ height: 110px; display: flex; align-items: center; justify-content: center;
48
+ text-align: center; background: #fff; padding: 12px; /* 17. padding */
49
+ border: 1px solid #e5e7eb; border-radius: var(--radius);/* 18. border, 19. border-radius */
50
+ font-weight: 600; /* 20. font-weight */
51
+ }
52
+ .shadow { box-shadow: 0 8px 20px rgba(0,0,0,.2); }
53
+ .shadow-inset { box-shadow: inset 0 0 15px rgba(0,0,0,.35); }
54
+ .shadow-multi { box-shadow: 0 0 0 4px var(--primary), 0 0 0 8px var(--accent), 0 10px 25px rgba(0,0,0,.3); }
55
+ .rounded { border-radius: 30px; }
56
+ .circle { border-radius: 50%; width: 110px; margin: auto; }
57
+ .dashed { border: 3px dashed var(--accent); } /* border-style */
58
+ .outlined { outline: 3px solid var(--primary); outline-offset: 5px; } /* 21. outline, outline-offset */
59
+ .padded { padding: 24px; margin: 8px; background: #eef2ff; }
60
+
61
+ /* ---------- Typography ---------- */
62
+ .t-spacing { letter-spacing: 3px; word-spacing: 8px; line-height: 2; } /* 22. letter/word-spacing */
63
+ .t-shadow { text-shadow: 2px 2px 4px rgba(0,0,0,.4); font-size: 1.6rem; } /* 23. text-shadow */
64
+ .t-upper { text-transform: uppercase; } /* 24. text-transform */
65
+ .t-deco { text-decoration: underline wavy var(--accent); }
66
+ .t-clamp { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 380px; } /* 25. text-overflow */
67
+ .t-indent { text-indent: 30px; text-align: justify; } /* 26. text-indent, text-align */
68
+ .t-weight { font-weight: 800; font-style: italic; font-variant: small-caps; }
69
+ .big { font-size: 2rem; }
70
+ .gradient-text {
71
+ background: linear-gradient(90deg, var(--primary), var(--accent)); /* 27. linear-gradient */
72
+ -webkit-background-clip: text; background-clip: text; /* 28. background-clip */
73
+ -webkit-text-fill-color: transparent; color: transparent;
74
+ }
75
+
76
+ /* ---------- Layout ---------- */
77
+ .flex-demo { display: flex; justify-content: space-around; align-items: center; gap: 10px; flex-wrap: wrap; } /* 29. flexbox */
78
+ .flex-demo div, .grid-demo div { background: var(--primary); color: #fff; padding: 20px; border-radius: 8px; flex: 1; text-align: center; }
79
+ .grid-demo { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
80
+ .pos-parent { position: relative; height: 80px; background: #e0e7ff; padding: 10px; border-radius: 8px; } /* 30. position relative */
81
+ .badge { position: absolute; top: 8px; right: 8px; background: var(--accent); color: #fff; padding: 4px 10px; border-radius: 20px; font-size: .8rem; } /* 31. absolute */
82
+ .float-box { float: left; width: 90px; height: 70px; margin-right: 12px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; } /* 32. float */
83
+ .clearfix::after { content: ""; display: table; clear: both; } /* 33. pseudo-element + clear */
84
+ .scroll-box { height: 70px; overflow: auto; border: 1px solid #ccc; padding: 8px; background: #fff; resize: both; } /* 34. overflow, resize */
85
+
86
+ /* ---------- Colours, backgrounds, effects ---------- */
87
+ .bg-linear { background: linear-gradient(135deg, #667eea, #764ba2); color: #fff; }
88
+ .bg-radial { background: radial-gradient(circle, #fbbf24, #ef4444); color: #fff; } /* 35. radial-gradient */
89
+ .bg-conic { background: conic-gradient(from 0deg, #f43f5e, #3b82f6, #22c55e, #f43f5e); color: #fff; } /* 36. conic-gradient */
90
+ .opacity { opacity: .5; } /* 37. opacity */
91
+ .blur-glass { background: rgba(255,255,255,.25); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.5); } /* 38. backdrop-filter */
92
+ .filter-fx { filter: grayscale(80%) blur(1px); } /* 39. filter */
93
+ .transform-fx { transform: rotate(-4deg) scale(1.05); } /* 40. transform */
94
+ .clip { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); background: var(--primary); color: #fff; } /* 41. clip-path */
95
+ .cursor-demo { cursor: pointer; user-select: none; } /* 42. cursor, user-select */
96
+ .hover-lift { transition: transform .25s, box-shadow .25s; }
97
+ .hover-lift:hover { transform: translateY(-8px); box-shadow: 0 14px 28px rgba(0,0,0,.25); }
98
+ .blend { background: var(--accent); mix-blend-mode: multiply; } /* 43. mix-blend-mode */
99
+ .var-demo { background: var(--primary); color: #fff; }
100
+
101
+ /* ---------- Transitions & animations ---------- */
102
+ .btn {
103
+ background: var(--primary); color: #fff; border: none; padding: 10px 22px;
104
+ border-radius: 8px; cursor: pointer; font-size: 1rem;
105
+ transition: all .3s ease;
106
+ }
107
+ .btn:hover { background: var(--accent); transform: scale(1.08); box-shadow: 0 6px 16px rgba(0,0,0,.3); }
108
+ .btn:active { transform: scale(.97); }
109
+ .spinner { width: 40px; height: 40px; border: 5px solid #ddd; border-top-color: var(--primary); border-radius: 50%; display: inline-block; vertical-align: middle; margin: 0 20px; animation: spin 1s linear infinite; } /* 44. animation */
110
+ @keyframes spin { to { transform: rotate(360deg); } } /* 45. @keyframes */
111
+ .pulse { display: inline-block; padding: 10px 20px; background: var(--accent); color: #fff; border-radius: 8px; animation: pulse 1.5s ease-in-out infinite; }
112
+ @keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
113
+ .bounce { display: inline-block; margin-left: 20px; padding: 10px 20px; background: #10b981; color: #fff; border-radius: 8px; animation: bounce 1s infinite; }
114
+ @keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
115
+
116
+ /* ---------- Forms, tables, lists ---------- */
117
+ .form { display: flex; flex-direction: column; gap: 10px; max-width: 360px; margin: 14px 0; } /* flex-direction */
118
+ .form input[type=text], .form select, .form textarea {
119
+ padding: 10px; border: 2px solid #d1d5db; border-radius: 8px; font: inherit; transition: border-color .2s, box-shadow .2s;
120
+ }
121
+ .form input:focus, .form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79,70,229,.2); } /* :focus */
122
+ .form textarea { resize: vertical; }
123
+ .form input[type=checkbox] { accent-color: var(--accent); } /* 46. accent-color */
124
+ .table { border-collapse: collapse; width: 100%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.1); } /* 47. border-collapse */
125
+ .table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid #e5e7eb; }
126
+ .table thead { background: var(--primary); color: #fff; }
127
+ .table tbody tr:nth-child(even) { background: #f3f4f6; } /* 48. :nth-child */
128
+ .table tbody tr:hover { background: #e0e7ff; }
129
+ .list { margin: 14px 0 0 22px; list-style: square; } /* 49. list-style */
130
+ .list li::marker { color: var(--accent); } /* ::marker */
131
+ .list li::before { content: ""; } /* ::before */
132
+
133
+ .site-footer { text-align: center; padding: 20px; background: #111827; color: #9ca3af; }
134
+
135
+ /* 50. Media query (responsive) */
136
+ @media (max-width: 600px) {
137
+ .site-header { flex-direction: column; gap: 8px; }
138
+ .grid-demo { grid-template-columns: 1fr; }
139
+ }
@@ -0,0 +1,3 @@
1
+ wrapperVersion=3.3.4
2
+ distributionType=only-script
3
+ distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.10.0/apache-maven-3.10.0-bin.zip
@@ -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 "$@"
@@ -0,0 +1,189 @@
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.4
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-<version>,maven-mvnd-<version>-<platform>}/<hash>
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"
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+ <modelVersion>4.0.0</modelVersion>
5
+ <parent>
6
+ <groupId>org.springframework.boot</groupId>
7
+ <artifactId>spring-boot-starter-parent</artifactId>
8
+ <version>4.1.1</version>
9
+ <relativePath/>
10
+ </parent>
11
+ <groupId>com.example</groupId>
12
+ <artifactId>springboot-mongo-aggregation-join</artifactId>
13
+ <version>0.0.1-SNAPSHOT</version>
14
+ <properties>
15
+ <java.version>21</java.version>
16
+ </properties>
17
+ <dependencies>
18
+ <dependency>
19
+ <groupId>org.springframework.boot</groupId>
20
+ <artifactId>spring-boot-starter-data-mongodb</artifactId>
21
+ </dependency>
22
+ <dependency>
23
+ <groupId>org.springframework.boot</groupId>
24
+ <artifactId>spring-boot-starter-webmvc</artifactId>
25
+ </dependency>
26
+ <dependency>
27
+ <groupId>org.projectlombok</groupId>
28
+ <artifactId>lombok</artifactId>
29
+ <optional>true</optional>
30
+ </dependency>
31
+ <dependency>
32
+ <groupId>org.springframework.boot</groupId>
33
+ <artifactId>spring-boot-starter-test</artifactId>
34
+ <scope>test</scope>
35
+ </dependency>
36
+ <dependency>
37
+ <groupId>org.springframework.boot</groupId>
38
+ <artifactId>spring-boot-starter-data-mongodb-test</artifactId>
39
+ <scope>test</scope>
40
+ </dependency>
41
+ <dependency>
42
+ <groupId>org.springframework.boot</groupId>
43
+ <artifactId>spring-boot-starter-webmvc-test</artifactId>
44
+ <scope>test</scope>
45
+ </dependency>
46
+ </dependencies>
47
+ <build>
48
+ <plugins>
49
+ <plugin>
50
+ <groupId>org.springframework.boot</groupId>
51
+ <artifactId>spring-boot-maven-plugin</artifactId>
52
+ </plugin>
53
+ <plugin>
54
+ <groupId>org.apache.maven.plugins</groupId>
55
+ <artifactId>maven-compiler-plugin</artifactId>
56
+ <executions>
57
+ <execution>
58
+ <id>default-compile</id>
59
+ <phase>compile</phase>
60
+ <goals>
61
+ <goal>compile</goal>
62
+ </goals>
63
+ <configuration>
64
+ <annotationProcessorPaths>
65
+ <path>
66
+ <groupId>org.projectlombok</groupId>
67
+ <artifactId>lombok</artifactId>
68
+ </path>
69
+ </annotationProcessorPaths>
70
+ </configuration>
71
+ </execution>
72
+ <execution>
73
+ <id>default-testCompile</id>
74
+ <phase>test-compile</phase>
75
+ <goals>
76
+ <goal>testCompile</goal>
77
+ </goals>
78
+ <configuration>
79
+ <annotationProcessorPaths>
80
+ <path>
81
+ <groupId>org.projectlombok</groupId>
82
+ <artifactId>lombok</artifactId>
83
+ </path>
84
+ </annotationProcessorPaths>
85
+ </configuration>
86
+ </execution>
87
+ </executions>
88
+ </plugin>
89
+ </plugins>
90
+ </build>
91
+ </project>
@@ -0,0 +1,36 @@
1
+ package com.example.joinagg;
2
+
3
+ import com.example.joinagg.model.Customer;
4
+ import com.example.joinagg.model.Order;
5
+ import com.example.joinagg.repository.CustomerRepository;
6
+ import com.example.joinagg.repository.OrderRepository;
7
+ import org.springframework.boot.CommandLineRunner;
8
+ import org.springframework.boot.SpringApplication;
9
+ import org.springframework.boot.autoconfigure.SpringBootApplication;
10
+ import org.springframework.context.annotation.Bean;
11
+
12
+ @SpringBootApplication
13
+ public class JoinAggApplication {
14
+ public static void main(String[] args) {
15
+ SpringApplication.run(JoinAggApplication.class, args);
16
+ }
17
+
18
+ // Seed sample data (only when collections are empty)
19
+ @Bean
20
+ CommandLineRunner seed(CustomerRepository c, OrderRepository o) {
21
+ return args -> {
22
+ if (c.count() == 0) {
23
+ c.save(new Customer("c1", "Asha", "Chennai"));
24
+ c.save(new Customer("c2", "Ravi", "Mumbai"));
25
+ c.save(new Customer("c3", "Meena", "Chennai"));
26
+ }
27
+ if (o.count() == 0) {
28
+ o.save(new Order(null, "c1", "Laptop", 55000, "DELIVERED"));
29
+ o.save(new Order(null, "c1", "Mouse", 700, "DELIVERED"));
30
+ o.save(new Order(null, "c2", "Phone", 30000, "PENDING"));
31
+ o.save(new Order(null, "c3", "Monitor", 12000, "DELIVERED"));
32
+ o.save(new Order(null, "c3", "Keyboard", 2500, "PENDING"));
33
+ }
34
+ };
35
+ }
36
+ }
@@ -0,0 +1,33 @@
1
+ package com.example.joinagg.controller;
2
+
3
+ import com.example.joinagg.model.CustomerTotal;
4
+ import com.example.joinagg.model.Order;
5
+ import com.example.joinagg.model.OrderWithCustomer;
6
+ import com.example.joinagg.repository.OrderRepository;
7
+ import com.example.joinagg.service.JoinService;
8
+ import org.springframework.beans.factory.annotation.Autowired;
9
+ import org.springframework.web.bind.annotation.*;
10
+
11
+ import java.util.List;
12
+
13
+ @RestController
14
+ @RequestMapping("/api")
15
+ @CrossOrigin(origins = "*")
16
+ public class JoinController {
17
+ @Autowired private JoinService service;
18
+ @Autowired private OrderRepository repo;
19
+
20
+ // --- via MongoTemplate ---
21
+ @GetMapping("/join/orders") public List<OrderWithCustomer> join() { return service.ordersWithCustomers(); }
22
+ @GetMapping("/join/orders/city/{city}") public List<OrderWithCustomer> byCity(@PathVariable String city) { return service.ordersByCity(city); }
23
+ @GetMapping("/join/total") public List<CustomerTotal> total() { return service.totalPerCustomer(); }
24
+
25
+ // --- via @Aggregation on repository ---
26
+ @GetMapping("/agg/join") public List<OrderWithCustomer> aggJoin() { return repo.joinOrdersWithCustomers(); }
27
+ @GetMapping("/agg/join/{status}") public List<OrderWithCustomer> aggJoin(@PathVariable String status) { return repo.joinByStatus(status); }
28
+ @GetMapping("/agg/total") public List<CustomerTotal> aggTotal() { return repo.totalSpentPerCustomer(); }
29
+
30
+ // --- via @Query ---
31
+ @GetMapping("/query/status/{s}") public List<Order> byStatus(@PathVariable String s) { return repo.findByStatusQuery(s); }
32
+ @GetMapping("/query/gt/{amt}") public List<Order> gt(@PathVariable double amt) { return repo.findAmountGreaterThan(amt); }
33
+ }
@@ -0,0 +1,14 @@
1
+ package com.example.joinagg.model;
2
+
3
+ import lombok.*;
4
+ import org.springframework.data.annotation.Id;
5
+ import org.springframework.data.mongodb.core.mapping.Document;
6
+
7
+ @Data @NoArgsConstructor @AllArgsConstructor
8
+ @Document(collection = "customers")
9
+ public class Customer {
10
+ @Id
11
+ private String id;
12
+ private String name;
13
+ private String city;
14
+ }
@@ -0,0 +1,11 @@
1
+ package com.example.joinagg.model;
2
+
3
+ import lombok.*;
4
+
5
+ // Result of JOIN + GROUP: total spent per customer
6
+ @Data @NoArgsConstructor @AllArgsConstructor
7
+ public class CustomerTotal {
8
+ private String customerName;
9
+ private double totalSpent;
10
+ private int orderCount;
11
+ }
@@ -0,0 +1,16 @@
1
+ package com.example.joinagg.model;
2
+
3
+ import lombok.*;
4
+ import org.springframework.data.annotation.Id;
5
+ import org.springframework.data.mongodb.core.mapping.Document;
6
+
7
+ @Data @NoArgsConstructor @AllArgsConstructor
8
+ @Document(collection = "orders")
9
+ public class Order {
10
+ @Id
11
+ private String id;
12
+ private String customerId; // foreign key -> customers._id
13
+ private String product;
14
+ private double amount;
15
+ private String status;
16
+ }
@@ -0,0 +1,14 @@
1
+ package com.example.joinagg.model;
2
+
3
+ import lombok.*;
4
+
5
+ // Result of orders JOIN customers
6
+ @Data @NoArgsConstructor @AllArgsConstructor
7
+ public class OrderWithCustomer {
8
+ private String id;
9
+ private String product;
10
+ private double amount;
11
+ private String status;
12
+ private String customerName;
13
+ private String city;
14
+ }
@@ -0,0 +1,9 @@
1
+ package com.example.joinagg.repository;
2
+
3
+ import com.example.joinagg.model.Customer;
4
+ import org.springframework.data.mongodb.repository.MongoRepository;
5
+ import org.springframework.stereotype.Repository;
6
+
7
+ @Repository
8
+ public interface CustomerRepository extends MongoRepository<Customer, String> {
9
+ }
@@ -0,0 +1,73 @@
1
+ package com.example.joinagg.repository;
2
+
3
+ import com.example.joinagg.model.CustomerTotal;
4
+ import com.example.joinagg.model.Order;
5
+ import com.example.joinagg.model.OrderWithCustomer;
6
+ import org.springframework.data.mongodb.repository.Aggregation;
7
+ import org.springframework.data.mongodb.repository.MongoRepository;
8
+ import org.springframework.data.mongodb.repository.Query;
9
+ import org.springframework.stereotype.Repository;
10
+
11
+ import java.util.List;
12
+
13
+ @Repository
14
+ public interface OrderRepository extends MongoRepository<Order, String> {
15
+
16
+ // ---------- @Query (plain filters) ----------
17
+ @Query("{ 'status': ?0 }")
18
+ List<Order> findByStatusQuery(String status);
19
+
20
+ @Query("{ 'amount': { $gt: ?0 } }")
21
+ List<Order> findAmountGreaterThan(double amount);
22
+
23
+ @Query("{ 'amount': { $gte: ?0, $lte: ?1 } }")
24
+ List<Order> findAmountBetween(double min, double max);
25
+
26
+ @Query("{ $and: [ { 'status': ?0 }, { 'amount': { $gt: ?1 } } ] }")
27
+ List<Order> findByStatusAndMinAmount(String status, double min);
28
+
29
+ @Query("{ 'product': { $regex: ?0, $options: 'i' } }")
30
+ List<Order> searchByProduct(String regex);
31
+
32
+ @Query(value = "{ 'status': ?0 }", count = true)
33
+ long countByStatusQuery(String status);
34
+
35
+ @Query(value = "{ 'status': ?0 }", sort = "{ 'amount': -1 }")
36
+ List<Order> findByStatusSorted(String status);
37
+
38
+ @Query(value = "{ }", fields = "{ 'product': 1, 'amount': 1 }")
39
+ List<Order> findOnlyProductAndAmount();
40
+
41
+ // ---------- @Aggregation (JOIN with $lookup) ----------
42
+ @Aggregation(pipeline = {
43
+ "{ $lookup: { from: 'customers', localField: 'customerId', foreignField: '_id', as: 'customer' } }",
44
+ "{ $unwind: '$customer' }",
45
+ "{ $project: { product: 1, amount: 1, status: 1, customerName: '$customer.name', city: '$customer.city' } }"
46
+ })
47
+ List<OrderWithCustomer> joinOrdersWithCustomers();
48
+
49
+ // JOIN + filter (use ?0 placeholders inside pipeline stages)
50
+ @Aggregation(pipeline = {
51
+ "{ $match: { status: ?0 } }",
52
+ "{ $lookup: { from: 'customers', localField: 'customerId', foreignField: '_id', as: 'customer' } }",
53
+ "{ $unwind: '$customer' }",
54
+ "{ $project: { product: 1, amount: 1, status: 1, customerName: '$customer.name', city: '$customer.city' } }"
55
+ })
56
+ List<OrderWithCustomer> joinByStatus(String status);
57
+
58
+ // JOIN + GROUP: total spent per customer
59
+ @Aggregation(pipeline = {
60
+ "{ $lookup: { from: 'customers', localField: 'customerId', foreignField: '_id', as: 'customer' } }",
61
+ "{ $unwind: '$customer' }",
62
+ "{ $group: { _id: '$customer.name', totalSpent: { $sum: '$amount' }, orderCount: { $sum: 1 } } }",
63
+ "{ $project: { _id: 0, customerName: '$_id', totalSpent: 1, orderCount: 1 } }",
64
+ "{ $sort: { totalSpent: -1 } }"
65
+ })
66
+ List<CustomerTotal> totalSpentPerCustomer();
67
+
68
+ // Plain group (no join) returning a scalar-ish result
69
+ @Aggregation(pipeline = {
70
+ "{ $group: { _id: '$status', total: { $sum: '$amount' } } }"
71
+ })
72
+ List<org.bson.Document> totalByStatus();
73
+ }
@@ -0,0 +1,58 @@
1
+ package com.example.joinagg.service;
2
+
3
+ import com.example.joinagg.model.CustomerTotal;
4
+ import com.example.joinagg.model.OrderWithCustomer;
5
+ import org.springframework.beans.factory.annotation.Autowired;
6
+ import org.springframework.data.domain.Sort;
7
+ import org.springframework.data.mongodb.core.MongoTemplate;
8
+ import org.springframework.data.mongodb.core.aggregation.Aggregation;
9
+ import org.springframework.data.mongodb.core.query.Criteria;
10
+ import org.springframework.stereotype.Service;
11
+
12
+ import java.util.List;
13
+
14
+ import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
15
+
16
+ /** Same JOINs as OrderRepository, but built with the Aggregation Java API (MongoTemplate). */
17
+ @Service
18
+ public class JoinService {
19
+ @Autowired
20
+ private MongoTemplate mongoTemplate;
21
+
22
+ // orders JOIN customers (SQL: SELECT ... FROM orders o JOIN customers c ON o.customerId = c.id)
23
+ public List<OrderWithCustomer> ordersWithCustomers() {
24
+ Aggregation agg = newAggregation(
25
+ lookup("customers", "customerId", "_id", "customer"),
26
+ unwind("customer"),
27
+ project("product", "amount", "status")
28
+ .and("customer.name").as("customerName")
29
+ .and("customer.city").as("city")
30
+ );
31
+ return mongoTemplate.aggregate(agg, "orders", OrderWithCustomer.class).getMappedResults();
32
+ }
33
+
34
+ // JOIN + WHERE city = ?
35
+ public List<OrderWithCustomer> ordersByCity(String city) {
36
+ Aggregation agg = newAggregation(
37
+ lookup("customers", "customerId", "_id", "customer"),
38
+ unwind("customer"),
39
+ match(Criteria.where("customer.city").is(city)),
40
+ project("product", "amount", "status")
41
+ .and("customer.name").as("customerName")
42
+ .and("customer.city").as("city")
43
+ );
44
+ return mongoTemplate.aggregate(agg, "orders", OrderWithCustomer.class).getMappedResults();
45
+ }
46
+
47
+ // JOIN + GROUP BY customer
48
+ public List<CustomerTotal> totalPerCustomer() {
49
+ Aggregation agg = newAggregation(
50
+ lookup("customers", "customerId", "_id", "customer"),
51
+ unwind("customer"),
52
+ group("customer.name").sum("amount").as("totalSpent").count().as("orderCount"),
53
+ project("totalSpent", "orderCount").and("_id").as("customerName"),
54
+ sort(Sort.Direction.DESC, "totalSpent")
55
+ );
56
+ return mongoTemplate.aggregate(agg, "orders", CustomerTotal.class).getMappedResults();
57
+ }
58
+ }
@@ -0,0 +1,4 @@
1
+ spring.application.name=springboot-mongo-aggregation-join
2
+ server.port=8080
3
+ spring.data.mongodb.uri=mongodb://localhost:27017/my_crud_db
4
+ spring.data.mongodb.database=my_crud_db