List of usage examples for org.eclipse.jgit.storage.file FileBasedConfig getFile
public final File getFile()
From source file:com.collabnet.gerrit.SecureStoreJasypt.java
License:Apache License
private static void saveSecure(final FileBasedConfig sec) throws IOException { if (FileUtil.modified(sec)) { final byte[] out = Constants.encode(sec.toText()); final File path = sec.getFile(); final LockFile lf = new LockFile(path, FS.DETECTED); if (!lf.lock()) { throw new IOException("Cannot lock " + path); }// ww w . j a v a 2 s.co m try { FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock")); lf.write(out); if (!lf.commit()) { throw new IOException("Cannot commit write to " + path); } } finally { lf.unlock(); } } }
From source file:com.google.gerrit.acceptance.PluginDaemonTest.java
License:Apache License
private FileBasedConfig getGerritConfigFile(SitePaths sitePath) throws IOException { FileBasedConfig cfg = new FileBasedConfig(sitePath.gerrit_config.toFile(), FS.DETECTED); if (!cfg.getFile().exists()) { Path etc_path = Files.createDirectories(sitePath.etc_dir); Files.createFile(etc_path.resolve("gerrit.config")); }/*from w w w. ja v a 2s . c o m*/ return cfg; }
From source file:com.google.gerrit.common.FileUtil.java
License:Apache License
public static boolean modified(FileBasedConfig cfg) throws IOException { byte[] curVers; try {/*from w ww . j a v a2 s .c o m*/ curVers = IO.readFully(cfg.getFile()); } catch (FileNotFoundException notFound) { return true; } byte[] newVers = Constants.encode(cfg.toText()); return !Arrays.equals(curVers, newVers); }
From source file:com.google.gerrit.pgm.init.InitUtil.java
License:Apache License
static void saveSecure(final FileBasedConfig sec) throws IOException { if (modified(sec)) { final byte[] out = Constants.encode(sec.toText()); final File path = sec.getFile(); final LockFile lf = new LockFile(path, FS.DETECTED); if (!lf.lock()) { throw new IOException("Cannot lock " + path); }/* www . j av a2s . co m*/ try { chmod(0600, new File(path.getParentFile(), path.getName() + ".lock")); lf.write(out); if (!lf.commit()) { throw new IOException("Cannot commit write to " + path); } } finally { lf.unlock(); } } }
From source file:com.google.gerrit.pgm.init.InitUtil.java
License:Apache License
private static boolean modified(FileBasedConfig cfg) throws IOException { byte[] curVers; try {// w w w . ja v a2 s . c om curVers = IO.readFully(cfg.getFile()); } catch (FileNotFoundException notFound) { return true; } byte[] newVers = Constants.encode(cfg.toText()); return !Arrays.equals(curVers, newVers); }
From source file:com.google.gerrit.server.config.GerritServerConfigModule.java
License:Apache License
private static String getSecureStoreFromGerritConfig(final Path sitePath) { AbstractModule m = new AbstractModule() { @Override/* w w w . ja va 2 s. co m*/ protected void configure() { bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath); bind(SitePaths.class); } }; Injector injector = Guice.createInjector(m); SitePaths site = injector.getInstance(SitePaths.class); FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED); if (!cfg.getFile().exists()) { return DefaultSecureStore.class.getName(); } try { cfg.load(); String className = cfg.getString("gerrit", null, "secureStoreClass"); return nullToDefault(className); } catch (IOException | ConfigInvalidException e) { throw new ProvisionException(e.getMessage(), e); } }
From source file:com.google.gerrit.server.config.GerritServerConfigProvider.java
License:Apache License
@Override public Config get() { FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED); if (!cfg.getFile().exists()) { log.info("No " + site.gerrit_config.toAbsolutePath() + "; assuming defaults"); return new GerritConfig(cfg, secureStore); }/*w w w. jav a 2 s . com*/ try { cfg.load(); } catch (IOException | ConfigInvalidException e) { throw new ProvisionException(e.getMessage(), e); } return new GerritConfig(cfg, secureStore); }
From source file:com.google.gerrit.server.config.GerritServerIdProvider.java
License:Apache License
private static Config readGerritConfig(SitePaths sitePaths) throws IOException, ConfigInvalidException { // Reread gerrit.config from disk before writing. We can't just use // cfg.toText(), as the @GerritServerConfig only has gerrit.config as a // fallback./* www .j av a 2 s . c o m*/ FileBasedConfig cfg = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED); if (!cfg.getFile().exists()) { return new Config(); } cfg.load(); return cfg; }
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 * plugin configuration file '{@code etc/<plugin-name>.config}'. * * The plugin configuration is only loaded once and is then cached. * * @param pluginName the name of the plugin for which the configuration should * be returned//from w w w . j a v a 2 s.co m * @return the plugin configuration from the * '{@code etc/<plugin-name>.config}' file */ public synchronized Config getGlobalPluginConfig(String pluginName) { if (pluginConfigs.containsKey(pluginName)) { return pluginConfigs.get(pluginName); } Path pluginConfigFile = site.etc_dir.resolve(pluginName + ".config"); FileBasedConfig cfg = new FileBasedConfig(pluginConfigFile.toFile(), FS.DETECTED); pluginConfigs.put(pluginName, cfg); if (!cfg.getFile().exists()) { log.info("No " + pluginConfigFile.toAbsolutePath() + "; assuming defaults"); return cfg; } try { cfg.load(); } catch (IOException | ConfigInvalidException e) { log.warn("Failed to load " + pluginConfigFile.toAbsolutePath(), e); } return cfg; }
From source file:com.google.gerrit.server.git.PushReplication.java
License:Apache License
private List<ReplicationConfig> allConfigs(final SitePaths site) throws ConfigInvalidException, IOException { final FileBasedConfig cfg = new FileBasedConfig(site.replication_config, FS.DETECTED); if (!cfg.getFile().exists()) { log.warn("No " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); }//from w w w. j ava 2 s. co m if (cfg.getFile().length() == 0) { log.info("Empty " + cfg.getFile() + "; not replicating"); return Collections.emptyList(); } try { cfg.load(); } catch (ConfigInvalidException e) { throw new ConfigInvalidException("Config file " + cfg.getFile() + " is invalid: " + e.getMessage(), e); } catch (IOException e) { throw new IOException("Cannot read " + cfg.getFile() + ": " + e.getMessage(), e); } final List<ReplicationConfig> r = new ArrayList<ReplicationConfig>(); for (final RemoteConfig c : allRemotes(cfg)) { if (c.getURIs().isEmpty()) { continue; } for (final URIish u : c.getURIs()) { if (u.getPath() == null || !u.getPath().contains("${name}")) { throw new ConfigInvalidException("remote." + c.getName() + ".url" + " \"" + u + "\" lacks ${name} placeholder in " + cfg.getFile()); } } // In case if refspec destination for push is not set then we assume it is // equal to source for (RefSpec ref : c.getPushRefSpecs()) { if (ref.getDestination() == null) { ref.setDestination(ref.getSource()); } } if (c.getPushRefSpecs().isEmpty()) { RefSpec spec = new RefSpec(); spec = spec.setSourceDestination("refs/*", "refs/*"); spec = spec.setForceUpdate(true); c.addPushRefSpec(spec); } r.add(new ReplicationConfig(injector, workQueue, c, cfg, database, replicationUserFactory)); } return Collections.unmodifiableList(r); }