Skip to content

Commit 423d5a2

Browse files
bedaHovorkaclaude
andcommitted
Modernize project structure with Maven-style layout and Ivy dependency management
Major improvements to project organization and build system: - Restructure to Maven/Gradle standard layout (src/main/java, src/test/java, src/main/resources) - Replace bundled junit.jar with Apache Ivy dependency management - Add ivy.xml and ivysettings.xml for automatic dependency resolution - Build jDisco as standalone Maven library (separate module with POM) - Update Ant build.xml for new directory structure and Ivy integration - Reorganize test files to match source package structure - Update Dockerfile for Ivy-based build with jDisco Maven install - Update .gitignore for Maven/Ivy artifacts (lib/, .ivy2/) - Update documentation (README.md, CLAUDE.md) with Ivy instructions This modernization maintains Java 6 compatibility while adopting industry-standard project structure and eliminating binary JAR files from version control. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e404b49 commit 423d5a2

89 files changed

Lines changed: 466 additions & 146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ artifacts/
4242
jdisco/target/
4343
.m2/
4444

45+
# Ivy artifacts
46+
.ivy2/
47+
lib/
48+
4549
# OS files
4650
.DS_Store
4751
Thumbs.db
48-
*~
52+
*~
53+
/out/

CLAUDE.md

Lines changed: 82 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,40 @@ Railway Interlocking Simulator - A BSc thesis project (2006/2007) from Brno Univ
88

99
## Build System
1010

11-
This project uses Apache Ant for building. Java 6 is required (`javac 1.6`), with JUnit for testing.
11+
This project uses Apache Ant for building with Apache Ivy for dependency management. Java 6 is required (`javac 1.6`).
12+
13+
### Dependency Management
14+
15+
Dependencies are managed via Apache Ivy:
16+
- **jDisco 1.2.0** - Discrete event simulation library (from Maven local repository)
17+
- **JUnit 3.8.2** - Testing framework (from Maven Central)
18+
19+
Ivy automatically downloads dependencies during the build. Configuration files:
20+
- `ivy.xml` - Dependency declarations
21+
- `ivysettings.xml` - Repository resolver configuration
1222

1323
### Common Build Commands
1424

15-
**Clean build:**
25+
**Resolve dependencies:**
26+
```bash
27+
ant resolve
28+
```
29+
30+
**Clean build (includes dependency resolution and test execution):**
1631
```bash
1732
ant clean build
1833
```
1934

20-
**Build only:**
35+
**Build only (compiles main code, tests, and runs tests):**
2136
```bash
2237
ant build
2338
```
2439

40+
**Run tests only:**
41+
```bash
42+
ant test
43+
```
44+
2545
**Run simulation (pre-configured shunting loop example):**
2646
```bash
2747
ant start
@@ -37,28 +57,44 @@ ant run
3757
ant doc
3858
```
3959

60+
**Clean everything including Ivy cache:**
61+
```bash
62+
ant clean-all
63+
```
64+
65+
### Directory Structure
66+
67+
The project follows Maven/Gradle standard directory layout:
68+
- `src/main/java/` - Main source code
69+
- `src/test/java/` - Test source code
70+
- `src/main/resources/` - Resource files (XML schemas, examples)
71+
- `build/main/` - Compiled main classes
72+
- `build/test/` - Compiled test classes
73+
- `lib/compile/` - Compile-time dependencies (jDisco)
74+
- `lib/test/` - Test dependencies (JUnit)
75+
4076
### Running Manually
4177

42-
After building with `ant build`, run from the `build/` directory:
78+
After building with `ant build`, run from the project root:
4379

4480
**Simulation mode:**
4581
```bash
46-
java -ea cz.vutbr.fit.interlockSim.Main sim [xmlFile]
82+
java -ea -cp "build/main:lib/compile/*" cz.vutbr.fit.interlockSim.Main sim [xmlFile]
4783
```
4884

