Search in sources :

Example 1 with CustomURLClassLoader

use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.

the class URLHelperURLClassPathHelperStaleEntryCompatibilityTest method executeTest.

private boolean executeTest(String[] urls, String[][] classesToLoad, String classPath, String[] classesToFind, String[] results, String batchFile, String[] foundAt, String javacpath) {
    String urlsString = urls[0];
    for (int index = 1; index < urls.length; index++) {
        urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).append(File.pathSeparatorChar).toString();
    }
    System.out.println("\n** urlsString: " + urlsString);
    URLClassPathCreator creator = new URLClassPathCreator(urlsString);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLLoader[] loaderArray = new CustomURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            loaderArray[urlIndex] = new CustomURLLoader(urlPath, this.getClass().getClassLoader());
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    runBatchFile(batchFile, javacpath);
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath2, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(cl.isClassInSharedCache(classToFind));
            if (!(expectedResult.equals(testResult))) {
                System.out.println("\nFailure finding class: " + classToFind + " result: " + testResult + " expecting: " + expectedResult);
                result = false;
            } else {
                if (testResult.equals("true")) {
                    result = validateReturnedClass(classToFind, foundAt[classIndex], cl);
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Example 2 with CustomURLClassLoader

use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.

the class URLHelperURLClassPathHelperCompatibilityTest method executeTest.

private boolean executeTest(String[] urls, String[][] classesToLoad, String classPath, String[] classesToFind, String[] results, String[] foundAt) {
    String urlsString = urls[0];
    for (int index = 1; index < urls.length; index++) {
        urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).append(File.pathSeparatorChar).toString();
    }
    URLClassPathCreator creator = new URLClassPathCreator(urlsString);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLLoader[] loaderArray = new CustomURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            loaderArray[urlIndex] = new CustomURLLoader(urlPath, this.getClass().getClassLoader());
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath2, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(cl.isClassInSharedCache(classToFind));
            if (!(expectedResult.equals(testResult))) {
                System.out.println("\nFailure finding class: " + classToFind + " result: " + testResult + " expecting: " + expectedResult);
                result = false;
            } else {
                if (testResult.equals("true")) {
                    result = validateReturnedClass(classToFind, foundAt[classIndex], cl);
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Example 3 with CustomURLClassLoader

use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.

the class FilterTester_2 method test2.

public boolean test2() {
    System.out.println("\nTest " + ++counter + ": Store Filter = Data");
    String testClassName = "sharedclasses.storefilter.resources.A_Main";
    URLClassPathCreator pathCreator = new URLClassPathCreator("./Resources/resources.jar");
    CustomURLClassLoader customURLCL = new CustomURLClassLoader(pathCreator.createURLClassPath());
    SharedClassHelperFactory schFactory = Shared.getSharedClassHelperFactory();
    SharedClassURLClasspathHelper newHelper;
    try {
        newHelper = schFactory.getURLClasspathHelper(customURLCL, pathCreator.createURLClassPath(), new StoreFilter("Data"));
        if (null == newHelper) {
            System.out.println("\t->newHelper is null.");
            return false;
        }
    } catch (HelperAlreadyDefinedException e) {
        System.out.println("\t->HelperAlreadyDefinedException is thrown.");
        return false;
    }
    try {
        Class c = Class.forName(testClassName, true, customURLCL);
        Method meth = c.getDeclaredMethod("run", new Class[0]);
        invokeMethod(c.newInstance(), "run", new Class[0]);
        /* Set the filter to null, 
			 * so there will be no filter to prevent some class names to be looked in shared cache.
			 * See SharedClassFilter#acceptFind 
			 */
        newHelper.setSharingFilter(null);
        if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.A_Main$Data")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.A_Main$Data is in shared cache.");
            return false;
        }
        if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.B_Dummy$Data")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.B_Dummy$Data is in shared cache.");
            return false;
        }
        if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.C_Dummy$Data")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.C_Dummy$Data is in shared cache.");
            return false;
        }
        if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.D_Dummy$Data")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.D_Dummy$Data is in shared cache.");
            return false;
        }
        if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.A_Main")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.A_Main is not in shared cache.");
            return false;
        }
        if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.B_Dummy")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.B_Dummy is not in shared cache.");
            return false;
        }
        if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.C_Dummy")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.C_Dummy is not in shared cache.");
            return false;
        }
        if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.D_Dummy")) {
            System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.D_Dummy is not in shared cache.");
            return false;
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        return false;
    }
    return true;
}
Also used : URLClassPathCreator(Utilities.URLClassPathCreator) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException) SharedClassHelperFactory(com.ibm.oti.shared.SharedClassHelperFactory) SharedClassURLClasspathHelper(com.ibm.oti.shared.SharedClassURLClasspathHelper) Method(java.lang.reflect.Method) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException)

Example 4 with CustomURLClassLoader

use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.

the class URLClassPathHelperURLHelperCompatibilityTest method executeTest.

private boolean executeTest(String classPath, String[] classesToLoad, String[] urls, String[][] classesToFind, String[][] results) {
    URLClassPathCreator creator = new URLClassPathCreator(classPath);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToLoad = classesToLoad[classIndex];
        if (classToLoad != null) {
            try {
                cl.loadClass(classToLoad);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    String urlsString = urls[0];
    for (int index = 1; index < urls.length; index++) {
        urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
    }
    System.out.println("\n** urlsString: " + urlsString);
    URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLLoader urlcl = new CustomURLLoader(urlPath2, this.getClass().getClassLoader());
    boolean result = true;
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++) {
            String classToFind = classesToFind[urlIndex][classIndex];
            String expectedResult = results[urlIndex][classIndex];
            if (classToFind != null) {
                String testResult = String.valueOf(urlcl.isClassInSharedCache(urlIndex, classToFind));
                if (!(expectedResult.equals(testResult))) {
                    System.out.println("\nFailure finding class: " + classToFind + " on path: " + urls[urlIndex] + " which is index: " + urlIndex + " result: " + testResult + " expecting: " + expectedResult);
                    result = false;
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Example 5 with CustomURLClassLoader

use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.

the class Loader method executeTest.

public void executeTest(String classpath, String[] classes) {
    System.out.println("\nLoading Classes.....");
    URLClassPathCreator creator = new URLClassPathCreator(classpath);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
    for (int index = 0; index < classes.length; index++) {
        String classToLoad = classes[index];
        if (classToLoad != null) {
            try {
                cl.loadClass(classToLoad);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Aggregations

CustomURLClassLoader (CustomCLs.CustomURLClassLoader)11 URLClassPathCreator (Utilities.URLClassPathCreator)9 URL (java.net.URL)8 CustomURLLoader (CustomCLs.CustomURLLoader)5 HelperAlreadyDefinedException (com.ibm.oti.shared.HelperAlreadyDefinedException)3 SharedClassHelperFactory (com.ibm.oti.shared.SharedClassHelperFactory)3 SharedClassURLClasspathHelper (com.ibm.oti.shared.SharedClassURLClasspathHelper)3 Method (java.lang.reflect.Method)3 CustomTokenClassLoader (CustomCLs.CustomTokenClassLoader)1 CannotSetClasspathException (com.ibm.oti.shared.CannotSetClasspathException)1