Skip to content

Commit ebd9eb1

Browse files
committed
fix: update Makefile to handle cross-platform
1 parent 5a33527 commit ebd9eb1

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

Makefile

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
qodana semgrep verify-image health-check lint test-unit test-integration \
44
install-pipx install-semgrep
55

6-
GRADLE := ./gradlew
76
DOCKER := docker
87
IMAGE_NAME := backend-app
98
IMAGE_TAG := latest
@@ -27,6 +26,15 @@ else
2726
DETECTED_OS := Unknown
2827
endif
2928

29+
# Set GRADLE command based on OS
30+
ifeq ($(DETECTED_OS),Windows)
31+
GRADLE := gradlew.bat
32+
PWD := $(shell cd)
33+
else
34+
GRADLE := ./gradlew
35+
PWD := $(shell pwd)
36+
endif
37+
3038
.DEFAULT_GOAL := help
3139

3240
help:
@@ -56,16 +64,24 @@ dev: ## Run with development profile
5664
##@ Testing
5765

5866
test: ## Run all tests
67+
ifeq ($(DETECTED_OS),Windows)
68+
@set TESTCONTAINERS_RYUK_DISABLED=true && set TESTCONTAINERS_CHECKS_DISABLE=true && $(GRADLE) clean test --info --no-daemon
69+
else
5970
@TESTCONTAINERS_RYUK_DISABLED=true \
6071
TESTCONTAINERS_CHECKS_DISABLE=true \
6172
$(GRADLE) clean test --info --no-daemon
73+
endif
6274

6375
test-unit: ## Run unit tests only
6476
$(GRADLE) test --tests '*Test' --no-daemon
6577

6678
test-integration: ## Run integration tests only
79+
ifeq ($(DETECTED_OS),Windows)
80+
@set TESTCONTAINERS_RYUK_DISABLED=true && $(GRADLE) test --tests '*IT' --no-daemon
81+
else
6782
@TESTCONTAINERS_RYUK_DISABLED=true \
6883
$(GRADLE) test --tests '*IT' --no-daemon
84+
endif
6985

7086
##@ Code Quality
7187

@@ -94,12 +110,17 @@ lint: ## Run linting checks
94110
$(GRADLE) check --no-daemon
95111

96112
qodana: ## Run Qodana code analysis
113+
ifeq ($(DETECTED_OS),Windows)
114+
@if not exist qodana-results mkdir qodana-results
115+
@docker run --rm -v $(PWD):/data/project -v $(PWD)/qodana-results:/data/results jetbrains/qodana-jvm-community:latest --save-report --results-dir=/data/results
116+
else
97117
@mkdir -p $(PWD)/qodana-results
98118
@docker run --rm \
99119
-v $(PWD):/data/project \
100120
-v $(PWD)/qodana-results:/data/results \
101121
jetbrains/qodana-jvm-community:latest \
102122
--save-report --results-dir=/data/results
123+
endif
103124

104125
install-pipx: ## Install pipx based on OS
105126
ifeq ($(DETECTED_OS),Linux)
@@ -134,21 +155,35 @@ else ifeq ($(DETECTED_OS),MacOS)
134155
echo "pipx is already installed"; \
135156
fi
136157
else ifeq ($(DETECTED_OS),Windows)
137-
@echo "Installing pipx on Windows..."
138-
@python -m pip install --user pipx || python3 -m pip install --user pipx
139-
@python -m pipx ensurepath || python3 -m pipx ensurepath
158+
@where pipx >nul 2>nul || ( \
159+
echo Installing pipx on Windows... && \
160+
python -m pip install --user pipx && \
161+
python -m pipx ensurepath \
162+
) || ( \
163+
python3 -m pip install --user pipx && \
164+
python3 -m pipx ensurepath \
165+
)
166+
@where pipx >nul 2>nul && echo pipx is already installed
140167
else
141168
@echo "Unknown OS. Please install pipx manually."
142169
@exit 1
143170
endif
144171

145172
install-semgrep: install-pipx ## Install Semgrep using pipx
173+
ifeq ($(DETECTED_OS),Windows)
174+
@where semgrep >nul 2>nul || ( \
175+
echo Installing Semgrep via pipx... && \
176+
pipx install semgrep || (echo Failed to install Semgrep && exit 1) \
177+
)
178+
@where semgrep >nul 2>nul && echo Semgrep is already installed
179+
else
146180
@if ! command -v semgrep >/dev/null 2>&1; then \
147181
echo "Installing Semgrep via pipx..."; \
148182
pipx install semgrep || (echo "Failed to install Semgrep" && exit 1); \
149183
else \
150184
echo "Semgrep is already installed"; \
151185
fi
186+
endif
152187

