private Evaluator instantiateJPMMLModel() { PMML pmml = null; try { pmml = IOUtil.unmarshal(Launcher.class.getResource("/predictionModel-PMML.xml").openStream()); } catch (Exception e) { e.printStackTrace(); } PMMLManager pmmlManager = new PMMLManager(pmml); Evaluator evaluator = (Evaluator) pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance()); return evaluator; }
private void invokeMethod(String className, URL url, String methodName, String args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { final ClassLoader appClassLoader = Launcher.getLauncher().getClassLoader(); final Class<?> agentClass = appClassLoader.loadClass(className); Method method = null; Object[] invokeArgs = null; try { method = lookupMainOrAgentClass(agentClass, methodName, new Class<?>[] {String.class, Instrumentation.class}); invokeArgs = new Object[2]; invokeArgs[1] = InstrumentationManager.createInstrumentation(); } catch (NoSuchMethodException ex) { method = lookupMainOrAgentClass(agentClass, methodName, new Class<?>[] {String.class}); invokeArgs = new Object[1]; } invokeArgs[0] = args; InstrumentationManager.registerAgent(url); method.invoke(null, invokeArgs); }
/** * see test name. */ @Test public void shouldCoverAllFunctionsFromJDKPackage() throws Exception { final Reflections reflections = new Reflections( "java.util.function", Launcher.getBootstrapClassPath().getURLs() ); final Set<Class<?>> jdkFunctions = reflections.getTypesAnnotatedWith( FunctionalInterface.class ); final Set<Class<?>> serializableFunctions = serializableFunctions(); final Set<Class<?>> notFoundJdkFunctions = new HashSet<>(); for ( final Class<?> jdkFunction : jdkFunctions ) { final Class<?> correspondingSerializableFunction = findSerializableVariantOf( jdkFunction.getSimpleName(), serializableFunctions ); if ( correspondingSerializableFunction == null ) { notFoundJdkFunctions.add( jdkFunction ); } } assertThat( String.format( "Not covered ( %s ): %s ", notFoundJdkFunctions.size(), notFoundJdkFunctions ), notFoundJdkFunctions.isEmpty() ); }
@Override void handle(String className, URL[] urls, String agentArgs) throws IOException, ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException { for (URL url : urls) { addURLToAppClassLoader.invoke(Launcher.getLauncher().getClassLoader(), url); } invokeMethod(className, urls[0], "premain", agentArgs); }
public void test(String path) throws Exception { final File jarFile = getJarFile(null); if(jarFile.isFile()) { // Run with JAR file final JarFile jar = new JarFile(jarFile); final Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar while(entries.hasMoreElements()) { final String name = entries.nextElement().getName(); if (name.startsWith(path + "/")) { //filter according to the path System.out.println(name); } } jar.close(); } else { // Run with IDE final URL url = Launcher.class.getResource("/" + path); if (url != null) { try { final File apps = new File(url.toURI()); for (File app : apps.listFiles()) { System.out.println(app); } } catch (URISyntaxException e) { e.printStackTrace(); } } } }
private static synchronized void initSystemClassLoader() { if (!sclSet) { if (scl != null) throw new IllegalStateException("recursive call"); sun.misc.Launcher l = sun.misc.Launcher.getLauncher(); if (l != null) { Throwable oops = null; scl = l.getClassLoader(); try { PrivilegedExceptionAction a; a = new SystemClassLoaderAction(scl); scl = (ClassLoader) AccessController.doPrivileged(a); } catch (PrivilegedActionException pae) { oops = pae.getCause(); if (oops instanceof InvocationTargetException) { oops = oops.getCause(); } } if (oops != null) { if (oops instanceof Error) { throw (Error) oops; } else { // wrap the exception throw new Error(oops); } } } sclSet = true; } }
@ALIAS(declaringClass = Launcher.class, name = "<clinit>") private static native void Launcher_clinit();
private Class<?> loadMainClass() throws IOException, ClassNotFoundException { final ClassLoader appClassLoader = Launcher.getLauncher().getClassLoader(); return appClassLoader.loadClass(mainClassName); }
static boolean shouldUseOpaqueButtons() { final ClassLoader launcherClassLoader = Launcher.getLauncher().getClassLoader(); if (classExists(launcherClassLoader, "com.installshield.wizard.platform.macosx.MacOSXUtils")) return true; return false; }
static URLClassPath getBootstrapClassPath() { if (bootstrapClassPath == null) { bootstrapClassPath = sun.misc.Launcher.getBootstrapClassPath(); } return bootstrapClassPath; }
/** * Implementation of parent {@link URLClassLoader} and {@link ClassLoader} * class method for filter parent ClassLoader and current * {@link ClassLoader}'s resources * * @return {@link Enumeration} */ static Enumeration<Resource> getBootstrapsResources(String name) { return Launcher.getBootstrapClassPath().getResources(name); }