mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
4cd02529ca
Simplify the Claude Code guidance document by: - Condensing verbose descriptions into concise bullet points - Adding current version info (7.2.0-SNAPSHOT) - Improving build commands section with more examples - Reorganizing architecture section for better readability - Streamlining security patterns section - Adding clear request lifecycle diagram - Consolidating available tools into organized sections 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
4.9 KiB
4.9 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
For detailed procedures, use the specialized agents and commands in .claude/agents/ and .claude/commands/.
Project Overview
Apache Struts is a mature MVC web application framework for Java (originally WebWork 2). Current version: * 7.2.0-SNAPSHOT*.
Build Commands
# Full build with tests
mvn clean install
# Run all tests (faster, skips assembly)
mvn test -DskipAssembly
# Run single test class
mvn test -DskipAssembly -Dtest=MyClassTest
# Run single test method
mvn test -DskipAssembly -Dtest=MyClassTest#testMethodName
# Run tests in a specific module
mvn test -DskipAssembly -pl core
# Build without tests
mvn clean install -DskipTests
# Build with code coverage (JaCoCo)
mvn clean install -Pcoverage
# Build with Jakarta EE 11 (Spring 7)
mvn clean install -Pjakartaee11
# Run OWASP dependency vulnerability check
mvn verify -Pdependency-check
Project Structure
struts/
├── core/ # struts2-core - main framework
├── plugins/ # Plugin modules (json, rest, spring, tiles, velocity, etc.)
├── apps/ # Sample applications (showcase, rest-showcase)
├── assembly/ # Distribution packaging
├── bom/ # Bill of Materials for dependency management
├── parent/ # Parent POM with shared configuration
└── jakarta/ # Jakarta EE compatibility modules
Core Architecture
Request Lifecycle: Dispatcher → ActionProxy → ActionInvocation → Interceptor stack → Action → Result
Key components:
- ActionSupport: Base class for actions (validation, i18n, messages)
- ActionContext: Thread-local context with request/response/session data
- Interceptors: Cross-cutting concerns (validation, file upload, security, params)
- Results: Response handlers (dispatcher, redirect, json, stream)
Key packages in org.apache.struts2:
dispatcher- Request handling,Dispatcher, servlet integrationinterceptor- Built-in interceptors (params, validation, fileUpload)components- UI tag components (form, textfield, submit)action- Action interfaces (UploadedFilesAware,SessionAware, etc.)security- Security utilities and OGNL member access policies
Technology Stack
- Java 17+ with Jakarta EE 10 (Servlet 6.0, JSP 3.1)
- OGNL - Expression language for value stack access
- FreeMarker - Default template engine for UI tags
- Commons FileUpload2 - File upload handling
- Log4j2/SLF4J - Logging
Security-Critical Patterns
Apache Struts has a history of security vulnerabilities. Follow these strictly:
- Temporary files: Never use system temp directory; use UUID-based names in controlled locations
- OGNL expressions: Never evaluate user-controlled OGNL; use allowlist member access
- File uploads: Validate content types, sanitize filenames, enforce size limits
- Parameter injection: Use
ParameterNameAwareto filter dangerous parameter names
// Secure temporary file pattern
protected File createTemporaryFile(String fileName, Path location) {
String uid = UUID.randomUUID().toString().replace("-", "_");
return location.resolve("upload_" + uid + ".tmp").toFile();
}
Run /security_scan for comprehensive security analysis.
Testing
Priority order for running tests:
- JetBrains MCP (in IntelliJ):
mcp__jetbrains__execute_run_configuration - test-runner agent:
Tasktool withsubagent_type="test-runner" - Direct Maven:
mvn test -DskipAssembly -Dtest=TestClassName
Tests use JUnit 5 with AssertJ assertions and Mockito for mocking.
Available Tools
Commands
/security_scan- OGNL injection, CVE detection, security analysis/quality_check- JavaDoc compliance, coding standards/config_analyze- struts.xml validation, interceptor analysis/create_plan//validate_plan- Implementation planning/research_codebase- Codebase exploration
Specialized Agents
test-runner- Maven test execution (use this to RUN tests)security-analyzer- Security vulnerability scanningcodebase-locator- Find files, classes, implementationscodebase-pattern-finder- Find similar code patternsconfig-validator- Validate Struts configuration files
Pull Requests
- Title format:
WW-XXXX Description(Jira ticket ID required) - Link ticket in description:
Fixes [WW-XXXX](https://issues.apache.org/jira/browse/WW-XXXX) - Issue tracker: https://issues.apache.org/jira/projects/WW
Common Pitfalls
- Never use
File.createTempFile()without controlling the directory - Always clean up temporary files (track and delete in finally blocks)
- Test error paths and cleanup behavior, not just happy paths
- Don't catch generic
Exception- catch specific types - Use
protectedvisibility for methods subclasses may override