List of usage examples for org.eclipse.jgit.internal.storage.file FileSnapshot save
public static FileSnapshot save(Instant modified)
From source file:com.google.gerrit.server.config.PluginConfigFactory.java
License:Apache License
@Inject PluginConfigFactory(SitePaths site, GerritServerConfigProvider cfgProvider, ProjectCache projectCache, ProjectState.Factory projectStateFactory) { this.site = site; this.cfgProvider = cfgProvider; this.projectCache = projectCache; this.projectStateFactory = projectStateFactory; this.pluginConfigs = Maps.newHashMap(); this.cfgSnapshot = FileSnapshot.save(site.gerrit_config.toFile()); this.cfg = cfgProvider.get(); }
From source file:com.google.gerrit.server.config.PluginConfigFactory.java
License:Apache License
/** * Returns the configuration for the specified plugin that is stored in the * 'gerrit.config' file./*from w w w. j a va2 s .c o m*/ * * The returned plugin configuration provides access to all parameters of the * 'gerrit.config' file that are set in the 'plugin' subsection of the * specified plugin. * * E.g.: [plugin "my-plugin"] myKey = myValue * * @param pluginName the name of the plugin for which the configuration should * be returned * @param refresh if <code>true</code> it is checked if the 'gerrit.config' * file was modified and if yes the Gerrit configuration is reloaded, * if <code>false</code> the cached Gerrit configuration is used * @return the plugin configuration from the 'gerrit.config' file */ public PluginConfig getFromGerritConfig(String pluginName, boolean refresh) { File configFile = site.gerrit_config.toFile(); if (refresh && cfgSnapshot.isModified(configFile)) { cfgSnapshot = FileSnapshot.save(configFile); cfg = cfgProvider.get(); } return new PluginConfig(pluginName, cfg); }
From source file:com.google.gerrit.server.plugins.PluginLoader.java
License:Apache License
public void disablePlugins(Set<String> names) { if (!isRemoteAdminEnabled()) { log.warn("Remote plugin administration is disabled," + " ignoring disablePlugins(" + names + ")"); return;//from ww w . ja v a 2s. c o m } synchronized (this) { for (String name : names) { Plugin active = running.get(name); if (active == null) { continue; } log.info(String.format("Disabling plugin %s", active.getName())); Path off = active.getSrcFile().resolveSibling(active.getSrcFile().getFileName() + ".disabled"); try { Files.move(active.getSrcFile(), off); } catch (IOException e) { log.error("Failed to disable plugin", e); // In theory we could still unload the plugin even if the rename // failed. However, it would be reloaded on the next server startup, // which is probably not what the user expects. continue; } unloadPlugin(active); try { FileSnapshot snapshot = FileSnapshot.save(off.toFile()); Plugin offPlugin = loadPlugin(name, off, snapshot); disabled.put(name, offPlugin); } catch (Throwable e) { // This shouldn't happen, as the plugin was loaded earlier. log.warn(String.format("Cannot load disabled plugin %s", active.getName()), e.getCause()); } } cleanInBackground(); } }
From source file:com.google.gerrit.server.plugins.PluginLoader.java
License:Apache License
private Plugin runPlugin(String name, Path plugin, Plugin oldPlugin) throws PluginInstallException { FileSnapshot snapshot = FileSnapshot.save(plugin.toFile()); try {//from ww w . ja v a 2 s. c o m Plugin newPlugin = loadPlugin(name, plugin, snapshot); if (newPlugin.getCleanupHandle() != null) { cleanupHandles.put(newPlugin, newPlugin.getCleanupHandle()); } /* * Pluggable plugin provider may have assigned a plugin name that could be * actually different from the initial one assigned during scan. It is * safer then to reassign it. */ name = newPlugin.getName(); boolean reload = oldPlugin != null && oldPlugin.canReload() && newPlugin.canReload(); if (!reload && oldPlugin != null) { unloadPlugin(oldPlugin); } if (!newPlugin.isDisabled()) { newPlugin.start(env); } if (reload) { env.onReloadPlugin(oldPlugin, newPlugin); unloadPlugin(oldPlugin); } else if (!newPlugin.isDisabled()) { env.onStartPlugin(newPlugin); } if (!newPlugin.isDisabled()) { running.put(name, newPlugin); } else { disabled.put(name, newPlugin); } broken.remove(name); return newPlugin; } catch (Throwable err) { broken.put(name, snapshot); throw new PluginInstallException(err); } }