/** * Get classpath which should be located in the head of classpath. * * @param properties system properties * @param handler language specific handler * @param logger logger * @return foremost classpath */ private String getForeMostClassPath(Properties properties, AbstractLanguageHandler handler, Logger logger) { String systemClassPath = properties.getProperty("java.class.path"); AbstractGrinderClassPathProcessor classPathProcessor = handler.getClassPathProcessor(); return classPathProcessor.filterForeMostClassPath(systemClassPath, logger) + File.pathSeparator + classPathProcessor.filterPatchClassPath(systemClassPath, logger); }
properties.setInt("grinder.threads", 1); properties.setBoolean("grinder.script.validation", true); String grinderJVMClassPath = getHomeLibraryPath(classPathProcessor.buildForemostClasspathBasedOnCurrentClassLoader(LOGGER)) + File.pathSeparator + getHomeLibraryPath(classPathProcessor.buildPatchClasspathBasedOnCurrentClassLoader(LOGGER)) + File.pathSeparator + builder.buildCustomClassPath(true); properties.setProperty("grinder.jvm.classpath", grinderJVMClassPath = grinderJVMClassPath.replace(";;", ";")); AgentIdentityImplementation agentIdentity = new AgentIdentityImplementation("validation"); agentIdentity.setNumber(0); String newClassPath = classPathProcessor.buildClasspathBasedOnCurrentClassLoader(LOGGER); LOGGER.debug("validation class path " + newClassPath); Properties systemProperties = new Properties();
/** * Construct the classpath of ngrinder which is very important and located in the head of * classpath. * * @param classPath classpath string * @param logger logger * @return classpath optimized for grinder. */ public String filterForeMostClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isForemostJar(filename) || isUsefulForForemostReferenceProject(eachClassPath)) { logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } } return StringUtils.join(classPathList, File.pathSeparator); }
private boolean isUsefulJar(String jarFilename) { if (isPatchJar(jarFilename)) { return false; } if (!"jar".equals(FilenameUtils.getExtension(jarFilename))) { return false; } for (String jarName : uselessJarList) { if (jarFilename.contains(jarName)) { return false; } } for (String jarName : usefulJarList) { if (jarFilename.contains(jarName)) { return true; } } return false; }
/** * Construct classPath from current classLoader. * * @param logger logger * @return classpath optimized for grinder. */ public String buildClasspathBasedOnCurrentClassLoader(Logger logger) { URL[] urls = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs(); StringBuilder builder = new StringBuilder(); for (URL each : urls) { builder.append(each.getFile()).append(File.pathSeparator); } if (builder.length() < 300) { // In case of the URLClassLoader is not activated, Try with system class path final String property = System.getProperty("java.class.path", ""); for (String each : property.split(File.pathSeparator)) { builder.append(each).append(File.pathSeparator); } } return filterClassPath(builder.toString(), logger); }
/** * Construct the foremost classPath from current classLoader. * * @param logger logger * @return classpath optimized for grinder. */ public String buildForemostClasspathBasedOnCurrentClassLoader(Logger logger) { URL[] urLs = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs(); StringBuilder builder = new StringBuilder(); for (URL each : urLs) { builder.append(each.getFile()).append(File.pathSeparator); } return filterForeMostClassPath(builder.toString(), logger); }
/** * Construct the patch classPath from current classLoader. * * @param logger logger * @return classpath optimized for grinder. */ public String buildPatchClasspathBasedOnCurrentClassLoader(Logger logger) { URL[] urLs = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs(); StringBuilder builder = new StringBuilder(); for (URL each : urLs) { builder.append(each.getFile()).append(File.pathSeparator); } return filterPatchClassPath(builder.toString(), logger); }
/** * Construct the classpath of ngrinder which is very important and located in the head of * classpath. * * @param classPath classpath string * @param logger logger * @return classpath optimized for grinder. */ public String filterPatchClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isPatchJar(filename)) { logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } } return StringUtils.join(classPathList, File.pathSeparator); }
/** * Filter classpath to prevent too many instrumentation. * * @param properties system properties * @param handler Language specific handler * @param logger logger * @return new filtered properties */ private Properties filterSystemClassPath(Properties properties, AbstractLanguageHandler handler, Logger logger) { String property = properties.getProperty("java.class.path", ""); logger.debug("Total system class path in total is " + property); String newClassPath = handler.getClassPathProcessor().filterClassPath(property, logger); Properties returnProperties = new Properties(properties); returnProperties.setProperty("java.class.path", newClassPath); logger.debug("Filtered system class path is {}", newClassPath); return returnProperties; }