mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-18 16:50:16 +02:00
fix review findings
This commit is contained in:
@@ -46,20 +46,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public final class UserAgent
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs a new user agent
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* @param browser
|
||||
* @param basicAuthenticationCharset
|
||||
*/
|
||||
private UserAgent(String name, boolean browser,
|
||||
Charset basicAuthenticationCharset)
|
||||
{
|
||||
this(name, browser, basicAuthenticationCharset, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new user agent
|
||||
*
|
||||
@@ -87,8 +73,30 @@ public final class UserAgent
|
||||
* @param name name of the UserAgent
|
||||
*
|
||||
* @return builder for UserAgent
|
||||
*
|
||||
* @deprecated Use {@link #browser(String)}, {@link #scmClient(String)} or {@link #other(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static Builder builder(String name)
|
||||
{
|
||||
return other(name);
|
||||
}
|
||||
|
||||
public static Builder browser(String name)
|
||||
{
|
||||
final Builder builder = new Builder(name);
|
||||
builder.browser = true;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static Builder scmClient(String name)
|
||||
{
|
||||
final Builder builder = new Builder(name);
|
||||
builder.scmClient = true;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static Builder other(String name)
|
||||
{
|
||||
return new Builder(name);
|
||||
}
|
||||
@@ -175,6 +183,12 @@ public final class UserAgent
|
||||
return browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if UserAgent is an scm client (e.g. git, svn or hg).
|
||||
*
|
||||
*
|
||||
* @return {@code true} if UserAgent is an scm client
|
||||
*/
|
||||
public boolean isScmClient() {
|
||||
return scmClient;
|
||||
}
|
||||
@@ -224,7 +238,10 @@ public final class UserAgent
|
||||
* @param browser {@code true} for a browser
|
||||
*
|
||||
* @return {@code this}
|
||||
*
|
||||
* @deprecated Use {@link #browser(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder browser(boolean browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
@@ -232,25 +249,9 @@ public final class UserAgent
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to {@code true} if the {@link UserAgent} is an scm client.
|
||||
*
|
||||
*
|
||||
* @param scmClient {@code true} for an scm client
|
||||
*
|
||||
* @return {@code this}
|
||||
*/
|
||||
public Builder scmClient(boolean scmClient)
|
||||
{
|
||||
this.scmClient = scmClient;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the {@link UserAgent}.
|
||||
*
|
||||
*
|
||||
* @return new {@link UserAgent}
|
||||
*/
|
||||
public UserAgent build()
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class UserAgentParser
|
||||
|
||||
/** unknown UserAgent */
|
||||
@VisibleForTesting
|
||||
static final UserAgent UNKNOWN = UserAgent.builder("UNKNOWN").build();
|
||||
static final UserAgent UNKNOWN = UserAgent.other("UNKNOWN").build();
|
||||
|
||||
/** logger */
|
||||
private static final Logger logger =
|
||||
|
||||
@@ -44,36 +44,30 @@ public class GitUserAgentProvider implements UserAgentProvider {
|
||||
private static final String PREFIX_JGIT = "jgit/";
|
||||
|
||||
@VisibleForTesting
|
||||
static final UserAgent JGIT = UserAgent.builder("JGit")
|
||||
static final UserAgent JGIT = UserAgent.scmClient("JGit")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
private static final String PREFIX_REGULAR = "git/";
|
||||
|
||||
@VisibleForTesting
|
||||
static final UserAgent GIT = UserAgent.builder("Git")
|
||||
static final UserAgent GIT = UserAgent.scmClient("Git")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
private static final String PREFIX_LFS = "git-lfs/";
|
||||
|
||||
@VisibleForTesting
|
||||
static final UserAgent GIT_LFS = UserAgent.builder("Git Lfs")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
static final UserAgent GIT_LFS = UserAgent.scmClient("Git Lfs")
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
private static final String SUFFIX_MSYSGIT = "msysgit";
|
||||
|
||||
@VisibleForTesting
|
||||
static final UserAgent MSYSGIT = UserAgent.builder("msysGit")
|
||||
.browser(false)
|
||||
.scmClient(true)
|
||||
static final UserAgent MSYSGIT = UserAgent.scmClient("msysGit")
|
||||
.basicAuthenticationCharset(Charsets.UTF_8)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ public class HgUserAgentProvider implements UserAgentProvider
|
||||
|
||||
/** mercurial seems to use system encoding */
|
||||
@VisibleForTesting
|
||||
static UserAgent HG = UserAgent.builder("Mercurial").browser(
|
||||
false).scmClient(true).basicAuthenticationCharset(
|
||||
static UserAgent HG = UserAgent.scmClient("Mercurial").basicAuthenticationCharset(
|
||||
Charset.defaultCharset()).build();
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -49,13 +49,13 @@ public final class SvnUserAgentProvider implements UserAgentProvider
|
||||
/** TortoiseSVN */
|
||||
@VisibleForTesting
|
||||
static final UserAgent TORTOISE_SVN =
|
||||
UserAgent.builder("TortoiseSVN").browser(false).scmClient(true)
|
||||
UserAgent.scmClient("TortoiseSVN")
|
||||
.basicAuthenticationCharset(Charsets.UTF_8).build();
|
||||
|
||||
/** Subversion cli client */
|
||||
@VisibleForTesting
|
||||
static final UserAgent SVN =
|
||||
UserAgent.builder("Subversion").browser(false).scmClient(true)
|
||||
UserAgent.scmClient("Subversion")
|
||||
.basicAuthenticationCharset(Charsets.UTF_8).build();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -41,30 +41,30 @@ public class BrowserUserAgentProvider implements UserAgentProvider
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final UserAgent CHROME = UserAgent.builder(
|
||||
static final UserAgent CHROME = UserAgent.browser(
|
||||
"Chrome").basicAuthenticationCharset(
|
||||
Charsets.UTF_8).browser(true).build();
|
||||
Charsets.UTF_8).build();
|
||||
|
||||
/** Field description */
|
||||
private static final String CHROME_PATTERN = "chrome";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final UserAgent FIREFOX = UserAgent.builder("Firefox").browser(true).build();
|
||||
static final UserAgent FIREFOX = UserAgent.browser("Firefox").build();
|
||||
|
||||
/** Field description */
|
||||
private static final String FIREFOX_PATTERN = "firefox";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting
|
||||
static final UserAgent MSIE = UserAgent.builder("Internet Explorer").browser(true).build();
|
||||
static final UserAgent MSIE = UserAgent.browser("Internet Explorer").build();
|
||||
|
||||
/** Field description */
|
||||
private static final String MSIE_PATTERN = "msie";
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting // todo check charset
|
||||
static final UserAgent SAFARI = UserAgent.builder("Safari").browser(true).build();
|
||||
static final UserAgent SAFARI = UserAgent.browser("Safari").build();
|
||||
|
||||
/** Field description */
|
||||
private static final String OPERA_PATTERN = "opera";
|
||||
@@ -74,9 +74,9 @@ public class BrowserUserAgentProvider implements UserAgentProvider
|
||||
|
||||
/** Field description */
|
||||
@VisibleForTesting // todo check charset
|
||||
static final UserAgent OPERA = UserAgent.builder(
|
||||
static final UserAgent OPERA = UserAgent.browser(
|
||||
"Opera").basicAuthenticationCharset(
|
||||
Charsets.UTF_8).browser(true).build();
|
||||
Charsets.UTF_8).build();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class HttpProtocolServlet extends HttpServlet {
|
||||
response.setStatus(HttpStatus.SC_BAD_REQUEST);
|
||||
}
|
||||
} else {
|
||||
log.trace("dispatch browser request for user agent {}", userAgent);
|
||||
log.trace("dispatch non-scm-client request for user agent {}", userAgent);
|
||||
dispatcher.dispatch(request, response, request.getRequestURI());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user