All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.gradle_plugins.api.classes_processing.ClassesProcessor Maven / Gradle / Ivy

package name.remal.gradle_plugins.api.classes_processing;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;

public interface ClassesProcessor extends Comparable {

    void process(@NotNull byte[] bytecode, @NotNull BytecodeModifier bytecodeModifier, @NotNull ProcessContext context);

    @FunctionalInterface
    interface BytecodeModifier {

        void modify(@NotNull byte[] modifiedBytecode);

    }

    interface ProcessContext {

        @NotNull
        File getClassesDir();

        @NotNull
        List getClasspath();

        @Nullable
        byte[] readBinaryResource(@NotNull String relativePath);

        @Nullable
        String readTextResource(@NotNull String relativePath);

        void writeTextResource(@NotNull String relativePath, @NotNull String text);

        void appendTextResource(@NotNull String relativePath, @NotNull String text);

        default void writeService(@NotNull String serviceName, @NotNull String implementationName) {
            appendTextResource("META-INF/services/" + serviceName, "\n" + implementationName);
        }

        default void writeService(@NotNull Class serviceClass, @NotNull String implementationName) {
            writeService(serviceClass.getName(), implementationName);
        }

        default void writeService(@NotNull String serviceName, @NotNull Class implementationClass) {
            writeService(serviceName, implementationClass.getName());
        }

        default void writeService(@NotNull Class serviceClass, @NotNull Class implementationClass) {
            writeService(serviceClass.getName(), implementationClass.getName());
        }

        @Nullable
        byte[] readClasspathBinaryResource(@NotNull String relativePath);

        @Nullable
        String readClasspathTextResource(@NotNull String relativePath);

    }


    int DEFAULT_STAGE = 0;
    int POST_PROCESSING_STAGE = 900_000;
    int VALIDATION_STAGE = 1_000_000;
    int COLLECTION_STAGE = 1_100_000;

    default int getStage() {
        return DEFAULT_STAGE;
    }

    default int getOrder() {
        return 0;
    }

    @Override
    default int compareTo(@NotNull ClassesProcessor other) {
        int result = Integer.compare(getStage(), other.getStage());
        if (0 == result) result = Integer.compare(getOrder(), other.getOrder());
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy