Search in sources :

Example 51 with ProvisionException

use of com.google.inject.ProvisionException in project gerrit by GerritCodeReview.

the class InMemoryModule method indexModule.

private Module indexModule(String moduleClassName) {
    try {
        Class<?> clazz = Class.forName(moduleClassName);
        Method m = clazz.getMethod("singleVersionWithExplicitVersions", Map.class, int.class);
        return (Module) m.invoke(null, getSingleSchemaVersions(), 0);
    } catch (ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
        ProvisionException pe = new ProvisionException(e.getMessage());
        pe.initCause(e);
        throw pe;
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) Method(java.lang.reflect.Method) Module(com.google.inject.Module) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GpgModule(com.google.gerrit.gpg.GpgModule) AbstractModule(com.google.inject.AbstractModule) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 52 with ProvisionException

use of com.google.inject.ProvisionException in project gerrit by GerritCodeReview.

the class HostKeyProvider method get.

@Override
public KeyPairProvider get() {
    Path objKey = site.ssh_key;
    Path rsaKey = site.ssh_rsa;
    Path dsaKey = site.ssh_dsa;
    Path ecdsaKey_256 = site.ssh_ecdsa_256;
    Path ecdsaKey_384 = site.ssh_ecdsa_384;
    Path ecdsaKey_521 = site.ssh_ecdsa_521;
    Path ed25519Key = site.ssh_ed25519;
    final List<File> stdKeys = new ArrayList<>(6);
    if (Files.exists(rsaKey)) {
        stdKeys.add(rsaKey.toAbsolutePath().toFile());
    }
    if (Files.exists(dsaKey)) {
        stdKeys.add(dsaKey.toAbsolutePath().toFile());
    }
    if (Files.exists(ecdsaKey_256)) {
        stdKeys.add(ecdsaKey_256.toAbsolutePath().toFile());
    }
    if (Files.exists(ecdsaKey_384)) {
        stdKeys.add(ecdsaKey_384.toAbsolutePath().toFile());
    }
    if (Files.exists(ecdsaKey_521)) {
        stdKeys.add(ecdsaKey_521.toAbsolutePath().toFile());
    }
    if (Files.exists(ed25519Key)) {
        stdKeys.add(ed25519Key.toAbsolutePath().toFile());
    }
    if (Files.exists(objKey)) {
        if (stdKeys.isEmpty()) {
            SimpleGeneratorHostKeyProvider p = new SimpleGeneratorHostKeyProvider();
            p.setPath(objKey.toAbsolutePath());
            return p;
        }
        // Both formats of host key exist, we don't know which format
        // should be authoritative. Complain and abort.
        //
        stdKeys.add(objKey.toAbsolutePath().toFile());
        throw new ProvisionException("Multiple host keys exist: " + stdKeys);
    }
    if (stdKeys.isEmpty()) {
        throw new ProvisionException("No SSH keys under " + site.etc_dir);
    }
    FileKeyPairProvider kp = new FileKeyPairProvider();
    kp.setFiles(stdKeys);
    return kp;
}
Also used : Path(java.nio.file.Path) SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ProvisionException(com.google.inject.ProvisionException) FileKeyPairProvider(org.apache.sshd.common.keyprovider.FileKeyPairProvider) ArrayList(java.util.ArrayList) File(java.io.File)

Example 53 with ProvisionException

use of com.google.inject.ProvisionException in project gerrit by GerritCodeReview.

the class DataSourceProvider method open.

private DataSource open(final Config cfg, final Context context, final DataSourceType dst) {
    ConfigSection dbs = new ConfigSection(cfg, "database");
    String driver = dbs.optional("driver");
    if (Strings.isNullOrEmpty(driver)) {
        driver = dst.getDriver();
    }
    String url = dbs.optional("url");
    if (Strings.isNullOrEmpty(url)) {
        url = dst.getUrl();
    }
    String username = dbs.optional("username");
    String password = dbs.optional("password");
    String interceptor = dbs.optional("dataSourceInterceptorClass");
    boolean usePool;
    if (context == Context.SINGLE_USER) {
        usePool = false;
    } else {
        usePool = cfg.getBoolean("database", "connectionpool", dst.usePool());
    }
    if (usePool) {
        final BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        if (username != null && !username.isEmpty()) {
            ds.setUsername(username);
        }
        if (password != null && !password.isEmpty()) {
            ds.setPassword(password);
        }
        int poolLimit = threadSettingsConfig.getDatabasePoolLimit();
        ds.setMaxActive(poolLimit);
        ds.setMinIdle(cfg.getInt("database", "poolminidle", 4));
        ds.setMaxIdle(cfg.getInt("database", "poolmaxidle", Math.min(poolLimit, 16)));
        ds.setMaxWait(ConfigUtil.getTimeUnit(cfg, "database", null, "poolmaxwait", MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
        ds.setInitialSize(ds.getMinIdle());
        ds.setValidationQuery(dst.getValidationQuery());
        ds.setValidationQueryTimeout(5);
        exportPoolMetrics(ds);
        return intercept(interceptor, ds);
    }
    //
    try {
        final Properties p = new Properties();
        p.setProperty("driver", driver);
        p.setProperty("url", url);
        if (username != null) {
            p.setProperty("user", username);
        }
        if (password != null) {
            p.setProperty("password", password);
        }
        return intercept(interceptor, new SimpleDataSource(p));
    } catch (SQLException se) {
        throw new ProvisionException("Database unavailable", se);
    }
}
Also used : ProvisionException(com.google.inject.ProvisionException) SQLException(java.sql.SQLException) SimpleDataSource(com.google.gwtorm.jdbc.SimpleDataSource) ConfigSection(com.google.gerrit.server.config.ConfigSection) Properties(java.util.Properties) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 54 with ProvisionException

use of com.google.inject.ProvisionException in project gerrit by GerritCodeReview.

the class MailSoyTofuProvider method addTemplate.

private void addTemplate(SoyFileSet.Builder builder, String name) throws ProvisionException {
    // Load as a file in the mail templates directory if present.
    Path tmpl = site.mail_dir.resolve(name);
    if (Files.isRegularFile(tmpl)) {
        String content;
        // mtime.
        try (Reader r = Files.newBufferedReader(tmpl, StandardCharsets.UTF_8)) {
            content = CharStreams.toString(r);
        } catch (IOException err) {
            throw new ProvisionException("Failed to read template file " + tmpl.toAbsolutePath().toString(), err);
        }
        builder.add(content, tmpl.toAbsolutePath().toString());
        return;
    }
    // Otherwise load the template as a resource.
    String resourcePath = "com/google/gerrit/server/mail/" + name;
    builder.add(Resources.getResource(resourcePath));
}
Also used : Path(java.nio.file.Path) ProvisionException(com.google.inject.ProvisionException) Reader(java.io.Reader) IOException(java.io.IOException)

Example 55 with ProvisionException

use of com.google.inject.ProvisionException in project gerrit by GerritCodeReview.

the class VelocityRuntimeProvider method get.

@Override
public RuntimeInstance get() {
    String rl = "resource.loader";
    String pkg = "org.apache.velocity.runtime.resource.loader";
    Properties p = new Properties();
    p.setProperty(RuntimeConstants.VM_PERM_INLINE_LOCAL, "true");
    p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, Slf4jLogChute.class.getName());
    p.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, "true");
    p.setProperty("runtime.log.logsystem.log4j.category", "velocity");
    if (Files.isDirectory(site.mail_dir)) {
        p.setProperty(rl, "file, class");
        p.setProperty("file." + rl + ".class", pkg + ".FileResourceLoader");
        p.setProperty("file." + rl + ".path", site.mail_dir.toAbsolutePath().toString());
        p.setProperty("class." + rl + ".class", pkg + ".ClasspathResourceLoader");
    } else {
        p.setProperty(rl, "class");
        p.setProperty("class." + rl + ".class", pkg + ".ClasspathResourceLoader");
    }
    RuntimeInstance ri = new RuntimeInstance();
    try {
        ri.init(p);
    } catch (Exception err) {
        throw new ProvisionException("Cannot configure Velocity templates", err);
    }
    return ri;
}
Also used : ProvisionException(com.google.inject.ProvisionException) RuntimeInstance(org.apache.velocity.runtime.RuntimeInstance) Properties(java.util.Properties) ProvisionException(com.google.inject.ProvisionException)

Aggregations

ProvisionException (com.google.inject.ProvisionException)57 Injector (com.google.inject.Injector)22 AbstractModule (com.google.inject.AbstractModule)20 Module (com.google.inject.Module)11 Provider (com.google.inject.Provider)9 OutOfScopeException (com.google.inject.OutOfScopeException)6 TypeLiteral (com.google.inject.TypeLiteral)6 Key (com.google.inject.Key)5 Message (com.google.inject.spi.Message)5 ImmutableList (com.google.common.collect.ImmutableList)4 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 OrmException (com.google.gwtorm.server.OrmException)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Provides (com.google.inject.Provides)3 Dependency (com.google.inject.spi.Dependency)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 Path (java.nio.file.Path)3