<commit_before>package com.nugetmonkey

import org.apache.commons.io.FileUtils
import org.codehaus.jackson.map.ObjectMapper
import org.gradle.api.tasks.TaskAction

import java.util.regex.Pattern

class NugetMonkey extends Ikvm {
    private static final String TEX_IKVMHome = "\\\$\\(IKVMHome\\)"
    private static final String TEX_ProjectHome = "\\\$\\(ProjectHome\\)"
    private static final String TEX_BackTick = "`"
    private static final File additionalDeps = new File("./AdditionalJavaDependencies.json")
    private static final ObjectMapper mapper = new ObjectMapper();

    NugetMonkey() {
        super()
        /*File debugFile = getDestinationDebugFile()
        outputs.upToDateWhen {
            if (debug) {
                if (debugFile.isFile()
                        && debugFile.exists()) {
                    return true
                }
            }
            if (destFile.isFile()
                    && destFile.exists()) {
                return destFile.exists()
            }
            return false;
        }*/
    }
    private static getNugetMonkeyDependencyModel(){
        if (additionalDeps.exists()) {
            GradleObjectModelModifications model = mapper.readValue(additionalDeps, GradleObjectModelModifications.class)
            if (model != null) {
                return model
            }
        }
        return new GradleObjectModelModifications();
    }
    def writeTofile(String fileName, String text){
        def myFile = new File(fileName)
        PrintWriter pr = new PrintWriter(myFile)
        try{
            pr.println(text)
        }finally {
            pr.close()
        }
    }
    @TaskAction
    def build() {
        def home = resolveIkvmHome().getAbsolutePath()

        List<String> lstIKVMIKVMc = new LinkedList<>()
        lstIKVMIKVMc.add "${home}\\bin\\ICSharpCode.SharpZipLib.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.AWT.WinForms.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.OpenJDK.Core.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.OpenJDK.Tools.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Reflection.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Runtime.JNI.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Runtime.dll"

        /**
         * http://permalink.gmane.org/gmane.comp.java.ikvm.devel/4085
         */
        List<String> lstIKVMRequiredRefs = new LinkedList<>();
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Beans.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Charsets.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Cldrdata.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Corba.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Jdbc.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Localedata.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Management.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Media.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Misc.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Naming.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Nashorn.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Remoting.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Security.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.SwingAWT.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Text.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Util.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.API.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Bind.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Crypto.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Parse.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Transform.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.WebServices.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.XPath.dll"

        GradleObjectModelModifications model = getNugetMonkeyDependencyModel()

        if (model.removedProjectDependencies != null && model.removedProjectDependencies.length>0) {

            lstIKVMIKVMc.each {
                removeOneReference(new File(it))
            }
            lstIKVMRequiredRefs.each {
                removeOneReference(new File(it))
            }
            File rootLibFolder = new File(project.rootDir, "build/libs/")
            rootLibFolder.listFiles().each {
                if(it.path.endsWith(".dll")){
                    removeOneReference(it)
                }
            }
            removeAllReferences(rootLibFolder)
            model.removedProjectDependencies = new String[0]
            mapper.writeValue(additionalDeps,  model)
        }


        // Add dependencies provided through additional dependencies json file.
        if (model.additionalProjectDependencies != null) {
            model.getAdditionalProjectDependencies().each { ad ->
                project.dependencies {
                    "compile" "$ad"
                }<commit_msg>deleting files after reset because IKVM seems to be using it.<commit_after>package com.nugetmonkey

import org.apache.commons.io.FileUtils
import org.codehaus.jackson.map.ObjectMapper
import org.gradle.api.tasks.TaskAction

import java.util.regex.Pattern

class NugetMonkey extends Ikvm {
    private static final String TEX_IKVMHome = "\\\$\\(IKVMHome\\)"
    private static final String TEX_ProjectHome = "\\\$\\(ProjectHome\\)"
    private static final String TEX_BackTick = "`"
    private static final File additionalDeps = new File("./AdditionalJavaDependencies.json")
    private static final ObjectMapper mapper = new ObjectMapper();

    NugetMonkey() {
        super()
        /*File debugFile = getDestinationDebugFile()
        outputs.upToDateWhen {
            if (debug) {
                if (debugFile.isFile()
                        && debugFile.exists()) {
                    return true
                }
            }
            if (destFile.isFile()
                    && destFile.exists()) {
                return destFile.exists()
            }
            return false;
        }*/
    }
    private static getNugetMonkeyDependencyModel(){
        if (additionalDeps.exists()) {
            GradleObjectModelModifications model = mapper.readValue(additionalDeps, GradleObjectModelModifications.class)
            if (model != null) {
                return model
            }
        }
        return new GradleObjectModelModifications();
    }
    def writeTofile(String fileName, String text){
        def myFile = new File(fileName)
        PrintWriter pr = new PrintWriter(myFile)
        try{
            pr.println(text)
        }finally {
            pr.close()
        }
    }
    @TaskAction
    def build() {
        def home = resolveIkvmHome().getAbsolutePath()

        List<String> lstIKVMIKVMc = new LinkedList<>()
        lstIKVMIKVMc.add "${home}\\bin\\ICSharpCode.SharpZipLib.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.AWT.WinForms.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.OpenJDK.Core.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.OpenJDK.Tools.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Reflection.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Runtime.JNI.dll"
        lstIKVMIKVMc.add "${home}\\bin\\IKVM.Runtime.dll"

        /**
         * http://permalink.gmane.org/gmane.comp.java.ikvm.devel/4085
         */
        List<String> lstIKVMRequiredRefs = new LinkedList<>();
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Beans.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Charsets.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Cldrdata.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Corba.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Jdbc.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Localedata.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Management.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Media.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Misc.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Naming.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Nashorn.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Remoting.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Security.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.SwingAWT.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Text.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.Util.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.API.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Bind.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Crypto.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Parse.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.Transform.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.WebServices.dll"
        lstIKVMRequiredRefs.add "${home}\\bin\\IKVM.OpenJDK.XML.XPath.dll"

        GradleObjectModelModifications model = getNugetMonkeyDependencyModel()

        if (model.removedProjectDependencies != null && model.removedProjectDependencies.length>0) {

            lstIKVMIKVMc.each {
                removeOneReference(new File(it))
            }
            lstIKVMRequiredRefs.each {
                removeOneReference(new File(it))
            }
            File rootLibFolder = new File(project.rootDir, "build/libs/")
            rootLibFolder.listFiles().each {
                if(it.path.endsWith(".dll")){
                    removeOneReference(it)
                }
                it.delete()
            }
            removeAllReferences(rootLibFolder)
            model.removedProjectDependencies = new String[0]
            mapper.writeValue(additionalDeps,  model)
        }


        // Add dependencies provided through additional dependencies json file.
        if (model.additionalProjectDependencies != null) {
            model.getAdditionalProjectDependencies().each { ad ->
                project.dependencies {
                    "compile" "$ad"
                }
{'fraction_non_alphanumeric': 0.13111620795107035, 'fraction_numerical': 0.0011467889908256881, 'mean_word_length': 2.2239679605668514, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1686017', 'n_tokens_mistral': 3610, 'n_tokens_neox': 3197, 'n_words': 445}