Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Use Logger's built-in string formatting where possible
  Doc: Fix code example in JS API

Change-Id: I1b953b6d9ab5cd066b8b6f43bb1843dcb1736d1b
This commit is contained in:
David Pursehouse
2018-05-23 20:17:58 +09:00
26 changed files with 116 additions and 124 deletions

View File

@@ -769,7 +769,7 @@ Gerrit.get(url, callback)
---- ----
Gerrit.get('/changes/?q=status:open', function (open) { Gerrit.get('/changes/?q=status:open', function (open) {
for (var i = 0; i < open.length; i++) { for (var i = 0; i < open.length; i++) {
console.log(open.get(i).change_id); console.log(open[i].change_id);
} }
}); });
---- ----

View File

@@ -191,7 +191,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
try { try {
filter = plugin.getHttpInjector().getInstance(GuiceFilter.class); filter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
} catch (RuntimeException e) { } catch (RuntimeException e) {
log.warn(String.format("Plugin %s cannot load GuiceFilter", name), e); log.warn("Plugin {} cannot load GuiceFilter", name, e);
return null; return null;
} }
@@ -199,7 +199,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
ServletContext ctx = PluginServletContext.create(plugin, wrapper.getFullPath(name)); ServletContext ctx = PluginServletContext.create(plugin, wrapper.getFullPath(name));
filter.init(new WrappedFilterConfig(ctx)); filter.init(new WrappedFilterConfig(ctx));
} catch (ServletException e) { } catch (ServletException e) {
log.warn(String.format("Plugin %s failed to initialize HTTP", name), e); log.warn("Plugin {} failed to initialize HTTP", name, e);
return null; return null;
} }
@@ -430,10 +430,11 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
&& size.isPresent()) { && size.isPresent()) {
if (size.get() <= 0 || size.get() > SMALL_RESOURCE) { if (size.get() <= 0 || size.get() > SMALL_RESOURCE) {
log.warn( log.warn(
String.format( "Plugin {}: {} omitted from document index. Size {} out of range (0,{}).",
"Plugin %s: %s omitted from document index. " pluginName,
+ "Size %d out of range (0,%d).", name.substring(prefix.length()),
pluginName, name.substring(prefix.length()), size.get(), SMALL_RESOURCE)); size.get(),
SMALL_RESOURCE);
return false; return false;
} }
return true; return true;
@@ -456,9 +457,9 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
about = entry; about = entry;
} else { } else {
log.warn( log.warn(
String.format( "Plugin {}: Multiple 'about' documents found; using {}",
"Plugin %s: Multiple 'about' documents found; using %s", pluginName,
pluginName, about.getName().substring(prefix.length()))); about.getName().substring(prefix.length()));
} }
} else { } else {
docs.add(entry); docs.add(entry);
@@ -736,9 +737,7 @@ class HttpPluginServlet extends HttpServlet implements StartPluginListener, Relo
} }
return def; return def;
} catch (IOException e) { } catch (IOException e) {
log.warn( log.warn("Error getting {} for plugin {}, using default", attr, plugin.getName(), e);
String.format("Error getting %s for plugin %s, using default", attr, plugin.getName()),
e);
return null; return null;
} }
} }

View File

@@ -139,7 +139,7 @@ public class LfsPluginServlet extends HttpServlet
try { try {
guiceFilter = plugin.getHttpInjector().getInstance(GuiceFilter.class); guiceFilter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
} catch (RuntimeException e) { } catch (RuntimeException e) {
log.warn(String.format("Plugin %s cannot load GuiceFilter", name), e); log.warn("Plugin {} cannot load GuiceFilter", name, e);
return null; return null;
} }
@@ -147,7 +147,7 @@ public class LfsPluginServlet extends HttpServlet
ServletContext ctx = PluginServletContext.create(plugin, "/"); ServletContext ctx = PluginServletContext.create(plugin, "/");
guiceFilter.init(new WrappedFilterConfig(ctx)); guiceFilter.init(new WrappedFilterConfig(ctx));
} catch (ServletException e) { } catch (ServletException e) {
log.warn(String.format("Plugin %s failed to initialize HTTP", name), e); log.warn("Plugin {} failed to initialize HTTP", name, e);
return null; return null;
} }

View File

