|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Apache Struts 2 Framework (Version 6.7.x) |
| 6 | + |
| 7 | +This is the Apache Struts 2 web framework, a free open-source solution for creating Java web applications. The codebase is a multi-module Maven project with comprehensive plugin architecture. |
| 8 | + |
| 9 | +## Build System & Common Commands |
| 10 | + |
| 11 | +### Maven Commands |
| 12 | +```bash |
| 13 | +# Build entire project |
| 14 | +./mvnw clean install |
| 15 | + |
| 16 | +# Build without running tests |
| 17 | +./mvnw clean install -DskipTests |
| 18 | + |
| 19 | +# Build without assembly |
| 20 | +./mvnw clean install -DskipAssembly |
| 21 | + |
| 22 | +# Run all tests |
| 23 | +./mvnw clean test |
| 24 | + |
| 25 | +# Run tests with coverage |
| 26 | +./mvnw clean verify -Pcoverage -DskipAssembly |
| 27 | + |
| 28 | +# Run integration tests |
| 29 | +./mvnw clean verify -DskipAssembly |
| 30 | + |
| 31 | +# Test specific module |
| 32 | +./mvnw -pl core clean test |
| 33 | +./mvnw -pl plugins/spring clean test |
| 34 | + |
| 35 | +# Check for security vulnerabilities |
| 36 | +./mvnw clean verify -Pdependency-check |
| 37 | + |
| 38 | +# Run Apache RAT license check |
| 39 | +./mvnw clean prepare-package |
| 40 | +``` |
| 41 | + |
| 42 | +### Test Framework |
| 43 | +- **Primary**: JUnit 4.13.2 with Maven Surefire Plugin 3.5.1 |
| 44 | +- **Pattern**: `**/*Test.java` (excludes `**/TestBean.java`) |
| 45 | +- **Coverage**: JaCoCo 0.8.12 |
| 46 | +- **Additional**: Mockito, EasyMock, AssertJ, Spring Test |
| 47 | +- **Integration**: Maven Failsafe Plugin with Jetty on port 8090 |
| 48 | + |
| 49 | +## Project Architecture |
| 50 | + |
| 51 | +### Core Structure |
| 52 | +``` |
| 53 | +struts6/ |
| 54 | +├── core/ # Core Struts 2 framework (main dependency) |
| 55 | +├── plugins/ # Plugin modules |
| 56 | +│ ├── spring/ # Spring integration |
| 57 | +│ ├── json/ # JSON support |
| 58 | +│ ├── tiles/ # Apache Tiles integration |
| 59 | +│ ├── velocity/ # Velocity template engine |
| 60 | +│ └── [20+ other plugins] |
| 61 | +├── apps/ # Sample applications |
| 62 | +│ ├── showcase/ # Feature demonstration app |
| 63 | +│ └── rest-showcase/ # REST API examples |
| 64 | +├── bundles/ # OSGi bundles |
| 65 | +├── bom/ # Bill of Materials |
| 66 | +└── assembly/ # Distribution packaging |
| 67 | +``` |
| 68 | + |
| 69 | +### Key Technologies |
| 70 | +- **Java**: Minimum JDK 8, supports up to JDK 21 |
| 71 | +- **Servlet API**: 3.1+ required |
| 72 | +- **Expression Language**: OGNL 3.3.5 |
| 73 | +- **Dependency Injection**: Custom container (`com.opensymphony.xwork2.inject`) |
| 74 | +- **Templating**: FreeMarker 2.3.33 (default), Velocity, JSP |
| 75 | +- **Logging**: SLF4J 2.0.16 with Log4j2 2.24.1 |
| 76 | +- **Build**: Maven with wrapper (3.9.6) |
| 77 | + |
| 78 | +### Core Components Architecture |
| 79 | + |
| 80 | +#### Action Framework (MVC Pattern) |
| 81 | +- **Actions**: Located in `core/src/main/java/org/apache/struts2/action/` |
| 82 | +- **Action Support**: `ActionSupport` base class with validation and i18n |
| 83 | +- **Action Context**: `ActionContext` provides access to servlet objects |
| 84 | +- **Action Invocation**: `DefaultActionInvocation` handles action execution |
| 85 | + |
| 86 | +#### Configuration System |
| 87 | +- **XML-based**: Primary configuration via `struts.xml` files |
| 88 | +- **Annotation-based**: Convention plugin for zero-config approach |
| 89 | +- **Java-based**: `StrutsJavaConfiguration` for programmatic setup |
| 90 | +- **Property files**: `struts.properties` for framework settings |
| 91 | + |
| 92 | +#### Interceptor Chain |
| 93 | +- **Framework Core**: All requests processed through interceptor chain |
| 94 | +- **Built-in Interceptors**: 20+ interceptors in `org.apache.struts2.interceptor` |
| 95 | +- **Validation**: `ValidationInterceptor` with annotation support |
| 96 | +- **File Upload**: `FileUploadInterceptor` with security controls |
| 97 | +- **Parameters**: `ParametersInterceptor` with OGNL expression handling |
| 98 | + |
| 99 | +#### Result Framework |
| 100 | +- **Result Types**: JSP, FreeMarker, Redirect, Stream, JSON, etc. |
| 101 | +- **Chaining**: `ActionChainResult` for action-to-action calls |
| 102 | +- **Templates**: Pluggable result renderers |
| 103 | + |
| 104 | +#### Value Stack (OGNL Integration) |
| 105 | +- **Expression Language**: OGNL for property access and method calls |
| 106 | +- **Security**: `SecurityMemberAccess` prevents dangerous operations |
| 107 | +- **Performance**: Caffeine-based expression caching |
| 108 | +- **Context**: CompoundRoot provides hierarchical value resolution |
| 109 | + |
| 110 | +### Plugin Architecture |
| 111 | +Each plugin is a separate Maven module with: |
| 112 | +- **Plugin Descriptor**: `struts-plugin.xml` defines beans and configuration |
| 113 | +- **Dependency Isolation**: Separate classloaders for plugin resources |
| 114 | +- **Extension Points**: Configurable via dependency injection |
| 115 | +- **Popular Plugins**: Spring (DI), JSON (REST), Tiles (Layout), Bean Validation (JSR-303) |
| 116 | + |
| 117 | +### Security Architecture |
| 118 | +- **OGNL Security**: Restricted method access and class loading |
| 119 | +- **CSRF Protection**: Token-based with `TokenInterceptor` |
| 120 | +- **File Upload Security**: Type and size restrictions |
| 121 | +- **Content Security Policy**: Built-in CSP support |
| 122 | +- **Input Validation**: Server-side validation framework |
| 123 | +- **Pattern Matching**: Configurable allowed/excluded patterns |
| 124 | + |
| 125 | +## Development Guidelines |
| 126 | + |
| 127 | +### Code Organization |
| 128 | +- **Package Structure**: Follow existing `org.apache.struts2.*` hierarchy |
| 129 | +- **Naming Conventions**: Use Struts conventions (Actions end with `Action`) |
| 130 | +- **Configuration**: Prefer XML configuration in `struts.xml` for complex setups |
| 131 | +- **Testing**: Each module has comprehensive unit and integration tests |
| 132 | + |
| 133 | +### Plugin Development |
| 134 | +```java |
| 135 | +// Plugin descriptor example (struts-plugin.xml) |
| 136 | +<bean type="com.opensymphony.xwork2.ObjectFactory" |
| 137 | + name="myObjectFactory" |
| 138 | + class="com.example.MyObjectFactory" /> |
| 139 | +``` |
| 140 | + |
| 141 | +### Common Patterns |
| 142 | +- **Action Implementation**: Extend `ActionSupport` or implement `Action` |
| 143 | +- **Result Mapping**: Use result configuration in `struts.xml` |
| 144 | +- **Interceptor Development**: Extend `AbstractInterceptor` |
| 145 | +- **Type Conversion**: Implement `TypeConverter` for custom types |
| 146 | +- **Validation**: Use validation XML or annotations |
| 147 | + |
| 148 | +### Important Notes |
| 149 | +- **Version**: Currently 6.7.5-SNAPSHOT (release branch: `release/struts-6-7-x`) |
| 150 | +- **Java Compatibility**: Compiled for Java 8, tested through Java 21 |
| 151 | +- **Security**: Always validate inputs and follow OWASP guidelines |
| 152 | +- **Performance**: Leverage built-in caching (OGNL expressions, templates) |
| 153 | +- **Deprecation**: Some legacy XWork components marked for removal |
| 154 | + |
| 155 | +### Build Profiles |
| 156 | +- **coverage**: Enables JaCoCo coverage reporting |
| 157 | +- **dependency-check**: OWASP dependency vulnerability scanning |
| 158 | +- **jdk17**: Special configuration for Java 17+ module system |
| 159 | + |
| 160 | +This is a mature, enterprise-grade framework with extensive documentation at https://struts.apache.org/ and active community support through Apache mailing lists and JIRA (project WW). |
0 commit comments