diff --git a/src/main/java/JettyLauncher.java b/src/main/java/JettyLauncher.java index d810941..bae7ae1 100644 --- a/src/main/java/JettyLauncher.java +++ b/src/main/java/JettyLauncher.java @@ -19,19 +19,25 @@ if(arg.startsWith("--") && arg.contains("=")) { String[] dim = arg.split("="); if(dim.length >= 2) { - if(dim[0].equals("--host")) { - host = dim[1]; - } else if(dim[0].equals("--port")) { - port = Integer.parseInt(dim[1]); - } else if(dim[0].equals("--prefix")) { - contextPath = dim[1]; - if(!contextPath.startsWith("/")){ - contextPath = "/" + contextPath; - } - } else if(dim[0].equals("--gitbucket.home")){ - System.setProperty("gitbucket.home", dim[1]); - } else if(dim[0].equals("--temp_dir")){ - tmpDirPath = dim[1]; + switch (dim[0]) { + case "--host": + host = dim[1]; + break; + case "--port": + port = Integer.parseInt(dim[1]); + break; + case "--prefix": + contextPath = dim[1]; + if (!contextPath.startsWith("/")) { + contextPath = "/" + contextPath; + } + break; + case "--gitbucket.home": + System.setProperty("gitbucket.home", dim[1]); + break; + case "--temp_dir": + tmpDirPath = dim[1]; + break; } } } diff --git a/src/main/scala/gitbucket/core/api/CreateAStatus.scala b/src/main/scala/gitbucket/core/api/CreateAStatus.scala index 3871999..f8c087f 100644 --- a/src/main/scala/gitbucket/core/api/CreateAStatus.scala +++ b/src/main/scala/gitbucket/core/api/CreateAStatus.scala @@ -19,8 +19,8 @@ def isValid: Boolean = { CommitState.valueOf(state).isDefined && // only http - target_url.filterNot(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length<255).isEmpty && - context.filterNot(f => f.length<255).isEmpty && - description.filterNot(f => f.length<1000).isEmpty + target_url.forall(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length < 255) && + context.forall(f => f.length < 255) && + description.forall(f => f.length < 1000) } } diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index ab2a0f1..e873ae2 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -125,7 +125,7 @@ get ("/api/v3/repos/:owner/:repo/branches/:branch")(referrersOnly { repository => //import gitbucket.core.api._ (for{ - branch <- params.get("branch") if repository.branchList.find(_ == branch).isDefined + branch <- params.get("branch") if repository.branchList.contains(branch) br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch) } yield { val protection = getProtectedBranchInfo(repository.owner, repository.name, branch) @@ -287,7 +287,7 @@ patch("/api/v3/repos/:owner/:repo/branches/:branch")(ownerOnly { repository => import gitbucket.core.api._ (for{ - branch <- params.get("branch") if repository.branchList.find(_ == branch).isDefined + branch <- params.get("branch") if repository.branchList.contains(branch) protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection) br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch) } yield { diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index 0ca0305..7e016a5 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -157,7 +157,7 @@ /** Update default branch */ post("/:owner/:repository/settings/update_default_branch", defaultBranchForm)(ownerOnly { (form, repository) => - if(repository.branchList.find(_ == form.defaultBranch).isEmpty){ + if(!repository.branchList.contains(form.defaultBranch)){ redirect(s"/${repository.owner}/${repository.name}/settings/options") } else { saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch) @@ -174,7 +174,7 @@ get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository => import gitbucket.core.api._ val branch = params("branch") - if(repository.branchList.find(_ == branch).isEmpty){ + if(!repository.branchList.contains(branch)){ redirect(s"/${repository.owner}/${repository.name}/settings/branches") } else { val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch)) diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 1b4ecc9..896ec82 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -232,7 +232,7 @@ oldFileName = form.oldFileName, content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator), charset = form.charset, - message = if(form.oldFileName.exists(_ == form.newFileName)){ + message = if(form.oldFileName.contains(form.newFileName)){ form.message.getOrElse(s"Update ${form.newFileName}") } else { form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}") @@ -614,7 +614,7 @@ val permission = JGitUtil.processTree(git, headTip){ (path, tree) => // Add all entries except the editing file - if(!newPath.exists(_ == path) && !oldPath.exists(_ == path)){ + if(!newPath.contains(path) && !oldPath.contains(path)){ builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId)) } // Retrieve permission if file exists to keep it diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index c0bc923..a2e8976 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -83,7 +83,7 @@ def addRenderer(extension: String, renderer: Renderer): Unit = renderers += ((extension, renderer)) - def getRenderer(extension: String): Renderer = renderers.get(extension).getOrElse(DefaultRenderer) + def getRenderer(extension: String): Renderer = renderers.getOrElse(extension, DefaultRenderer) def renderableExtensions: Seq[String] = renderers.keys.toSeq diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index c6c4085..4a9b12c 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -111,7 +111,7 @@ val (_, cs) = status.head Some(CommitStatusInfo( count = status.length, - successCount = status.filter(_._2.state == CommitState.SUCCESS).length, + successCount = status.count(_._2.state == CommitState.SUCCESS), context = (if(status.length == 1) Some(cs.context) else None), state = (if(status.length == 1) Some(cs.state) else None), targetUrl = (if(status.length == 1) cs.targetUrl else None), diff --git a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala index 577b843..d74280c 100644 --- a/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala +++ b/src/main/scala/gitbucket/core/service/ProtectedBranchService.scala @@ -76,7 +76,7 @@ includeAdministrators: Boolean) extends AccountService with CommitStatusService { def isAdministrator(pusher: String)(implicit session: Session): Boolean = - pusher == owner || getGroupMembers(owner).filter(gm => gm.userName == pusher && gm.isManager).nonEmpty + pusher == owner || getGroupMembers(owner).exists(gm => gm.userName == pusher && gm.isManager) /** * Can't be force pushed diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index 3807e55..03f2e6e 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -265,7 +265,7 @@ val summary = stateMap.map{ case (keyState, states) => states.size+" "+keyState.name }.mkString(", ") state -> summary } - lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.exists(_==s.context) } + lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.contains(s.context) } lazy val isAllSuccess = commitStateSummary._1==CommitState.SUCCESS } } diff --git a/src/main/scala/gitbucket/core/service/WikiService.scala b/src/main/scala/gitbucket/core/service/WikiService.scala index c5dad27..ab034fc 100644 --- a/src/main/scala/gitbucket/core/service/WikiService.scala +++ b/src/main/scala/gitbucket/core/service/WikiService.scala @@ -177,7 +177,7 @@ val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}") JGitUtil.processTree(git, headId){ (path, tree) => - if(revertInfo.find(x => x.filePath == path).isEmpty){ + if(!revertInfo.exists(x => x.filePath == path)){ builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId)) } } diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index 9461803..0629c14 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -105,7 +105,7 @@ } } case AuthType.DeployKeyType(key) => { - getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)) match { + getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match { case List(_) => true case _ => false } @@ -123,7 +123,7 @@ } } case AuthType.DeployKeyType(key) => { - getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)) match { + getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match { case List(x) if x.allowWrite => true case _ => false } diff --git a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala index 814e3e9..e3be40d 100644 --- a/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala +++ b/src/main/scala/gitbucket/core/ssh/PublicKeyAuthenticator.scala @@ -68,7 +68,7 @@ private def authenticateGenericUser(userName: String, key: PublicKey, session: ServerSession, genericUser: String)(implicit s: Session): Boolean = { // find all users having the key we got from ssh val possibleUserNames = getAllKeys().filter { sshKey => - SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key) + SshUtil.str2PublicKey(sshKey.publicKey).contains(key) }.map(_.userName).distinct // determine the user - if different accounts share the same key, tough luck @@ -85,7 +85,7 @@ }.getOrElse { // search deploy keys val existsDeployKey = getAllDeployKeys().exists { sshKey => - SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key) + SshUtil.str2PublicKey(sshKey.publicKey).contains(key) } if(existsDeployKey){ // found deploy key for repository diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index ac1a9b5..3c494ae 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -952,7 +952,7 @@ * @return the last modified commit of specified path */ def getLastModifiedCommit(git: Git, startCommit: RevCommit, path: String): RevCommit = { - return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next + git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next } def getBranches(owner: String, name: String, defaultBranch: String, origin: Boolean): Seq[BranchInfo] = {