@@ -155,7 +155,7 @@ class PluginServletContext {
@Override @Override
public void log(String msg, Throwable reason) { public void log(String msg, Throwable reason) {
log.warn(String.format("[plugin %s] %s", plugin.getName(), msg), reason); log.warn("[plugin {}] {}", plugin.getName(), msg, reason);
} }
@Override @Override

View File

@@ -161,7 +161,7 @@ public abstract class ResourceServlet extends HttpServlet {
r = cache.get(p, newLoader(p)); r = cache.get(p, newLoader(p));
} }
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn("Cannot load static resource " + req.getPathInfo(), e); log.warn("Cannot load static resource {}", req.getPathInfo(), e);
CacheHeaders.setNotCacheable(rsp); CacheHeaders.setNotCacheable(rsp);
rsp.setStatus(SC_INTERNAL_SERVER_ERROR); rsp.setStatus(SC_INTERNAL_SERVER_ERROR);
return; return;
@@ -214,12 +214,12 @@ public abstract class ResourceServlet extends HttpServlet {
try { try {
Path p = getResourcePath(name); Path p = getResourcePath(name);
if (p == null) { if (p == null) {
log.warn(String.format("Path doesn't exist %s", name)); log.warn("Path doesn't exist {}", name);
return null; return null;
} }
return cache.get(p, newLoader(p)); return cache.get(p, newLoader(p));
} catch (ExecutionException | IOException e) { } catch (ExecutionException | IOException e) {
log.warn(String.format("Cannot load static resource %s", name), e); log.warn("Cannot load static resource {}", name, e);
return null; return null;
} }
} }

View File

@@ -1172,7 +1172,7 @@ public class RestApiServlet extends HttpServlet {
if (!Strings.isNullOrEmpty(req.getQueryString())) { if (!Strings.isNullOrEmpty(req.getQueryString())) {
uri += "?" + req.getQueryString(); uri += "?" + req.getQueryString();
} }
log.error(String.format("Error in %s %s", req.getMethod(), uri), err); log.error("Error in {} {}", req.getMethod(), uri, err);
if (!res.isCommitted()) { if (!res.isCommitted()) {
res.reset(); res.reset();

View File

@@ -184,7 +184,7 @@ public class Schema<T> {
try { try {
v = f.get(obj); v = f.get(obj);
} catch (OrmException e) { } catch (OrmException e) {
log.error(String.format("error getting field %s of %s", f.getName(), obj), e); log.error("error getting field {} of {}", f.getName(), obj, e);
return null; return null;
} }
if (v == null) { if (v == null) {

View File

@@ -68,7 +68,7 @@ public class SwitchSecureStore extends SiteProgram {
SitePaths sitePaths = new SitePaths(getSitePath()); SitePaths sitePaths = new SitePaths(getSitePath());
Path newSecureStorePath = Paths.get(newSecureStoreLib); Path newSecureStorePath = Paths.get(newSecureStoreLib);
if (!Files.exists(newSecureStorePath)) { if (!Files.exists(newSecureStorePath)) {
log.error(String.format("File %s doesn't exist", newSecureStorePath.toAbsolutePath())); log.error("File {} doesn't exist", newSecureStorePath.toAbsolutePath());
return -1; return -1;
} }
@@ -77,8 +77,7 @@ public class SwitchSecureStore extends SiteProgram {
if (currentSecureStoreName.equals(newSecureStore)) { if (currentSecureStoreName.equals(newSecureStore)) {
log.error( log.error(
"Old and new SecureStore implementation names " "Old and new SecureStore implementation names are the same. Migration will not work");
+ "are the same. Migration will not work");
return -1; return -1;
} }

View File

@@ -79,7 +79,7 @@ class HiddenErrorHandler extends ErrorHandler {
if (!Strings.isNullOrEmpty(req.getQueryString())) { if (!Strings.isNullOrEmpty(req.getQueryString())) {
uri += "?" + req.getQueryString(); uri += "?" + req.getQueryString();
} }
log.error(String.format("Error in %s %s", req.getMethod(), uri), err); log.error("Error in {} {}", req.getMethod(), uri, err);
} }
} }
} }

View File

@@ -49,7 +49,7 @@ public class WebLinks {
if (link == null) { if (link == null) {
return false; return false;
} else if (Strings.isNullOrEmpty(link.name) || Strings.isNullOrEmpty(link.url)) { } else if (Strings.isNullOrEmpty(link.name) || Strings.isNullOrEmpty(link.url)) {
log.warn(String.format("%s is missing name and/or url", link.getClass().getName())); log.warn("{} is missing name and/or url", link.getClass().getName());
return false; return false;
} }
return true; return true;
@@ -60,7 +60,7 @@ public class WebLinks {
if (link == null) { if (link == null) {
return false; return false;
} else if (Strings.isNullOrEmpty(link.name) || Strings.isNullOrEmpty(link.url)) { } else if (Strings.isNullOrEmpty(link.name) || Strings.isNullOrEmpty(link.url)) {
log.warn(String.format("%s is missing name and/or url", link.getClass().getName())); log.warn("{} is missing name and/or url", link.getClass().getName());
return false; return false;
} }
return true; return true;

View File

@@ -88,7 +88,7 @@ public class GroupCacheImpl implements GroupCache {
try { try {
return byId.get(groupId); return byId.get(groupId);
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn("Cannot load group " + groupId, e); log.warn("Cannot load group {}", groupId, e);
return Optional.empty(); return Optional.empty();
} }
} }
@@ -124,7 +124,7 @@ public class GroupCacheImpl implements GroupCache {
try { try {
return byName.get(name.get()); return byName.get(name.get());
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn(String.format("Cannot look up group %s by name", name.get()), e); log.warn("Cannot look up group {} by name", name.get(), e);
return Optional.empty(); return Optional.empty();
} }
} }
@@ -138,7 +138,7 @@ public class GroupCacheImpl implements GroupCache {
try { try {
return byUUID.get(groupUuid.get()); return byUUID.get(groupUuid.get());
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn(String.format("Cannot look up group %s by uuid", groupUuid.get()), e); log.warn("Cannot look up group {} by uuid", groupUuid.get(), e);
return Optional.empty(); return Optional.empty();
} }
} }

View File

@@ -126,7 +126,7 @@ public class LdapGroupBackend implements GroupBackend {
return null; return null;
} }
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn(String.format("Cannot lookup group %s in LDAP", groupDn), e); log.warn("Cannot lookup group {} in LDAP", groupDn, e);
return null; return null;
} }
} }

