Search in sources :

Example 1 with FileBasedConfig

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;
}
Also used : FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig)

Example 2 with FileBasedConfig

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);
}
Also used : Config(org.eclipse.jgit.lib.Config) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) MockSystemReader(org.eclipse.jgit.junit.MockSystemReader) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) FS(org.eclipse.jgit.util.FS) Before(org.junit.Before)

Example 3 with FileBasedConfig

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;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) Repository(org.eclipse.jgit.lib.Repository) Composite(org.eclipse.swt.widgets.Composite) ConfigurationEditorComponent(org.eclipse.egit.ui.internal.preferences.ConfigurationEditorComponent) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Example 4 with FileBasedConfig

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]);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig)

Example 5 with FileBasedConfig

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;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigChangedListener(org.eclipse.jgit.events.ConfigChangedListener) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) File(java.io.File) ConfigChangedEvent(org.eclipse.jgit.events.ConfigChangedEvent)

Aggregations

FileBasedConfig (org.eclipse.jgit.storage.file.FileBasedConfig)47 File (java.io.File)19 IOException (java.io.IOException)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)12 Config (org.eclipse.jgit.lib.Config)10 FS (org.eclipse.jgit.util.FS)7 Test (org.junit.Test)7 StoredConfig (org.eclipse.jgit.lib.StoredConfig)6 Path (java.nio.file.Path)5 Repository (org.eclipse.jgit.lib.Repository)5 SitePaths (com.google.gerrit.server.config.SitePaths)4 HashMap (java.util.HashMap)4 UserModel (com.gitblit.models.UserModel)3 FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 SystemReader (org.eclipse.jgit.util.SystemReader)3 Before (org.junit.Before)3