Path: blob/master/test/functional/cmdLineTests/shareClassTests/utils/src/Utilities/Loader.java
6005 views
/*******************************************************************************1* Copyright (c) 2005, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package Utilities;2223import java.io.FileInputStream;24import java.net.URL;25import java.util.Properties;2627import CustomCLs.CustomURLClassLoader;28import Utilities.StringManipulator;29import Utilities.URLClassPathCreator;3031/**32* @author Matthew Kilner33*/34public class Loader {3536StringManipulator manipulator = new StringManipulator();3738public static void main(String[] args) {3940if(args.length != 2){41System.out.println("\n Incorrect usage");42System.out.println("\n Please specifiy -testfile <filename>");43}4445Loader test = new Loader();4647String testFile = args[1];4849test.testWrapper(testFile);50}5152public void testWrapper(String testFileName){5354System.out.println("\n** Running loader for properties: "+testFileName+"\n");5556Properties props = new Properties();57try{58FileInputStream PropertiesFile = new FileInputStream(testFileName);59props.load(PropertiesFile);6061PropertiesFile.close();62} catch (Exception e){63e.printStackTrace();64}6566String classPath = props.getProperty("ClassPath");6768String nctls = props.getProperty("NumberOfClassesToLoad");69Integer i = Integer.valueOf(nctls);70int classesToLoadCount = i.intValue();7172String[] classesToLoad = new String[classesToLoadCount];73String classesString = props.getProperty("ClassesToLoad");74for(int index = 0; index < classesToLoadCount; index ++){75classesToLoad[index] = manipulator.getStringElement(index, classesString);76}7778executeTest(classPath, classesToLoad);79}8081public void executeTest(String classpath, String[] classes){8283System.out.println("\nLoading Classes.....");84URLClassPathCreator creator = new URLClassPathCreator(classpath);85URL[] urlPath;86urlPath = creator.createURLClassPath();87CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());88for(int index = 0; index < classes.length; index++){89String classToLoad = classes[index];90if (classToLoad != null){91try{92cl.loadClass(classToLoad);93} catch (Exception e){94e.printStackTrace();95}96}97}98}99100}101102103