Skip to content

The Unified and Autonomous Development Platform

midwork

robin shine373e96dc2567
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js
index 8ac0d8df09..274518e4ea 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js
@@ -1,6 +1,6 @@
(function ( $ ) {
- var pageMargin = 8;
+ var pageMargin = 30;
var scrollbarWidth = 20;
var textHeight = 25;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
index e4a9ec1fbc..0bc982c08a 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/CoreModule.java
@@ -172,6 +172,7 @@ public class CoreModule extends AbstractPluginModule {
contribute(DepotListener.class, DefaultAuxiliaryManager.class);
contribute(RefListener.class, DefaultPullRequestManager.class);
contribute(RefListener.class, DefaultAuxiliaryManager.class);
+ contribute(RefListener.class, DefaultDepotManager.class);
contribute(PullRequestListener.class, DefaultNotificationManager.class);
contribute(PullRequestListener.class, DefaultPullRequestWatchManager.class);
contribute(LifecycleListener.class, DefaultPullRequestManager.class);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
index 3e7e34359f..e27b899988 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/Depot.java
@@ -114,6 +114,8 @@ public class Depot extends AbstractEntity implements UserBelonging {
public static final String FQN_SEPARATOR = "/";
+ public static final String REF_FQN_SEPARATOR = ":";
+
public static final String REFS_GITPLEX = "refs/gitplex/";
private static final int LAST_COMMITS_CACHE_THRESHOLD = 1000;
@@ -980,10 +982,6 @@ public class Depot extends AbstractEntity implements UserBelonging {
return submodules;
}
- public String getRevisionFQN(String revision) {
- return getFQN() + ":" + revision;
- }
-
public void deleteBranch(String branch) {
String refName = GitUtils.branch2ref(branch);
git().deleteRef(refName);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
index 4aff593f05..5ca57c7aca 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
@@ -1,8 +1,6 @@
package com.pmease.gitplex.core.entity.component;
import java.io.Serializable;
-import java.util.Collection;
-import java.util.Iterator;
import javax.annotation.Nullable;
@@ -105,16 +103,7 @@ public class DepotAndRevision implements Serializable {
}
public String getFQN() {
- return getDepot().getRevisionFQN(revision);
- }
-
- public static void trim(Collection<String> depotAndBranches) {
- Dao dao = GitPlex.getInstance(Dao.class);
- for (Iterator<String> it = depotAndBranches.iterator(); it.hasNext();) {
- DepotAndRevision depotAndRevision = new DepotAndRevision(it.next());
- if (dao.get(Depot.class, depotAndRevision.getDepotId()) == null)
- it.remove();
- }
+ return getDepot().getFQN() + SEPARATOR + revision;
}
public boolean isDefault() {
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.java
index c37f21d66e..35fa72ca06 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
@@ -17,6 +17,8 @@ import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.User;
import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.util.fullbranchmatch.FullBranchMatchUtils;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
import com.pmease.gitplex.core.util.fullbranchmatch.FullBranchMatchParser.CriteriaContext;
import com.pmease.gitplex.core.util.fullbranchmatch.FullBranchMatchParser.FullBranchMatchContext;
@@ -94,7 +96,7 @@ public class IntegrationPolicy implements Serializable {
if (deleted != null)
builder.append(String.format("include(%s) ", deleted));
} else {
- String deleted = deleteUser(user, criteriaContext.includeMatch().fullBranchMatch());
+ String deleted = deleteUser(user, criteriaContext.excludeMatch().fullBranchMatch());
if (deleted != null)
builder.append(String.format("exclude(%s) ", deleted));
}
@@ -113,6 +115,56 @@ public class IntegrationPolicy implements Serializable {
}
return fullBranchMatchContext.getText();
}
+
+ public boolean onBranchDelete(Depot depotDefiningPolicy, Depot depotContainingRef, String branch) {
+ StringBuilder builder = new StringBuilder();
+ if (depotDefiningPolicy.equals(depotContainingRef)) {
+ for (IncludeExcludeParser.CriteriaContext criteriaContext: IncludeExcludeUtils.parse(targetBranchMatch).criteria()) {
+ if (criteriaContext.includeMatch() != null) {
+ String value = IncludeExcludeUtils.getValue(criteriaContext.includeMatch().Value());
+ if (!value.equals(branch))
+ builder.append(String.format("include(%s) ", value));
+ } else {
+ String value = IncludeExcludeUtils.getValue(criteriaContext.excludeMatch().Value());
+ if (!value.equals(branch))
+ builder.append(String.format("exclude(%s) ", value));
+ }
+ }
+ targetBranchMatch = builder.toString().trim();
+ if (targetBranchMatch.length() == 0)
+ return true;
+ }
+
+ builder = new StringBuilder();
+ for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
+ if (criteriaContext.includeMatch() != null) {
+ String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingRef,
+ branch, criteriaContext.includeMatch().fullBranchMatch());
+ if (deleted != null)
+ builder.append(String.format("include(%s) ", deleted));
+ } else {
+ String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingRef,
+ branch, criteriaContext.excludeMatch().fullBranchMatch());
+ if (deleted != null)
+ builder.append(String.format("exclude(%s) ", deleted));
+ }
+ }
+ sourceBranchMatch = builder.toString().trim();
+
+ return sourceBranchMatch.length() == 0;
+ }
+
+ private String deleteSourceBranch(Depot depotDefiningPolicy, Depot depotContainingBranch,
+ String branch, FullBranchMatchContext fullBranchMatchContext) {
+ DepotAndRevision depotAndRevision = new DepotAndRevision(depotContainingBranch, branch);
+ String fullBranchMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.getText());
+ if (fullBranchMatch.equals(depotAndRevision.getFQN())
+ || depotContainingBranch.equals(depotDefiningPolicy) && branch.equals(fullBranchMatch)) {
+ return null;
+ } else {
+ return fullBranchMatchContext.getText();
+ }
+ }
public boolean onDepotDelete(Depot depot) {
StringBuilder builder = new StringBuilder();
@@ -122,7 +174,7 @@ public class IntegrationPolicy implements Serializable {
if (deleted != null)
builder.append(String.format("include(%s) ", deleted));
} else {
- String deleted = deleteDepot(depot, criteriaContext.includeMatch().fullBranchMatch());
+ String deleted = deleteDepot(depot, criteriaContext.excludeMatch().fullBranchMatch());
if (deleted != null)
builder.append(String.format("exclude(%s) ", deleted));
}
@@ -150,7 +202,7 @@ public class IntegrationPolicy implements Serializable {
builder.append(String.format("include(%s) ", updated));
} else {
String updated = updateDepotName(depotOwner, oldName, newName,
- criteriaContext.includeMatch().fullBranchMatch());
+ criteriaContext.excludeMatch().fullBranchMatch());
builder.append(String.format("exclude(%s) ", updated));
}
}
@@ -181,7 +233,7 @@ public class IntegrationPolicy implements Serializable {
builder.append(String.format("include(%s) ", updated));
} else {
String updated = updateUserName(oldName, newName,
- criteriaContext.includeMatch().fullBranchMatch());
+ criteriaContext.excludeMatch().fullBranchMatch());
builder.append(String.format("exclude(%s) ", updated));
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
index 8c06a0af43..76ab237b9c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java
@@ -140,5 +140,10 @@ public abstract class AbstractGateKeeper implements GateKeeper {
public boolean onTeamDelete(Team team) {
return false;
}
+
+ @Override
+ public boolean onRefDelete(String refName) {
+ return false;
+ }
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndOrGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndOrGateKeeper.java
index 06c78dd785..0ae1180db3 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndOrGateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndOrGateKeeper.java
@@ -71,5 +71,14 @@ public abstract class AndOrGateKeeper extends CompositeGateKeeper {
}
return gateKeepers.isEmpty();
}
+
+ @Override
+ public boolean onRefDelete(String refName) {
+ for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
+ if (it.next().onRefDelete(refName))
+ it.remove();
+ }
+ return gateKeepers.isEmpty();
+ }
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
index 61ecef1391..b539ec11ba 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java
@@ -73,5 +73,7 @@ public interface GateKeeper extends Serializable {
boolean onUserDelete(User user);
+ boolean onRefDelete(String refName);
+
boolean isEnabled();
}
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.java
index 56a905743c..0a7061a57b 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
@@ -11,6 +11,7 @@ import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.User;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeParser;
import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
@Editable(order=100, icon="fa-code-fork", description=
@@ -55,4 +56,22 @@ public class IfChangeSpecifiedRefs extends AbstractGateKeeper {
return doCheck(refName);
}
+ @Override
+ public boolean onRefDelete(String refName) {
+ StringBuilder builder = new StringBuilder();
+ for (IncludeExcludeParser.CriteriaContext criteriaContext: IncludeExcludeUtils.parse(refMatch).criteria()) {
+ if (criteriaContext.includeMatch() != null) {
+ String value = IncludeExcludeUtils.getValue(criteriaContext.includeMatch().Value());
+ if (!value.equals(refName))
+ builder.append(String.format("include(%s) ", value));
+ } else {
+ String value = IncludeExcludeUtils.getValue(criteriaContext.excludeMatch().Value());
+ if (!value.equals(refName))
+ builder.append(String.format("exclude(%s) ", value));
+ }
+ }
+ refMatch = builder.toString().trim();
+ return refMatch.length() == 0;
+ }
+
}
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.java
index 2f5aaf35c7..86047f0301 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
@@ -6,6 +6,7 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.Horizontal;
import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.Team;
import com.pmease.gitplex.core.entity.User;
import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
@@ -87,4 +88,20 @@ public class IfThenGateKeeper extends CompositeGateKeeper {
return ifGate.onDepotDelete(depot) || thenGate.onDepotDelete(depot);
}
+ @Override
+ public void onTeamRename(String oldName, String newName) {
+ ifGate.onTeamRename(oldName, newName);
+ thenGate.onTeamRename(oldName, newName);
+ }
+
+ @Override
+ public boolean onTeamDelete(Team team) {
+ return ifGate.onTeamDelete(team) || thenGate.onTeamDelete(team);
+ }
+
+ @Override
+ public boolean onRefDelete(String refName) {
+ return ifGate.onRefDelete(refName) || thenGate.onRefDelete(refName);
+ }
+
}
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.java
index a51c797d08..0f2789adca 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
@@ -6,6 +6,7 @@ import javax.validation.constraints.NotNull;
import com.pmease.commons.wicket.editable.annotation.Editable;
import com.pmease.commons.wicket.editable.annotation.Horizontal;
import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.Team;
import com.pmease.gitplex.core.entity.User;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
@@ -62,4 +63,19 @@ public class NotGateKeeper extends CompositeGateKeeper {
gateKeeper.onUserRename(oldName, newName);
}
+ @Override
+ public void onTeamRename(String oldName, String newName) {
+ gateKeeper.onTeamRename(oldName, newName);
+ }
+
+ @Override
+ public boolean onTeamDelete(Team team) {
+ return gateKeeper.onTeamDelete(team);
+ }
+
+ @Override
+ public boolean onRefDelete(String refName) {
+ return gateKeeper.onRefDelete(refName);
+ }
+
}
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.java
index a0feee4bef..db24b1379d 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
@@ -23,6 +23,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.pmease.commons.git.Git;
+import com.pmease.commons.git.GitUtils;
import com.pmease.commons.hibernate.Sessional;
import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.DefaultDao;
@@ -35,6 +36,7 @@ import com.pmease.gitplex.core.entity.User;
import com.pmease.gitplex.core.entity.component.IntegrationPolicy;
import com.pmease.gitplex.core.extensionpoint.DepotListener;
import com.pmease.gitplex.core.extensionpoint.LifecycleListener;
+import com.pmease.gitplex.core.extensionpoint.RefListener;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
import com.pmease.gitplex.core.manager.AuxiliaryManager;
import com.pmease.gitplex.core.manager.DepotManager;
@@ -43,7 +45,7 @@ import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.manager.UserManager;
@Singleton
-public class DefaultDepotManager extends DefaultDao implements DepotManager, LifecycleListener {
+public class DefaultDepotManager extends DefaultDao implements DepotManager, LifecycleListener, RefListener {
private static final Logger logger = LoggerFactory.getLogger(DefaultDepotManager.class);
@@ -329,4 +331,24 @@ public class DefaultDepotManager extends DefaultDao implements DepotManager, Lif
}
+ @Transactional
+ @Override
+ public void onRefUpdate(Depot depot, String refName, String newCommitHash) {
+ if (newCommitHash == null) {
+ for (Depot each: allOf(Depot.class)) {
+ String branch = GitUtils.ref2branch(refName);
+ if (branch != null) {
+ for (Iterator<IntegrationPolicy> it = each.getIntegrationPolicies().iterator(); it.hasNext();) {
+ if (it.next().onBranchDelete(each, depot, branch))
+ it.remove();
+ }
+ }
+ for (Iterator<GateKeeper> it = each.getGateKeepers().iterator(); it.hasNext();) {
+ if (it.next().onRefDelete(refName))
+ it.remove();
+ }
+ }
+ }
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatch.g4 b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatch.g4
index 2e46f1be0c..95007418b2 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatch.g4
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatch.g4
@@ -15,7 +15,7 @@ branchMatch: Value;
INCLUDE: 'include';
EXCLUDE: 'exclude';
-Value: (ESCAPE|~[:()\\])+;
+Value: (ESCAPE|~[:() \\])+;
fragment
ESCAPE: '\\'[:()\\];
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
index e7c36bdff3..813aecceee 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/fullbranchmatch/FullBranchMatchUtils.java
@@ -78,7 +78,7 @@ public class FullBranchMatchUtils {
}
} else if (criteriaContext.excludeMatch() != null) {
if (criteriaContext.excludeMatch().fullBranchMatch().fullDepotMatch() != null) {
- String fullDepotMatch = criteriaContext.includeMatch().fullBranchMatch().fullDepotMatch().getText();
+ String fullDepotMatch = criteriaContext.excludeMatch().fullBranchMatch().fullDepotMatch().getText();
if (fullDepotMatch.indexOf("/") == -1)
throw new ValidationException("Depot match '" + fullDepotMatch + "' should contain '/'");
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
index c160c4fb0e..790beaee70 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/util/includeexclude/IncludeExcludeUtils.java
@@ -26,7 +26,7 @@ public class IncludeExcludeUtils {
return parser.match();
}
- private static String getValue(TerminalNode terminal) {
+ public static String getValue(TerminalNode terminal) {
String value = terminal.getText().substring(1);
value = value.substring(0, value.length()-1).trim();
if (value.endsWith("/") && !value.endsWith("*")) {
@@ -34,7 +34,7 @@ public class IncludeExcludeUtils {
}
return value;
}
-
+
public static boolean matches(String match, String value) {
MatchContext matchContext = parse(match);
List<String> includes = new ArrayList<>();