Skip to content

Commit 074f67e

Browse files
committed
Merge master into release dependency upgrades
Resolve CI and Maven repository restoration conflicts, preserving release dispatch correlation and candidate validation. Ensure the source release check also validates the Maven wrapper.
2 parents 8c866da + 23dc1bd commit 074f67e

364 files changed

Lines changed: 31851 additions & 910 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.

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
<!-- Describe your PR here; e.g. Fixes #issueNo -->
22

3+
## Problem and change
4+
5+
<!-- Explain the trigger and resulting behavior, material choices, compatibility
6+
and limitations. Link issues and any required unmerged PRs. Keep small
7+
changes brief. Use Fixes only when the issue is fully resolved. -->
8+
9+
## IssueSpec
10+
11+
<!-- Choose full or lightweight. Keep the metadata below as plain lines.
12+
See issue-spec/project/workflow.md for examples and maintainer classification.
13+
For lightweight, remove Proposal/Design/Implement/Specs/Tasks.
14+
For full, replace every reference and ID with the actual selected artifacts. -->
15+
IssueSpec-Mode: full | lightweight
16+
IssueSpec-Reason: describe the scope and why this mode applies
17+
IssueSpec-Proposal: #NUMBER
18+
IssueSpec-Design: #NUMBER
19+
IssueSpec-Implement: #NUMBER
20+
IssueSpec-Specs: SPEC-ID
21+
IssueSpec-Tasks: TASK-ID
22+
IssueSpec-Validation: describe checks, results and important checks not run
23+
324
<!--
425
Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
526
-->
627
Make sure that:
728