4985
**Editor mode:**
5086
```bash
51-
java -ea cz.vutbr.fit.interlockSim.Main edit [xmlFile]
87+
java -ea -cp "build/main:lib/compile/*" cz.vutbr.fit.interlockSim.Main edit [xmlFile]
5288
```
5389

5490
**Built-in examples:**
5591
```bash
56-
java -ea cz.vutbr.fit.interlockSim.Main example [exampleName] [endTime]
92+
java -ea -cp "build/main:lib/compile/*" cz.vutbr.fit.interlockSim.Main example [exampleName] [endTime]
5793
```
5894

5995
To list available examples, run:
6096
```bash
61-
java -ea cz.vutbr.fit.interlockSim.Main example
97+
java -ea -cp "build/main:lib/compile/*" cz.vutbr.fit.interlockSim.Main example
6298
```
6399

64100
**Note:** Enable assertions with `-ea` flag. For memory-constrained environments, add `-Xmx300`.
@@ -127,11 +163,13 @@ docker compose build app
127163
### Docker Architecture
128164

129165
**Root Dockerfile (multi-stage build):**
130-
1. **Builder stage** - Uses `caninjas/jdk6` with Ant
131-
- Compiles Java sources
132-
- Runs tests
133-
- Creates JAR with all dependencies
134-
2. **Runner stage** - JRE 6 with X11 libraries
166+
1. **Builder stage** - Uses Debian Buster with OpenJDK 11, Maven, and Ant
167+
- Builds jDisco dependency (Maven install)
168+
- Resolves dependencies via Apache Ivy (automatic download)
169+
- Compiles Java sources (Java 6 compatibility mode)
170+
- Runs all tests (build fails if tests fail)
171+
- Creates uber JAR with all dependencies
172+
2. **Runner stage** - Debian Buster with OpenJDK 11 JRE and X11 libraries
135173
- Minimal runtime environment
136174
- X11 forwarding for GUI support
137175
- No build tools in final image
@@ -223,25 +261,32 @@ Both services copy build outputs to `/artifacts` inside the container, which is
223261

224262
**XML Configuration:**
225263
- Railway networks defined in XML format
226-
- Schema: `src/cz/vutbr/fit/interlockSim/resource/data.xsd`
227-
- Example: `src/cz/vutbr/fit/interlockSim/resource/vyhybna.xml`
264+
- Schema: `src/main/resources/cz/vutbr/fit/interlockSim/resource/data.xsd`
265+
- Example: `src/main/resources/cz/vutbr/fit/interlockSim/resource/vyhybna.xml`
228266
- Elements include: RailSwitch, RailSemaphore, InOut (entry/exit points), track connections
229267

230268
### Package Structure
231269

232270
```
233-
cz.vutbr.fit.interlockSim/
234-
├── Main.java - Application entry point
235-
├── context/ - Context management and factories
236-
├── gui/ - Graphical editor
237-
├── objects/ - Domain model (tracks, paths, cells)
238-
├── sim/ - Simulation scenarios
239-
├── test/ - Unit tests (JUnit)
240-
├── util/ - Utilities and reporting
241-
├── xml/ - XML parsing and serialization
242-
└── resource/ - XML schemas and configuration files
243-
244-
jDisco/ - Third-party discrete event simulation library
271+
src/
272+
├── main/
273+
│ ├── java/cz/vutbr/fit/interlockSim/
274+
│ │ ├── Main.java - Application entry point
275+
│ │ ├── context/ - Context management and factories
276+
│ │ ├── gui/ - Graphical editor
277+
│ │ ├── objects/ - Domain model (tracks, paths, cells)
278+
│ │ ├── sim/ - Simulation scenarios
279+
│ │ ├── util/ - Utilities and reporting
280+
│ │ └── xml/ - XML parsing and serialization
281+
│ └── resources/cz/vutbr/fit/interlockSim/
282+
│ └── resource/ - XML schemas and configuration files
283+
└── test/
284+
└── java/cz/vutbr/fit/interlockSim/test/
285+
├── TestArray2DMap.java - Array2DMap unit tests
286+
├── TestCell.java - Cell unit tests
287+
└── TestContext.java - Context unit tests
288+
289+
jdisco/ - Third-party discrete event simulation library (separate module)
245290
```
246291