153188
semgrep: install-semgrep ## Run Semgrep security scanning
154189
@semgrep ci --config=auto --sarif --output=semgrep.sarif --verbose
@@ -159,10 +194,14 @@ docker-build: ## Build Docker image
159194
$(DOCKER) build -t $(IMAGE_NAME):$(IMAGE_TAG) .
160195

161196
docker-build-cache: ## Build Docker image with buildx cache
197+
ifeq ($(DETECTED_OS),Windows)
198+
$(DOCKER) buildx build --cache-from type=local,src=%TEMP%\.buildx-cache --cache-to type=local,dest=%TEMP%\.buildx-cache -t $(IMAGE_NAME):$(IMAGE_TAG) .
199+
else
162200
$(DOCKER) buildx build \
163201
--cache-from type=local,src=/tmp/.buildx-cache \
164202
--cache-to type=local,dest=/tmp/.buildx-cache \
165203
-t $(IMAGE_NAME):$(IMAGE_TAG) .
204+
endif
166205

167206
verify-image: ## Verify Docker image contents and configuration
168207
@echo "Verifying image exists:"
@@ -187,7 +226,11 @@ docker-logs: ## View container logs
187226
$(DOCKER) logs -f $(CONTAINER_NAME)
188227

189228
health-check: ## Check application health endpoint
229+
ifeq ($(DETECTED_OS),Windows)
230+
@powershell -Command "Invoke-WebRequest -Uri http://localhost:$(PORT)/actuator/health -UseBasicParsing"
231+
else
190232
@curl -f http://localhost:$(PORT)/actuator/health
233+
endif
191234

192235
##@ CI/CD
193236

@@ -205,7 +248,11 @@ ci-semgrep: semgrep ## Run CI Semgrep pipeline locally
205248

206249
clean: ## Clean build artifacts
207250
$(GRADLE) clean --no-daemon
251+
ifeq ($(DETECTED_OS),Windows)
252+
@if exist build rmdir /s /q build
253+
else
208254
@rm -rf build/
255+
endif
209256

210257
clean-docker: docker-stop ## Remove Docker images and containers
211258
@$(DOCKER) rmi $(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
@@ -215,15 +262,23 @@ clean-all: clean clean-docker ## Complete cleanup
215262
##@ Setup
216263

217264
install: ## Install and verify development tools
265+
ifeq ($(DETECTED_OS),Windows)
266+
@if not exist google-java-format-1.28.0-all-deps.jar ( \
267+
curl -L -o google-java-format-1.28.0-all-deps.jar https://github.com/google/google-java-format/releases/download/v1.28.0/google-java-format-1.28.0-all-deps.jar \
268+
)
269+
@if exist format.sh ( attrib +x format.sh 2>nul )
270+
@if exist yamlfmt ( attrib +x yamlfmt\* 2>nul )
271+
else
218272
@test -f google-java-format-1.28.0-all-deps.jar || \
219273
curl -L -o google-java-format-1.28.0-all-deps.jar \
220274
https://github.com/google/google-java-format/releases/download/v1.28.0/google-java-format-1.28.0-all-deps.jar
221275
@if [ -f "format.sh" ]; then chmod +x format.sh; fi
222276
@if [ -d "yamlfmt" ]; then chmod +x yamlfmt/* 2>/dev/null || true; fi
277+
endif
223278

224279
verify: ## Verify development environment
225280
@echo "Detected OS: $(DETECTED_OS)"
226-
@echo "Format script: $(FORMAT_SCRIPT)"
281+
@echo "Gradle command: $(GRADLE)"
227282
@java -version
228283
@$(GRADLE) --version
229284
@docker --version

src/test/java/com/example/arinfra/file/SecureTempFileManagerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ void should_create_writable_file() throws IOException {
308308
}
309309

310310
@Test
311+
@EnabledOnOs({OS.LINUX, OS.MAC})
311312
void should_not_create_executable_file_on_unix() throws IOException {
312313
createdFile = subject.createSecureTempFile(TEST_PREFIX, TEST_SUFFIX);
313314

0 commit comments

Comments
 (0)