<commit_before>package common;


import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.StaleProxyException;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Stack;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class ClassLoaderUtil {

    // Log object
   

    // Parameters
    private static final Class<? extends Object>[] parameters = new Class[]{URL.class};

    /**
     * Add file to CLASSPATH
     * @param s File name
     * @throws IOException  IOException
     */
    public static void addFile(String s) throws IOException {
        File f = new File(s);
        addFile(f);
    }
    
    public static void removeFile(String [] files) throws RuntimeException, NoSuchFieldException, IllegalAccessException
    {
    URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Field [] fields=null;
    Class sysclass = URLClassLoader.class;
    fields=sysclass.getDeclaredFields();
    java.lang.reflect.Field ucp = sysclass.getDeclaredField("ucp");
    ucp.setAccessible(true);
    Object sun_misc_URLClassPath = ucp.get(sysLoader);
    Class c=  sun_misc_URLClassPath.getClass();
    fields=c.getDeclaredFields();
    Field path=c.getDeclaredField("path");
    path.setAccessible(true);
          
    Field urlsField=c.getDeclaredField("urls");
    Object tmpObject=new Object();
    urlsField.setAccessible(true);
    tmpObject=path.get(sun_misc_URLClassPath);
    Object stack=urlsField.get(sun_misc_URLClassPath);
    Stack myStack= (Stack) stack;
    ArrayList list= (ArrayList) tmpObject;
    //System.out.println("Size:"+list.size());
    ArrayList<URL> urls=new ArrayList<URL>();
    for(int i=0;i<list.size();i++)
    {
       	
    	URL url=(URL) list.get(i); 
     	for(String jarFile : files)
     	{	
     		
     		jarFile=jarFile.replace("\\", "/");
     		jarFile="/"+jarFile;
     		if(url.getPath().equals(jarFile))
     		{
     			
     			urls.add(url);
     		
     		}
     	}
    }
     	
    for(URL url: urls)
    {
      list.remove(url);
      myStack.remove(url);
    }

     	
    for(int i=0;i<list.size();i++)
    {
         URL url=(URL) list.get(i); 
     	
    }
        
        path.set(sun_misc_URLClassPath, list);
        ucp.set(ClassLoader.getSystemClassLoader(),  sun_misc_URLClassPath);
      
}
        
    

    /**
     * Add file to CLASSPATH
     * @param f  File object<commit_msg>Remove File from Classpath<commit_after>package common;


import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.StaleProxyException;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Stack;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class ClassLoaderUtil {

    // Log object
   

    // Parameters
    private static final Class<? extends Object>[] parameters = new Class[]{URL.class};

    /**
     * Add file to CLASSPATH
     * @param s File name
     * @throws IOException  IOException
     */
    public static void addFile(String s) throws IOException {
        File f = new File(s);
        addFile(f);
    }
    
    public static void removeFile(String [] files) throws RuntimeException, NoSuchFieldException, IllegalAccessException
    {
    URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Field [] fields=null;
    Class sysclass = URLClassLoader.class;
    fields=sysclass.getDeclaredFields();
    java.lang.reflect.Field ucp = sysclass.getDeclaredField("ucp");
    ucp.setAccessible(true);
    Object sun_misc_URLClassPath = ucp.get(sysLoader);
    Class c=  sun_misc_URLClassPath.getClass();
    fields=c.getDeclaredFields();
    Field path=c.getDeclaredField("path");
    path.setAccessible(true);
          
    Field urlsField=c.getDeclaredField("urls");
    Object tmpObject=new Object();
    urlsField.setAccessible(true);
    tmpObject=path.get(sun_misc_URLClassPath);
    Object stack=urlsField.get(sun_misc_URLClassPath);
    Stack myStack= (Stack) stack;
    ArrayList list= (ArrayList) tmpObject;
    //System.out.println("Size:"+list.size());
    ArrayList<URL> urls=new ArrayList<URL>();
    for(int i=0;i<list.size();i++)
    {
       	
    	URL url=(URL) list.get(i); 
     	for(String jarFile : files)
     	{	
     		
     		jarFile=jarFile.replace("\\", "/");
     		jarFile="/"+jarFile;
     		if(url.getPath().equals(jarFile))
     		{
     			
     			urls.add(url);
     		
     		}
     	}
    }
     	
    for(URL url: urls)
    {
      list.remove(url);
      myStack.remove(url);
    }

     	
    for(int i=0;i<list.size();i++)
    {
         URL url=(URL) list.get(i); 
     	
    }
        
        path.set(sun_misc_URLClassPath, list);
        ucp.set(ClassLoader.getSystemClassLoader(),  sun_misc_URLClassPath);
      
}
    
    
    public static void removeFile(String jarFile) throws RuntimeException, NoSuchFieldException, IllegalAccessException
    {
    URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Field [] fields=null;
    Class sysclass = URLClassLoader.class;
    fields=sysclass.getDeclaredFields();
    java.lang.reflect.Field ucp = sysclass.getDeclaredField("ucp");
    ucp.setAccessible(true);
    Object sun_misc_URLClassPath = ucp.get(sysLoader);
    Class c=  sun_misc_URLClassPath.getClass();
    fields=c.getDeclaredFields();
    Field path=c.getDeclaredField("path");
    path.setAccessible(true);
          
    Field urlsField=c.getDeclaredField("urls");
    Object tmpObject=new Object();
    urlsField.setAccessible(true);
    tmpObject=path.get(sun_misc_URLClassPath);
    Object stack=urlsField.get(sun_misc_URLClassPath);
    Stack myStack= (Stack) stack;
    ArrayList list= (ArrayList) tmpObject;
    //System.out.println("Size:"+list.size());
    ArrayList<URL> urls=new ArrayList<URL>();
    for(int i=0;i<list.size();i++)
    {
       	
    	URL url=(URL) list.get(i); 
     	     		
     		jarFile=jarFile.replace("\\", "/");
     		jarFile="/"+jarFile;
     		if(url.getPath().equals(jarFile))
     		{
     			
     			urls.add(url);
     		
     		}
     	
    }
     	
    for(URL url: urls)
    {
      list.remove(url);
      myStack.remove(url);
    }

     	
    for(int i=0;i<list.size();i++)
    {
         URL url=(URL) list.get(i); 
     	
    }
        
        path.set(sun_misc_URLClassPath, list);
        ucp.set(ClassLoader.getSystemClassLoader(),  sun_misc_URLClassPath);
      
}
        
    
        
    

    /**
     * Add file to CLASSPATH
     * @param f  File object
{'fraction_non_alphanumeric': 0.12277309763844772, 'fraction_numerical': 0.0008286148322054964, 'mean_word_length': 2.8297197250132204, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '6415517', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2361, 'n_words': 411}