Skip to content

Commit be34a11

Browse files
committed
Merge remote-tracking branch 'origin/agent-friendly' into agent-friendly-p6-fix3
2 parents 1987124 + ef6cb85 commit be34a11

4 files changed

Lines changed: 393 additions & 3 deletions

File tree

‎AGENTS.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Bugfixes and small features stop at this skill.
4747
## Releases
4848

4949
Follow the [Releasing a version](https://github.com/graphql-java-kickstart/graphql-java-tools/wiki/Releasing-a-version) wiki
50-
page. `github-build.sh` and `.github/workflows/release.yml` do the version bump, tag and publish.
50+
page. `github-build.sh` and `.github/workflows/release.yml` do the version bump, tag and publish. After an X.0.0 release,
51+
delete the `<excludes>` under japicmp-maven-plugin in `pom.xml`. The version is X.0.1-SNAPSHOT by then and the API check
52+
fails while they remain.
5153

5254
After the release is published, record what it builds, so `CompatTest` checks later changes against it. Check out the
5355
release tag in a worktree, run `mvn -B -ntp clean test -Dtest=CompatTest -Dcompat.capture`, and open a PR with the
@@ -94,7 +96,7 @@ happening. "docs only" means nothing does yet, so the rule depends on you readin
9496
| Argument conversion goes through one entry point | docs only |
9597
| An input field's Java type comes from the mapping Jackson uses, not from guessed getters | docs only |
9698
| Every recursive walk over the type graph handles cycles, and a test covers a cycle | docs only |
97-
| Public signatures stay binary compatible, data class `copy()` and `componentN` included | docs only |
99+
| Public signatures stay binary compatible, data class `copy()` and `componentN` included | japicmp with `build/japicmp-kotlin-public.groovy` at `mvn verify`, which allows excludes and other narrowing options only at an X.0.0 version |
98100
| Remove the plumbing a change leaves unused | Compiler warnings for unused locals, docs only for the rest |
99101
| A new warning or build error names the type and the item and uses `SourceLocation.describe()` for its location | docs only |
100102
| A check keyed on a class name or an exception type has a test that fails when the dependency moves it | docs only |
@@ -110,7 +112,7 @@ happening. "docs only" means nothing does yet, so the rule depends on you readin
110112
| The first commit of a fix tests the neighbouring shapes, not just the reported one | docs only |
111113
| The build passes on JDK 17, the lowest supported version | CI on JDK 17, 21 and 25 |
112114
| Run verify-tools before you push a schema-building change | docs only |
113-
| The packaged jar holds `module-info.class`, its non-static `requires` resolve from the runtime dependencies, and every class targets the pom's `java.version` | docs only |
115+
| The packaged jar holds `module-info.class`, its non-static `requires` resolve from the runtime dependencies, and every class targets the pom's `java.version` | `build/JarCheck.java` at `mvn verify` |
114116
| Compiler warnings fail the build | `-Werror` and `failOnWarning` in `pom.xml` |
115117
| Check every claim in a PR body or release note at the current head | docs only |
116118
| Keep a comment only for a non-obvious why, with no history and no issue numbers outside a TODO | docs only |

‎build/JarCheck.java‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import java.io.DataInputStream;
2+
import java.io.File;
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.lang.module.Configuration;
6+
import java.lang.module.FindException;
7+
import java.lang.module.ModuleDescriptor;
8+
import java.lang.module.ModuleFinder;
9+
import java.lang.module.ResolutionException;
10+
import java.nio.file.Path;
11+
import java.util.ArrayList;
12+
import java.util.Arrays;
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.Set;
16+
import java.util.TreeMap;
17+
import java.util.jar.JarEntry;
18+
import java.util.jar.JarFile;
19+
20+
public class JarCheck {
21+
public static void main(String[] args) throws IOException {
22+
Path jar = Path.of(args[0]);
23+
int release = Integer.parseInt(args[1]);
24+
int expectedMajor = release + 44;
25+
String runtimeClasspath = args[2];
26+
List<String> expectedClasses = Arrays.asList(args).subList(3, args.length);
27+
List<String> problems = new ArrayList<>();
28+
29+
TreeMap<Integer, List<String>> byMajor = new TreeMap<>();
30+
ModuleDescriptor descriptor = null;
31+
try (JarFile jarFile = new JarFile(jar.toFile())) {
32+
for (String expected : expectedClasses) {
33+
if (jarFile.getJarEntry(expected.replace('.', '/') + ".class") == null) {
34+
problems.add("The jar has no " + expected + ". Check <sourceDirectory> in pom.xml: Kotlin and Java sources live in src/main/kotlin.");
35+
}
36+
}
37+
for (JarEntry entry : Collections.list(jarFile.entries())) {
38+
if (!entry.getName().endsWith(".class")) continue;
39+
try (DataInputStream data = new DataInputStream(jarFile.getInputStream(entry))) {
40+
data.readInt();
41+
data.readUnsignedShort();
42+
int major = data.readUnsignedShort();
43+
byMajor.computeIfAbsent(major, k -> new ArrayList<>()).add(entry.getName());
44+
}
45+
}
46+
JarEntry moduleInfo = jarFile.getJarEntry("module-info.class");
47+
if (moduleInfo != null) {
48+
try (InputStream in = jarFile.getInputStream(moduleInfo)) {
49+
descriptor = ModuleDescriptor.read(in);
50+
}
51+
}
52+
}
53+
byMajor.forEach((major, classes) -> {
54+
if (major != expectedMajor) {
55+
problems.add(classes.size() + " classes are Java " + (major - 44) + " bytecode (major " + major + "), expected Java " + release
56+
+ " (major " + expectedMajor + "), e.g. " + classes.get(0)
57+
+ ". Set <jvmTarget>${java.version}</jvmTarget> on kotlin-maven-plugin and <release>${java.version}</release> on maven-compiler-plugin.");
58+
}
59+
});
60+
61+
if (descriptor == null) {
62+
problems.add("The jar has no module-info.class. Keep src/main/kotlin/module-info.java, which maven-compiler-plugin compiles into the jar.");
63+
} else {
64+
List<Path> modulePath = new ArrayList<>();
65+
modulePath.add(jar);
66+
for (String entry : runtimeClasspath.split(File.pathSeparator)) {
67+
if (!entry.isEmpty() && !Path.of(entry).equals(jar)) modulePath.add(Path.of(entry));
68+
}
69+
try {
70+
Configuration.resolve(ModuleFinder.of(modulePath.toArray(Path[]::new)), List.of(ModuleLayer.boot().configuration()),
71+
ModuleFinder.of(), Set.of(descriptor.name()));
72+
} catch (FindException | ResolutionException e) {
73+
problems.add("A JPMS application with only this jar's compile and runtime dependencies can't start: " + e.getMessage()
74+
+ ". A module from a provided or optional dependency must be 'requires static' in module-info.java.");
75+
}
76+
}
77+
78+
if (!problems.isEmpty()) {
79+
System.err.println("Jar check failed for " + jar.getFileName() + ":");
80+
problems.forEach(p -> System.err.println(" " + p));
81+
System.exit(1);
82+
}
83+
int classCount = byMajor.values().stream().mapToInt(List::size).sum();
84+
System.out.println("Jar check passed for " + jar.getFileName() + ": " + classCount + " classes, all major " + expectedMajor
85+
+ ", module " + descriptor.name() + " resolves against the runtime classpath.");
86+
}
87+
}

0 commit comments

Comments
 (0)