Spaces:
Sleeping
Sleeping
GitHub Actions
commited on
Commit
·
4cdf2b9
0
Parent(s):
Sync from GitHub
Browse files- .env.example +7 -0
- .gitattributes +2 -0
- .gitignore +38 -0
- .mvn/wrapper/maven-wrapper.properties +3 -0
- Dockerfile +34 -0
- README.md +139 -0
- db.sql +21 -0
- mvnw +295 -0
- mvnw.cmd +189 -0
- pom.xml +99 -0
- src/main/java/com/backend/cs203/Cs203Application.java +13 -0
- src/main/java/com/backend/cs203/controller/ApiController.java +41 -0
- src/main/resources/application.properties +15 -0
- src/test/java/com/backend/cs203/Cs203ApplicationTests.java +13 -0
.env.example
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Database Config
|
| 2 |
+
DB_HOST=
|
| 3 |
+
DB_USER=
|
| 4 |
+
DB_PASSWORD=
|
| 5 |
+
DB_NAME=
|
| 6 |
+
DB_PORT=
|
| 7 |
+
|
.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/mvnw text eol=lf
|
| 2 |
+
*.cmd text eol=crlf
|
.gitignore
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HELP.md
|
| 2 |
+
target/
|
| 3 |
+
.mvn/wrapper/maven-wrapper.jar
|
| 4 |
+
!**/src/main/**/target/
|
| 5 |
+
!**/src/test/**/target/
|
| 6 |
+
|
| 7 |
+
### STS ###
|
| 8 |
+
.apt_generated
|
| 9 |
+
.classpath
|
| 10 |
+
.factorypath
|
| 11 |
+
.project
|
| 12 |
+
.settings
|
| 13 |
+
.springBeans
|
| 14 |
+
.sts4-cache
|
| 15 |
+
|
| 16 |
+
### IntelliJ IDEA ###
|
| 17 |
+
.idea
|
| 18 |
+
*.iws
|
| 19 |
+
*.iml
|
| 20 |
+
*.ipr
|
| 21 |
+
|
| 22 |
+
### NetBeans ###
|
| 23 |
+
/nbproject/private/
|
| 24 |
+
/nbbuild/
|
| 25 |
+
/dist/
|
| 26 |
+
/nbdist/
|
| 27 |
+
/.nb-gradle/
|
| 28 |
+
build/
|
| 29 |
+
!**/src/main/**/build/
|
| 30 |
+
!**/src/test/**/build/
|
| 31 |
+
|
| 32 |
+
### VS Code ###
|
| 33 |
+
.vscode/
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Local Dev
|
| 37 |
+
application-local.properties
|
| 38 |
+
.env
|
.mvn/wrapper/maven-wrapper.properties
ADDED
|
@@ -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.9.12/apache-maven-3.9.12-bin.zip
|
Dockerfile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Build stage
|
| 2 |
+
FROM maven:3.9-eclipse-temurin-21-alpine AS build
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Copy Maven files first for better layer caching
|
| 6 |
+
COPY pom.xml .
|
| 7 |
+
COPY .mvn .mvn
|
| 8 |
+
COPY mvnw .
|
| 9 |
+
|
| 10 |
+
# Download dependencies (cached layer)
|
| 11 |
+
RUN mvn dependency:go-offline -B
|
| 12 |
+
|
| 13 |
+
# Copy source code and build
|
| 14 |
+
COPY src ./src
|
| 15 |
+
RUN mvn clean package -DskipTests
|
| 16 |
+
|
| 17 |
+
# Runtime stage
|
| 18 |
+
FROM eclipse-temurin:21-jre-alpine
|
| 19 |
+
WORKDIR /app
|
| 20 |
+
|
| 21 |
+
# Create non-root user (required by Hugging Face Spaces)
|
| 22 |
+
RUN adduser -D -u 1000 appuser
|
| 23 |
+
|
| 24 |
+
# Copy the built jar
|
| 25 |
+
COPY --from=build --chown=appuser:appuser /app/target/*.jar app.jar
|
| 26 |
+
|
| 27 |
+
# Switch to non-root user
|
| 28 |
+
USER appuser
|
| 29 |
+
|
| 30 |
+
# Hugging Face Spaces requires port 7860
|
| 31 |
+
EXPOSE 7860
|
| 32 |
+
|
| 33 |
+
# Run the application with optimized JVM settings for containers
|
| 34 |
+
ENTRYPOINT ["java", "-XX:+UseContainerSupport", "-XX:MaxRAMPercentage=75.0", "-jar", "app.jar"]
|
README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Spring Boot API
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Spring Boot API on Hugging Face Spaces
|
| 11 |
+
|
| 12 |
+
A Spring Boot REST API deployed on Hugging Face Spaces using Docker.
|
| 13 |
+
|
| 14 |
+
## Endpoints
|
| 15 |
+
|
| 16 |
+
| Method | Endpoint | Description |
|
| 17 |
+
|--------|----------|-------------|
|
| 18 |
+
| GET | `/api/health` | Health check endpoint |
|
| 19 |
+
| GET | `/api/hello?name={name}` | Returns a greeting message |
|
| 20 |
+
| POST | `/api/echo` | Echoes back the JSON body |
|
| 21 |
+
|
| 22 |
+
## Example Usage
|
| 23 |
+
|
| 24 |
+
### Health Check
|
| 25 |
+
```bash
|
| 26 |
+
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/health
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
### Hello Endpoint
|
| 30 |
+
```bash
|
| 31 |
+
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/hello?name=Developer
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
### Echo Endpoint
|
| 35 |
+
```bash
|
| 36 |
+
curl -X POST https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/echo \
|
| 37 |
+
-H "Content-Type: application/json" \
|
| 38 |
+
-d '{"message": "Hello from Hugging Face!"}'
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Local Development
|
| 42 |
+
|
| 43 |
+
### Prerequisites
|
| 44 |
+
- Java 21 (or use the Maven wrapper which handles this)
|
| 45 |
+
- Maven 3.9+ (optional, wrapper included)
|
| 46 |
+
- Docker (optional, for container testing)
|
| 47 |
+
|
| 48 |
+
### Run with Maven
|
| 49 |
+
```bash
|
| 50 |
+
# On Linux/macOS
|
| 51 |
+
./mvnw spring-boot:run
|
| 52 |
+
|
| 53 |
+
# On Windows
|
| 54 |
+
mvnw.cmd spring-boot:run
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
The app will start on `http://localhost:7860`
|
| 58 |
+
|
| 59 |
+
### Build and Run with Docker
|
| 60 |
+
```bash
|
| 61 |
+
# Build the image
|
| 62 |
+
docker build -t springboot-hf .
|
| 63 |
+
|
| 64 |
+
# Run the container
|
| 65 |
+
docker run -p 7860:7860 springboot-hf
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Deploy to Hugging Face Spaces
|
| 69 |
+
|
| 70 |
+
### Option 1: Push Entire Backend Folder as a Space
|
| 71 |
+
|
| 72 |
+
1. Create a new Space on [Hugging Face](https://huggingface.co/new-space)
|
| 73 |
+
- Select **Docker** as the SDK
|
| 74 |
+
- Choose a name for your Space
|
| 75 |
+
|
| 76 |
+
2. Clone your new Space repository:
|
| 77 |
+
```bash
|
| 78 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 79 |
+
cd YOUR_SPACE_NAME
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
3. Copy the contents of this `backend` folder into the Space:
|
| 83 |
+
```bash
|
| 84 |
+
# Copy all files from backend folder
|
| 85 |
+
cp -r /path/to/backend/* .
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
4. Push to Hugging Face:
|
| 89 |
+
```bash
|
| 90 |
+
git add .
|
| 91 |
+
git commit -m "Initial Spring Boot deployment"
|
| 92 |
+
git push
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Option 2: Direct Git Push (if backend is standalone)
|
| 96 |
+
|
| 97 |
+
1. Add Hugging Face as a remote:
|
| 98 |
+
```bash
|
| 99 |
+
cd backend
|
| 100 |
+
git init # if not already a git repo
|
| 101 |
+
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
2. Push to Hugging Face:
|
| 105 |
+
```bash
|
| 106 |
+
git add .
|
| 107 |
+
git commit -m "Deploy Spring Boot to HF Spaces"
|
| 108 |
+
git push hf main
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
### Important Notes for Hugging Face Spaces
|
| 112 |
+
|
| 113 |
+
- The app **must** run on port **7860** (already configured)
|
| 114 |
+
- The container runs as a **non-root user** (UID 1000) - this is required by HF Spaces
|
| 115 |
+
- Build times may vary; initial deployment can take a few minutes
|
| 116 |
+
- Check the **Logs** tab in your Space for debugging
|
| 117 |
+
|
| 118 |
+
## Project Structure
|
| 119 |
+
|
| 120 |
+
```
|
| 121 |
+
backend/
|
| 122 |
+
├── src/
|
| 123 |
+
│ ├── main/
|
| 124 |
+
│ │ ├── java/com/backend/cs203/
|
| 125 |
+
│ │ │ └── Cs203Application.java # Main entry point
|
| 126 |
+
│ │ └── resources/
|
| 127 |
+
│ │ └── application.properties # App configuration
|
| 128 |
+
│ └── test/
|
| 129 |
+
├── pom.xml # Maven dependencies
|
| 130 |
+
├── Dockerfile # Multi-stage Docker build
|
| 131 |
+
└── README.md # This file
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
## Tech Stack
|
| 135 |
+
|
| 136 |
+
- **Java 21**
|
| 137 |
+
- **Spring Boot 4.0.1**
|
| 138 |
+
- **Maven** (with wrapper)
|
| 139 |
+
- **Docker** (multi-stage build)
|
db.sql
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
USE defaultdb;
|
| 2 |
+
|
| 3 |
+
CREATE TABLE IF NOT EXISTS user(
|
| 4 |
+
username varchar(45) UNIQUE NOT NULL PRIMARY KEY,
|
| 5 |
+
email varchar(100) NOT NULL,
|
| 6 |
+
password varchar(100) NOT NULL,
|
| 7 |
+
usertype ENUM('user','admin','root') NOT NULL,
|
| 8 |
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
|
| 9 |
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
| 10 |
+
deactivated_at TIMESTAMP NULL
|
| 11 |
+
);
|
| 12 |
+
|
| 13 |
+
-- user1 is requestor, user2 is acceptor
|
| 14 |
+
CREATE TABLE IF NOT EXISTS friendship(
|
| 15 |
+
username1 varchar(45) NOT NULL,
|
| 16 |
+
username2 varchar(45) NOT NULL,
|
| 17 |
+
status ENUM('pending', 'confirmed'),
|
| 18 |
+
PRIMARY KEY (username1, username2),
|
| 19 |
+
FOREIGN KEY (`username1`) REFERENCES user(`username`),
|
| 20 |
+
FOREIGN KEY (`username2`) REFERENCES user(`username`)
|
| 21 |
+
);
|
mvnw
ADDED
|
@@ -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 "$@"
|
mvnw.cmd
ADDED
|
@@ -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"
|
pom.xml
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.0.1</version>
|
| 9 |
+
<relativePath/> <!-- lookup parent from repository -->
|
| 10 |
+
</parent>
|
| 11 |
+
<groupId>com.backend</groupId>
|
| 12 |
+
<artifactId>cs203</artifactId>
|
| 13 |
+
<version>0.0.1-SNAPSHOT</version>
|
| 14 |
+
<name>cs203</name>
|
| 15 |
+
<description>CS203 Backend</description>
|
| 16 |
+
<url/>
|
| 17 |
+
<licenses>
|
| 18 |
+
<license/>
|
| 19 |
+
</licenses>
|
| 20 |
+
<developers>
|
| 21 |
+
<developer/>
|
| 22 |
+
</developers>
|
| 23 |
+
<scm>
|
| 24 |
+
<connection/>
|
| 25 |
+
<developerConnection/>
|
| 26 |
+
<tag/>
|
| 27 |
+
<url/>
|
| 28 |
+
</scm>
|
| 29 |
+
<properties>
|
| 30 |
+
<java.version>21</java.version>
|
| 31 |
+
</properties>
|
| 32 |
+
<dependencies>
|
| 33 |
+
<dependency>
|
| 34 |
+
<groupId>org.springframework.boot</groupId>
|
| 35 |
+
<artifactId>spring-boot-starter-restclient</artifactId>
|
| 36 |
+
</dependency>
|
| 37 |
+
<dependency>
|
| 38 |
+
<groupId>org.springframework.boot</groupId>
|
| 39 |
+
<artifactId>spring-boot-starter-webclient</artifactId>
|
| 40 |
+
</dependency>
|
| 41 |
+
<dependency>
|
| 42 |
+
<groupId>org.springframework.boot</groupId>
|
| 43 |
+
<artifactId>spring-boot-starter-webflux</artifactId>
|
| 44 |
+
</dependency>
|
| 45 |
+
<dependency>
|
| 46 |
+
<groupId>org.springframework.boot</groupId>
|
| 47 |
+
<artifactId>spring-boot-starter-webmvc</artifactId>
|
| 48 |
+
</dependency>
|
| 49 |
+
|
| 50 |
+
<dependency>
|
| 51 |
+
<groupId>org.springdoc</groupId>
|
| 52 |
+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
| 53 |
+
<version>2.8.4</version>
|
| 54 |
+
</dependency>
|
| 55 |
+
|
| 56 |
+
<dependency>
|
| 57 |
+
<groupId>org.springframework.boot</groupId>
|
| 58 |
+
<artifactId>spring-boot-starter-restclient-test</artifactId>
|
| 59 |
+
<scope>test</scope>
|
| 60 |
+
</dependency>
|
| 61 |
+
<dependency>
|
| 62 |
+
<groupId>org.springframework.boot</groupId>
|
| 63 |
+
<artifactId>spring-boot-starter-webclient-test</artifactId>
|
| 64 |
+
<scope>test</scope>
|
| 65 |
+
</dependency>
|
| 66 |
+
<dependency>
|
| 67 |
+
<groupId>org.springframework.boot</groupId>
|
| 68 |
+
<artifactId>spring-boot-starter-webflux-test</artifactId>
|
| 69 |
+
<scope>test</scope>
|
| 70 |
+
</dependency>
|
| 71 |
+
<dependency>
|
| 72 |
+
<groupId>org.springframework.boot</groupId>
|
| 73 |
+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
| 74 |
+
<scope>test</scope>
|
| 75 |
+
</dependency>
|
| 76 |
+
|
| 77 |
+
<!-- JPA (Hibernate) support -->
|
| 78 |
+
<dependency>
|
| 79 |
+
<groupId>org.springframework.boot</groupId>
|
| 80 |
+
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
| 81 |
+
</dependency>
|
| 82 |
+
|
| 83 |
+
<!-- MySQL JDBC driver -->
|
| 84 |
+
<dependency>
|
| 85 |
+
<groupId>com.mysql</groupId>
|
| 86 |
+
<artifactId>mysql-connector-j</artifactId>
|
| 87 |
+
</dependency>
|
| 88 |
+
</dependencies>
|
| 89 |
+
|
| 90 |
+
<build>
|
| 91 |
+
<plugins>
|
| 92 |
+
<plugin>
|
| 93 |
+
<groupId>org.springframework.boot</groupId>
|
| 94 |
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
| 95 |
+
</plugin>
|
| 96 |
+
</plugins>
|
| 97 |
+
</build>
|
| 98 |
+
|
| 99 |
+
</project>
|
src/main/java/com/backend/cs203/Cs203Application.java
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.backend.cs203;
|
| 2 |
+
|
| 3 |
+
import org.springframework.boot.SpringApplication;
|
| 4 |
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 5 |
+
|
| 6 |
+
@SpringBootApplication
|
| 7 |
+
public class Cs203Application {
|
| 8 |
+
|
| 9 |
+
public static void main(String[] args) {
|
| 10 |
+
SpringApplication.run(Cs203Application.class, args);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
}
|
src/main/java/com/backend/cs203/controller/ApiController.java
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.backend.cs203.controller;
|
| 2 |
+
|
| 3 |
+
import java.util.Map;
|
| 4 |
+
|
| 5 |
+
import org.springframework.beans.factory.annotation.Autowired;
|
| 6 |
+
import org.springframework.http.ResponseEntity;
|
| 7 |
+
import org.springframework.jdbc.core.JdbcTemplate;
|
| 8 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
| 9 |
+
import org.springframework.web.bind.annotation.RequestMapping;
|
| 10 |
+
import org.springframework.web.bind.annotation.RequestParam;
|
| 11 |
+
import org.springframework.web.bind.annotation.RestController;
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@RestController
|
| 15 |
+
@RequestMapping("/api")
|
| 16 |
+
public class ApiController {
|
| 17 |
+
|
| 18 |
+
@Autowired
|
| 19 |
+
private JdbcTemplate jdbcTemplate;
|
| 20 |
+
|
| 21 |
+
@GetMapping("/health")
|
| 22 |
+
public ResponseEntity<Map<String, String>> health() {
|
| 23 |
+
return ResponseEntity.ok(Map.of(
|
| 24 |
+
"status", "healthy",
|
| 25 |
+
"service", "cs203-backend"
|
| 26 |
+
));
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
@GetMapping("/hello")
|
| 30 |
+
public ResponseEntity<Map<String, String>> hello(@RequestParam(defaultValue = "World") String name) {
|
| 31 |
+
return ResponseEntity.ok(Map.of(
|
| 32 |
+
"message", "Hello, " + name + "!"
|
| 33 |
+
));
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
@GetMapping("/db/test")
|
| 37 |
+
public String dbTest() {
|
| 38 |
+
Integer v = jdbcTemplate.queryForObject("SELECT 1", Integer.class);
|
| 39 |
+
return v != null && v == 1 ? "DB OK" : "DB FAIL";
|
| 40 |
+
}
|
| 41 |
+
}
|
src/main/resources/application.properties
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
spring.application.name=cs203
|
| 2 |
+
|
| 3 |
+
# Server configuration for Hugging Face Spaces
|
| 4 |
+
server.port=7860
|
| 5 |
+
|
| 6 |
+
# Optional: Allow all origins for API access (adjust as needed)
|
| 7 |
+
# spring.web.cors.allowed-origins=*
|
| 8 |
+
# Database Configuration
|
| 9 |
+
spring.datasource.url=jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Singapore
|
| 10 |
+
spring.datasource.username=${DB_USER}
|
| 11 |
+
spring.datasource.password=${DB_PASSWORD}
|
| 12 |
+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
| 13 |
+
# Swagger/OpenAPI configuration
|
| 14 |
+
springdoc.swagger-ui.path=/api/docs
|
| 15 |
+
springdoc.api-docs.path=/api/docs/openapi
|
src/test/java/com/backend/cs203/Cs203ApplicationTests.java
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.backend.cs203;
|
| 2 |
+
|
| 3 |
+
import org.junit.jupiter.api.Test;
|
| 4 |
+
import org.springframework.boot.test.context.SpringBootTest;
|
| 5 |
+
|
| 6 |
+
@SpringBootTest
|
| 7 |
+
class Cs203ApplicationTests {
|
| 8 |
+
|
| 9 |
+
@Test
|
| 10 |
+
void contextLoads() {
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
}
|