|
| 1 | +# java-code-upgrade |
| 2 | + |
| 3 | +An agent skill that helps developers upgrade Java code from older idioms to modern equivalents. Built on the comprehensive pattern database from [java.evolved](https://javaevolved.github.io/) by [Bruno Borges](https://github.com/brunoborges) ([source](https://github.com/javaevolved/javaevolved.github.io)). |
| 4 | + |
| 5 | +## What it does |
| 6 | + |
| 7 | +This skill enables AI coding agents to: |
| 8 | + |
| 9 | +- **Detect legacy Java patterns** in codebases and suggest modern replacements |
| 10 | +- **Provide before/after code examples** for 113 patterns across 11 categories |
| 11 | +- **Guide enterprise migrations** from Java EE to Jakarta EE, Spring XML to annotations |
| 12 | +- **Filter by JDK version** to only suggest patterns compatible with the project's target |
| 13 | +- **Prioritize upgrades** by difficulty (beginner, intermediate, advanced) |
| 14 | + |
| 15 | +## Coverage |
| 16 | + |
| 17 | +| Category | Patterns | Examples | |
| 18 | +|-------------|----------|---------------------------------------------------------------------------------| |
| 19 | +| Language | 24 | var, records, sealed classes, pattern matching, switch expressions, text blocks | |
| 20 | +| Enterprise | 16 | EJB to CDI, Servlet to JAX-RS, JDBC to JPA, SOAP to REST, Spring modernization | |
| 21 | +| Streams | 12 | toList(), mapMulti(), gatherers, takeWhile/dropWhile, optional improvements | |
| 22 | +| Concurrency | 11 | Virtual threads, structured concurrency, scoped values, stable values | |
| 23 | +| Collections | 11 | List.of(), Map.of(), sequenced collections, unmodifiable collectors | |
| 24 | +| I/O | 11 | HTTP client, Files API, Path.of(), transferTo, memory-mapped files | |
| 25 | +| Strings | 7 | isBlank(), strip(), repeat(), lines(), formatted() | |
| 26 | +| Errors | 7 | Helpful NPE, multi-catch, optional chaining, null-in-switch | |
| 27 | +| Tooling | 8 | JShell, single-file execution, JFR, AOT preloading | |
| 28 | +| Date/Time | 6 | java.time API, Duration/Period, HexFormat, Math.clamp | |
| 29 | +| Security | 5 | PEM encoding, KDF, strong random, TLS defaults | |
| 30 | +| **Total** | **113** | **Java 7 through Java 25** | |
| 31 | + |
| 32 | +## JDK Version Quick Reference |
| 33 | + |
| 34 | +| JDK | Key Patterns | |
| 35 | +|-----|----------------------------------------------------------------------------| |
| 36 | +| 7 | multi-catch, diamond operator | |
| 37 | +| 8 | default/static interface methods, streams, CompletableFuture, java.time | |
| 38 | +| 9 | List/Set/Map.of(), Optional improvements, private interface methods | |
| 39 | +| 10 | var, unmodifiable copy | |
| 40 | +| 11 | String.isBlank/strip/repeat/lines, HTTP client, Path.of | |
| 41 | +| 14 | switch expressions, helpful NPE | |
| 42 | +| 15 | text blocks, String.formatted | |
| 43 | +| 16 | records, Stream.toList(), mapMulti | |
| 44 | +| 17 | sealed classes, RandomGenerator | |
| 45 | +| 21 | virtual threads, pattern matching, sequenced collections | |
| 46 | +| 22 | unnamed variables, FFM API | |
| 47 | +| 24 | stream gatherers | |
| 48 | +| 25 | structured concurrency, scoped values, stable values, compact source files | |
| 49 | + |
| 50 | +## Installation |
| 51 | + |
| 52 | +### Quick Install (recommended) |
| 53 | + |
| 54 | +Install using [skills.sh](https://skills.sh/) — works with Claude Code, GitHub Copilot, Cursor, Cline, Windsurf, and 15+ other agents: |
| 55 | + |
| 56 | +```bash |
| 57 | +npx skillsadd darshitpp/java-code-upgrade |
| 58 | +``` |
| 59 | + |
| 60 | +This auto-detects the agent and installs the skill in the correct location. No manual setup needed. |
| 61 | + |
| 62 | +### Claude Code (manual) |
| 63 | + |
| 64 | +There are two installation scopes: |
| 65 | + |
| 66 | +**Global (available in all projects):** |
| 67 | + |
| 68 | +```bash |
| 69 | +git clone https://github.com/darshitpp/java-code-upgrade.git ~/.claude/skills/java-code-upgrade |
| 70 | +``` |
| 71 | + |
| 72 | +**Per-project (available only in that project):** |
| 73 | + |
| 74 | +```bash |
| 75 | +cd /path/to/your/project |
| 76 | +mkdir -p .claude/skills |
| 77 | +git clone https://github.com/darshitpp/java-code-upgrade.git .claude/skills/java-code-upgrade |
| 78 | +``` |
| 79 | + |
| 80 | +After installation, the skill appears automatically in Claude Code's available skills list. It triggers when asking to modernize Java code, review for outdated patterns, or upgrade JDK idioms. It can also be invoked explicitly with `/java-code-upgrade`. |
| 81 | + |
| 82 | +To update the skill later: |
| 83 | + |
| 84 | +```bash |
| 85 | +cd ~/.claude/skills/java-code-upgrade # or .claude/skills/java-code-upgrade |
| 86 | +git pull |
| 87 | +``` |
| 88 | + |
| 89 | +### Other Agent Frameworks |
| 90 | + |
| 91 | +This skill follows the [agentskills.io](https://agentskills.io) specification: |
| 92 | + |
| 93 | +- `SKILL.md` — core agent instructions (entry point) |
| 94 | +- `references/` — pattern database loaded on demand via progressive disclosure |
| 95 | +- `scripts/find-pattern.py` — CLI tool for programmatic pattern search |
| 96 | +- `assets/` — output templates |
| 97 | + |
| 98 | +Clone the repo and point the agent framework at `SKILL.md` as the skill entry point. |
| 99 | + |
| 100 | +## Directory Structure |
| 101 | + |
| 102 | +``` |
| 103 | +java-code-upgrade/ |
| 104 | + SKILL.md # Core skill instructions |
| 105 | + scripts/ |
| 106 | + find-pattern.py # CLI tool for searching patterns |
| 107 | + generate-references.py # Regenerates references from upstream YAML |
| 108 | + sync-from-source.sh # Pulls upstream and regenerates |
| 109 | + references/ |
| 110 | + detection-patterns.md # Code signatures for detecting legacy patterns |
| 111 | + pattern-index.md # Quick lookup table of all 113 patterns |
| 112 | + language.md # Language feature patterns (23) |
| 113 | + collections.md # Collection patterns (11) |
| 114 | + strings.md # String patterns (7) |
| 115 | + streams.md # Stream patterns (12) |
| 116 | + concurrency.md # Concurrency patterns (11) |
| 117 | + io.md # I/O patterns (11) |
| 118 | + errors.md # Error handling patterns (7) |
| 119 | + datetime.md # Date/time patterns (6) |
| 120 | + security.md # Security patterns (5) |
| 121 | + tooling.md # Tooling patterns (8) |
| 122 | + enterprise.md # Enterprise migration patterns (16) |
| 123 | + assets/ |
| 124 | + upgrade-report-template.md # Template for upgrade reports |
| 125 | +``` |
| 126 | + |
| 127 | +## Usage Examples |
| 128 | + |
| 129 | +### Search patterns by category |
| 130 | +```bash |
| 131 | +python3 scripts/find-pattern.py --category concurrency --format brief |
| 132 | +``` |
| 133 | + |
| 134 | +### Find patterns for a specific JDK version |
| 135 | +```bash |
| 136 | +python3 scripts/find-pattern.py --min-jdk 17 --max-jdk 21 --format brief |
| 137 | +``` |
| 138 | + |
| 139 | +### Search by keyword |
| 140 | +```bash |
| 141 | +python3 scripts/find-pattern.py --keyword "virtual thread" --format full |
| 142 | +``` |
| 143 | + |
| 144 | +### Detect patterns in code |
| 145 | +```bash |
| 146 | +python3 scripts/find-pattern.py --detect 'Collections.unmodifiableList(Arrays.asList("a"))' --format brief |
| 147 | +``` |
| 148 | + |
| 149 | +## Keeping Up to Date |
| 150 | + |
| 151 | +All files in `references/` are auto-generated from upstream YAML data. No manual editing needed. |
| 152 | + |
| 153 | +The reference files can be automatically synced from the upstream [javaevolved](https://github.com/javaevolved/javaevolved.github.io) repository. |
| 154 | + |
| 155 | +### Manual sync |
| 156 | +```bash |
| 157 | +./scripts/sync-from-source.sh |
| 158 | +``` |
| 159 | + |
| 160 | +### GitHub Actions (automated) |
| 161 | + |
| 162 | +The included `.github/workflows/sync-upstream.yml` runs weekly and opens a pull request if patterns changed. |
| 163 | + |
| 164 | +**Setup:** |
| 165 | +1. No extra tokens needed — the default `GITHUB_TOKEN` handles everything. |
| 166 | +2. The schedule runs weekly on Monday at 06:00 UTC. Adjust the cron in the workflow file if needed. |
| 167 | +3. Trigger manually anytime from **Actions > Sync from upstream java.evolved > Run workflow**. |
| 168 | + |
| 169 | +### GitLab CI (automated) |
| 170 | + |
| 171 | +The included `.gitlab-ci.yml` defines a `sync-upstream` job with the same behavior, opening a merge request on changes. |
| 172 | + |
| 173 | +**Setup:** |
| 174 | +1. Go to **Settings > CI/CD > Variables** and add `GITLAB_TOKEN` — a project access token with `write_repository` and `api` scopes. |
| 175 | +2. Go to **CI/CD > Schedules** and create a new schedule with cron `0 6 * * 1` (weekly Monday 06:00 UTC) or any frequency you prefer. |
| 176 | +3. Trigger manually anytime from **CI/CD > Pipelines > Run pipeline**. |
| 177 | + |
| 178 | +Both CI options create a PR/MR for review rather than pushing directly, so you can inspect changes before merging. |
| 179 | + |
| 180 | +## Credits & Data Source |
| 181 | + |
| 182 | +All pattern data is sourced from the **[java.evolved](https://javaevolved.github.io/)** project, created by [Bruno Borges](https://github.com/brunoborges). The original YAML content files have been consolidated into markdown reference files for efficient agent consumption with progressive disclosure. |
| 183 | + |
| 184 | +- **Source repository:** [javaevolved/javaevolved.github.io](https://github.com/javaevolved/javaevolved.github.io) |
| 185 | +- **Original license:** [MIT License](https://github.com/javaevolved/javaevolved.github.io/blob/main/LICENSE) - Copyright (c) 2026 Bruno Borges |
| 186 | + |
| 187 | +## License |
| 188 | + |
| 189 | +MIT — same as the upstream source data. |
| 190 | + |
| 191 | +``` |
| 192 | +MIT License |
| 193 | +
|
| 194 | +Copyright (c) 2026 Bruno Borges |
| 195 | +
|
| 196 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 197 | +of this software and associated documentation files (the "Software"), to deal |
| 198 | +in the Software without restriction, including without limitation the rights |
| 199 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 200 | +copies of the Software, and to permit persons to whom the Software is |
| 201 | +furnished to do so, subject to the following conditions: |
| 202 | +
|
| 203 | +The above copyright notice and this permission notice shall be included in all |
| 204 | +copies or substantial portions of the Software. |
| 205 | +
|
| 206 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 207 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 208 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 209 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 210 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 211 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 212 | +SOFTWARE. |
| 213 | +``` |
0 commit comments