View File

@@ -65,7 +65,7 @@ class LdapGroupMembership implements GroupMembership {
try { try {
membership = new ListGroupMembership(membershipCache.get(id)); membership = new ListGroupMembership(membershipCache.get(id));
} catch (ExecutionException e) { } catch (ExecutionException e) {
LdapGroupBackend.log.warn(String.format("Cannot lookup membershipsOf %s in LDAP", id), e); LdapGroupBackend.log.warn("Cannot lookup membershipsOf {} in LDAP", id, e);
membership = GroupMembership.EMPTY; membership = GroupMembership.EMPTY;
} }
} }

View File

@@ -315,7 +315,7 @@ class LdapRealm extends AbstractRealm {
Optional<Account.Id> id = usernameCache.get(accountName); Optional<Account.Id> id = usernameCache.get(accountName);
return id != null ? id.orElse(null) : null; return id != null ? id.orElse(null) : null;
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.warn(String.format("Cannot lookup account %s in LDAP", accountName), e); log.warn("Cannot lookup account {} in LDAP", accountName, e);
return null; return null;
} }
} }

View File

@@ -96,7 +96,7 @@ public class AbandonUtil {
log.error(msg.toString(), e); log.error(msg.toString(), e);
} }
} }
log.info(String.format("Auto-Abandoned %d of %d changes.", count, changesToAbandon.size())); log.info("Auto-Abandoned {} of {} changes.", count, changesToAbandon.size());
} catch (QueryParseException | OrmException e) { } catch (QueryParseException | OrmException e) {
log.error("Failed to query inactive open changes for auto-abandoning.", e); log.error("Failed to query inactive open changes for auto-abandoning.", e);
} }

View File

@@ -151,7 +151,7 @@ public class EventFactory {
try { try {
a.commitMessage = changeDataFactory.create(db, change).commitMessage(); a.commitMessage = changeDataFactory.create(db, change).commitMessage();
} catch (Exception e) { } catch (Exception e) {
log.error("Error while getting full commit message for change " + a.number, e); log.error("Error while getting full commit message for change {}", a.number, e);
} }
a.url = getChangeUrl(change); a.url = getChangeUrl(change);
a.owner = asAccountAttribute(change.getOwner()); a.owner = asAccountAttribute(change.getOwner());
@@ -502,11 +502,11 @@ public class EventFactory {
} }
p.kind = changeKindCache.getChangeKind(db, change, patchSet); p.kind = changeKindCache.getChangeKind(db, change, patchSet);
} catch (IOException | OrmException e) { } catch (IOException | OrmException e) {
log.error("Cannot load patch set data for " + patchSet.getId(), e); log.error("Cannot load patch set data for {}", patchSet.getId(), e);
} catch (PatchListObjectTooLargeException e) { } catch (PatchListObjectTooLargeException e) {
log.warn(String.format("Cannot get size information for %s: %s", pId, e.getMessage())); log.warn(String.format("Cannot get size information for %s: %s", pId, e.getMessage()));
} catch (PatchListNotAvailableException e) { } catch (PatchListNotAvailableException e) {
log.error(String.format("Cannot get size information for %s.", pId), e); log.error("Cannot get size information for {}.", pId, e);
} }
return p; return p;
} }

View File