247292
## Code Style
@@ -265,14 +310,22 @@ This is a working historical codebase from 2007. Stability and preservation are
265310

266311
## Testing
267312

268-
JUnit tests located in `cz.vutbr.fit.interlockSim.test/`. The `junit.jar` library is included in the repository root.
313+
JUnit 3.8.2 tests located in `src/test/java/cz/vutbr/fit/interlockSim/test/`. JUnit is managed via Apache Ivy.
314+
315+
**Current tests:**
316+
- `TestArray2DMap` - 10 tests for 2D array-based map implementation
317+
- `TestCell` - 2 tests for cell segment and direction logic
318+
- `TestContext` - 4 tests for railway network context operations
269319

270320
**Run tests:**
271321
```bash
322+
ant test
323+
# Or as part of build:
272324
ant build
273-
# Tests run during build
274325
```
275326

327+
Tests are automatically executed during the build process. The build will fail if any test fails (`haltonfailure="yes"`).
328+
276329
## Documentation
277330

278331
LaTeX-based thesis documentation in `text/` directory.

Dockerfile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Dockerization: 2025
1010
#
1111
# Multi-stage build for interlockSim with GUI support
12+
# Dependency management: Apache Ivy
1213
#
1314

1415
# ============================================
@@ -43,22 +44,13 @@ WORKDIR /build/interlockSim
4344
# Copy source files and build configuration
4445
COPY src/ /build/interlockSim/src/
4546
COPY build.xml /build/interlockSim/
46-
COPY junit.jar /build/interlockSim/
47+
COPY ivy.xml /build/interlockSim/
48+
COPY ivysettings.xml /build/interlockSim/
4749

48-
# Patch build.xml to add Java 6 source/target compatibility and ISO-8859-1 encoding
49-
# Note: jDisco library files use ISO-8859-1 encoding
50-
RUN sed -i 's|<javac destdir="build">|<javac destdir="build" source="1.6" target="1.6" encoding="ISO-8859-1" includeantruntime="false">|g' build.xml
51-
52-
# Patch build.xml to add junit.jar to the classpath
53-
RUN sed -i 's|<path id="project.classpath">|<path id="project.classpath">\n <pathelement location="junit.jar"/>|g' build.xml
54-
55-
# Build the project (compiles code and resources)
50+
# Build the project (compiles code, runs tests)
51+
# Ivy downloads dependencies automatically during resolve phase
5652
RUN ant clean build
5753

58-
# Run tests if they exist
59-
# Note: build.xml doesn't have explicit test target, but tests are in src
60-
RUN ant build
61-
6254
# Create JAR with manifest
6355
RUN ant pack
6456

@@ -104,7 +96,7 @@ WORKDIR /app
10496
COPY --from=builder /build/interlockSim/jar/interlockSim.jar /app/
10597

10698
# Copy resources if needed at runtime (XML schemas, examples)
107-
COPY --from=builder /build/interlockSim/build/cz/vutbr/fit/interlockSim/resource/ \
99+
COPY --from=builder /build/interlockSim/build/main/cz/vutbr/fit/interlockSim/resource/ \
108100
/app/resource/
109101

110102
# Create artifacts directory for extraction
@@ -117,5 +109,5 @@ RUN cp /app/interlockSim.jar /artifacts/
117109
ENV DISPLAY=:0
118110

119111
# Default command: run editor GUI
120-
# Users can override with: docker-compose run app java -ea -jar interlockSim.jar sim file.xml
121-
CMD ["java", "-ea", "-jar", "interlockSim.jar", "edit"]
112+
# Users can override with: docker compose run app java -ea -jar interlockSim.jar sim file.xml
113+
CMD ["java", "-ea", "-jar", "interlockSim.jar", "edit"]

0 commit comments

Comments
 (0)