The Unified and Autonomous Development Platform
midwork
robin shine7e6cf343fcdd
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Account.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Account.javaindex 51c959dbf7..e4b465ea74 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Account.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Account.java@@ -4,7 +4,6 @@ import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.LinkedHashMap;-import java.util.Map;import javax.persistence.Column;import javax.persistence.Entity;@@ -59,10 +58,11 @@ public class Account extends AbstractUser implements ProtectedObject {private String description;/* used by organization account */- private DepotPrivilege defaultPrivilege;+ @Column(nullable=false)+ private DepotPrivilege defaultPrivilege = DepotPrivilege.NONE;/* used by organization account */- private Map<String, Team> teams = new LinkedHashMap<>();+ private LinkedHashMap<String, Team> teams = new LinkedHashMap<>();@Column(nullable=false)private String noSpaceName;@@ -258,11 +258,11 @@ public class Account extends AbstractUser implements ProtectedObject {this.depots = depots;}- public Map<String, Team> getTeams() {+ public LinkedHashMap<String, Team> getTeams() {return teams;}- public void setTeams(Map<String, Team> teams) {+ public void setTeams(LinkedHashMap<String, Team> teams) {this.teams = teams;}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Membership.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Membership.javaindex e3246aed75..88f5f8cf73 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Membership.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Membership.java@@ -1,7 +1,6 @@package com.pmease.gitplex.core.entity;import java.util.LinkedHashSet;-import java.util.Set;import javax.persistence.Entity;import javax.persistence.FetchType;@@ -31,7 +30,7 @@ public class Membership extends AbstractEntity {private boolean admin;- private Set<String> joinedTeams = new LinkedHashSet<>();+ private LinkedHashSet<String> joinedTeams = new LinkedHashSet<>();/** Optimistic lock is necessary to ensure database integrity when update@@ -64,11 +63,11 @@ public class Membership extends AbstractEntity {this.admin = admin;}- public Set<String> getJoinedTeams() {+ public LinkedHashSet<String> getJoinedTeams() {return joinedTeams;}- public void setJoinedTeams(Set<String> joinedTeams) {+ public void setJoinedTeams(LinkedHashSet<String> joinedTeams) {this.joinedTeams = joinedTeams;}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/IntegrationPolicy.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/IntegrationPolicy.javaindex 81c7977aa6..95f5f8e205 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/IntegrationPolicy.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/IntegrationPolicy.java@@ -116,9 +116,9 @@ public class IntegrationPolicy implements Serializable {return fullBranchMatchContext.getText();}- public boolean onBranchDelete(Depot depotDefiningPolicy, Depot depotContainingRef, String branch) {+ public boolean onBranchDelete(Depot depotDefiningPolicy, Depot depotContainingBranch, String branch) {StringBuilder builder = new StringBuilder();- if (depotDefiningPolicy.equals(depotContainingRef)) {+ if (depotDefiningPolicy.equals(depotContainingBranch)) {for (IncludeExcludeParser.CriteriaContext criteriaContext: IncludeExcludeUtils.parse(targetBranchMatch).criteria()) {if (criteriaContext.includeMatch() != null) {String value = IncludeExcludeUtils.getValue(criteriaContext.includeMatch().Value());@@ -138,12 +138,12 @@ public class IntegrationPolicy implements Serializable {builder = new StringBuilder();for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {if (criteriaContext.includeMatch() != null) {- String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingRef,+ String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingBranch,branch, criteriaContext.includeMatch().fullBranchMatch());if (deleted != null)builder.append(String.format("include(%s) ", deleted));} else {- String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingRef,+ String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingBranch,branch, criteriaContext.excludeMatch().fullBranchMatch());if (deleted != null)builder.append(String.format("exclude(%s) ", deleted));diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.javaindex 0c70a45d0c..471f8156ec 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java@@ -13,7 +13,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;@Editable(name="And Composition", icon="fa-object-group", order=100,category=GateKeeper.CATEGORY_COMPOSITION,- description="This gate keeper will be passed if all contained gate keepers are passed.")+ description="This gate keeper will be passed if all contained gate keepers are passed")@Horizontalpublic class AndGateKeeper extends AndOrGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.javaindex 44cfb47856..e78153129f 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java@@ -19,7 +19,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGORY_USER, description="This gate keeper will be passed if the commit is approved by specified number of users "- + "from specified team.")+ + "from specified team")public class IfApprovedBySpecifiedTeam extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.javaindex 6daf676259..671c313dfe 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.manager.AccountManager;@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGORY_USER, description=- "This gate keeper will be passed if the commit is approved by specified user.")+ "This gate keeper will be passed if the commit is approved by specified user")public class IfApprovedBySpecifiedUser extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.javaindex 2031738eb2..6dc25e8d2a 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfChangeSpecifiedRefs.java@@ -15,7 +15,7 @@ import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@Editable(order=100, icon="fa-code-fork", description=- "This gate keeper will be passed if specified refs is being changed.")+ "This gate keeper will be passed if specified refs is being changed")public class IfChangeSpecifiedRefs extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedTeam.javanew file mode 100644index 0000000000..8a7ce506ce--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedTeam.java@@ -0,0 +1,107 @@+package com.pmease.gitplex.core.gatekeeper;++import java.util.ArrayList;+import java.util.Collection;++import javax.validation.constraints.Min;++import org.eclipse.jgit.lib.ObjectId;+import org.hibernate.validator.constraints.NotEmpty;++import com.google.common.collect.Lists;+import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.gitplex.core.entity.Account;+import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.Membership;+import com.pmease.gitplex.core.entity.PullRequest;+import com.pmease.gitplex.core.entity.Review;+import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;++@Editable(order=300, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=+ "This gate keeper will be passed if the commit gets specified number "+ + "of disapprovals from specified team. It normally works together "+ + "with a NOT container to reject the pull request in case there are "+ + "disapprovals")+public class IfDisapprovedBySpecifiedTeam extends AbstractGateKeeper {++ private static final long serialVersionUID = 1L;++ private String teamName;++ private int leastDisapprovals = 1;++ @Editable(name="Team", order=100)+ @NotEmpty+ public String getTeamName() {+ return teamName;+ }++ public void setTeamName(String teamName) {+ this.teamName = teamName;+ }++ @Editable(name="Least Disapprovals Required", order=200)+ @Min(value = 1, message = "Least disapprovals should not be less than 1")+ public int getLeastDisapprovals() {+ return leastDisapprovals;+ }++ public void setLeastDisapprovals(int leastDisapprovals) {+ this.leastDisapprovals = leastDisapprovals;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ int disapprovals = 0;++ Collection<Account> members = new ArrayList<>();+ for (Membership membership: request.getTargetDepot().getOwner().getUserMemberships()) {+ if (membership.getJoinedTeams().contains(teamName))+ members.add(membership.getUser());+ }++ for (Account member : members) {+ Review.Result result = member.checkReviewSince(request.getReferentialUpdate());+ if (result == Review.Result.DISAPPROVE) {+ disapprovals++;+ }+ }++ if (disapprovals >= getLeastDisapprovals()) {+ return passed(Lists.newArrayList("Disapproved by at least " + getLeastDisapprovals()+ + " member(s) of team " + teamName));+ } else {+ return failed(Lists.newArrayList("Not disapproved by at least " + getLeastDisapprovals()+ + " member(s) of team " + teamName));+ }+ }++ @Override+ protected CheckResult doCheckFile(Account user, Depot depot, String branch, String file) {+ return failed(Lists.newArrayList("Not disapproved by anyone from team " + teamName));+ }++ @Override+ protected CheckResult doCheckPush(Account user, Depot depot, String refName, ObjectId oldCommit,+ ObjectId newCommit) {+ return failed(Lists.newArrayList("Not disapproved by anyone from team " + teamName));+ }++ @Override+ public void onTeamRename(String oldName, String newName) {+ if (teamName.equals(oldName))+ teamName = newName;+ }++ @Override+ public boolean onTeamDelete(String teamName) {+ return this.teamName.equals(teamName);+ }++ @Override+ public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,+ Account originalOwner) {+ return depotDefiningGateKeeper.equals(transferredDepot);+ }++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedUser.javanew file mode 100644index 0000000000..8f9c388fa0--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfDisapprovedBySpecifiedUser.java@@ -0,0 +1,73 @@+package com.pmease.gitplex.core.gatekeeper;++import org.eclipse.jgit.lib.ObjectId;+import org.hibernate.validator.constraints.NotEmpty;++import com.google.common.base.Preconditions;+import com.google.common.collect.Lists;+import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.annotation.UserChoice;+import com.pmease.gitplex.core.entity.Account;+import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.PullRequest;+import com.pmease.gitplex.core.entity.Review;+import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;+import com.pmease.gitplex.core.manager.AccountManager;++@Editable(order=300, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=+ "This gate keeper will be passed if the commit is disapproved by specified user. "+ + "It normally works together with a NOT container to reject the pull request "+ + "in case the user disapproved it")+public class IfDisapprovedBySpecifiedUser extends AbstractGateKeeper {++ private static final long serialVersionUID = 1L;++ private String userName;++ @Editable(name="Select User Below")+ @UserChoice+ @NotEmpty+ public String getUserName() {+ return userName;+ }++ public void setUserName(String userName) {+ this.userName = userName;+ }++ @Override+ protected CheckResult doCheckRequest(PullRequest request) {+ Account user = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class)+ .findByName(userName));+ Review.Result result = user.checkReviewSince(request.getReferentialUpdate());+ if (result == Review.Result.DISAPPROVE) {+ return passed(Lists.newArrayList("Disapproved by " + userName));+ } else {+ return failed(Lists.newArrayList("Not disapproved by " + userName));+ }+ }++ @Override+ protected CheckResult doCheckFile(Account user, Depot depot, String branch, String file) {+ return failed(Lists.newArrayList("Not disapproved by " + userName));+ }++ @Override+ protected CheckResult doCheckPush(Account user, Depot depot, String refName, ObjectId oldCommit,+ ObjectId newCommit) {+ return failed(Lists.newArrayList("Not disapproved by " + userName));+ }++ @Override+ public void onAccountRename(String oldName, String newName) {+ if (userName.equals(oldName))+ userName = newName;+ }++ @Override+ public boolean onAccountDelete(String accountName) {+ return userName.equals(accountName);+ }++}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPerformSpecifiedOperations.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPerformSpecifiedOperations.javaindex 0c7c3d3195..3da5f53371 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPerformSpecifiedOperations.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPerformSpecifiedOperations.java@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.entity.Account;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@Editable(order=200, icon="fa-wrench", description=- "This gate keeper will be passed if one of specified operations is performed.")+ "This gate keeper will be passed if one of specified operations is performed")@ClassValidatingpublic class IfPerformSpecifiedOperations extends AbstractGateKeeper implements Validatable {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.javaindex c9b6d10812..361633c6f7 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@Editable(order=2000, icon="fa-ext fa-repo-lock", description="This gate keeper will be passed if the push "+ "operation does not rewrite history of target branch. Rewriting history of public branches "+ "is dangerous, and it happens when user forces a push without merging/rebasing with the "- + "branch head.")+ + "branch head")public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.javaindex e904be2738..2e76c41103 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@Editable(order=3000, icon="fa-ext fa-file-diff", description="This gate keeper will be passed if the pull request "+ "is submitted with gerrit style patch, that is, only one commit is submitted for review at "- + "a time, and subsequent updates to the review should be done by amending previous commit.")+ + "a time, and subsequent updates to the review should be done by amending previous commit")public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.javaindex ead4f4b673..fd92437361 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@Editable(order=500, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=- "This gate keeper will be passed if the commit is submitted by a member of specified team.")+ "This gate keeper will be passed if the commit is submitted by a member of specified team")public class IfSubmittedBySpecifiedTeam extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.javaindex 28c995f050..daa27e0ddc 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java@@ -15,7 +15,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.manager.AccountManager;@Editable(order=600, icon="fa-user", category=GateKeeper.CATEGORY_USER, description=- "This gate keeper will be passed if the commit is submitted by specified user.")+ "This gate keeper will be passed if the commit is submitted by specified user")public class IfSubmittedBySpecifiedUser extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.javaindex 196f83cd29..7bb7ef5656 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java@@ -15,7 +15,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;@Editable(name="If...Then... Composition", order=300, icon="fa-object-group",category=GateKeeper.CATEGORY_COMPOSITION,- description="If first gate keeper is passed, then go ahead to check second gate keeper;")+ description="If first gate keeper is passed, then go ahead to check second gate keeper")@Horizontalpublic class IfThenGateKeeper extends CompositeGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.javaindex df3c63ed82..4b96ac569c 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFiles.java@@ -14,7 +14,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;@Editable(order=300, icon="fa-file-text", description=- "This gate keeper will be passed if specified files are modified.")+ "This gate keeper will be passed if specified files are modified")public class IfTouchSpecifiedFiles extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.javaindex 8733551183..7f2c448a0c 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java@@ -20,7 +20,7 @@ import com.pmease.gitplex.core.manager.VerificationManager;@Editable(icon="fa-check-circle", order=1000,description="This gate keeper will be satisfied if commit is verified successfully "+ "by specified number of builds. To make this working, your CI system has to "- + "be configured to build against GitPlex pull requests.")+ + "be configured to build against GitPlex pull requests")public class IfVerifiedByBuilds extends AbstractGateKeeper {private static final long serialVersionUID = 1L;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.javaindex eaa5ddfd96..b9180c076b 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;@Editable(name="Not Composition", order=400, icon="fa-object-group", category=GateKeeper.CATEGORY_COMPOSITION,- description="This gate keeper will be passed if contained gate keeper is not passed.")+ description="This gate keeper will be passed if contained gate keeper is not passed")@Horizontalpublic class NotGateKeeper extends CompositeGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.javaindex 5c26789765..8497964f98 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;@Editable(name="Or Composition", order=200, icon="fa-object-group", category=GateKeeper.CATEGORY_COMPOSITION,- description="This gate keeper will be passed if any of the contained gate keepers is passed.")+ description="This gate keeper will be passed if any of the contained gate keepers is passed")@Horizontalpublic class OrGateKeeper extends AndOrGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDataManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDataManager.javaindex bed814cb06..891787b569 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDataManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDataManager.java@@ -55,7 +55,7 @@ public class DefaultDataManager implements DataManager, Serializable {rootUser = new Account();rootUser.setId(Account.ROOT_ID);manualConfigs.add(new ManualConfig("Create Administator Account", rootUser,- Sets.newHashSet("description", "admin")) {+ Sets.newHashSet("description", "admin", "defaultPrivilege")) {@Overridepublic Skippable getSkippable() {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDepotManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDepotManager.javaindex a75e16fa41..176cc477e5 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDepotManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultDepotManager.java@@ -97,7 +97,7 @@ public class DefaultDepotManager extends AbstractEntityDao<Depot> implements Dep@Transactional@Overridepublic void save(Depot depot, Long oldOwnerId, String oldName) {- Preconditions.checkArgument(oldOwnerId!=null && oldName!=null,+ Preconditions.checkArgument(oldOwnerId==null || oldName==null,"Can not rename and transfer depot in the same time");boolean isNew = depot.isNew();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultTeamManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultTeamManager.javaindex b740073af2..56bad3849e 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultTeamManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultTeamManager.java@@ -4,7 +4,6 @@ import java.util.Iterator;import java.util.LinkedHashMap;import java.util.LinkedHashSet;import java.util.Map;-import java.util.Set;import javax.inject.Singleton;@@ -50,7 +49,7 @@ public class DefaultTeamManager implements TeamManager, DepotListener {throw new RuntimeException("Team with name '" + newTeamName + "' already exists");}- Map<String, Team> teams = new LinkedHashMap<>();+ LinkedHashMap<String, Team> teams = new LinkedHashMap<>();for (Map.Entry<String, Team> entry: organization.getTeams().entrySet()) {if (entry.getKey().equals(oldTeamName)) {Team team = entry.getValue();@@ -63,7 +62,7 @@ public class DefaultTeamManager implements TeamManager, DepotListener {organization.setTeams(teams);for (Membership membership: organization.getUserMemberships()) {- Set<String> joinedTeams = new LinkedHashSet<>();+ LinkedHashSet<String> joinedTeams = new LinkedHashSet<>();for (String teamName: membership.getJoinedTeams()) {if (teamName.equals(oldTeamName))joinedTeams.add(newTeamName);diff --git a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.javaindex 4a8033f905..c08504e649 100644--- a/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java+++ b/gitplex.search/src/main/java/com/pmease/gitplex/search/query/TextQuery.java@@ -1,197 +1,201 @@-package com.pmease.gitplex.search.query;--import static com.pmease.gitplex.search.FieldConstants.BLOB_NAME;-import static com.pmease.gitplex.search.FieldConstants.BLOB_TEXT;-import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;--import java.io.IOException;-import java.util.List;-import java.util.regex.Matcher;-import java.util.regex.Pattern;--import javax.annotation.Nullable;--import org.apache.commons.lang3.CharUtils;-import org.apache.lucene.index.Term;-import org.apache.lucene.search.BooleanClause.Occur;-import org.apache.lucene.search.BooleanQuery;-import org.apache.lucene.search.Query;-import org.apache.lucene.search.WildcardQuery;-import org.eclipse.jgit.lib.ObjectLoader;-import org.eclipse.jgit.treewalk.TreeWalk;--import com.google.common.base.CharMatcher;-import com.google.common.base.Splitter;-import com.pmease.commons.lang.extractors.TokenPosition;-import com.pmease.commons.util.ContentDetector;-import com.pmease.commons.util.Range;-import com.pmease.gitplex.search.IndexConstants;-import com.pmease.gitplex.search.hit.QueryHit;-import com.pmease.gitplex.search.hit.TextHit;-import com.pmease.gitplex.search.query.regex.RegexLiterals;--public class TextQuery extends BlobQuery {-- private static int MAX_LINE_LEN = 1024;-- private final String term;-- private final boolean regex;-- private final boolean caseSensitive;-- private final boolean wholeWord;-- private final String directory;-- private final String fileNames;-- private transient Pattern pattern;-- public TextQuery(String term, boolean regex, boolean caseSensitive, boolean wordMatch,- @Nullable String directory, @Nullable String fileNames, int count) {- super(count);-- this.term = term;- this.regex = regex;- this.caseSensitive = caseSensitive;- this.wholeWord = wordMatch;- this.directory = directory;- this.fileNames = fileNames;- }-- @Nullable- private Pattern getPattern() {- if (regex) {- if (pattern == null) {- String expression = term;- if (wholeWord) {- if (!expression.startsWith("\\b"))- expression = "\\b" + expression;- if (!expression.endsWith("\\b"))- expression = expression + "\\b";- }- if (caseSensitive)- pattern = Pattern.compile(expression);- else- pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);- }- return pattern;- } else {- return null;- }- }-- @Override- public void collect(TreeWalk treeWalk, List<QueryHit> hits) {- ObjectLoader objectLoader;- try {- objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));- if (objectLoader.getSize() <= IndexConstants.MAX_INDEXABLE_SIZE) {- String blobPath = treeWalk.getPathString();- String content = ContentDetector.convertToText(objectLoader.getCachedBytes(), blobPath);- if (content != null) {- Pattern pattern = getPattern();- if (pattern != null) {- int lineNo = 0;- for (String line: Splitter.on(CharMatcher.anyOf("\n\r")).split(content)) {- if (line.length() <= MAX_LINE_LEN) {- Matcher matcher = pattern.matcher(line);- while (matcher.find()) {- Range range = new Range(matcher.start(), matcher.end());- hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));- if (hits.size() >= getCount())- break;- }- if (hits.size() >= getCount())- break;- }- lineNo++;- }- } else {- String normalizedTerm;- if (!caseSensitive)- normalizedTerm = term.toLowerCase();- else- normalizedTerm = term;-- int lineNo = 0;- for (String line: Splitter.on("\n").split(content)) {- String normalizedLine;- if (!caseSensitive)- normalizedLine = line.toLowerCase();- else- normalizedLine = line;-- int start = normalizedLine.indexOf(normalizedTerm, 0);- while (start != -1) {- int end = start + normalizedTerm.length();- if (wholeWord) {- char beforeChar;- if (start == 0)- beforeChar = ' ';- else- beforeChar = line.charAt(start-1);-- char afterChar;- if (end == line.length())- afterChar = ' ';- else- afterChar = line.charAt(end);-- if (!isWordChar(beforeChar) && !isWordChar(afterChar)) {- Range range = new Range(start, end);- hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));- if (hits.size() >= getCount())- break;- }- } else {- Range range = new Range(start, end);- hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));- if (hits.size() >= getCount())- break;- }- start = normalizedLine.indexOf(normalizedTerm, end);- }- if (hits.size() >= getCount())- break;- lineNo++;- }- }- }- }- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- private boolean isWordChar(char ch) {- return CharUtils.isAsciiAlphanumeric(ch) || ch == '_';- }-- @Override- public Query asLuceneQuery() throws TooGeneralQueryException {- BooleanQuery query = new BooleanQuery(true);-- if (directory != null)- applyDirectory(query, directory);-- if (fileNames != null) {- BooleanQuery subQuery = new BooleanQuery(true);- for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))- subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);- if (subQuery.getClauses().length != 0)- query.add(subQuery, Occur.MUST);- }-- if (regex)- query.add(new RegexLiterals(term).asNGramQuery(BLOB_TEXT.name(), NGRAM_SIZE), Occur.MUST);- else if (term.length() >= NGRAM_SIZE)- query.add(new NGramLuceneQuery(BLOB_TEXT.name(), term, NGRAM_SIZE), Occur.MUST);- else- throw new TooGeneralQueryException();-- return query;- }--}+package com.pmease.gitplex.search.query;++import static com.pmease.gitplex.search.FieldConstants.BLOB_NAME;+import static com.pmease.gitplex.search.FieldConstants.BLOB_TEXT;+import static com.pmease.gitplex.search.IndexConstants.NGRAM_SIZE;++import java.io.IOException;+import java.util.List;+import java.util.regex.Matcher;+import java.util.regex.Pattern;++import javax.annotation.Nullable;++import org.apache.commons.lang3.CharUtils;+import org.apache.lucene.index.Term;+import org.apache.lucene.search.BooleanClause.Occur;+import org.apache.lucene.search.BooleanQuery;+import org.apache.lucene.search.Query;+import org.apache.lucene.search.WildcardQuery;+import org.eclipse.jgit.lib.ObjectLoader;+import org.eclipse.jgit.treewalk.TreeWalk;++import com.google.common.base.CharMatcher;+import com.google.common.base.Splitter;+import com.pmease.commons.lang.extractors.TokenPosition;+import com.pmease.commons.util.ContentDetector;+import com.pmease.commons.util.Range;+import com.pmease.gitplex.search.IndexConstants;+import com.pmease.gitplex.search.hit.QueryHit;+import com.pmease.gitplex.search.hit.TextHit;+import com.pmease.gitplex.search.query.regex.RegexLiterals;++public class TextQuery extends BlobQuery {++ private static int MAX_LINE_LEN = 1024;++ private static CharMatcher EOL_MATCHER = CharMatcher.anyOf("\r\n");++ private final String term;++ private final boolean regex;++ private final boolean caseSensitive;++ private final boolean wholeWord;++ private final String directory;++ private final String fileNames;++ private transient Pattern pattern;++ public TextQuery(String term, boolean regex, boolean caseSensitive, boolean wordMatch,+ @Nullable String directory, @Nullable String fileNames, int count) {+ super(count);++ this.term = term;+ this.regex = regex;+ this.caseSensitive = caseSensitive;+ this.wholeWord = wordMatch;+ this.directory = directory;+ this.fileNames = fileNames;+ }++ @Nullable+ private Pattern getPattern() {+ if (regex) {+ if (pattern == null) {+ String expression = term;+ if (wholeWord) {+ if (!expression.startsWith("\\b"))+ expression = "\\b" + expression;+ if (!expression.endsWith("\\b"))+ expression = expression + "\\b";+ }+ if (caseSensitive)+ pattern = Pattern.compile(expression);+ else+ pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);+ }+ return pattern;+ } else {+ return null;+ }+ }++ @Override+ public void collect(TreeWalk treeWalk, List<QueryHit> hits) {+ ObjectLoader objectLoader;+ try {+ objectLoader = treeWalk.getObjectReader().open(treeWalk.getObjectId(0));+ if (objectLoader.getSize() <= IndexConstants.MAX_INDEXABLE_SIZE) {+ String blobPath = treeWalk.getPathString();+ String content = ContentDetector.convertToText(objectLoader.getCachedBytes(), blobPath);+ if (content != null) {+ Pattern pattern = getPattern();+ if (pattern != null) {+ int lineNo = 0;+ for (String line: Splitter.on(EOL_MATCHER).split(content)) {+ if (line.length() <= MAX_LINE_LEN) {+ Matcher matcher = pattern.matcher(line);+ while (matcher.find()) {+ Range range = new Range(matcher.start(), matcher.end());+ hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));+ if (hits.size() >= getCount())+ break;+ }+ if (hits.size() >= getCount())+ break;+ }+ lineNo++;+ }+ } else {+ String normalizedTerm;+ if (!caseSensitive)+ normalizedTerm = term.toLowerCase();+ else+ normalizedTerm = term;++ int lineNo = 0;+ for (String line: Splitter.on(EOL_MATCHER).split(content)) {+ if (line.length() <= MAX_LINE_LEN) {+ String normalizedLine;+ if (!caseSensitive)+ normalizedLine = line.toLowerCase();+ else+ normalizedLine = line;++ int start = normalizedLine.indexOf(normalizedTerm, 0);+ while (start != -1) {+ int end = start + normalizedTerm.length();+ if (wholeWord) {+ char beforeChar;+ if (start == 0)+ beforeChar = ' ';+ else+ beforeChar = line.charAt(start-1);++ char afterChar;+ if (end == line.length())+ afterChar = ' ';+ else+ afterChar = line.charAt(end);++ if (!isWordChar(beforeChar) && !isWordChar(afterChar)) {+ Range range = new Range(start, end);+ hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));+ if (hits.size() >= getCount())+ break;+ }+ } else {+ Range range = new Range(start, end);+ hits.add(new TextHit(blobPath, line, new TokenPosition(lineNo, range)));+ if (hits.size() >= getCount())+ break;+ }+ start = normalizedLine.indexOf(normalizedTerm, end);+ }+ if (hits.size() >= getCount())+ break;+ }+ lineNo++;+ }+ }+ }+ }+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }++ private boolean isWordChar(char ch) {+ return CharUtils.isAsciiAlphanumeric(ch) || ch == '_';+ }++ @Override+ public Query asLuceneQuery() throws TooGeneralQueryException {+ BooleanQuery query = new BooleanQuery(true);++ if (directory != null)+ applyDirectory(query, directory);++ if (fileNames != null) {+ BooleanQuery subQuery = new BooleanQuery(true);+ for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))+ subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);+ if (subQuery.getClauses().length != 0)+ query.add(subQuery, Occur.MUST);+ }++ if (regex)+ query.add(new RegexLiterals(term).asNGramQuery(BLOB_TEXT.name(), NGRAM_SIZE), Occur.MUST);+ else if (term.length() >= NGRAM_SIZE)+ query.add(new NGramLuceneQuery(BLOB_TEXT.name(), term, NGRAM_SIZE), Occur.MUST);+ else+ throw new TooGeneralQueryException();++ return query;+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/setting/ProfileEditPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/setting/ProfileEditPage.javaindex 24e5b851e1..675921abd7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/setting/ProfileEditPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/account/setting/ProfileEditPage.java@@ -53,7 +53,7 @@ public class ProfileEditPage extends AccountSettingPage {editor.getBeanDescriptor().copyProperties(object, getAccount());}- }, Sets.newHashSet("password"));+ }, Sets.newHashSet("admin", "description", "defaultPrivilege", "password"));Form<?> form = new Form<Void>("form") {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/security/RegisterPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/security/RegisterPage.javaindex 2527c444e3..683417337d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/security/RegisterPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/security/RegisterPage.java@@ -20,6 +20,8 @@ import com.pmease.gitplex.web.page.account.setting.AvatarEditPage;import com.pmease.gitplex.web.page.base.BasePage;import com.pmease.gitplex.web.page.home.DashboardPage;+import jersey.repackaged.com.google.common.collect.Sets;+@SuppressWarnings("serial")public class RegisterPage extends BasePage {@@ -33,7 +35,8 @@ public class RegisterPage extends BasePage {super.onInitialize();final Account account = new Account();- final BeanEditor<?> editor = BeanContext.editBean("editor", account);+ final BeanEditor<?> editor = BeanContext.editBean("editor", account,+ Sets.newHashSet("admin", "description", "defaultPrivilege"));Form<?> form = new Form<Void>("form") {