@@ -119,9 +119,9 @@ public class EventUtil {
public void logEventListenerError(Object event, Object listener, Exception error) { public void logEventListenerError(Object event, Object listener, Exception error) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
String.format( "Error in event listener {} for event {}",
"Error in event listener %s for event %s", listener.getClass().getName(),
listener.getClass().getName(), event.getClass().getName()), event.getClass().getName(),
error); error);
} else { } else {
log.warn( log.warn(
@@ -134,7 +134,7 @@ public class EventUtil {
public static void logEventListenerError(Object listener, Exception error) { public static void logEventListenerError(Object listener, Exception error) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug(String.format("Error in event listener %s", listener.getClass().getName()), error); log.debug("Error in event listener {}", listener.getClass().getName(), error);
} else { } else {
log.warn("Error in event listener {}: {}", listener.getClass().getName(), error.getMessage()); log.warn("Error in event listener {}: {}", listener.getClass().getName(), error.getMessage());
} }

View File

@@ -52,7 +52,7 @@ public class GarbageCollectionRunner implements Runnable {
if (delay == MISSING_CONFIG && interval == MISSING_CONFIG) { if (delay == MISSING_CONFIG && interval == MISSING_CONFIG) {
log.info("Ignoring missing gc schedule configuration"); log.info("Ignoring missing gc schedule configuration");
} else if (delay < 0 || interval <= 0) { } else if (delay < 0 || interval <= 0) {
log.warn(String.format("Ignoring invalid gc schedule configuration: %s", scheduleConfig)); log.warn("Ignoring invalid gc schedule configuration: {}", scheduleConfig);
} else { } else {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Future<?> possiblyIgnoredError = Future<?> possiblyIgnoredError =

View File

@@ -100,7 +100,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
} else { } else {
desc = String.format("%d", limit); desc = String.format("%d", limit);
} }
log.info(String.format("Defaulting core.streamFileThreshold to %s", desc)); log.info("Defaulting core.streamFileThreshold to {}", desc);
cfg.setStreamFileThreshold(limit); cfg.setStreamFileThreshold(limit);
} }
cfg.install(); cfg.install();
@@ -226,9 +226,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
// //
File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG); File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG);
if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) { if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) {
log.error( log.error("Failed to create ref log for {} in repository {}", RefNames.REFS_CONFIG, name);
String.format(
"Failed to create ref log for %s in repository %s", RefNames.REFS_CONFIG, name));
} }
onCreateProject(name); onCreateProject(name);
@@ -306,7 +304,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
Integer.MAX_VALUE, Integer.MAX_VALUE,
visitor); visitor);
} catch (IOException e) { } catch (IOException e) {
log.error("Error walking repository tree " + visitor.startFolder.toAbsolutePath(), e); log.error("Error walking repository tree {}", visitor.startFolder.toAbsolutePath(), e);
} }
} }
@@ -361,7 +359,7 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
Project.NameKey nameKey = getProjectName(startFolder, p); Project.NameKey nameKey = getProjectName(startFolder, p);
if (getBasePath(nameKey).equals(startFolder)) { if (getBasePath(nameKey).equals(startFolder)) {
if (isUnreasonableName(nameKey)) { if (isUnreasonableName(nameKey)) {
log.warn("Ignoring unreasonably named repository " + p.toAbsolutePath()); log.warn("Ignoring unreasonably named repository {}", p.toAbsolutePath());
} else { } else {
found.add(nameKey); found.add(nameKey);
} }

View File

@@ -214,7 +214,7 @@ public class StalenessChecker {
} }
return false; return false;
} catch (IOException e) { } catch (IOException e) {
log.warn(String.format("error checking staleness of %s in %s", id, project), e); log.warn("error checking staleness of {} in {}", id, project, e);
return true; return true;
} }
} }

View File

