Search in sources :

Example 56 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 57 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)

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