Skip to content

Implement C++ CLI tool for parsing Tomcat server.xml with configurable output modes - #1

Merged
JonasGao merged 14 commits into
mainfrom
copilot/add-tomcat-parser-cli-tool
Jan 7, 2026
Merged

JonasGao merged 14 commits into
mainfrom
copilot/add-tomcat-parser-cli-tool

Conversation

Copilot AI commented Dec 9, 2025 •

Copy link
Copy Markdown
Contributor

Implementation Plan: Tomcat Port Parser CLI Tool

  • Set up basic C++ project structure
    • Create CMakeLists.txt for build configuration
    • Create .gitignore for C++ project
    • Create src directory structure
  • Implement XML parsing functionality
    • Add XML parsing library (tinyxml2 - lightweight and easy to use)
    • Create XML parser module to read server.xml
  • Implement port discovery logic
    • Parse Server port attribute
    • Parse Connector port attributes
    • Parse Connector redirectPort attributes
    • Handle multiple connectors
  • Create CLI interface
    • Add command-line argument parsing
    • Implement file path input
    • Add output formatting
  • Create sample server.xml for testing
  • Test the implementation manually
    • Test with sample server.xml (found 5 ports: 8005, 8009, 8080, 8443 redirect)
    • Test with minimal configuration
    • Test with server-only configuration
    • Test error handling (missing file, no arguments)
  • Update README.md with usage instructions
  • Run code review and security checks
    • Code review passed with no comments
    • CodeQL security scan found 0 vulnerabilities
  • Add GitHub Actions workflows
    • CI workflow for automated builds on push/PR
    • Release workflow for automatic Linux binary publishing
    • Updated README with release documentation
  • Add automatic server.xml discovery features
    • Search current directory for server.xml or conf/server.xml when no args provided
    • Recursive directory walking to find all server.xml files
    • Multi-file processing with summary output
    • Updated usage documentation and examples
    • Address all code review feedback
  • Add configurable output modes
    • Implement --mode / -m flag for output format selection
    • List mode: Hierarchical tree with file path, server port, services and connectors
    • Simple mode: Plain minimal output with unique ports (deduplicated)
    • Table mode: Formatted table with separators between multiple files
    • Updated README with accurate examples for all modes
    • Tested all modes with single and multiple files
    • Address all code review feedback
  • Add comprehensive test suite
    • Integrated Google Test framework
    • Created 11 unit tests covering parsing and edge cases
    • Created 14 integration tests covering end-to-end scenarios
    • Refactored code into testable library (tomport_core)
    • Updated CI workflow to run tests automatically
    • All 25 tests passing
    • Added tests README with documentation
    • Address code review feedback:
      • Removed unnecessary tinyxml2 include from header
      • Removed using namespace declarations from source files
      • Use explicit namespace qualification

Test Results

✅ All 25 tests passing (11 unit tests + 14 integration tests)

Security Summary

No security vulnerabilities. The code properly handles:

  • File path input validation
  • XML parsing errors
  • Memory management through C++ RAII principles
  • No buffer overflows or injection vulnerabilities
  • Depth limits with bounds checking (max 100 levels)
  • Safe directory traversal without following symlinks (default behavior)
  • Permission-denied errors handled gracefully
  • Integer overflow/underflow protection
Original prompt

A small cli tool written in cpp to do:
Parses Apache Tomcat server.xml configuration files.
Discovers all configured ports (server ports, connector ports, redirect ports).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 9, 2025 14:27
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CLI tool to parse Apache Tomcat server.xml Implement C++ CLI tool for parsing Tomcat server.xml port configurations Dec 9, 2025
Copilot AI requested a review from JonasGao December 9, 2025 14:31
@JonasGao

Copy link
Copy Markdown
Collaborator

@copilot add workflow automatic build and publish linux release

Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>

Copilot AI commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

@copilot add workflow automatic build and publish linux release

Added GitHub Actions workflows in commit 28715b4:

CI Workflow (.github/workflows/ci.yml):

  • Runs on every push/PR to main/master
  • Builds and tests the project automatically

Release Workflow (.github/workflows/release.yml):

  • Triggers on version tags (e.g., v1.0.0) or manual dispatch
  • Builds Linux x64 binary
  • Packages it with README and sample config
  • Creates GitHub release with tomport-linux-x64.tar.gz

To create a release, simply tag and push:

git tag v1.0.0
git push origin v1.0.0