@@ -140,9 +140,10 @@ public class MailProcessor {
for (DynamicMap.Entry<MailFilter> filter : mailFilters) { for (DynamicMap.Entry<MailFilter> filter : mailFilters) {
if (!filter.getProvider().get().shouldProcessMessage(message)) { if (!filter.getProvider().get().shouldProcessMessage(message)) {
log.warn( log.warn(
String.format( "Message {} filtered by plugin {} {}. Will delete message.",
"Message %s filtered by plugin %s %s. Will delete message.", message.id(),
message.id(), filter.getPluginName(), filter.getExportName())); filter.getPluginName(),
filter.getExportName());
return; return;
} }
} }
@@ -150,23 +151,24 @@ public class MailProcessor {
MailMetadata metadata = MetadataParser.parse(message); MailMetadata metadata = MetadataParser.parse(message);
if (!metadata.hasRequiredFields()) { if (!metadata.hasRequiredFields()) {
log.error( log.error(
String.format( "Message {} is missing required metadata, have {}. Will delete message.",
"Message %s is missing required metadata, have %s. Will delete message.", message.id(),
message.id(), metadata)); metadata);
return; return;
} }
Set<Account.Id> accountIds = emails.getAccountFor(metadata.author); Set<Account.Id> accountIds = emails.getAccountFor(metadata.author);
if (accountIds.size() != 1) { if (accountIds.size() != 1) {
log.error( log.error(
String.format( "Address {} could not be matched to a unique account. It was matched to {}."
"Address %s could not be matched to a unique account. It was matched to %s. Will delete message.", + " Will delete message.",
metadata.author, accountIds)); metadata.author,
accountIds);
return; return;
} }
Account.Id account = accountIds.iterator().next(); Account.Id account = accountIds.iterator().next();
if (!accountCache.get(account).getAccount().isActive()) { if (!accountCache.get(account).getAccount().isActive()) {
log.warn(String.format("Mail: Account %s is inactive. Will delete message.", account)); log.warn("Mail: Account {} is inactive. Will delete message.", account);
return; return;
} }
@@ -181,15 +183,16 @@ public class MailProcessor {
queryProvider.get().byLegacyChangeId(new Change.Id(metadata.changeNumber)); queryProvider.get().byLegacyChangeId(new Change.Id(metadata.changeNumber));
if (changeDataList.size() != 1) { if (changeDataList.size() != 1) {
log.error( log.error(
String.format( "Message {} references unique change {}, but there are {} matching changes in "
"Message %s references unique change %s, but there are %d matching changes in the index. Will delete message.", + "the index. Will delete message.",
message.id(), metadata.changeNumber, changeDataList.size())); message.id(),
metadata.changeNumber,
changeDataList.size());
return; return;
} }
ChangeData cd = changeDataList.get(0); ChangeData cd = changeDataList.get(0);
if (existingMessageIds(cd).contains(message.id())) { if (existingMessageIds(cd).contains(message.id())) {
log.info( log.info("Message {} was already processed. Will delete message.", message.id());
String.format("Message %s was already processed. Will delete message.", message.id()));
return; return;
} }
// Get all comments; filter and sort them to get the original list of // Get all comments; filter and sort them to get the original list of
@@ -212,9 +215,7 @@ public class MailProcessor {
} }
if (parsedComments.isEmpty()) { if (parsedComments.isEmpty()) {
log.warn( log.warn("Could not parse any comments from {}. Will delete message.", message.id());
String.format(
"Could not parse any comments from %s. Will delete message.", message.id()));
return; return;
} }

View File

@@ -257,9 +257,10 @@ public class CommentSender extends ReplyToChangeSender {
currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename); currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename);
} catch (IOException e) { } catch (IOException e) {
log.warn( log.warn(
String.format( "Cannot load {} from {} in {}",
"Cannot load %s from %s in %s", c.key.filename,
c.key.filename, patchList.getNewId().name(), projectState.getName()), patchList.getNewId().name(),
projectState.getName(),
e); e);
currentGroup.fileData = null; currentGroup.fileData = null;
} }
@@ -353,10 +354,10 @@ public class CommentSender extends ReplyToChangeSender {
maxLines = currentFileData.getLineCount(side); maxLines = currentFileData.getLineCount(side);
} catch (IOException err) { } catch (IOException err) {
// The file could not be read, leave the max as is. // The file could not be read, leave the max as is.
log.warn(String.format("Failed to read file %s on side %d", comment.key.filename, side), err); log.warn("Failed to read file {} on side {}", comment.key.filename, side, err);
} catch (NoSuchEntityException err) { } catch (NoSuchEntityException err) {
// The file could not be read, leave the max as is. // The file could not be read, leave the max as is.
log.warn(String.format("Side %d of file %s didn't exist", side, comment.key.filename), err); log.warn("Side {} of file {} didn't exist", side, comment.key.filename, err);
} }
int startLine = Math.max(1, lineNbr - contextLines + 1); int startLine = Math.max(1, lineNbr - contextLines + 1);
@@ -405,7 +406,7 @@ public class CommentSender extends ReplyToChangeSender {
try { try {
return commentsUtil.getPublished(args.db.get(), changeData.notes(), key); return commentsUtil.getPublished(args.db.get(), changeData.notes(), key);
} catch (OrmException e) { } catch (OrmException e) {
log.warn("Could not find the parent of this comment: " + child.toString()); log.warn("Could not find the parent of this comment: {}", child.toString());
return Optional.empty(); return Optional.empty();
} }
} }
@@ -619,16 +620,16 @@ public class CommentSender extends ReplyToChangeSender {
return fileInfo.getLine(side, lineNbr); return fileInfo.getLine(side, lineNbr);
} catch (IOException err) { } catch (IOException err) {
// Default to the empty string if the file cannot be safely read. // Default to the empty string if the file cannot be safely read.
log.warn(String.format("Failed to read file on side %d", side), err); log.warn("Failed to read file on side {}", side, err);
return ""; return "";
} catch (IndexOutOfBoundsException err) { } catch (IndexOutOfBoundsException err) {
// Default to the empty string if the given line number does not appear // Default to the empty string if the given line number does not appear
// in the file. // in the file.
log.debug(String.format("Failed to get line number of file on side %d", side), err); log.debug("Failed to get line number of file on side {}", side, err);
return ""; return "";
} catch (NoSuchEntityException err) { } catch (NoSuchEntityException err) {
// Default to the empty string if the side cannot be found. // Default to the empty string if the side cannot be found.
log.warn(String.format("Side %d of file didn't exist", side), err); log.warn("Side {} of file didn't exist", side, err);
return ""; return "";
} }
} }

