public IOpenSourceCodeModule findInclude(String include) throws IOException { String p = PathTool.mergePath(INCLUDE, include); URL url = ucxt.findClassPathResource(p); File f = ucxt.findFileSystemResource(p);
protected String getAntFile(String openl) { String name = getResourceContext().findProperty(openl + ".ant.build.file"); if (name != null) { File f = getResourceContext().findFileSystemResource(name); if (f != null) { return f.getAbsolutePath(); } throw new OpenConfigurationException("File " + name + " is not found ", null, null); } name = openl + ".build.xml"; if (name != null) { File f = getResourceContext().findFileSystemResource(name); if (f != null) { return f.getAbsolutePath(); } } name = getResourceContext().findProperty("org.openl.default.ant.build.file"); if (name != null) { File f = getResourceContext().findFileSystemResource(name); if (f != null) { return f.getAbsolutePath(); } throw new OpenConfigurationException("File " + name + " is not found ", null, null); } throw new OpenConfigurationException("Can not find Ant configuration file for " + openl, null, null); }
public static Object newInstance(String classname, IConfigurableResourceContext cxt, String uri) throws OpenConfigurationException { try { return cxt.getClassLoader().loadClass(classname).newInstance(); } catch (Throwable t) { throw new OpenConfigurationException("Can't create a new " + classname, uri, t); } }
boolean loadAsResource(String name) { try { URL url = getContext().findClassPathResource(name); if (url == null) { return false; } InputStream in = url.openStream(); Properties p = new Properties(); p.load(in); properties = p; in.close(); return true; } catch (Throwable t) { // Log.debug("Loading as resource: ", t); return false; } }
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(); } }
boolean loadAsFile(String url) { try { File f = getContext().findFileSystemResource(url); if (f == null) { return false; } InputStream in = new FileInputStream(f); properties = new Properties(); properties.load(in); in.close(); return true; } catch (Throwable t) { // System.out.println("File not as found: " + url); return false; } }
boolean loadAsResource(String name) { try { URL url = getContext().findClassPathResource(name); if (url == null) { return false; } InputStream in = url.openStream(); Properties p = new Properties(); p.load(in); properties = p; in.close(); return true; } catch (Throwable t) { // Log.debug("Loading as resource: ", t); return false; } }
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(); } }
boolean loadAsFile(String url) { try { File f = getContext().findFileSystemResource(url); if (f == null) { return false; } InputStream in = new FileInputStream(f); properties = new Properties(); properties.load(in); in.close(); return true; } catch (Throwable t) { // System.out.println("File not as found: " + url); return false; } }
public synchronized ITypeLibrary getLibrary(IConfigurableResourceContext cxt) { if (library == null) { library = new JavaImportTypeLibrary(packages.toArray(new String[]{}), classes.toArray(new String[]{}), cxt.getClassLoader()); } return library; }
protected Properties getProperties(String openl) { URL url = getResourceContext().findClassPathResource(openl.replace('.', '/') + '/' + openl + ".ant.properties"); if (url == null) { return null; } InputStream is = null; try { is = url.openStream(); Properties p = new Properties(); p.load(is); return p; } catch (IOException e) { throw RuntimeExceptionWrapper.wrap(e); } finally { try { if (is != null) { is.close(); } } catch (Throwable t) { Log.error("Error closing stream", t); } } }
private ICompileContext buildCompileContext() { ICompileContext compileContext = new DefaultCompileContext(); IConfigurableResourceContext resourceContext = getResourceContext(); if (resourceContext != null) { String propertyValue = resourceContext.findProperty("validation"); if (propertyValue != null) { Boolean value = Boolean.valueOf(propertyValue); compileContext.setValidationEnabled(value); } } return compileContext; }
public static Object newInstance(String classname, IConfigurableResourceContext cxt, String uri) throws OpenConfigurationException { try { return cxt.getClassLoader().loadClass(classname).newInstance(); } catch (Throwable t) { throw new OpenConfigurationException("Can't create a new " + classname, uri, t); } }
protected Properties getProperties(String openl) { URL url = getResourceContext().findClassPathResource(openl.replace('.', '/') + '/' + openl + ".ant.properties"); if (url == null) { return null; } InputStream is = null; try { is = url.openStream(); Properties p = new Properties(); p.load(is); return p; } catch (IOException e) { throw RuntimeExceptionWrapper.wrap(e); } finally { try { if (is != null) { is.close(); } } catch (Throwable t) { Log.error("Error closing stream", t); } } }
public String getProperty(String propertyName) { String res = getProperties().getProperty(propertyName); if (res != null) { return res; } res = getContext().findProperty(propertyName); if (res != null) { return res; } return parent == null ? null : parent.getProperty(propertyName); }
public synchronized ITypeLibrary getLibrary(IConfigurableResourceContext cxt) { if (library == null) { library = new JavaLongNameTypeLibrary(cxt.getClassLoader()); } return library; }
/** * @param openl */ protected Properties getProperties(String openl) { URL url = getResourceContext().findClassPathResource(openl.replace('.', '/') + '/' + openl + ".ant.properties"); if (url == null) { return null; } InputStream is = null; try { is = url.openStream(); Properties p = new Properties(); p.load(is); return p; } catch (IOException e) { throw RuntimeExceptionWrapper.wrap(e); } finally { try { if (is != null) { is.close(); } } catch (Throwable t) { Log.error("Error closing stream", t); } } }
public String getProperty(String propertyName) { String res = getProperties().getProperty(propertyName); if (res != null) { return res; } res = getContext().findProperty(propertyName); if (res != null) { return res; } return parent == null ? null : parent.getProperty(propertyName); }
public synchronized ITypeLibrary getLibrary(IConfigurableResourceContext cxt) { if (library == null) { library = new JavaImportTypeLibrary(packages.toArray(new String[]{}), classes.toArray(new String[]{}), cxt.getClassLoader()); } return library; }
Properties getProperties() { if (properties != null) { return properties; } // check the propertiesFileProperty first String propertiesFileName = getContext().findProperty(propertiesFileProperty); if (propertiesFileName == null) { propertiesFileName = propertiesFileDefaultName; } // is it valid URL? Log.debug("Looking for " + propertiesFileName); if (!loadAsURL(propertiesFileName) && !loadAsResource(propertiesFileName) && !loadAsFile(propertiesFileName)) { properties = parent == null ? NO_PROPERTIES : parent.getProperties(); } return properties; }