desruisseaux commented on code in PR #1162: URL: https://github.com/apache/maven-compiler-plugin/pull/1162#discussion_r4732378146
########## src/main/java/org/apache/maven/plugin/compiler/incremental/IncrementalState.java: ########## @@ -0,0 +1,428 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugin.compiler.incremental; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.OptionalLong; +import java.util.Set; +import java.util.TreeSet; + +/** + * Persistent state for incremental compilation, storing per-source-file content + * hashes and per-type metadata. + * + * <p>{@link GraphTypeInfo} stores class-level dependency references (all types + * referenced in the classfile constant pool). All consumers are stored in a + * single index (no signature/implementation distinction). + * + * <p>Serialized as a compact binary format via {@link DataOutputStream} and stored alongside + * the class output as {@code .incremental-state}. + * + * @see GraphIncrementalBuild + */ +public class IncrementalState { + + private static final int VERSION = 1; + + private final Map<String, String> sourceHashes = new LinkedHashMap<>(); + private final Map<String, Long> sourceMtimes = new LinkedHashMap<>(); + private final Map<String, TypeInfo> types = new LinkedHashMap<>(); + private final Map<String, String> classpathIdentities = new LinkedHashMap<>(); + private final Map<String, Set<String>> consumersIndex = new LinkedHashMap<>(); + + private final Map<String, Set<String>> sourceToTypesIndex = new LinkedHashMap<>(); + private String configHash = ""; + + // ----------------------------------------------------------------------- + // TypeInfo + // ----------------------------------------------------------------------- + + /** + * Per-type metadata stored by the incremental engine. + */ + public sealed interface TypeInfo permits GraphTypeInfo { Review Comment: There is no reason to create a sealed interface here which will be implemented only by the `GraphTypeInfo` record. It is actually error prone because `IncrementalState` casts this interface to `(GraphTypeInfo)` at line 347, which would cause a `ClassCastException` if any other implementations were allowed. This interface is not protecting users from API evolution because this package is not public API. By the way (as an additional comment to the interface being counter-productive), to enforce the last sentence above, the `public` keyword should be removed everywhere except in the `GraphIncrementalBuild` class. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
