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));
}
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;
}
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]);
}
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();
}
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();
}
Aggregations