package net.bytebuddy.test.utility;

import com.sun.jna.Platform;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.logging.Logger;

public class UnixRule implements MethodRule {

    private final boolean enabled;

    public UnixRule() {
        this.enabled = !Platform.isWindows() && !Platform.isWindowsCE();
    }

    public Statement apply(Statement base, FrameworkMethod method, Object target) {
        return enabled || method.getAnnotation(Enforce.class) == null
                ? base
                : new NoOpStatement();
    }

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface Enforce {

    }

    private static class NoOpStatement extends Statement {

        public void evaluate() {
            Logger.getLogger("net.bytebuddy").warning("Ignoring Unix sockets on this machine");
        }
    }
}


@@ -558,16 +558,75 @@
 dowsCE()
+ && System.getProperty(%22java.vm.vendor%22).contains(%22OpenJ9%22)
 ;%0A    %7D%0A

Exclude emulated attachment on OpenJ9.