use of com.google.gerrit.server.config.PluginConfig in project gerrit by GerritCodeReview.
the class JarPluginProvider method loadJarPlugin.
private ServerPlugin loadJarPlugin(String name, Path srcJar, FileSnapshot snapshot, Path tmp, PluginDescription description) throws IOException, InvalidPluginException, MalformedURLException {
JarFile jarFile = new JarFile(tmp.toFile());
boolean keep = false;
try {
Manifest manifest = jarFile.getManifest();
Plugin.ApiType type = Plugin.getApiType(manifest);
List<URL> urls = new ArrayList<>(2);
String overlay = System.getProperty("gerrit.plugin-classes");
if (overlay != null) {
Path classes = Paths.get(overlay).resolve(name).resolve("main");
if (Files.isDirectory(classes)) {
log.info(String.format("plugin %s: including %s", name, classes));
urls.add(classes.toUri().toURL());
}
}
urls.add(tmp.toUri().toURL());
ClassLoader pluginLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), PluginLoader.parentFor(type));
JarScanner jarScanner = createJarScanner(tmp);
PluginConfig pluginConfig = configFactory.getFromGerritConfig(name);
ServerPlugin plugin = new ServerPlugin(name, description.canonicalUrl, description.user, srcJar, snapshot, jarScanner, description.dataDir, pluginLoader, pluginConfig.getString("metricsPrefix", null));
plugin.setCleanupHandle(new CleanupHandle(tmp, jarFile));
keep = true;
return plugin;
} finally {
if (!keep) {
jarFile.close();
}
}
}
use of com.google.gerrit.server.config.PluginConfig in project gerrit by GerritCodeReview.
the class ProjectConfig method getPluginConfig.
public PluginConfig getPluginConfig(String pluginName) {
Config pluginConfig = pluginConfigs.get(pluginName);
if (pluginConfig == null) {
pluginConfig = new Config();
pluginConfigs.put(pluginName, pluginConfig);
}
return new PluginConfig(pluginName, pluginConfig, this);
}
use of com.google.gerrit.server.config.PluginConfig in project gerrit by GerritCodeReview.
the class PutConfig method setPluginConfigValues.
private void setPluginConfigValues(ProjectState projectState, ProjectConfig projectConfig, Map<String, Map<String, ConfigValue>> pluginConfigValues) throws BadRequestException {
for (Entry<String, Map<String, ConfigValue>> e : pluginConfigValues.entrySet()) {
String pluginName = e.getKey();
PluginConfig cfg = projectConfig.getPluginConfig(pluginName);
for (Entry<String, ConfigValue> v : e.getValue().entrySet()) {
ProjectConfigEntry projectConfigEntry = pluginConfigEntries.get(pluginName, v.getKey());
if (projectConfigEntry != null) {
if (!isValidParameterName(v.getKey())) {
log.warn(String.format("Parameter name '%s' must match '^[a-zA-Z0-9]+[a-zA-Z0-9-]*$'", v.getKey()));
continue;
}
String oldValue = cfg.getString(v.getKey());
String value = v.getValue().value;
if (projectConfigEntry.getType() == ProjectConfigEntryType.ARRAY) {
List<String> l = Arrays.asList(cfg.getStringList(v.getKey()));
oldValue = Joiner.on("\n").join(l);
value = Joiner.on("\n").join(v.getValue().values);
}
if (Strings.emptyToNull(value) != null) {
if (!value.equals(oldValue)) {
validateProjectConfigEntryIsEditable(projectConfigEntry, projectState, v.getKey(), pluginName);
v.setValue(projectConfigEntry.preUpdate(v.getValue()));
value = v.getValue().value;
try {
switch(projectConfigEntry.getType()) {
case BOOLEAN:
boolean newBooleanValue = Boolean.parseBoolean(value);
cfg.setBoolean(v.getKey(), newBooleanValue);
break;
case INT:
int newIntValue = Integer.parseInt(value);
cfg.setInt(v.getKey(), newIntValue);
break;
case LONG:
long newLongValue = Long.parseLong(value);
cfg.setLong(v.getKey(), newLongValue);
break;
case LIST:
if (!projectConfigEntry.getPermittedValues().contains(value)) {
throw new BadRequestException(String.format("The value '%s' is not permitted for parameter '%s' of plugin '" + pluginName + "'", value, v.getKey()));
}
//$FALL-THROUGH$
case STRING:
cfg.setString(v.getKey(), value);
break;
case ARRAY:
cfg.setStringList(v.getKey(), v.getValue().values);
break;
default:
log.warn(String.format("The type '%s' of parameter '%s' is not supported.", projectConfigEntry.getType().name(), v.getKey()));
}
} catch (NumberFormatException ex) {
throw new BadRequestException(String.format("The value '%s' of config parameter '%s' of plugin '%s' is invalid: %s", v.getValue(), v.getKey(), pluginName, ex.getMessage()));
}
}
} else {
if (oldValue != null) {
validateProjectConfigEntryIsEditable(projectConfigEntry, projectState, v.getKey(), pluginName);
cfg.unset(v.getKey());
}
}
} else {
throw new BadRequestException(String.format("The config parameter '%s' of plugin '%s' does not exist.", v.getKey(), pluginName));
}
}
}
}
Aggregations