829
- [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
930
- [ ] You submit test cases (unit or integration tests) that back your changes.
31+
- [ ] New production code follows the code quality rules Q1-Q9 in `AGENTS.md` (no magic numbers, focused methods, reuse of existing utilities).
1032
- [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.

‎.github/copilot-instructions.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Prefer immutable data, explicit generics, and existing project utilities. Do not use raw types, unchecked casts, or swallowed exceptions to bypass type safety or error handling.
2626
- Catch only specific exceptions that can be handled. Include enough context in error logs to diagnose problems, but never log passwords, tokens, keys, or complete sensitive request data.
2727
- Keep methods focused, and avoid deep nesting and duplicated logic. Do not introduce abstractions that duplicate existing architecture for a local requirement.
28+
- Follow the code quality rules Q1-Q9 in `AGENTS.md` for new production code: no magic numbers or repeated string literals, small methods, shallow control flow, at most 5 parameters, TODOs with an issue reference, reuse of existing utilities and no dead code. The `new-code-quality` workflow reports Q1-Q6 on added lines.
2829
- Do not introduce blocking calls into reactive request chains. Avoid unnecessary `block()`, blocking I/O, or expensive work on event-loop threads. When blocking work is unavoidable, use the project's established scheduling and isolation patterns.
2930
- Comments should explain design rationale, boundary conditions, or protocol details rather than restating the code. Use English Javadoc for public APIs and complex extension points, consistent with adjacent code. Do not add `@author` tags.
3031
- Every new Java file must include the Apache License 2.0 header. Other checked files must follow the repository's existing license-header format.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
applyTo: "**/src/main/java/**/*.java"
3+
excludeAgent: "coding-agent"
4+
---
5+
6+
# Java code review rules for Apache ShenYu
7+
8+
Review only lines changed by the pull request. Rule IDs Q1-Q9 are defined in `AGENTS.md`.
9+
10+
## Do not repeat CI
11+
12+
Checkstyle (`script/shenyu_checkstyle.xml`) enforces formatting, imports, Javadoc, final parameters and license headers. The `new-code-quality` job reports Q1-Q6 on added lines. Do not comment on findings those tools already report.
13+
14+
## Check what tools miss
15+
16+
- Q1: named constants without meaning or unit (`NUM`, `VALUE_3`); numbers inside strings or durations (`"3000"`, `Duration.ofMillis(3000)`); a new constant that duplicates an existing one in `Constants` or the module.
17+
- Q7: re-implemented helpers that already exist (`GsonUtils`, `JsonUtils`, `UriUtils`, `MapUtils`, `ListUtil`, plugin base classes, SPI loaders).
18+
- Q8: commented-out code, unused members or parameters, speculative options or extension points.
19+
- Q9: names that hide intent, methods doing several things, comments restating code.
20+
- Reactive code: blocking calls on event-loop threads, `DataBuffer` not released, errors swallowed, subscriptions not cancelled with the request.
21+
- Compatibility: changed public SPI, plugin names, configuration keys or defaults without a stated reason.
22+
- Secrets: credentials or tokens in logs or exceptions.
23+
24+
## Comment format
25+
26+
- One finding per comment, on the relevant line.
27+
- Start with a severity and rule, for example `[blocking][Q7]` or `[suggestion][Q1]`. Use `blocking` only for correctness, compatibility, security or resource leaks.
28+
- State the problem, why it matters here, and a concrete fix.
29+
- Say "verified" when you traced the code, otherwise "suspected".
30+
- At most 10 comments. No praise, no summary of the change.
31+
32+
## Guarded files
33+
34+
If the pull request changes `AGENTS.md`, `.github/copilot-instructions.md`, `.github/instructions/**`, `script/shenyu_checkstyle*.xml` or `.github/scripts/check-new-code-quality.py`, point it out explicitly: these define the rules for authors and reviewers.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/usr/bin/env python3
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
"""Report stricter Checkstyle findings only on lines added by the current change.
18+
19+
The build-wide rules in script/shenyu_checkstyle.xml apply to the whole tree. The
20+
rules in script/shenyu_checkstyle_new_code.xml (magic numbers, complexity, ...)
21+
would flag a large amount of existing code, so this script runs them on the
22+
changed production sources and keeps only the findings on added lines.
23+
24+
Method-level checks (length, complexity, parameters) are reported by Checkstyle on
25+
the method declaration line, so they apply to new methods and to methods whose
26+
declaration line changed.
27+
"""
28+
29+
import argparse
30+
import os
31+
import re
32+
import subprocess
33+
import sys
34+
import xml.etree.ElementTree as ElementTree
35+
from pathlib import Path
36+
from typing import Dict, Iterable, List, NamedTuple, Optional, Set
37+
38+
ROOT = Path(__file__).resolve().parents[2]
39+
DEFAULT_CONFIG = ROOT / "script" / "shenyu_checkstyle_new_code.xml"
40+
HUNK_HEADER = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
41+
# Mirror the excludes of the build-wide maven-checkstyle-plugin configuration.
42+
EXCLUDED_SEGMENTS = ("/transfer/", "/generated")
43+
FILE_BATCH_SIZE = 200
44+
45+
46+
class Violation(NamedTuple):
47+
path: str
48+
line: int
49+
column: int
50+
rule: str
51+
message: str
52+
53+
54+
def is_candidate(path: str) -> bool:
55+
"""Return whether a changed file is a production Java source checked by this gate."""
56+
normalized = "/" + path.replace(os.sep, "/")
57+
return (normalized.endswith(".java")
58+
and "/src/main/java/" in normalized
59+
and not any(segment in normalized for segment in EXCLUDED_SEGMENTS))
60+
61+
62+
def parse_added_lines(diff_text: str) -> Dict[str, Set[int]]:
63+
"""Map each file of a zero-context unified diff to the line numbers it adds."""
64+
added: Dict[str, Set[int]] = {}
65+
current: Optional[Set[int]] = None
66+
for line in diff_text.splitlines():
67+
if line.startswith("+++ "):
68+
target = line[4:]
69+
if target == "/dev/null":
70+
current = None
71+
continue
72+
target = target[2:] if target.startswith("b/") else target
73+
current = added.setdefault(target, set())
74+
continue
75+
match = HUNK_HEADER.match(line)
76+
if match and current is not None:
77+
start = int(match.group(1))
78+
count = 1 if match.group(2) is None else int(match.group(2))
79+
current.update(range(start, start + count))
80+
return {path: lines for path, lines in added.items() if lines}
81+
82+
83+
def parse_report(report_xml: str, root: Path) -> List[Violation]:
84+
"""Read a Checkstyle XML report into violations with repository-relative paths."""
85+
violations = []
86+
for file_element in ElementTree.fromstring(report_xml).iter("file"):
87+
name = Path(file_element.get("name", ""))
88+
try:
89+
relative = name.resolve().relative_to(root.resolve()).as_posix()
90+
except ValueError:
91+
relative = name.as_posix()
92+
for error in file_element.iter("error"):
93+
violations.append(Violation(relative, int(error.get("line", "0")), int(error.get("column", "0")),
94+
error.get("source", ""), error.get("message", "")))
95+
return violations
96+
97+
98+
def filter_added(violations: Iterable[Violation], added: Dict[str, Set[int]]) -> List[Violation]:
99+
"""Keep the violations located on added lines, in a stable order."""
100+
kept = [violation for violation in violations if violation.line in added.get(violation.path, set())]
101+
return sorted(kept, key=lambda violation: (violation.path, violation.line, violation.column, violation.rule))
102+
103+
104+
def escape_data(value: str) -> str:
105+
return value.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
106+
107+
108+
def escape_property(value: str) -> str:
109+
return escape_data(value).replace(":", "%3A").replace(",", "%2C")
110+
111+
112+
def annotation(violation: Violation, level: str) -> str:
113+
"""Format a GitHub Actions workflow command for one violation."""
114+
properties = "file={},line={},col={},title={}".format(
115+
escape_property(violation.path), violation.line, violation.column,
116+
escape_property("New code quality " + (violation.rule or "rule")))
117+
return "::{} {}::{}".format(level, properties, escape_data(violation.message))
118+
119+
120+
def git(*args: str) -> str:
121+
return subprocess.run(["git", *args], cwd=ROOT, check=True, capture_output=True, text=True).stdout
122+
123+
124+
def changed_candidates(merge_base: str) -> List[str]:
125+
names = git("diff", "--name-only", "--diff-filter=AMR", "--no-renames", merge_base, "HEAD", "--", "*.java")
126+
return [name for name in names.splitlines() if name and is_candidate(name)]
127+
128+
129+
def run_checkstyle(java: str, jar: str, config: Path, files: List[str]) -> List[Violation]:
130+
violations: List[Violation] = []
131+
for start in range(0, len(files), FILE_BATCH_SIZE):
132+
batch = files[start:start + FILE_BATCH_SIZE]
133+
result = subprocess.run([java, "-Duser.language=en", "-Duser.country=US", "-jar", jar,
134+
"-c", str(config), "-f", "xml", *batch],
135+
cwd=ROOT, capture_output=True, text=True)
136+
try:
137+
violations.extend(parse_report(result.stdout, ROOT))
138+
except ElementTree.ParseError as error:
139+
raise RuntimeError("Checkstyle did not produce a report (exit {}): {}".format(
140+
result.returncode, result.stderr.strip() or error)) from error
141+
return violations
142+
143+
144+
def write_summary(violations: List[Violation], mode: str) -> None:
145+
summary = os.environ.get("GITHUB_STEP_SUMMARY")
146+
if not summary:
147+
return
148+
with open(summary, "a", encoding="utf-8") as output:
149+
output.write("### New code quality ({})\n\n".format(mode))
150+
if not violations:
151+
output.write("No findings on added lines.\n")
152+
return
153+
output.write("| File | Line | Rule | Message |\n|---|---|---|---|\n")
154+
for violation in violations:
155+
output.write("| `{}` | {} | {} | {} |\n".format(violation.path, violation.line, violation.rule,
156+
violation.message.replace("|", "\\|")))
157+
158+
159+
def main(argv: Optional[List[str]] = None) -> int:
160+
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
161+
parser.add_argument("--base", default="origin/master", help="base ref of the change")
162+
parser.add_argument("--checkstyle-jar", required=True, help="path to a checkstyle-<version>-all.jar")
163+
parser.add_argument("--java", default="java", help="java executable")
164+
parser.add_argument("--config", default=str(DEFAULT_CONFIG), help="Checkstyle configuration")
165+
parser.add_argument("--mode", choices=("advisory", "enforce"), default="advisory",
166+
help="advisory reports findings and exits 0; enforce exits 1 on findings")
167+
args = parser.parse_args(argv)
168+
169+
merge_base = git("merge-base", args.base, "HEAD").strip()
170+
files = changed_candidates(merge_base)
171+
if not files:
172+
print("No changed production Java sources.")
173+
write_summary([], args.mode)
174+
return 0
175+
added = parse_added_lines(git("diff", "-U0", "--no-color", "--no-ext-diff", "--no-renames",
176+
merge_base, "HEAD", "--", *files))
177+
violations = filter_added(run_checkstyle(args.java, args.checkstyle_jar, Path(args.config), files), added)
178+
179+
level = "error" if args.mode == "enforce" else "warning"
180+
for violation in violations:
181+
print(annotation(violation, level) if os.environ.get("GITHUB_ACTIONS") == "true"
182+
else "{}:{}:{}: {}".format(violation.path, violation.line, violation.column, violation.message))
183+
write_summary(violations, args.mode)
184+
print("{} finding(s) on added lines in {} changed file(s).".format(len(violations), len(files)))
185+
return 1 if violations and args.mode == "enforce" else 0
186+
187+
188+
if __name__ == "__main__":
189+
sys.exit(main())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
set -euo pipefail
19+
20+
wrapper_jar=.mvn/wrapper/maven-wrapper.jar
21+
wrapper_main=org/apache/maven/wrapper/MavenWrapperMain.class
22+
if [[ -r "$wrapper_jar" ]] && jar tf "$wrapper_jar" | grep -Fx "$wrapper_main" > /dev/null; then
23+
exit 0
24+
fi
25+
26+
wrapper_url="$(awk -F= '$1 == "wrapperUrl" { print substr($0, index($0, "=") + 1); exit }' .mvn/wrapper/maven-wrapper.properties)"
27+
if [[ -z "$wrapper_url" ]]; then
28+
echo "Could not find wrapperUrl in .mvn/wrapper/maven-wrapper.properties."
29+
exit 1
30+
fi
31+
32+
wrapper_tmp="$(mktemp .mvn/wrapper/maven-wrapper.jar.XXXXXX)"
33+
trap 'rm -f "$wrapper_tmp"' EXIT
34+
curl --fail --location --retry 5 --retry-all-errors --retry-delay 2 \
35+
--output "$wrapper_tmp" "$wrapper_url"
36+
if ! jar tf "$wrapper_tmp" | grep -Fx "$wrapper_main" > /dev/null; then
37+
echo "Downloaded Maven wrapper JAR does not contain $wrapper_main."
38+
exit 1
39+
fi
40+
mv "$wrapper_tmp" "$wrapper_jar"

0 commit comments

Comments
 (0)