List of usage examples for org.eclipse.jgit.util FS DETECTED
FS DETECTED
To view the source code for org.eclipse.jgit.util FS DETECTED.
Click Source Link
From source file:au.id.soundadvice.systemdesign.versioning.jgit.GitVersionControl.java
License:Open Source License
public GitVersionControl(Path path) throws IOException { try {//from ww w. j a va2 s . c o m // Cribbed from Git.open, but with findGitDir rather than setGitDir // and extracting the location. FS fs = FS.DETECTED; RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(path.toFile(), fs); RepositoryBuilder builder = new RepositoryBuilder().setFS(fs).findGitDir(key.getFile()) .setMustExist(true); repositoryRoot = Paths.get(builder.getGitDir().getAbsolutePath()).getParent(); repo = new Git(builder.build()); checkCSVMergeDriver(repositoryRoot); } catch (RuntimeException ex) { throw new IOException(ex); } }
From source file:com.bacoder.scmtools.git.internal.InMemoryRepository.java
License:Apache License
@Override public FS getFS() { return FS.DETECTED; }
From source file:com.collabnet.gerrit.SecureStoreJasypt.java
License:Apache License
@Inject SecureStoreJasypt(SitePaths site) {//from ww w . jav a 2 s .c o m File secureConfig = new File(site.etc_dir, "secure.config"); if (!secureConfig.exists()) { try { if (!site.etc_dir.exists()) { Files.createDirectories(site.etc_dir.toPath()); } Files.createFile(secureConfig.toPath()); } catch (IOException e) { throw new RuntimeException("Cannot create: " + secureConfig.getAbsolutePath(), e); } } sec = new FileBasedConfig(secureConfig, FS.DETECTED); encryptor = new StandardPBEStringEncryptor(); encryptor.setPassword("8f(_^?2|#D/z->^4(>~(/y|3{7?^<J"); encryptor.setAlgorithm("PBEWithMD5AndTripleDES"); encryptor.setSaltGenerator(new StringFixedSaltGenerator("Kucudra4")); try { sec.load(); } catch (Exception e) { throw new RuntimeException("Cannot load secure.config", e); } }
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); }/*from ww w .j a v a 2 s . c o 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.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.java
License:Apache License
public static GitAttributesLineEndingPolicy create(File rootFolder) { return Errors.rethrow().get(() -> { FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.findGitDir(rootFolder);/*from w w w . j a v a 2 s.co m*/ if (builder.getGitDir() != null) { // we found a repository, so we can grab all the values we need from it Repository repo = builder.build(); AttributesNodeProvider nodeProvider = repo.createAttributesNodeProvider(); Function<AttributesNode, List<AttributesRule>> getRules = node -> node == null ? Collections.emptyList() : node.getRules(); return new GitAttributesLineEndingPolicy(repo.getConfig(), getRules.apply(nodeProvider.getInfoAttributesNode()), repo.getWorkTree(), getRules.apply(nodeProvider.getGlobalAttributesNode())); } else { // there's no repo, so it takes some work to grab the system-wide values Config systemConfig = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED); Config userConfig = SystemReader.getInstance().openUserConfig(systemConfig, FS.DETECTED); if (userConfig == null) { userConfig = new Config(); } List<AttributesRule> globalRules = Collections.emptyList(); // copy-pasted from org.eclipse.jgit.lib.CoreConfig String globalAttributesPath = userConfig.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); // copy-pasted from org.eclipse.jgit.internal.storage.file.GlobalAttributesNode if (globalAttributesPath != null) { FS fs = FS.detect(); File attributesFile; if (globalAttributesPath.startsWith("~/")) { //$NON-NLS-1$ attributesFile = fs.resolve(fs.userHome(), globalAttributesPath.substring(2)); } else { attributesFile = fs.resolve(null, globalAttributesPath); } globalRules = parseRules(attributesFile); } return new GitAttributesLineEndingPolicy(userConfig, // no git info file Collections.emptyList(), null, globalRules); } }); }
From source file:com.ericsson.gerrit.plugins.highavailability.Setup.java
License:Apache License
@Override public void run() throws Exception { ui.message("\n"); ui.header("%s Plugin", pluginName); if (ui.yesno(true, "Configure %s", pluginName)) { ui.header("Configuring %s", pluginName); Path pluginConfigFile = site.etc_dir.resolve(pluginName + ".config"); config = new FileBasedConfig(pluginConfigFile.toFile(), FS.DETECTED); config.load();/* w w w . j a v a 2 s . c o m*/ configureHttp(); configureCacheSection(); configureIndexSection(); configureWebsessionsSection(); if (!createHAReplicaSite(config)) { configureMainSection(); configurePeerInfoSection(); config.save(); } flags.cfg.setBoolean("database", "h2", "autoServer", true); } }
From source file:com.ericsson.gerrit.plugins.highavailability.SetupLocalHAReplica.java
License:Apache License
void run(SitePaths replica, FileBasedConfig pluginConfig) throws IOException, ConfigInvalidException { this.replicaSitePaths = replica; FileUtil.mkdirsOrDie(replicaSitePaths.site_path, "cannot create " + replicaSitePaths.site_path); configureMainSection(pluginConfig);/*from w w w . jav a2 s .co m*/ configurePeerInfo(pluginConfig); for (Path dir : listDirsForCopy()) { copyFiles(dir); } mkdir(replicaSitePaths.logs_dir); mkdir(replicaSitePaths.tmp_dir); symlink(Paths.get(masterConfig.getString("gerrit", null, "basePath"))); symlink(sharedDir); FileBasedConfig replicaConfig = new FileBasedConfig(replicaSitePaths.gerrit_config.toFile(), FS.DETECTED); replicaConfig.load(); if ("h2".equals(masterConfig.getString(DATABASE, null, "type"))) { masterConfig.setBoolean(DATABASE, "h2", "autoServer", true); replicaConfig.setBoolean(DATABASE, "h2", "autoServer", true); symlinkH2ReviewDbDir(); } }
From source file:com.ericsson.gerrit.plugins.projectgroupstructure.DefaultAccessRights.java
License:Apache License
@Inject public DefaultAccessRights(MetaDataUpdate.User metaDataUpdateFactory, ProjectCache projectCache, GroupCache groupCache, @PluginData Path dataDir) { this.groupCache = groupCache; this.projectCache = projectCache; this.metaDataUpdateFactory = metaDataUpdateFactory; defaultAccessRightsConfig = new FileBasedConfig(dataDir.resolve(ProjectConfig.PROJECT_CONFIG).toFile(), FS.DETECTED); try {// w ww . j a v a 2 s. co m defaultAccessRightsConfig.load(); } catch (IOException | ConfigInvalidException e) { // Swallow the exception to allow the plugin to load, we still want the // project structure to be enforced even if defaults access rights will // not be set. log.error( "Failed to load default access rights config {}, no access right will be set on root projects: {}", defaultAccessRightsConfig.getFile().getAbsolutePath(), e.getMessage(), e); } }
From source file:com.genuitec.eclipse.gerrit.tools.utils.RepositoryUtils.java
License:Open Source License
public static String getUserId(Repository repository) { StoredConfig config;/*from ww w.ja v a 2 s . com*/ if (repository == null) { if (StringUtils.isEmptyOrNull(SystemReader.getInstance().getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))) { config = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED); } else { config = new FileBasedConfig(null, FS.DETECTED) { public void load() { // empty, do not load } public boolean isOutdated() { // regular class would bomb here return false; } }; } try { config.load(); config = SystemReader.getInstance().openUserConfig(config, FS.DETECTED); config.load(); } catch (Exception ex) { throw new RuntimeException(ex); } } else { config = repository.getConfig(); } String email = config.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$ if (email != null) { int ind = email.indexOf('@'); if (ind > 0) { return email.substring(0, ind); } } return null; }
From source file:com.gitblit.AddIndexedBranch.java
License:Apache License
public static void main(String... args) { Params params = new Params(); CmdLineParser parser = new CmdLineParser(params); try {/* www . j ava 2 s.c o m*/ parser.parseArgument(args); } catch (CmdLineException t) { System.err.println(t.getMessage()); parser.printUsage(System.out); return; } // create a lowercase set of excluded repositories Set<String> exclusions = new TreeSet<String>(); for (String exclude : params.exclusions) { exclusions.add(exclude.toLowerCase()); } // determine available repositories File folder = new File(params.folder); List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1, null); int modCount = 0; int skipCount = 0; for (String repo : repoList) { boolean skip = false; for (String exclusion : exclusions) { if (StringUtils.fuzzyMatch(repo, exclusion)) { skip = true; break; } } if (skip) { System.out.println("skipping " + repo); skipCount++; continue; } try { // load repository config File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED); Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); StoredConfig config = repository.getConfig(); config.load(); Set<String> indexedBranches = new LinkedHashSet<String>(); // add all local branches to index if (params.addAllLocalBranches) { List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1); for (RefModel refModel : list) { System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo)); indexedBranches.add(refModel.getName()); } } else { // add only one branch to index ('default' if not specified) System.out.println( MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo)); indexedBranches.add(params.branch); } String[] branches = config.getStringList("gitblit", null, "indexBranch"); if (!ArrayUtils.isEmpty(branches)) { for (String branch : branches) { indexedBranches.add(branch); } } config.setStringList("gitblit", null, "indexBranch", new ArrayList<String>(indexedBranches)); config.save(); modCount++; } catch (Exception e) { System.err.println(repo); e.printStackTrace(); } } System.out.println( MessageFormat.format("updated {0} repository configurations, skipped {1}", modCount, skipCount)); }