The workflow will automatically build and publish the Linux release.

@JonasGao

Copy link
Copy Markdown
Collaborator

@copilot support Automatically finds and parses server.xml:
Looks for server.xml or conf/server.xml in the current working directory.
Or walks a given directory (recursive) to locate all server.xml files.

Copilot AI and others added 4 commits December 10, 2025 07:43
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
…ages

Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>

Copilot AI commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

@copilot support Automatically finds and parses server.xml:
Looks for server.xml or conf/server.xml in the current working directory.
Or walks a given directory (recursive) to locate all server.xml fi...

Implemented automatic server.xml discovery in commit ad2d5ec:

Automatic Discovery:

  • Run without arguments to search current directory for server.xml or conf/server.xml
  • Provide directory path to recursively find all server.xml files

Examples:

# Auto-find in current directory
./tomport

# Recursive search in directory
./tomport /opt/tomcat-instances

# Still works with specific file
./tomport /path/to/server.xml

Features:

  • Multi-file processing with summary reports
  • Depth limits (max 100 levels) to prevent excessive recursion
  • Safe traversal without following symlinks
  • Helpful error messages when files not found

Copilot AI changed the title Implement C++ CLI tool for parsing Tomcat server.xml port configurations Implement C++ CLI tool for parsing Tomcat server.xml port configurations with automatic discovery Dec 10, 2025
@JonasGao

Copy link
Copy Markdown
Collaborator

@copilot Configurable output via the --mode / -m flag:

list (default)
Hierarchical, human‑readable tree, including:
File path
Server port
Each service and its connectors (ports and redirect ports)
simple
Plain, minimal output:
First prints the server port.
Then prints each connector’s port and redirectPort as lines of text.
table
Formatted table output with columns:
Server Port
Service Name
Connector Port
Redirect Port

Copilot AI and others added 3 commits December 10, 2025 09:53
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
…warn on multiple paths

Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>

Copilot AI commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Configurable output via the --mode / -m flag:

list (default)...

Implemented configurable output modes via --mode / -m flag in commit 8510052:

List Mode (default):

Server Port: 8005
├─ Service: Catalina
   ├─ Connector Port: 8080 (Protocol: HTTP/1.1) → Redirect: 8443
   └─ Connector Port: 8009 (Protocol: AJP/1.3) → Redirect: 8443

Simple Mode:

$ tomport -m simple server.xml
8005
8080
8443
8009
  • Server port first
  • Then unique connector and redirect ports (deduplicated)

Table Mode:

$ tomport --mode table server.xml
Server Port    Service Name        Connector Port    Redirect Port  
--------------------------------------------------------------------
8005           Catalina            8080              8443           
               Catalina            8009              8443
  • Formatted table with aligned columns
  • Dotted separators between multiple files
  • Shows all relationships clearly

Copilot AI changed the title Implement C++ CLI tool for parsing Tomcat server.xml port configurations with automatic discovery Implement C++ CLI tool for parsing Tomcat server.xml with configurable output modes Dec 10, 2025
@JonasGao
JonasGao marked this pull request as ready for review December 11, 2025 03:18

@JonasGao JonasGao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit test and integration test

Copilot AI and others added 2 commits January 7, 2026 13:40
Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
…eclarations

Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>

Copilot AI commented Jan 7, 2026

Copy link
Copy Markdown
Contributor Author

Add unit test and integration test

Added comprehensive test suite in commits 0ded155 and 5db8408:

Test Framework:

  • Integrated Google Test (automatically downloaded via CMake)
  • 25 tests total (11 unit + 14 integration)
  • All tests passing ✅

Unit Tests:

  • XML parsing with various configurations
  • Edge cases (missing ports, invalid XML, non-existent files)
  • Data structure operations

Integration Tests:

  • Automatic file discovery (current dir, conf/server.xml)
  • Recursive directory search
  • Complex real-world configurations
  • Multi-file processing

CI Integration:

  • Updated CI workflow to run tests automatically
  • Tests run on every push/PR

Running tests:

cd build
ctest --output-on-failure

See tests/README.md for detailed documentation.

Co-authored-by: JonasGao <4549584+JonasGao@users.noreply.github.com>
@JonasGao
JonasGao merged commit dd760eb into main Jan 7, 2026
1 check passed
@JonasGao
JonasGao deleted the copilot/add-tomcat-parser-cli-tool branch January 7, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants