use of org.eclipse.jgit.storage.file.FileBasedConfig in project gitiles by GerritCodeReview.
the class GitilesConfig method loadDefault.
public static Config loadDefault(FilterConfig filterConfig) throws IOException, ConfigInvalidException {
FileBasedConfig config = new FileBasedConfig(defaultFile(filterConfig), FS.DETECTED);
config.load();
return config;
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project egit by eclipse.
the class GitTestCase method setUp.
@Before
public void setUp() throws Exception {
// ensure there are no shared Repository instances left
// when starting a new test
Activator.getDefault().getRepositoryCache().clear();
File configFile = File.createTempFile("gitconfigtest", "config");
MockSystemReader mockSystemReader = new MockSystemReader() {
@Override
public FileBasedConfig openUserConfig(Config parent, FS fs) {
return new FileBasedConfig(parent, configFile, fs);
}
};
configFile.deleteOnExit();
SystemReader.setInstance(mockSystemReader);
mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getParentFile().getAbsoluteFile().toString());
FileBasedConfig userConfig = mockSystemReader.openUserConfig(null, FS.DETECTED);
// We have to set autoDetach to false for tests, because tests expect to
// be able to clean up by recursively removing the repository, and
// background GC might be in the middle of writing or deleting files,
// which would disrupt this.
userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
userConfig.save();
project = new TestProject(true);
gitDir = new File(project.getProject().getWorkspace().getRoot().getRawLocation().toFile(), Constants.DOT_GIT);
if (gitDir.exists())
FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project egit by eclipse.
the class RepositoryPropertyPage method createContents.
@Override
protected Control createContents(Composite parent) {
Composite displayArea = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(displayArea);
GridDataFactory.fillDefaults().applyTo(displayArea);
final Repository repo = AdapterUtils.adapt(getElement(), Repository.class);
if (repo == null)
return displayArea;
StoredConfig config = repo.getConfig();
if (config instanceof FileBasedConfig) {
File configFile = ((FileBasedConfig) config).getFile();
config = new FileBasedConfig(configFile, repo.getFS());
config.addChangeListener(new ConfigChangedListener() {
@Override
public void onConfigChanged(ConfigChangedEvent event) {
repo.fireEvent(new ConfigChangedEvent());
}
});
}
editor = new ConfigurationEditorComponent(displayArea, config, true) {
@Override
protected void setErrorMessage(String message) {
RepositoryPropertyPage.this.setErrorMessage(message);
}
};
editor.createContents();
return displayArea;
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project egit by eclipse.
the class RepositoryPropertySource method getPropertyDescriptors.
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
try {
systemConfig.load();
userHomeConfig.load();
repositoryConfig.load();
effectiveConfig.load();
} catch (IOException e) {
showExceptionMessage(e);
} catch (ConfigInvalidException e) {
showExceptionMessage(e);
}
List<IPropertyDescriptor> resultList = new ArrayList<>();
StoredConfig config;
String category;
String prefix;
boolean recursive = false;
switch(getCurrentMode()) {
case EFFECTIVE:
prefix = EFFECTIVE_ID_PREFIX;
category = UIText.RepositoryPropertySource_EffectiveConfigurationCategory;
config = effectiveConfig;
recursive = true;
break;
case REPO:
{
prefix = REPO_ID_PREFIX;
// $NON-NLS-1$
String location = "";
if (repositoryConfig instanceof FileBasedConfig) {
location = ((FileBasedConfig) repositoryConfig).getFile().getAbsolutePath();
}
category = NLS.bind(UIText.RepositoryPropertySource_RepositoryConfigurationCategory, location);
config = repositoryConfig;
break;
}
case USER:
{
prefix = USER_ID_PREFIX;
String location = userHomeConfig.getFile().getAbsolutePath();
category = NLS.bind(UIText.RepositoryPropertySource_GlobalConfigurationCategory, location);
config = userHomeConfig;
break;
}
case SYSTEM:
{
prefix = SYSTEM_ID_PREFIX;
if (systemConfig.getFile() == null) {
return new IPropertyDescriptor[0];
}
String location = systemConfig.getFile().getAbsolutePath();
category = NLS.bind(UIText.RepositoryPropertySource_GlobalConfigurationCategory, location);
config = systemConfig;
break;
}
default:
return new IPropertyDescriptor[0];
}
for (String key : config.getSections()) {
for (String sectionItem : config.getNames(key, recursive)) {
// $NON-NLS-1$
String sectionId = key + "." + sectionItem;
PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
desc.setCategory(category);
resultList.add(desc);
}
for (String sub : config.getSubsections(key)) {
for (String sectionItem : config.getNames(key, sub, recursive)) {
// $NON-NLS-1$ //$NON-NLS-2$
String sectionId = key + "." + sub + "." + sectionItem;
PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
desc.setCategory(category);
resultList.add(desc);
}
}
}
return resultList.toArray(new IPropertyDescriptor[0]);
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project egit by eclipse.
the class GlobalConfigurationPreferencePage method createConfigurationEditor.
private ConfigurationEditorComponent createConfigurationEditor(final Repository repository) {
StoredConfig repositoryConfig;
if (repository.getConfig() instanceof FileBasedConfig) {
File configFile = ((FileBasedConfig) repository.getConfig()).getFile();
repositoryConfig = new FileBasedConfig(configFile, repository.getFS());
repositoryConfig.addChangeListener(new ConfigChangedListener() {
@Override
public void onConfigChanged(ConfigChangedEvent event) {
repository.getListenerList().dispatch(new ConfigChangedEvent());
}
});
} else {
repositoryConfig = repository.getConfig();
}
ConfigurationEditorComponent editorComponent = new ConfigurationEditorComponent(repoConfigComposite, repositoryConfig, true) {
@Override
protected void setErrorMessage(String message) {
GlobalConfigurationPreferencePage.this.setErrorMessage(message);
}
@Override
protected void setDirty(boolean dirty) {
if (dirty)
dirtyRepositories.add(repository);
else
dirtyRepositories.remove(repository);
updateApplyButton();
}
};
editorComponent.createContents();
return editorComponent;
}
Aggregations