private void loadLanguageMappings(Properties props) { Enumeration<?> en = props.propertyNames(); while (en.hasMoreElements()) { String propName = (String) en.nextElement(); String propVal = props.getProperty(propName); if (propName.startsWith(".")) { // This is an extension mapping if (propName.equals(".")) { // The default mapping defaultLanguageImplName = propVal; } else { propName = propName.substring(1); extensionMappings.put(propName, propVal); } } else { // value is made up of an optional module name followed by colon followed by the // FQCN of the factory int colonIndex = propVal.lastIndexOf(COLON); String moduleName; String factoryName; if (colonIndex != -1) { moduleName = propVal.substring(0, colonIndex); factoryName = propVal.substring(colonIndex + 1); } else { throw new IllegalArgumentException( "Language mapping: " + propVal + " does not specify an implementing module"); } LanguageImplInfo langImpl = new LanguageImplInfo(moduleName, factoryName); languageImpls.put(propName, langImpl); extensionMappings.put(propName, propName); // automatically register the name as a mapping } } }
private void loadLanguageMappings() { // The only language that Vert.x understands out of the box is Java, so we add the default // runtime and // extension mapping for that. This can be overridden in langs.properties languageImpls.put( "java", new LanguageImplInfo(null, "org.vertx.java.platform.impl.java.JavaVerticleFactory")); extensionMappings.put("java", "java"); extensionMappings.put("class", "java"); defaultLanguageImplName = "java"; // First try loading mappings from the LANG_PROPS_FILE_NAMEs file // This file is structured as follows: // It should contain one line for every language implementation that is to be used with Vert.x // That line should be structured as follows: // <lang_impl_name>=[module_name:]<factory_name> // Where: // <lang_impl_name> is the name you want to give to the language implementation, e.g. // 'jython' // module_name is the (optional) name of a module that contains the language // implementation // if ommitted it will be assumed the language implementation is included as part of the // Vert.x installation // - this is only true for the Java implementation // if included the module_name should be followed by a colon // factory_name is the FQCN of a VerticleFactory for the language implementation // Examples: // rhino=vertx.lang-rhino-v1.0.0:org.vertx.java.platform.impl.rhino.RhinoVerticleFactory // java=org.vertx.java.platform.impl.java.JavaVerticleFactory // The file should also contain one line for every extension mapping - this maps a file // extension to // a <lang_impl_name> as specified above // Examples: // .js=rhino // .rb=jruby // The file can also contain a line representing the default language runtime to be used when // no extension or // prefix maps, e.g. // .=java try (InputStream is = getClass().getClassLoader().getResourceAsStream(LANG_PROPS_FILE_NAME)) { if (is != null) { Properties props = new Properties(); props.load(new BufferedInputStream(is)); loadLanguageMappings(props); } } catch (IOException e) { log.error("Failed to load " + LANG_PROPS_FILE_NAME + " " + e.getMessage()); } // Then override any with system properties Properties sysProps = new Properties(); Set<String> propertyNames = System.getProperties().stringPropertyNames(); for (String propertyName : propertyNames) { if (propertyName.startsWith(LANG_IMPLS_SYS_PROP_ROOT)) { String lang = propertyName.substring(LANG_IMPLS_SYS_PROP_ROOT.length()); String value = System.getProperty(propertyName); sysProps.put(lang, value); } } loadLanguageMappings(sysProps); }