Skip to content

Commit 19680ab

Browse files
authored
Merge pull request #78 from amikos-tech/feature/77-add-makefile
[BLD] Add Makefile for common development tasks
2 parents dfe7efa + 895eb62 commit 19680ab

File tree

2 files changed

+284
-0
lines changed

2 files changed

+284
-0
lines changed

Makefile

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# ChromaDB Java Client Makefile
2+
# This Makefile provides convenient commands for common development tasks
3+
4+
# Variables
5+
MAVEN := mvn
6+
JAVA := java
7+
CHROMA_VERSIONS := 0.4.24 0.5.0 0.5.5 0.5.15
8+
9+
# Color output
10+
RED := \033[0;31m
11+
GREEN := \033[0;32m
12+
YELLOW := \033[0;33m
13+
BLUE := \033[0;34m
14+
NC := \033[0m # No Color
15+
16+
# Default target
17+
.DEFAULT_GOAL := help
18+
19+
# Check for required tools
20+
.PHONY: check-tools
21+
check-tools:
22+
@command -v $(JAVA) >/dev/null 2>&1 || { echo "$(RED)Error: Java is not installed$(NC)"; exit 1; }
23+
@command -v $(MAVEN) >/dev/null 2>&1 || { echo "$(RED)Error: Maven is not installed$(NC)"; exit 1; }
24+
@echo "$(GREEN)✓ All required tools are installed$(NC)"
25+
26+
##@ Core Build Targets
27+
28+
.PHONY: build
29+
build: check-tools ## Clean and compile the project
30+
@echo "$(BLUE)Building project...$(NC)"
31+
$(MAVEN) clean compile
32+
33+
.PHONY: test
34+
test: check-tools ## Run all tests
35+
@echo "$(BLUE)Running tests...$(NC)"
36+
$(MAVEN) test
37+
38+
.PHONY: package
39+
package: check-tools ## Create JAR package
40+
@echo "$(BLUE)Creating JAR package...$(NC)"
41+
$(MAVEN) clean package
42+
43+
.PHONY: install
44+
install: check-tools ## Install to local Maven repository
45+
@echo "$(BLUE)Installing to local Maven repository...$(NC)"
46+
$(MAVEN) clean install
47+
48+
.PHONY: clean
49+
clean: check-tools ## Clean build artifacts
50+
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
51+
$(MAVEN) clean
52+
53+
##@ Testing Targets
54+
55+
.PHONY: test-unit
56+
test-unit: check-tools ## Run unit tests only
57+
@echo "$(BLUE)Running unit tests...$(NC)"
58+
$(MAVEN) test -Dtest="!TestAPI,!*Integration*"
59+
60+
.PHONY: test-integration
61+
test-integration: check-tools ## Run integration tests only
62+
@echo "$(BLUE)Running integration tests...$(NC)"
63+
$(MAVEN) test -Dtest="TestAPI,*Integration*"
64+
65+
.PHONY: test-version
66+
test-version: check-tools ## Test with specific ChromaDB version (use CHROMA_VERSION=x.x.x)
67+
ifndef CHROMA_VERSION
68+
@echo "$(RED)Error: CHROMA_VERSION not specified$(NC)"
69+
@echo "Usage: make test-version CHROMA_VERSION=0.5.15"
70+
@exit 1
71+
endif
72+
@echo "$(BLUE)Testing with ChromaDB version $(CHROMA_VERSION)...$(NC)"
73+
CHROMA_VERSION=$(CHROMA_VERSION) $(MAVEN) test
74+
75+
.PHONY: test-all-versions
76+
test-all-versions: check-tools ## Run tests against all supported ChromaDB versions
77+
@echo "$(BLUE)Testing against all supported ChromaDB versions...$(NC)"
78+
@for version in $(CHROMA_VERSIONS); do \
79+
echo "$(YELLOW)Testing with ChromaDB $$version...$(NC)"; \
80+
CHROMA_VERSION=$$version $(MAVEN) test || exit 1; \
81+
done
82+
@echo "$(GREEN)✓ All version tests passed$(NC)"
83+
84+
.PHONY: test-class
85+
test-class: check-tools ## Run specific test class (use TEST=ClassName)
86+
ifndef TEST
87+
@echo "$(RED)Error: TEST not specified$(NC)"
88+
@echo "Usage: make test-class TEST=TestAPI"
89+
@exit 1
90+
endif
91+
@echo "$(BLUE)Running test class $(TEST)...$(NC)"
92+
$(MAVEN) test -Dtest=$(TEST)
93+
94+
.PHONY: test-method
95+
test-method: check-tools ## Run specific test method (use TEST=ClassName#methodName)
96+
ifndef TEST
97+
@echo "$(RED)Error: TEST not specified$(NC)"
98+
@echo "Usage: make test-method TEST=TestAPI#testCreateCollection"
99+
@exit 1
100+
endif
101+
@echo "$(BLUE)Running test method $(TEST)...$(NC)"
102+
$(MAVEN) test -Dtest=$(TEST)
103+
104+
##@ Code Generation
105+
106+
.PHONY: generate
107+
generate: check-tools ## Generate API client from OpenAPI spec
108+
@echo "$(BLUE)Generating API client from OpenAPI spec...$(NC)"
109+
$(MAVEN) generate-sources
110+
111+
.PHONY: generate-clean
112+
generate-clean: check-tools ## Clean and regenerate API client
113+
@echo "$(BLUE)Cleaning generated sources...$(NC)"
114+
rm -rf target/generated-sources
115+
@echo "$(BLUE)Regenerating API client...$(NC)"
116+
$(MAVEN) generate-sources
117+
118+
##@ Development Utilities
119+
120+
.PHONY: deps
121+
deps: check-tools ## Download/update dependencies
122+
@echo "$(BLUE)Resolving dependencies...$(NC)"
123+
$(MAVEN) dependency:resolve
124+
125+
.PHONY: deps-tree
126+
deps-tree: check-tools ## Display dependency tree
127+
@echo "$(BLUE)Displaying dependency tree...$(NC)"
128+
$(MAVEN) dependency:tree
129+
130+
.PHONY: deps-analyze
131+
deps-analyze: check-tools ## Analyze dependencies for conflicts
132+
@echo "$(BLUE)Analyzing dependencies...$(NC)"
133+
$(MAVEN) dependency:analyze
134+
135+
.PHONY: versions
136+
versions: check-tools ## Check for dependency updates
137+
@echo "$(BLUE)Checking for dependency updates...$(NC)"
138+
$(MAVEN) versions:display-dependency-updates
139+
140+
.PHONY: compile
141+
compile: check-tools ## Compile source code without cleaning
142+
@echo "$(BLUE)Compiling source code...$(NC)"
143+
$(MAVEN) compile
144+
145+
.PHONY: test-compile
146+
test-compile: check-tools ## Compile test source code
147+
@echo "$(BLUE)Compiling test source code...$(NC)"
148+
$(MAVEN) test-compile
149+
150+
##@ Release Targets
151+
152+
.PHONY: release-prepare
153+
release-prepare: check-tools ## Prepare for release (update versions)
154+
@echo "$(YELLOW)Preparing for release...$(NC)"
155+
@echo "Current version: $$($(MAVEN) help:evaluate -Dexpression=project.version -q -DforceStdout)"
156+
@read -p "Enter new version: " VERSION && \
157+
$(MAVEN) versions:set -DnewVersion=$$VERSION && \
158+
echo "$(GREEN)✓ Version updated to $$VERSION$(NC)"
159+
160+
.PHONY: release-rollback
161+
release-rollback: check-tools ## Rollback version changes
162+
@echo "$(YELLOW)Rolling back version changes...$(NC)"
163+
$(MAVEN) versions:revert
164+
165+
.PHONY: snapshot
166+
snapshot: check-tools ## Deploy snapshot version
167+
@echo "$(BLUE)Deploying snapshot...$(NC)"
168+
$(MAVEN) clean deploy
169+
170+
.PHONY: release
171+
release: check-tools ## Full release (CI only - requires GPG signing)
172+
@echo "$(YELLOW)⚠️ This target is intended for CI use only$(NC)"
173+
@echo "$(BLUE)Performing full release...$(NC)"
174+
$(MAVEN) clean deploy -P release
175+
176+
##@ Docker Targets
177+
178+
.PHONY: docker-test
179+
docker-test: ## Run tests in Docker environment
180+
@echo "$(BLUE)Running tests in Docker...$(NC)"
181+
docker run --rm -v $(PWD):/workspace -w /workspace maven:3-openjdk-8 mvn test
182+
183+
.PHONY: docker-build
184+
docker-build: ## Build project in Docker environment
185+
@echo "$(BLUE)Building in Docker...$(NC)"
186+
docker run --rm -v $(PWD):/workspace -w /workspace maven:3-openjdk-8 mvn clean package
187+
188+
##@ Utility Targets
189+
190+
.PHONY: info
191+
info: check-tools ## Display project information
192+
@echo "$(BLUE)Project Information:$(NC)"
193+
@echo " Name: $$($(MAVEN) help:evaluate -Dexpression=project.name -q -DforceStdout)"
194+
@echo " Group ID: $$($(MAVEN) help:evaluate -Dexpression=project.groupId -q -DforceStdout)"
195+
@echo " Artifact ID: $$($(MAVEN) help:evaluate -Dexpression=project.artifactId -q -DforceStdout)"
196+
@echo " Version: $$($(MAVEN) help:evaluate -Dexpression=project.version -q -DforceStdout)"
197+
@echo " Java Version: $$($(JAVA) -version 2>&1 | head -1)"
198+
@echo " Maven Version: $$($(MAVEN) -version | head -1)"
199+
200+
.PHONY: help
201+
help: ## Display this help message
202+
@echo "ChromaDB Java Client - Development Tasks"
203+
@echo ""
204+
@echo "Usage: make [target]"
205+
@echo ""
206+
@awk 'BEGIN {FS = ":.*##"; printf "$(YELLOW)Available targets:$(NC)\n"} \
207+
/^[a-zA-Z_-]+:.*?##/ { printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2 } \
208+
/^##@/ { printf "\n$(BLUE)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
209+
@echo ""
210+
@echo "$(YELLOW)Examples:$(NC)"
211+
@echo " make build # Build the project"
212+
@echo " make test # Run all tests"
213+
@echo " make test-version CHROMA_VERSION=0.5.15 # Test with specific version"
214+
@echo " make test-class TEST=TestAPI # Run specific test class"
215+
@echo " make help # Show this help"
216+
217+
# Quick shortcuts
218+
.PHONY: b
219+
b: build ## Shortcut for build
220+
221+
.PHONY: t
222+
t: test ## Shortcut for test
223+
224+
.PHONY: c
225+
c: clean ## Shortcut for clean
226+
227+
.PHONY: i
228+
i: install ## Shortcut for install

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,62 @@ This client works with Chroma Versions `>=0.4.3+ <1.0.0`
4949
- [x] Support for Sentence Transformers with Hugging Face API
5050
- ⚒️ Authentication ⚒️
5151

52+
## Development
53+
54+
This project includes a `Makefile` to simplify common development tasks. Make sure you have `make` installed on your system.
55+
56+
### Quick Start
57+
58+
```bash
59+
# Display available commands
60+
make help
61+
62+
# Build the project
63+
make build
64+
65+
# Run tests
66+
make test
67+
68+
# Create JAR package
69+
make package
70+
```
71+
72+
### Common Development Commands
73+
74+
| Command | Description |
75+
|---------|-------------|
76+
| `make build` | Clean and compile the project |
77+
| `make test` | Run all tests |
78+
| `make test-unit` | Run unit tests only |
79+
| `make test-integration` | Run integration tests only |
80+
| `make test-version CHROMA_VERSION=0.5.15` | Test with specific ChromaDB version |
81+
| `make test-all-versions` | Test against all supported versions (0.4.24, 0.5.0, 0.5.5, 0.5.15) |
82+
| `make test-class TEST=TestAPI` | Run specific test class |
83+
| `make test-method TEST=TestAPI#testMethod` | Run specific test method |
84+
| `make package` | Create JAR package |
85+
| `make install` | Install to local Maven repository |
86+
| `make clean` | Clean build artifacts |
87+
| `make generate` | Generate API client from OpenAPI spec |
88+
| `make deps` | Download/update dependencies |
89+
| `make deps-tree` | Display dependency tree |
90+
| `make info` | Display project information |
91+
92+
### Environment Variables
93+
94+
For testing with external services, set these environment variables:
95+
- `OPENAI_API_KEY` - Required for OpenAI embedding tests
96+
- `COHERE_API_KEY` - Required for Cohere embedding tests
97+
- `HF_API_KEY` - Required for HuggingFace embedding tests
98+
- `CHROMA_VERSION` - Specify ChromaDB version for tests (default: latest)
99+
100+
### Shortcuts
101+
102+
The Makefile also provides single-letter shortcuts for common commands:
103+
- `make b` - Build
104+
- `make t` - Test
105+
- `make c` - Clean
106+
- `make i` - Install
107+
52108
## Usage
53109

54110
Add Maven dependency:

0 commit comments

Comments
 (0)