Ejemplo n.º 1
0
 private void loadRepos() {
   try (InputStream is = getClass().getClassLoader().getResourceAsStream(REPOS_FILE_NAME)) {
     if (is != null) {
       BufferedReader rdr = new BufferedReader(new InputStreamReader(is));
       String line;
       while ((line = rdr.readLine()) != null) {
         line = line.trim();
         if (line.isEmpty() || line.startsWith("#")) {
           // blank line or comment
           continue;
         }
         int colonPos = line.indexOf(':');
         if (colonPos == -1 || colonPos == line.length() - 1) {
           throw new IllegalArgumentException("Invalid repo: " + line);
         }
         String type = line.substring(0, colonPos);
         String repoID = line.substring(colonPos + 1);
         RepoResolver resolver;
         switch (type) {
           case "mavenLocal":
             resolver = new MavenLocalRepoResolver(repoID);
             type = "maven";
             break;
           case "maven":
             resolver = new MavenRepoResolver(vertx, repoID);
             break;
           case "bintray":
             resolver = new BintrayRepoResolver(vertx, repoID);
             break;
           case "old":
             resolver = new OldRepoResolver(vertx, repoID);
             break;
           default:
             throw new IllegalArgumentException("Unknown repo type: " + type);
         }
         repos.add(resolver);
       }
     }
   } catch (IOException e) {
     log.error("Failed to load " + LANG_PROPS_FILE_NAME + " " + e.getMessage());
   }
 }
Ejemplo n.º 2
0
  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);
  }