/** * Creates a new instance. * @param callerClass the caller class (for detecting testing resources) * @param context the current testing context */ public BatchTestTool(Class<?> callerClass, TestContext context) { this(callerClass, context, new TestToolRepository(context.getClassLoader())); }
static void setCached(VerifyContext context, ExcelSheetRuleExtensionRepository repository) { Reference<ExcelSheetRuleExtensionRepository> ref; if (repository.getClass().getClassLoader() == ClassLoader.getSystemClassLoader()) { ref = new SoftReference<>(repository); } else { ref = new WeakReference<>(repository); } CACHE.put(context.getTestContext().getClassLoader(), ref); }
private static ExcelSheetRuleExtensionRepository newInstance(VerifyContext context) { ClassLoader classLoader = context.getTestContext().getClassLoader(); List<ExcelSheetRuleExtension> extensions = new ArrayList<>(); for (ExcelSheetRuleExtension extension : ServiceLoader.load(ExcelSheetRuleExtension.class, classLoader)) { extensions.add(extension); } return new ExcelSheetRuleExtensionRepository(extensions); }
/** * Creates a new instance. * @param callerClass the caller class (for detecting testing resources) * @param context the current testing context * @param tools the testing tools */ protected BatchTestTool(Class<?> callerClass, TestContext context, TestToolRepository tools) { this.classLoader = context.getClassLoader(); this.batchArguments = new LinkedHashMap<>(context.getArguments()); this.environmentVariables = new LinkedHashMap<>(context.getEnvironmentVariables()); this.callerClass = callerClass; this.tools = new TestToolRepository(classLoader); }
/** * Returns a {@link ExcelSheetRuleExtensionRepository} for the target context. * @param context the target context * @return a repository object * @throws IllegalArgumentException if some parameters were {@code null} */ public static ExcelSheetRuleExtensionRepository get(VerifyContext context) { if (context == null) { throw new IllegalArgumentException("context must not be null"); //$NON-NLS-1$ } Reference<ExcelSheetRuleExtensionRepository> ref = CACHE.get(context.getTestContext().getClassLoader()); ExcelSheetRuleExtensionRepository cached = ref == null ? null : ref.get(); if (cached != null) { return cached; } ExcelSheetRuleExtensionRepository created = newInstance(context); setCached(context, created); return created; }
private static ClassLoader findClassLoader(TestContext testContext) { assert testContext != null; ClassLoader current = testContext.getClassLoader(); File pluginDirectory = findFileOnHomePath(testContext, PRODUCTION_PLUGIN_DIRECTORY); if (pluginDirectory == null || pluginDirectory.isDirectory() == false) {
return null; ClassLoader classLoader = context.getClassLoader(); String rest = source.getSchemeSpecificPart(); LOG.debug("Attempts to load {} as a class", rest); //$NON-NLS-1$