View File

@@ -148,7 +148,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
throw new NoSuchChangeException(changeId); throw new NoSuchChangeException(changeId);
} }
if (changes.size() != 1) { if (changes.size() != 1) {
log.error(String.format("Multiple changes found for %d", changeId.get())); log.error("Multiple changes found for {}", changeId.get());
throw new NoSuchChangeException(changeId); throw new NoSuchChangeException(changeId);
} }
return changes.get(0).notes(); return changes.get(0).notes();

View File

@@ -129,7 +129,7 @@ public class JarPluginProvider implements ServerPluginProvider {
if (overlay != null) { if (overlay != null) {
Path classes = Paths.get(overlay).resolve(name).resolve("main"); Path classes = Paths.get(overlay).resolve(name).resolve("main");
if (Files.isDirectory(classes)) { if (Files.isDirectory(classes)) {
log.info(String.format("plugin %s: including %s", name, classes)); log.info("plugin {}: including {}", name, classes);
urls.add(classes.toUri().toURL()); urls.add(classes.toUri().toURL());
} }
} }

View File

@@ -164,9 +164,9 @@ public class PluginLoader implements LifecycleListener {
String name = MoreObjects.firstNonNull(getGerritPluginName(tmp), PluginUtil.nameOf(fileName)); String name = MoreObjects.firstNonNull(getGerritPluginName(tmp), PluginUtil.nameOf(fileName));
if (!originalName.equals(name)) { if (!originalName.equals(name)) {
log.warn( log.warn(
String.format( "Plugin provides its own name: <{}>, use it instead of the input name: <{}>",
"Plugin provides its own name: <%s>, use it instead of the input name: <%s>", name,
name, originalName)); originalName);
} }
String fileExtension = getExtension(fileName); String fileExtension = getExtension(fileName);
@@ -175,7 +175,7 @@ public class PluginLoader implements LifecycleListener {
Plugin active = running.get(name); Plugin active = running.get(name);
if (active != null) { if (active != null) {
fileName = active.getSrcFile().getFileName().toString(); fileName = active.getSrcFile().getFileName().toString();
log.info(String.format("Replacing plugin %s", active.getName())); log.info("Replacing plugin {}", active.getName());
Path old = pluginsDir.resolve(".last_" + fileName); Path old = pluginsDir.resolve(".last_" + fileName);
Files.deleteIfExists(old); Files.deleteIfExists(old);
Files.move(active.getSrcFile(), old); Files.move(active.getSrcFile(), old);
@@ -186,7 +186,7 @@ public class PluginLoader implements LifecycleListener {
try { try {
Plugin plugin = runPlugin(name, dst, active); Plugin plugin = runPlugin(name, dst, active);
if (active == null) { if (active == null) {
log.info(String.format("Installed plugin %s", plugin.getName())); log.info("Installed plugin {}", plugin.getName());
} }
} catch (PluginInstallException e) { } catch (PluginInstallException e) {
Files.deleteIfExists(dst); Files.deleteIfExists(dst);
@@ -202,7 +202,7 @@ public class PluginLoader implements LifecycleListener {
private synchronized void unloadPlugin(Plugin plugin) { private synchronized void unloadPlugin(Plugin plugin) {
persistentCacheFactory.onStop(plugin); persistentCacheFactory.onStop(plugin);
String name = plugin.getName(); String name = plugin.getName();
log.info(String.format("Unloading plugin %s, version %s", name, plugin.getVersion())); log.info("Unloading plugin {}, version {}", name, plugin.getVersion());
plugin.stop(env); plugin.stop(env);
env.onStopPlugin(plugin); env.onStopPlugin(plugin);
running.remove(name); running.remove(name);
@@ -212,7 +212,7 @@ public class PluginLoader implements LifecycleListener {
public void disablePlugins(Set<String> names) { public void disablePlugins(Set<String> names) {
if (!isRemoteAdminEnabled()) { if (!isRemoteAdminEnabled()) {
log.warn("Remote plugin administration is disabled, ignoring disablePlugins(" + names + ")"); log.warn("Remote plugin administration is disabled, ignoring disablePlugins({})", names);
return; return;
} }
@@ -223,7 +223,7 @@ public class PluginLoader implements LifecycleListener {
continue; continue;
} }
log.info(String.format("Disabling plugin %s", active.getName())); log.info("Disabling plugin {}", active.getName());
Path off = Path off =
active.getSrcFile().resolveSibling(active.getSrcFile().getFileName() + ".disabled"); active.getSrcFile().resolveSibling(active.getSrcFile().getFileName() + ".disabled");
try { try {
@@ -243,7 +243,7 @@ public class PluginLoader implements LifecycleListener {
disabled.put(name, offPlugin); disabled.put(name, offPlugin);
} catch (Throwable e) { } catch (Throwable e) {
// This shouldn't happen, as the plugin was loaded earlier. // This shouldn't happen, as the plugin was loaded earlier.
log.warn(String.format("Cannot load disabled plugin %s", active.getName()), e.getCause()); log.warn("Cannot load disabled plugin {}", active.getName(), e.getCause());
} }
} }
cleanInBackground(); cleanInBackground();
@@ -252,7 +252,7 @@ public class PluginLoader implements LifecycleListener {
public void enablePlugins(Set<String> names) throws PluginInstallException { public void enablePlugins(Set<String> names) throws PluginInstallException {
if (!isRemoteAdminEnabled()) { if (!isRemoteAdminEnabled()) {
log.warn("Remote plugin administration is disabled, ignoring enablePlugins(" + names + ")"); log.warn("Remote plugin administration is disabled, ignoring enablePlugins({})", names);
return; return;
} }
@@ -263,7 +263,7 @@ public class PluginLoader implements LifecycleListener {
continue; continue;
} }
log.info(String.format("Enabling plugin %s", name)); log.info("Enabling plugin {}", name);
String n = off.getSrcFile().toFile().getName(); String n = off.getSrcFile().toFile().getName();
if (n.endsWith(".disabled")) { if (n.endsWith(".disabled")) {
n = n.substring(0, n.lastIndexOf('.')); n = n.substring(0, n.lastIndexOf('.'));
@@ -272,7 +272,7 @@ public class PluginLoader implements LifecycleListener {
try { try {
Files.move(off.getSrcFile(), on); Files.move(off.getSrcFile(), on);
} catch (IOException e) { } catch (IOException e) {
log.error("Failed to move plugin " + name + " into place", e); log.error("Failed to move plugin {} into place", name, e);
continue; continue;
} }
disabled.remove(name); disabled.remove(name);
@@ -292,18 +292,16 @@ public class PluginLoader implements LifecycleListener {
}; };
try (DirectoryStream<Path> files = Files.newDirectoryStream(tempDir, filter)) { try (DirectoryStream<Path> files = Files.newDirectoryStream(tempDir, filter)) {
for (Path file : files) { for (Path file : files) {
log.info("Removing stale plugin file: " + file.toFile().getName()); log.info("Removing stale plugin file: {}", file.toFile().getName());
try { try {
Files.delete(file); Files.delete(file);
} catch (IOException e) { } catch (IOException e) {
log.error( log.error(
String.format( "Failed to remove stale plugin file {}: {}", file.toFile().getName(), e.getMessage());
"Failed to remove stale plugin file %s: %s",
file.toFile().getName(), e.getMessage()));
} }
} }
} catch (IOException e) { } catch (IOException e) {
log.warn("Unable to discover stale plugin files: " + e.getMessage()); log.warn("Unable to discover stale plugin files: {}", e.getMessage());
} }
} }
@@ -312,14 +310,14 @@ public class PluginLoader implements LifecycleListener {
removeStalePluginFiles(); removeStalePluginFiles();
Path absolutePath = pluginsDir.toAbsolutePath(); Path absolutePath = pluginsDir.toAbsolutePath();
if (!Files.exists(absolutePath)) { if (!Files.exists(absolutePath)) {
log.info(absolutePath + " does not exist; creating"); log.info("{} does not exist; creating", absolutePath);
try { try {
Files.createDirectories(absolutePath); Files.createDirectories(absolutePath);
} catch (IOException e) { } catch (IOException e) {
log.error(String.format("Failed to create %s: %s", absolutePath, e.getMessage())); log.error("Failed to create {}: {}", absolutePath, e.getMessage());
} }
} }
log.info("Loading plugins from " + absolutePath); log.info("Loading plugins from {}", absolutePath);
srvInfoImpl.state = ServerInformation.State.STARTUP; srvInfoImpl.state = ServerInformation.State.STARTUP;
rescan(); rescan();
srvInfoImpl.state = ServerInformation.State.RUNNING; srvInfoImpl.state = ServerInformation.State.RUNNING;
@@ -368,13 +366,11 @@ public class PluginLoader implements LifecycleListener {
for (Plugin active : reload) { for (Plugin active : reload) {
String name = active.getName(); String name = active.getName();
try { try {
log.info(String.format("Reloading plugin %s", name)); log.info("Reloading plugin {}", name);
Plugin newPlugin = runPlugin(name, active.getSrcFile(), active); Plugin newPlugin = runPlugin(name, active.getSrcFile(), active);
log.info( log.info("Reloaded plugin {}, version {}", newPlugin.getName(), newPlugin.getVersion());
String.format(
"Reloaded plugin %s, version %s", newPlugin.getName(), newPlugin.getVersion()));
} catch (PluginInstallException e) { } catch (PluginInstallException e) {
log.warn(String.format("Cannot reload plugin %s", name), e.getCause()); log.warn("Cannot reload plugin {}", name, e.getCause());
throw e; throw e;
} }
} }
@@ -412,21 +408,20 @@ public class PluginLoader implements LifecycleListener {
} }
if (active != null) { if (active != null) {
log.info(String.format("Reloading plugin %s", active.getName())); log.info("Reloading plugin {}", active.getName());
} }
try { try {
Plugin loadedPlugin = runPlugin(name, path, active); Plugin loadedPlugin = runPlugin(name, path, active);
if (!loadedPlugin.isDisabled()) { if (!loadedPlugin.isDisabled()) {
log.info( log.info(
String.format( "{} plugin {}, version {}",
"%s plugin %s, version %s", active == null ? "Loaded" : "Reloaded",
active == null ? "Loaded" : "Reloaded", loadedPlugin.getName(),
loadedPlugin.getName(), loadedPlugin.getVersion());
loadedPlugin.getVersion()));
} }
} catch (PluginInstallException e) { } catch (PluginInstallException e) {
log.warn(String.format("Cannot load plugin %s", name), e.getCause()); log.warn("Cannot load plugin {}", name, e.getCause());
} }
} }
@@ -655,18 +650,19 @@ public class PluginLoader implements LifecycleListener {
Collection<Path> elementsToAdd = new ArrayList<>(); Collection<Path> elementsToAdd = new ArrayList<>();
for (Path loser : Iterables.skip(enabled, 1)) { for (Path loser : Iterables.skip(enabled, 1)) {
log.warn( log.warn(
String.format( "Plugin <{}> was disabled, because"
"Plugin <%s> was disabled, because" + " another plugin <{}>"
+ " another plugin <%s>" + " with the same name <{}> already exists",
+ " with the same name <%s> already exists", loser,
loser, winner, plugin)); winner,
plugin);
Path disabledPlugin = Paths.get(loser + ".disabled"); Path disabledPlugin = Paths.get(loser + ".disabled");
elementsToAdd.add(disabledPlugin); elementsToAdd.add(disabledPlugin);
elementsToRemove.add(loser); elementsToRemove.add(loser);
try { try {
Files.move(loser, disabledPlugin); Files.move(loser, disabledPlugin);
} catch (IOException e) { } catch (IOException e) {
log.warn("Failed to fully disable plugin " + loser, e); log.warn("Failed to fully disable plugin {}", loser, e);
} }
} }
Iterables.removeAll(files, elementsToRemove); Iterables.removeAll(files, elementsToRemove);
@@ -679,7 +675,7 @@ public class PluginLoader implements LifecycleListener {
try { try {
return PluginUtil.listPlugins(pluginsDir); return PluginUtil.listPlugins(pluginsDir);
} catch (IOException e) { } catch (IOException e) {
log.error("Cannot list " + pluginsDir.toAbsolutePath(), e); log.error("Cannot list {}", pluginsDir.toAbsolutePath(), e);
return ImmutableList.of(); return ImmutableList.of();
} }
} }

View File

@@ -185,7 +185,7 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
throw new ResourceConflictException( throw new ResourceConflictException(
"Cannot update " + projectName + ": " + e.getCause().getMessage()); "Cannot update " + projectName + ": " + e.getCause().getMessage());
} }
log.warn(String.format("Failed to update config of project %s.", projectName), e); log.warn("Failed to update config of project {}.", projectName, e);
throw new ResourceConflictException("Cannot update " + projectName); throw new ResourceConflictException("Cannot update " + projectName);
} }
@@ -220,9 +220,7 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
ProjectConfigEntry projectConfigEntry = pluginConfigEntries.get(pluginName, v.getKey()); ProjectConfigEntry projectConfigEntry = pluginConfigEntries.get(pluginName, v.getKey());
if (projectConfigEntry != null) { if (projectConfigEntry != null) {
if (!isValidParameterName(v.getKey())) { if (!isValidParameterName(v.getKey())) {
log.warn( log.warn("Parameter name '{}' must match '^[a-zA-Z0-9]+[a-zA-Z0-9-]*$'", v.getKey());
String.format(
"Parameter name '%s' must match '^[a-zA-Z0-9]+[a-zA-Z0-9-]*$'", v.getKey()));
continue; continue;
} }
String oldValue = cfg.getString(v.getKey()); String oldValue = cfg.getString(v.getKey());
@@ -271,9 +269,9 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
break; break;
default: default:
log.warn( log.warn(
String.format( "The type '{}' of parameter '{}' is not supported.",
"The type '%s' of parameter '%s' is not supported.", projectConfigEntry.getType().name(),
projectConfigEntry.getType().name(), v.getKey())); v.getKey());
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
throw new BadRequestException( throw new BadRequestException(