use of org.eclipse.jgit.errors.ConfigInvalidException in project gitblit by gitblit.
the class BugtraqConfig method read.
// Static =================================================================
@Nullable
public static BugtraqConfig read(@NotNull Repository repository) throws IOException, ConfigInvalidException {
Config baseConfig = getBaseConfig(repository, DOT_GIT_BUGTRAQ);
if (baseConfig == null) {
baseConfig = getBaseConfig(repository, DOT_TGITCONFIG);
}
final Set<String> allNames = new HashSet<String>();
final Config config;
try {
config = repository.getConfig();
} catch (RuntimeException ex) {
final Throwable cause = ex.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw ex;
}
if (getString(null, URL, config, baseConfig) != null) {
allNames.add(null);
} else {
allNames.addAll(config.getSubsections(BUGTRAQ));
if (baseConfig != null) {
allNames.addAll(baseConfig.getSubsections(BUGTRAQ));
}
}
final List<BugtraqEntry> entries = new ArrayList<BugtraqEntry>();
for (String name : allNames) {
final String url = getString(name, URL, config, baseConfig);
if (url == null) {
continue;
}
final String enabled = getString(name, ENABLED, config, baseConfig);
if (enabled != null && !"true".equals(enabled)) {
continue;
}
String idRegex = getString(name, LOG_REGEX, config, baseConfig);
if (idRegex == null) {
return null;
}
String filterRegex = getString(name, LOG_FILTERREGEX, config, baseConfig);
final String linkRegex = getString(name, LOG_LINKREGEX, config, baseConfig);
if (filterRegex == null && linkRegex == null) {
final String[] split = idRegex.split("\n", Integer.MAX_VALUE);
if (split.length == 2) {
// Compatibility with TortoiseGit
filterRegex = split[0];
idRegex = split[1];
} else {
// Backwards compatibility with specification version < 0.3
final List<String> logIdRegexs = new ArrayList<String>();
for (int index = 1; index < Integer.MAX_VALUE; index++) {
final String logIdRegexN = getString(name, LOG_REGEX + index, config, baseConfig);
if (logIdRegexN == null) {
break;
}
logIdRegexs.add(logIdRegexN);
}
if (logIdRegexs.size() > 1) {
throw new ConfigInvalidException("More than three " + LOG_REGEX + " entries found. This is not supported anymore since bugtraq version 0.3, use " + LOG_FILTERREGEX + " and " + LOG_LINKREGEX + " instead.");
} else if (logIdRegexs.size() == 1) {
filterRegex = idRegex;
idRegex = logIdRegexs.get(0);
}
}
}
final String linkText = getString(name, LOG_LINKTEXT, config, baseConfig);
entries.add(new BugtraqEntry(url, idRegex, linkRegex, filterRegex, linkText));
}
if (entries.isEmpty()) {
return null;
}
return new BugtraqConfig(entries);
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gitblit by gitblit.
the class BugtraqProcessor method processTextRegex.
/**
* Apply globally or per-repository specified regex substitutions to the
* text.
*
* @param repository
* @param repositoryName
* @param text
* @return the processed text
*/
protected String processTextRegex(Repository repository, String repositoryName, String text) {
Map<String, String> map = new HashMap<String, String>();
// global regex keys
if (settings.getBoolean(Keys.regex.global, false)) {
for (String key : settings.getAllKeys(Keys.regex.global)) {
if (!key.equals(Keys.regex.global)) {
String subKey = key.substring(key.lastIndexOf('.') + 1);
map.put(subKey, settings.getString(key, ""));
}
}
}
// repository-specific regex keys
List<String> keys = settings.getAllKeys(Keys.regex._ROOT + "." + repositoryName.toLowerCase());
for (String key : keys) {
String subKey = key.substring(key.lastIndexOf('.') + 1);
map.put(subKey, settings.getString(key, ""));
}
for (Entry<String, String> entry : map.entrySet()) {
String definition = entry.getValue().trim();
String[] chunks = definition.split("!!!");
if (chunks.length == 2) {
text = text.replaceAll(chunks[0], chunks[1]);
} else {
logger.warn(entry.getKey() + " improperly formatted. Use !!! to separate match from replacement: " + definition);
}
}
try {
// parse bugtraq repo config
BugtraqConfig config = BugtraqConfig.read(repository);
if (config != null) {
BugtraqFormatter formatter = new BugtraqFormatter(config);
StringBuilder sb = new StringBuilder();
formatter.formatLogMessage(text, new BugtraqOutputHandler(sb));
text = sb.toString();
}
} catch (IOException e) {
logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
} catch (ConfigInvalidException e) {
logger.error(MessageFormat.format("Bugtraq config for {0} is invalid!", repositoryName), e);
}
return text;
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class ExternalIdCacheImpl method get.
/**
* Returns the cached value or a freshly loaded value that will be cached with this call in case
* the value was absent from the cache.
*
* <p>This method will load the value using {@link ExternalIdCacheLoader} in case it is not
* already cached. {@link ExternalIdCacheLoader} requires loading older versions of the cached
* value and Caffeine does not support recursive calls to the cache from loaders. Hence, we use a
* Cache instead of a LoadingCache and perform the loading ourselves here similar to what a
* loading cache would do.
*/
private AllExternalIds get(ObjectId rev) throws IOException {
AllExternalIds cachedValue = extIdsByAccount.getIfPresent(rev);
if (cachedValue != null) {
return cachedValue;
}
// Load the value and put it in the cache.
lock.lock();
try {
// Check if value was already loaded while waiting for the lock.
cachedValue = extIdsByAccount.getIfPresent(rev);
if (cachedValue != null) {
return cachedValue;
}
AllExternalIds newlyLoadedValue;
try {
newlyLoadedValue = externalIdCacheLoader.load(rev);
} catch (ConfigInvalidException e) {
throw new IOException("Cannot load external ids", e);
}
extIdsByAccount.put(rev, newlyLoadedValue);
return newlyLoadedValue;
} finally {
lock.unlock();
}
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class ExternalIdsConsistencyChecker method check.
private List<ConsistencyProblemInfo> check(ExternalIdNotes extIdNotes) throws IOException {
List<ConsistencyProblemInfo> problems = new ArrayList<>();
ListMultimap<String, ExternalId> emails = MultimapBuilder.hashKeys().arrayListValues().build();
try (RevWalk rw = new RevWalk(extIdNotes.getRepository())) {
NoteMap noteMap = extIdNotes.getNoteMap();
for (Note note : noteMap) {
byte[] raw = ExternalIdNotes.readNoteData(rw, note.getData());
try {
ExternalId extId = externalIdFactory.parse(note.getName(), raw, note.getData());
problems.addAll(validateExternalId(extId));
if (extId.email() != null) {
String email = extId.email();
if (emails.get(email).stream().noneMatch(e -> e.accountId().get() == extId.accountId().get())) {
emails.put(email, extId);
}
}
} catch (ConfigInvalidException e) {
addError(String.format(e.getMessage()), problems);
}
}
}
emails.asMap().entrySet().stream().filter(e -> e.getValue().size() > 1).forEach(e -> addError(String.format("Email '%s' is not unique, it's used by the following external IDs: %s", e.getKey(), e.getValue().stream().map(k -> "'" + k.key().get() + "'").sorted().collect(joining(", "))), problems));
return problems;
}
use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.
the class ExternalIdCaseSensitivityMigrator method migrate.
public void migrate(Collection<ExternalId> todo, Runnable monitor) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
try (Repository repo = repoManager.openRepository(allUsersName)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
for (ExternalId extId : todo) {
recomputeExternalIdNoteId(extIdNotes, extId);
monitor.run();
}
if (!dryRun) {
try (MetaDataUpdate metaDataUpdate = metaDataUpdateServerFactory.get().create(allUsersName)) {
metaDataUpdate.setMessage(String.format("Migration to case %ssensitive usernames", isUserNameCaseInsensitive ? "" : "in"));
extIdNotes.commit(metaDataUpdate);
} catch (Exception e) {
logger.atSevere().withCause(e).log("%s", e.getMessage());
}
}
} catch (DuplicateExternalIdKeyException e) {
logger.atSevere().withCause(e).log("%s", e.getMessage());
throw e;
}
}
Aggregations