From cf9662cdfedac2ccefc3c9267357e828cfa3155d Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 2 Aug 2017 16:50:57 -0400 Subject: Eliminate SectionParser construction boilerplate Happily, most anonymous SectionParser implementations can be replaced with FooConfig::new, as long as the constructor takes a single Config arg. Many of these, the non-public ones, can in turn be inlined. A few remaining SectionParsers can be lambdas. Change-Id: I3f563e752dfd2007dd3a48d6d313d20e2685943a --- .../org/eclipse/jgit/http/server/resolver/AsIsFileService.java | 10 +--------- .../jgit/http/server/resolver/DefaultReceivePackFactory.java | 10 +--------- .../jgit/http/server/resolver/DefaultUploadPackFactory.java | 10 +--------- 3 files changed, 3 insertions(+), 27 deletions(-) (limited to 'org.eclipse.jgit.http.server') diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java index 88ad472acb..d20fe9f27a 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/AsIsFileService.java @@ -47,7 +47,6 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.jgit.http.server.GitServlet; import org.eclipse.jgit.lib.Config; -import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; @@ -71,13 +70,6 @@ public class AsIsFileService { } }; - private static final SectionParser CONFIG = new SectionParser() { - @Override - public ServiceConfig parse(final Config cfg) { - return new ServiceConfig(cfg); - } - }; - private static class ServiceConfig { final boolean enabled; @@ -96,7 +88,7 @@ public class AsIsFileService { * {@code true}. */ protected static boolean isEnabled(Repository db) { - return db.getConfig().get(CONFIG).enabled; + return db.getConfig().get(ServiceConfig::new).enabled; } /** diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java index 04e192bcfb..c0ffbb64d7 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultReceivePackFactory.java @@ -46,7 +46,6 @@ package org.eclipse.jgit.http.server.resolver; import javax.servlet.http.HttpServletRequest; import org.eclipse.jgit.lib.Config; -import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.ReceivePack; @@ -68,13 +67,6 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; */ public class DefaultReceivePackFactory implements ReceivePackFactory { - private static final SectionParser CONFIG = new SectionParser() { - @Override - public ServiceConfig parse(final Config cfg) { - return new ServiceConfig(cfg); - } - }; - private static class ServiceConfig { final boolean set; @@ -89,7 +81,7 @@ public class DefaultReceivePackFactory implements @Override public ReceivePack create(final HttpServletRequest req, final Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { - final ServiceConfig cfg = db.getConfig().get(CONFIG); + final ServiceConfig cfg = db.getConfig().get(ServiceConfig::new); String user = req.getRemoteUser(); if (cfg.set) { diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java index d01e2efca4..642623bdd9 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/DefaultUploadPackFactory.java @@ -46,7 +46,6 @@ package org.eclipse.jgit.http.server.resolver; import javax.servlet.http.HttpServletRequest; import org.eclipse.jgit.lib.Config; -import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; @@ -61,13 +60,6 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory; */ public class DefaultUploadPackFactory implements UploadPackFactory { - private static final SectionParser CONFIG = new SectionParser() { - @Override - public ServiceConfig parse(final Config cfg) { - return new ServiceConfig(cfg); - } - }; - private static class ServiceConfig { final boolean enabled; @@ -79,7 +71,7 @@ public class DefaultUploadPackFactory implements @Override public UploadPack create(final HttpServletRequest req, final Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { - if (db.getConfig().get(CONFIG).enabled) + if (db.getConfig().get(ServiceConfig::new).enabled) return new UploadPack(db); else throw new ServiceNotEnabledException(); -- cgit v1.2.3