ChangeSetVerifyMojo.java

/*
 * Copyright © 2026 IKE Network (support@ike.network)
 *
 * Licensed 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 network.ike.plugin;

import network.ike.knowledge.spi.ChangeSetVerifier;
import org.apache.maven.api.Project;
import org.apache.maven.api.Session;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;

import java.util.List;

/**
 * {@code ike:changeset-verify} — check a change set against its format, and fail the build on any error: the manifest, the component table, every entry's count and SHA-256, the ids and references of every record.
 * The work is done by the {@link ChangeSetVerifier} on the project's runtime classpath,
 * in a forked JVM by default; no store is opened.
 */
@Mojo(name = IkeGoal.NAME_CHANGESET_VERIFY)
public class ChangeSetVerifyMojo implements org.apache.maven.api.plugin.Mojo {

    /** Instantiated by Maven. */
    public ChangeSetVerifyMojo() {
    }

    @Inject
    private org.apache.maven.api.plugin.Log log;

    @Inject
    private Session session;

    @Inject
    private Project project;

    /** The change set zip to read. */
    @Parameter(property = "ike.changeset.file", required = true)
    String file;

    @Parameter(property = "ike.changeset.target")
    String target;

    /** The implementation's simple class name, when several are on the classpath. */
    @Parameter(property = "ike.changeset.implementation")
    String implementation;

    @Parameter(property = "ike.changeset.fork", defaultValue = "true")
    boolean fork;

    @Parameter
    List<String> forkJvmArguments = List.of();

    @Parameter(property = "ike.changeset.classesDirectory", defaultValue = "${project.build.outputDirectory}")
    String classesDirectory;

    @Parameter(property = "ike.changeset.buildDirectory", defaultValue = "${project.build.directory}")
    String buildDirectory;

    @Parameter(property = "ike.changeset.skip", defaultValue = "false")
    boolean skip;

    @Override
    public void execute() {
        if (skip) {
            log.info("ike:changeset-verify skipped (ike.changeset.skip=true)");
            return;
        }
        ChangeSetToolSupport.run(log, session, project, IkeGoal.NAME_CHANGESET_VERIFY, ChangeSetVerifier.class, false,
                new ChangeSetToolSupport.Parameters(file, target, implementation, fork, forkJvmArguments,
                        classesDirectory, buildDirectory));
    }
}