@Override public OpenL build(String category) throws OpenConfigurationException { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader userEnvitonmentContextClassLoader = getUserEnvironmentContext().getUserClassLoader(); try { Thread.currentThread().setContextClassLoader(userEnvitonmentContextClassLoader); OpenL.getInstance(extendsCategory, getUserEnvironmentContext()); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } return super.build(category); }
@Override public OpenL build(String category) throws OpenConfigurationException { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader userEnvitonmentContextClassLoader = getUserEnvironmentContext().getUserClassLoader(); try { Thread.currentThread().setContextClassLoader(userEnvitonmentContextClassLoader); OpenL.getInstance(extendsCategory, getUserEnvironmentContext()); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } return super.build(category); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof IUserContext)) { return false; } IUserContext c = (IUserContext) obj; return Objects.equals(getUserClassLoader(), c.getUserClassLoader()) && Objects.equals(getUserHome(), c.getUserHome()); }
private void addImports(OpenLBuilderImpl builder, Collection<String> imports) { Collection<String> packageNames = new LinkedHashSet<String>(); Collection<String> classNames = new LinkedHashSet<String>(); Collection<String> libraries = new LinkedHashSet<String>(); for (String singleImport : imports) { if (singleImport.endsWith(".*")) { try { String libraryClassName = singleImport.substring(0, singleImport.length() - 2); userContext.getUserClassLoader().loadClass(libraryClassName); // try // load // class libraries.add(libraryClassName); } catch (Exception e) { packageNames.add(singleImport.substring(0, singleImport.length() - 2)); } } else { try { userContext.getUserClassLoader().loadClass(singleImport); // try // load // class classNames.add(singleImport); } catch (Exception e) { packageNames.add(singleImport); } } } builder.setPackageImports(packageNames.toArray(new String[] {})); builder.setClassImports(classNames.toArray(new String[] {})); builder.setLibraries(libraries.toArray(new String[] {})); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof IUserContext)) { return false; } IUserContext c = (IUserContext) obj; return Objects.equals(getUserClassLoader(), c.getUserClassLoader()) && Objects.equals(getUserHome(), c.getUserHome()); }
private IConfigurableResourceContext getConfigurationContext(IOpenLConfiguration extendsConfiguration, IUserContext ucxt) { ClassLoader parentLoader = extendsConfiguration == null ? OpenL.class.getClassLoader() : extendsConfiguration.getConfigurationContext().getClassLoader(); if (!inheritExtendedConfigurationLoader) { parentLoader = ucxt.getUserClassLoader(); } return new ConfigurableResourceContext(parentLoader, conf); }
private IConfigurableResourceContext getConfigurationContext(IOpenLConfiguration extendsConfiguration, IUserContext ucxt) { ClassLoader parentLoader = extendsConfiguration == null ? OpenL.class.getClassLoader() : extendsConfiguration.getConfigurationContext().getClassLoader(); if (!inheritExtendedConfigurationLoader) { parentLoader = ucxt.getUserClassLoader(); } return new ConfigurableResourceContext(parentLoader, conf); }
IConfigurableResourceContext getConfigurationContext(IOpenLConfiguration extendsConfiguration) throws Exception { ClassLoader parentLoader = extendsConfiguration == null ? ClassLoaderFactory.getOpenlCoreLoader(null) : extendsConfiguration.getConfigurationContext().getClassLoader(); ClassLoader myClassLoader = parentLoader; if (classpath != null && classpath.trim().length() != 0) { String baseDir = getProject().getBaseDir().getCanonicalPath(); UserContext ucxt = new UserContext(null, baseDir); myClassLoader = ClassLoaderFactory.createUserClassloader(category, classpath, parentLoader, ucxt); } else { myClassLoader = AntOpenLBuilder.userCxt.top().getUserClassLoader(); } return new ConfigurableResourceContext(myClassLoader, conf); }
private IOpenLBuilder makeBuilder(String openl, IConfigurableResourceContext cxt, IUserContext ucxt) throws Exception { String builderClassPath = cxt.findProperty(openl + BUILDER_CLASS_PATH); if (builderClassPath == null) { builderClassPath = cxt.findProperty(DEFAULT_BUILDER_CLASS_PATH_PROPERTY); } ClassLoader ucl = ucxt.getUserClassLoader(); ClassLoader cl = OpenL.class.getClassLoader(); try { Class<?> c = ucl.loadClass(OpenL.class.getName()); if (c != null) { cl = ucl; } } catch (Exception ignored) { // Ignore } if (builderClassPath != null) { cl = ClassLoaderFactory.createClassLoader(builderClassPath, cl, ucxt.getUserHome()); } String builderClassName = cxt.findProperty(openl + BUILDER_CLASS); if (builderClassName == null) { builderClassName = cxt.findProperty(DEFAULT_BUILDER_CLASS_PROPERTY); } if (builderClassName == null) { builderClassName = openl + "." + OPENL_BUILDER; } return (IOpenLBuilder)ClassFactory.forName(builderClassName, cl).newInstance(); } }
private IOpenLBuilder makeBuilder(String openl, IConfigurableResourceContext cxt, IUserContext ucxt) throws Exception { String builderClassPath = cxt.findProperty(openl + BUILDER_CLASS_PATH); if (builderClassPath == null) { builderClassPath = cxt.findProperty(DEFAULT_BUILDER_CLASS_PATH_PROPERTY); } ClassLoader ucl = ucxt.getUserClassLoader(); ClassLoader cl = OpenL.class.getClassLoader(); try { Class<?> c = ucl.loadClass(OpenL.class.getName()); if (c != null) { cl = ucl; } } catch (Exception ignored) { // Ignore } if (builderClassPath != null) { cl = ClassLoaderFactory.createClassLoader(builderClassPath, cl, ucxt.getUserHome()); } String builderClassName = cxt.findProperty(openl + BUILDER_CLASS); if (builderClassName == null) { builderClassName = cxt.findProperty(DEFAULT_BUILDER_CLASS_PROPERTY); } if (builderClassName == null) { builderClassName = openl + "." + OPENL_BUILDER; } return (IOpenLBuilder)ClassFactory.forName(builderClassName, cl).newInstance(); } }
try { IUserContext cxt = getUserContext(); Thread.currentThread().setContextClassLoader(cxt.getUserClassLoader());
public IParsedCode parseAsModule(IOpenSourceCodeModule source) { String[] roots = {userContext.getUserHome()}; ClassLoader classLoader = userContext.getUserClassLoader(); IncludeSearcher includeSeeker = new IncludeSearcher(new ConfigurableResourceContext(classLoader, roots)); XlsLoader xlsLoader = new XlsLoader(includeSeeker); return xlsLoader.parse(source); }
@Override public IParsedCode parseAsModule(IOpenSourceCodeModule source) { String[] roots = { userContext.getUserHome() }; ClassLoader classLoader = userContext.getUserClassLoader(); IncludeSearcher includeSeeker = new IncludeSearcher(new ConfigurableResourceContext(classLoader, roots)); return new SequentialXlsLoader(includeSeeker).parse(source); } }
public synchronized IOpenLBuilder getBuilder(String openlName, IUserContext ucxt) throws OpenConfigurationException { String userHome = ucxt.getUserHome(); String[] homes; try { String altHome = new File(userHome + "/../" + OPENL_ALT_CONFIG_ROOT).getCanonicalPath(); homes = new String[] { userHome, altHome }; } catch (Exception t) { homes = new String[] { userHome }; } ConfigurableResourceContext cxt = new ConfigurableResourceContext(ucxt.getUserClassLoader(), homes); PropertyFileLoader propertyLoader = new PropertyFileLoader(openlName + "." + OPENL_DEFAULT_PROPERTY_FILE_NAME, openlName + "." + OPENL_PROPERTY_FILE_PROPERTY, cxt, new PropertyFileLoader( OPENL_DEFAULT_PROPERTY_FILE_NAME, "org.openl." + OPENL_PROPERTY_FILE_PROPERTY, cxt, null)); Properties pp = propertyLoader.getProperties(); cxt.setProperties(pp); try { IOpenLBuilder builder = makeBuilder(openlName, cxt, ucxt); builder.setContexts(cxt, ucxt); return builder; } catch (Exception ex) { throw new OpenConfigurationException("Error creating builder: ", null, ex); } }
public synchronized IOpenLBuilder getBuilder(String openlName, IUserContext ucxt) throws OpenConfigurationException { String userHome = ucxt.getUserHome(); String[] homes; try { String altHome = new File(userHome + "/../" + OPENL_ALT_CONFIG_ROOT).getCanonicalPath(); homes = new String[] { userHome, altHome }; } catch (Exception t) { homes = new String[] { userHome }; } ConfigurableResourceContext cxt = new ConfigurableResourceContext(ucxt.getUserClassLoader(), homes); PropertyFileLoader propertyLoader = new PropertyFileLoader(openlName + "." + OPENL_DEFAULT_PROPERTY_FILE_NAME, openlName + "." + OPENL_PROPERTY_FILE_PROPERTY, cxt, new PropertyFileLoader( OPENL_DEFAULT_PROPERTY_FILE_NAME, "org.openl." + OPENL_PROPERTY_FILE_PROPERTY, cxt, null)); Properties pp = propertyLoader.getProperties(); cxt.setProperties(pp); try { IOpenLBuilder builder = makeBuilder(openlName, cxt, ucxt); builder.setContexts(cxt, ucxt); return builder; } catch (Exception ex) { throw new OpenConfigurationException("Error creating builder: ", null, ex); } }
Class<?> libraryClass = getUserEnvironmentContext().getUserClassLoader().loadClass(libraryName); if (libraryClass.getAnnotation(OperatorsNamespace.class) != null) { if (operationNamespaceLibrary == null) {
Class<?> libraryClass = getUserEnvironmentContext().getUserClassLoader().loadClass(libraryName); if (libraryClass.getAnnotation(OperatorsNamespace.class) != null) { if (operationNamespaceLibrary == null) {