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;
}
}
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;
}
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);
}
}
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));
}
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;
}
Aggregations