build: 템플릿 밖에서 혼자 빌드·배포되는 Gradle 루트를 만든다
옮겨 온 메시징 19개 모듈은 템플릿의 src/settings.gradle·build-logic· 카탈로그·registry에 기대고 있어 이 repo만으로는 빌드되지 않는다. repo 루트를 Gradle 루트로 하는 단독 빌드를 만든다. - build-logic/: grpc-library main 2e880c7의 줄인 사본(템플릿 22df3525에서 복사, 템플릿 2959eff0까지의 변경도 같은 내용)에서 gRPC BOM 규칙(ca.grpc-platform-module)만 뺐다. 배포 플러그인 ca.library-publishing과 서명 키 해석(SigningKeys)은 그대로다. 출처·뺀 것·고친 것은 build-logic/UPSTREAM.md. - settings.gradle·build.gradle·gradle.properties: group dev.cakit.messaging, 단계 태스크 ci·mainCheck·releaseCheck와 배포(release·releaseRehearsal·verifySigningKey)는 grpc-library와 같은 모양이다. 메시징만 다른 점: Buf가 없고, 성능 lane이 없고, mainCheck와 releaseCheck가 브로커 인증 증거 게이트 (verifyMessagingCertificationEvidence)를 부른다. 템플릿은 이 게이트를 따로 messaging-certification.yml로 돌렸다. 그 workflow는 지운다. - config/: registry 19행(source_path만 messaging/<leaf>로), 메시징 클래스만 남긴 SpotBugs 제외 목록, 이미지 셋(postgres-16, kafka, toxiproxy, 모두 digest 고정), checkstyle 사본. - gradle/libs.versions.toml: 메시징이 쓰는 항목만(avro, cloudevents, protobuf 4.33.2, toxiproxy, jmh)과 kafka-clients가 끌고 오는 취약 버전을 덮는 pinned-lz4-java·pinned-snappy-java. - 저장소 계약 테스트: MessagingPublicSurfaceContractTest(템플릿 app-bootstrap에서 이력째 옮김)와 새 MessagingSettingsOwnerContractTest (app.messaging 주인은 starter 하나)를 messaging-testkit의 repositoryContractTest lane에 둔다. check에 들어가 PR 단계에서 돈다. - messaging-kafka: 인증 manifest 경로를 새 배치로 고친다. 버린 대안: 계약 테스트를 build-logic 테스트로 두는 안. 빌드 플러그인 시험과 모듈 계약이 섞이고, 소스·build.gradle을 입력으로 선언하는 기존 lane 장치를 쓸 수 없다. 위험: 이 커밋 단독으로는 lockfile을 다시 쓰지 않았다(뒤 커밋에서 desktop에서 쓴다). 패키지는 아직 dev.caskeleton.messaging이다. 검증: desktop ./gradlew projects rc=0(19개 모듈 포함). Refs: design-docs repo-structure/05-library-repos.md 4·10.3·13.1절
This commit is contained in:
@@ -0,0 +1,307 @@
|
||||
package dev.caskeleton.buildlogic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.json.JsonMapper;
|
||||
|
||||
/** Typed representation of config/architecture/modules.json. */
|
||||
public record ModuleRegistry(List<Module> modules, File source) {
|
||||
private static final ObjectMapper JSON = JsonMapper.builder().build();
|
||||
private static final Set<String> REQUIRED_MODULE_FIELDS =
|
||||
Set.of("id", "gradle_path", "source_path", "allowed_dependencies");
|
||||
private static final Set<String> REQUIRED_ROOT_FIELDS = Set.of("modules");
|
||||
|
||||
public ModuleRegistry {
|
||||
modules = List.copyOf(modules);
|
||||
Objects.requireNonNull(source, "source");
|
||||
}
|
||||
|
||||
public record Module(
|
||||
String id,
|
||||
String gradlePath,
|
||||
String sourcePath,
|
||||
File sourceDirectory,
|
||||
String buildName,
|
||||
List<String> allowedDependencies) {
|
||||
public Module {
|
||||
Objects.requireNonNull(id, "id");
|
||||
Objects.requireNonNull(gradlePath, "gradlePath");
|
||||
Objects.requireNonNull(sourcePath, "sourcePath");
|
||||
Objects.requireNonNull(sourceDirectory, "sourceDirectory");
|
||||
Objects.requireNonNull(buildName, "buildName");
|
||||
allowedDependencies = List.copyOf(allowedDependencies);
|
||||
}
|
||||
}
|
||||
|
||||
public static ModuleRegistry read(File registryFile, File repositoryRoot) {
|
||||
if (!registryFile.isFile()) {
|
||||
throw new IllegalStateException("Missing module registry: " + registryFile);
|
||||
}
|
||||
JsonNode root;
|
||||
try {
|
||||
root = JSON.readTree(Files.readString(registryFile.toPath(), StandardCharsets.UTF_8));
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("failed to read " + registryFile, exception);
|
||||
}
|
||||
if (root == null || !root.isObject()) {
|
||||
throw new IllegalStateException("Module registry root must be a JSON object: " + registryFile);
|
||||
}
|
||||
Set<String> rootKeys = keys(root);
|
||||
Set<String> missingRootFields = new TreeSet<>(REQUIRED_ROOT_FIELDS);
|
||||
missingRootFields.removeAll(rootKeys);
|
||||
if (!missingRootFields.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry root is missing " + missingRootFields + ": " + registryFile);
|
||||
}
|
||||
|
||||
JsonNode modulesNode = root.get("modules");
|
||||
if (modulesNode == null || !modulesNode.isArray() || modulesNode.isEmpty()) {
|
||||
throw new IllegalStateException("Module registry has no modules: " + registryFile);
|
||||
}
|
||||
|
||||
File canonicalRoot;
|
||||
try {
|
||||
canonicalRoot = repositoryRoot.getCanonicalFile();
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("failed to canonicalize " + repositoryRoot, exception);
|
||||
}
|
||||
String rootPrefix = canonicalRoot.getPath() + File.separator;
|
||||
Set<String> ids = new LinkedHashSet<>();
|
||||
Set<String> gradlePaths = new LinkedHashSet<>();
|
||||
Set<String> sourceDirectories = new LinkedHashSet<>();
|
||||
List<Module> modules = new ArrayList<>();
|
||||
|
||||
for (int index = 0; index < modulesNode.size(); index++) {
|
||||
JsonNode module = modulesNode.get(index);
|
||||
if (module == null || !module.isObject()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry " + index + " must be a JSON object.");
|
||||
}
|
||||
Set<String> missingFields = new TreeSet<>(REQUIRED_MODULE_FIELDS);
|
||||
missingFields.removeAll(keys(module));
|
||||
if (!missingFields.isEmpty()) {
|
||||
JsonNode rawId = module.get("id");
|
||||
String named =
|
||||
rawId != null && rawId.isString() && !rawId.asText().isBlank()
|
||||
? "'" + rawId.asText() + "'"
|
||||
: "at index " + index;
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry " + named + " is missing " + missingFields);
|
||||
}
|
||||
|
||||
String id = requireNonBlankText(module, "id", index);
|
||||
String gradlePath = requireNonBlankText(module, "gradle_path", index);
|
||||
String sourcePath = requireNonBlankText(module, "source_path", index);
|
||||
// Every module belongs to the one build. A row naming any other build (a typo included) would
|
||||
// be included by no settings and checked by no direction gate while ci stays green, so the
|
||||
// field is refused rather than read (the template's optional build, which used it, is gone).
|
||||
if (module.has("build")) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' has a 'build' field; every module belongs to the main build, so remove it.");
|
||||
}
|
||||
String buildName = "main";
|
||||
List<String> allowedDependencies =
|
||||
requireStringList(module.get("allowed_dependencies"), id, "allowed_dependencies");
|
||||
|
||||
if (new HashSet<>(allowedDependencies).size() != allowedDependencies.size()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '" + id + "' contains duplicate allowed dependencies.");
|
||||
}
|
||||
if (!ids.add(id)) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry contains duplicate module id '" + id + "'.");
|
||||
}
|
||||
if (!gradlePath.startsWith(":")) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' has Gradle path '"
|
||||
+ gradlePath
|
||||
+ "' that does not start with ':'.");
|
||||
}
|
||||
if (!gradlePaths.add(gradlePath)) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry contains duplicate Gradle path '" + gradlePath + "'.");
|
||||
}
|
||||
if (new File(sourcePath).isAbsolute()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' source path must be repository-root-relative: '"
|
||||
+ sourcePath
|
||||
+ "'.");
|
||||
}
|
||||
|
||||
File sourceDirectory;
|
||||
try {
|
||||
sourceDirectory = new File(canonicalRoot, sourcePath).getCanonicalFile();
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("failed to canonicalize " + sourcePath, exception);
|
||||
}
|
||||
if (!sourceDirectory.getPath().startsWith(rootPrefix)) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' source path escapes the repository root: '"
|
||||
+ sourcePath
|
||||
+ "'.");
|
||||
}
|
||||
if (!sourceDirectory.isDirectory()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' source path is not an existing directory: "
|
||||
+ sourceDirectory);
|
||||
}
|
||||
if (!sourceDirectories.add(sourceDirectory.getPath())) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' resolves to duplicate or aliased canonical source directory: "
|
||||
+ sourceDirectory);
|
||||
}
|
||||
modules.add(
|
||||
new Module(
|
||||
id,
|
||||
gradlePath,
|
||||
sourcePath,
|
||||
sourceDirectory,
|
||||
buildName,
|
||||
allowedDependencies));
|
||||
}
|
||||
|
||||
return new ModuleRegistry(modules, registryFile);
|
||||
}
|
||||
|
||||
public Module byId(String id) {
|
||||
return modules.stream().filter(module -> module.id().equals(id)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build scripts under {@code gradleRoot} that no registered module owns, relative to it.
|
||||
*
|
||||
* <p>The settings plugin includes only registered modules, so a leaf directory nobody registered
|
||||
* is not compiled, not tested and not compared by any gate, while {@code ci} stays green (review
|
||||
* 2026-11-01 08-05). The walk skips the root's own script, every directory with its own settings
|
||||
* script (a separate build, such as build-logic or optional-platforms), build output, and the
|
||||
* inside of a module's {@code src} tree, where a build script is a test fixture.
|
||||
*/
|
||||
public List<String> unregisteredBuildScripts(File gradleRoot) {
|
||||
Path root = canonical(gradleRoot).toPath();
|
||||
Set<Path> owned = new HashSet<>();
|
||||
for (Module module : modules) {
|
||||
owned.add(canonical(module.sourceDirectory()).toPath());
|
||||
}
|
||||
List<String> unregistered = new ArrayList<>();
|
||||
try {
|
||||
Files.walkFileTree(
|
||||
root,
|
||||
new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) {
|
||||
String name = directory.getFileName().toString();
|
||||
boolean otherBuild =
|
||||
!directory.equals(root)
|
||||
&& (Files.isRegularFile(directory.resolve("settings.gradle"))
|
||||
|| Files.isRegularFile(directory.resolve("settings.gradle.kts")));
|
||||
boolean moduleSources =
|
||||
name.equals("src") && owned.contains(directory.getParent());
|
||||
if (otherBuild
|
||||
|| moduleSources
|
||||
|| name.equals("build")
|
||||
// IDE compiler output (Eclipse/VS Code `bin/`, git-ignored as `src/**/bin/`) copies
|
||||
// resource build scripts such as grpc-codegen's consumer fixtures; it is not source.
|
||||
|| name.equals("bin")
|
||||
|| name.startsWith(".")) {
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
}
|
||||
if (!directory.equals(root)
|
||||
&& !owned.contains(directory)
|
||||
&& (Files.isRegularFile(directory.resolve("build.gradle"))
|
||||
|| Files.isRegularFile(directory.resolve("build.gradle.kts")))) {
|
||||
String script =
|
||||
Files.isRegularFile(directory.resolve("build.gradle"))
|
||||
? "build.gradle"
|
||||
: "build.gradle.kts";
|
||||
unregistered.add(
|
||||
root.relativize(directory.resolve(script)).toString().replace(File.separatorChar, '/'));
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("failed to walk " + root, exception);
|
||||
}
|
||||
unregistered.sort(null);
|
||||
return List.copyOf(unregistered);
|
||||
}
|
||||
|
||||
private static File canonical(File file) {
|
||||
try {
|
||||
return file.getCanonicalFile();
|
||||
} catch (IOException exception) {
|
||||
throw new UncheckedIOException("failed to canonicalize " + file, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Module> modulesForBuild(String buildName) {
|
||||
return modules.stream().filter(module -> module.buildName().equals(buildName)).toList();
|
||||
}
|
||||
|
||||
private static Set<String> keys(JsonNode node) {
|
||||
Set<String> result = new LinkedHashSet<>();
|
||||
node.properties().forEach(entry -> result.add(entry.getKey()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String requireNonBlankText(JsonNode node, String field, Object entry) {
|
||||
JsonNode value = node.get(field);
|
||||
if (value == null || !value.isString() || value.asText().isBlank()) {
|
||||
String prefix = entry instanceof Integer ? "entry " + entry : "entry '" + entry + "'";
|
||||
throw new IllegalStateException(
|
||||
"Module registry " + prefix + " needs a nonblank string '" + field + "'.");
|
||||
}
|
||||
return value.asText();
|
||||
}
|
||||
|
||||
private static List<String> requireStringList(JsonNode raw, String id, String field) {
|
||||
if (raw == null || !raw.isArray()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '" + id + "' needs a '" + field + "' list.");
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
for (int index = 0; index < raw.size(); index++) {
|
||||
JsonNode value = raw.get(index);
|
||||
if (value == null || !value.isString() || value.asText().isBlank()) {
|
||||
throw new IllegalStateException(
|
||||
"Module registry entry '"
|
||||
+ id
|
||||
+ "' has a non-string or blank "
|
||||
+ field
|
||||
+ " entry at index "
|
||||
+ index
|
||||
+ ".");
|
||||
}
|
||||
result.add(value.asText());
|
||||
}
|
||||
return List.copyOf(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user