Search in sources :

Example 26 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gitiles by GerritCodeReview.

the class PathServlet method showGitlink.

private void showGitlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    String modulesUrl;
    String remoteUrl = null;
    try (SubmoduleWalk sw = SubmoduleWalk.forPath(ServletUtils.getRepository(req), wr.root, view.getPathPart())) {
        modulesUrl = sw.getModulesUrl();
        if (modulesUrl != null && (modulesUrl.startsWith("./") || modulesUrl.startsWith("../"))) {
            String moduleRepo = PathUtil.simplifyPathUpToRoot(modulesUrl, view.getRepositoryName());
            if (moduleRepo != null) {
                modulesUrl = urls.getBaseGitUrl(req) + moduleRepo;
            }
        } else {
            remoteUrl = sw.getRemoteUrl();
        }
    } catch (ConfigInvalidException e) {
        throw new IOException(e);
    }
    Map<String, Object> data = Maps.newHashMap();
    data.put("sha", ObjectId.toString(wr.id));
    data.put("remoteUrl", remoteUrl != null ? remoteUrl : modulesUrl);
    // TODO(dborowitz): Guess when we can put commit SHAs in the URL.
    String httpUrl = resolveHttpUrl(remoteUrl);
    if (httpUrl != null) {
        data.put("httpUrl", httpUrl);
    }
    // TODO(sop): Allow caching links by SHA-1 when no S cookie is sent.
    renderHtml(req, res, "gitiles.pathDetail", ImmutableMap.of("title", view.getPathPart(), "type", FileType.GITLINK.toString(), "data", data));
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevObject(org.eclipse.jgit.revwalk.RevObject) QuotedString(org.eclipse.jgit.util.QuotedString) IOException(java.io.IOException) SubmoduleWalk(org.eclipse.jgit.submodule.SubmoduleWalk)

Example 27 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gitiles by GerritCodeReview.

the class DefaultAccess method loadDescriptionText.

private String loadDescriptionText(Repository repo) throws IOException {
    String desc = null;
    StoredConfig config = repo.getConfig();
    IOException configError = null;
    try {
        config.load();
        desc = config.getString("gitweb", null, "description");
    } catch (ConfigInvalidException e) {
        configError = new IOException(e);
    }
    if (desc == null) {
        File descFile = new File(repo.getDirectory(), "description");
        if (descFile.exists()) {
            desc = new String(IO.readFully(descFile));
            if (DEFAULT_DESCRIPTION.equals(CharMatcher.whitespace().trimFrom(desc))) {
                desc = null;
            }
        } else if (configError != null) {
            throw configError;
        }
    }
    return desc;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) File(java.io.File)

Example 28 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException 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 29 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project egit by eclipse.

the class ConfigurationEditorComponent method restore.

/**
 * Restores and (in case of success) reloads the current configuration
 *
 * @throws IOException
 */
public void restore() throws IOException {
    try {
        editableConfig.clear();
        editableConfig.load();
    } catch (ConfigInvalidException e) {
        throw new IOException(e.getMessage());
    }
    initControlsFromConfig();
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException)

Example 30 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project egit by eclipse.

the class ConfigurationEditorComponent method setConfig.

void setConfig(FileBasedConfig config) throws IOException {
    editableConfig = config;
    try {
        editableConfig.clear();
        editableConfig.load();
    } catch (ConfigInvalidException e) {
        throw new IOException(e.getMessage());
    }
    initControlsFromConfig();
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException)

Aggregations

ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)158 IOException (java.io.IOException)95 Inject (com.google.inject.Inject)38 Repository (org.eclipse.jgit.lib.Repository)37 Provider (com.google.inject.Provider)34 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)31 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)30 ArrayList (java.util.ArrayList)30 Account (com.google.gerrit.entities.Account)27 List (java.util.List)26 Set (java.util.Set)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 AuthException (com.google.gerrit.extensions.restapi.AuthException)25 Config (org.eclipse.jgit.lib.Config)24 Singleton (com.google.inject.Singleton)23 OrmException (com.google.gwtorm.server.OrmException)22 AccountGroup (com.google.gerrit.entities.AccountGroup)21 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 StorageException (com.google.gerrit.exceptions.StorageException)20 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)20