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

org.pitest.mutationtest.verify.KotlinVerifierFactory Maven / Gradle / Ivy

There is a newer version: 1.17.1
Show newest version
package org.pitest.mutationtest.verify;

import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;

import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;

public class KotlinVerifierFactory implements BuildVerifierFactory {
    @Override
    public BuildVerifier create(CodeSource code) {
        return new KotlinVerifier(code);
    }

    @Override
    public String description() {
        return "Detect missing kotlin plugin";
    }
}

class KotlinVerifier implements BuildVerifier {

    private final CodeSource code;

    KotlinVerifier(CodeSource code) {
        this.code = code;
    }

    @Override
    public List verify() {
        if (kotlinIsOnClassPath() && !kotlinPluginIsPresent() && kotlinClassesToBeMutated()) {
            return asList("Project uses kotlin, but the Arcmutate kotlin plugin is not on classpath (https://docs.arcmutate.com/docs/kotlin.html)");
        }

        return Collections.emptyList();
    }

    private boolean kotlinClassesToBeMutated() {
        return code.codeTrees()
                .anyMatch(c -> c.rawNode().sourceFile != null && c.rawNode().sourceFile.endsWith(".kt"));
    }

    private boolean kotlinPluginIsPresent() {
        return code.fetchClassBytes(ClassName.fromString("com.groupcdg.pitest.kotlin.KotlinFilterInterceptor")).isPresent();
    }

    private boolean kotlinIsOnClassPath() {
        return code.fetchClassBytes(ClassName.fromString("kotlin.KotlinVersion")).isPresent();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy